diff --git a/crates/horizon-client/src/streaming.rs b/crates/horizon-client/src/streaming.rs index 4d9bac937..b77825b2f 100644 --- a/crates/horizon-client/src/streaming.rs +++ b/crates/horizon-client/src/streaming.rs @@ -10,6 +10,7 @@ use crate::{ world::World, }; use horizon_core::biome::BiomeZoom; +use horizon_world::block_render::FaceVisibility; use horizon_world::worldgen::decoration_order::DecorationOrder; use std::{ collections::{BinaryHeap, HashSet}, @@ -182,6 +183,10 @@ impl Streaming { .name(format!("horizon-worker-{i}")) .spawn(move || { let mut worker = generator.worker(); + // The face visibility table and its occlusion cache stay with + // the worker across mesh jobs, like vanilla's per-thread cache: + // cloning it per job copied every state and face shape. + let mut faces: Option<(Arc, FaceVisibility)> = None; loop { let job = { let mut queue = shared.queue.lock().unwrap(); @@ -210,6 +215,14 @@ impl Streaming { } Job::Mesh(x, sy, z, region, seq, settings) => { let context = shared.context.read().unwrap().clone(); + let visibility = match faces.take() { + Some((tables, visibility)) + if Arc::ptr_eq(&tables, &context.tables) => + { + visibility + } + _ => context.tables.visibility.clone(), + }; let mut mesher = Mesher { nether_shading: settings.nether, zoom: settings.zoom, @@ -219,9 +232,11 @@ impl Streaming { assets: &context.assets, tables: &context.tables, biomes: &context.biomes, - visibility: context.tables.visibility.clone(), + visibility, }; - Done::Meshed(x, sy, z, mesher.mesh(&borrow(®ion), sy), seq) + let mesh = mesher.mesh(&borrow(®ion), sy); + faces = Some((context.tables.clone(), mesher.visibility)); + Done::Meshed(x, sy, z, mesh, seq) } }; if send.send(done).is_err() {