Streaming: the last finished ring is lit against decorated neighbours
A chunk was lit only once all eight neighbours were finished, so the outermost finished ring of a loaded area (a /forceload square, a /pregen band's edge, a player's last ring) stayed unlit: saved as FULL with no light at all, and with no generation animals, which wait for light. Vanilla's LIGHT step needs its neighbours only at INITIALIZE_LIGHT (ChunkPyramid), so its last FULL ring is lit against decorated chunks. A light job now reads a neighbour that will not finish (past the area) from its decorated proto chunk (ChunkGenerator::light_view). A chunk saved unlit is saved again once lit, and one whose light changes when a neighbour finishes later is saved again. `execute if loaded` needs the chunk lit, as vanilla's needs it ENTITY_TICKING. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -807,10 +807,12 @@ impl Game<'_> {
|
||||
.coords(c, "pos")
|
||||
.map(|co| co.block(self.source_position(), self.source_rotation()));
|
||||
let dimension = self.command_source.map_or(self.dim, |s| s.dimension);
|
||||
return Ok(flag(
|
||||
dimension == self.dim
|
||||
&& p.is_some_and(|p| self.world.chunks.contains_key(&(p[0] >> 4, p[2] >> 4))),
|
||||
));
|
||||
// ExecuteCommand.isChunkLoaded: ENTITY_TICKING, which is past lit.
|
||||
let loaded = |p: [i32; 3]| {
|
||||
let key = (p[0] >> 4, p[2] >> 4);
|
||||
self.world.chunks.contains_key(&key) && self.streaming.is_lit(key.0, key.1)
|
||||
};
|
||||
return Ok(flag(dimension == self.dim && p.is_some_and(loaded)));
|
||||
}
|
||||
if c.has("dimension") {
|
||||
let dimension = self.command_source.map_or(self.dim, |s| s.dimension);
|
||||
|
||||
@@ -3841,6 +3841,9 @@ impl<G: ChunkGenerator> ChunkGenerator for Persistent<G> {
|
||||
fn is_decorated(&self, proto: &crate::streaming::Proto) -> bool {
|
||||
self.inner.is_decorated(proto)
|
||||
}
|
||||
fn light_view(&self, proto: &crate::streaming::Proto) -> Option<Chunk> {
|
||||
self.inner.light_view(proto)
|
||||
}
|
||||
fn save_protos(&self, protos: &[&crate::streaming::Proto]) {
|
||||
self.save
|
||||
.tables
|
||||
|
||||
@@ -70,6 +70,11 @@ pub trait ChunkGenerator: Send + Sync + 'static {
|
||||
false
|
||||
}
|
||||
/// What to save of a proto chunk dropped before it became final.
|
||||
/// A decorated proto chunk's blocks as a column, to light a finished
|
||||
/// neighbour against (vanilla lights with neighbours at FEATURES).
|
||||
fn light_view(&self, _proto: &Proto) -> Option<Chunk> {
|
||||
None
|
||||
}
|
||||
fn saved_proto(&self, _proto: &Proto) -> Option<crate::save::SavedProto> {
|
||||
None
|
||||
}
|
||||
@@ -207,6 +212,7 @@ struct Shared {
|
||||
}
|
||||
pub struct Streaming {
|
||||
shared: Arc<Shared>,
|
||||
light_view: Arc<dyn Fn(&Proto) -> Option<Chunk> + Send + Sync>,
|
||||
results: mpsc::Receiver<Done>,
|
||||
threads: Vec<thread::JoinHandle<()>>,
|
||||
order: u64,
|
||||
@@ -531,8 +537,13 @@ impl Streaming {
|
||||
.expect("spawn worker")
|
||||
})
|
||||
.collect();
|
||||
let light_view = {
|
||||
let generator = generator.clone();
|
||||
Arc::new(move |p: &Proto| generator.light_view(p))
|
||||
};
|
||||
Self {
|
||||
shared,
|
||||
light_view,
|
||||
results,
|
||||
threads,
|
||||
order: 0,
|
||||
@@ -746,6 +757,26 @@ impl Streaming {
|
||||
fn distance(&self, x: i32, z: i32) -> i64 {
|
||||
self.ranges().priority(x, z, self.loading)
|
||||
}
|
||||
/// The 3x3 a light job reads: the finished columns, and for a neighbour
|
||||
/// that will not finish (past the area), its decorated proto chunk, as
|
||||
/// vanilla lights its last FULL ring against neighbours at FEATURES.
|
||||
fn light_region(&self, world: &World, x: i32, z: i32) -> Option<Box<Region>> {
|
||||
let mut region: Region = Default::default();
|
||||
for dz in 0..3 {
|
||||
for dx in 0..3 {
|
||||
let n = (x + dx as i32 - 1, z + dz as i32 - 1);
|
||||
region[dz][dx] = Some(match world.chunks.get(&n) {
|
||||
Some(chunk) => chunk.clone(),
|
||||
None if !self.in_range(n.0, n.1, 1) && self.decorated.contains(&n) => {
|
||||
let proto = self.protos.get(&n)?.as_ref()?;
|
||||
Arc::new((self.light_view)(proto)?)
|
||||
}
|
||||
None => return None,
|
||||
});
|
||||
}
|
||||
}
|
||||
Some(Box::new(region))
|
||||
}
|
||||
fn region(world: &World, x: i32, z: i32) -> Option<Box<Region>> {
|
||||
let mut region: Region = Default::default();
|
||||
for dz in 0..3 {
|
||||
@@ -866,6 +897,11 @@ impl Streaming {
|
||||
} else {
|
||||
apply_relighting(chunk, sections, &mut changed);
|
||||
}
|
||||
// Saved unlit (at the edge of what was loaded), or its light
|
||||
// changed: saved again.
|
||||
if (first && !chunk.light_loaded) || !changed.is_empty() {
|
||||
world.modified.insert((x, z));
|
||||
}
|
||||
chunk.lit = true;
|
||||
if first {
|
||||
for dz in -1..=1 {
|
||||
@@ -1102,7 +1138,7 @@ impl Streaming {
|
||||
world.dirty_light.remove(&(x, z));
|
||||
continue;
|
||||
}
|
||||
let Some(region) = Self::region(world, x, z) else {
|
||||
let Some(region) = self.light_region(world, x, z) else {
|
||||
continue;
|
||||
};
|
||||
world.dirty_light.remove(&(x, z));
|
||||
@@ -1424,7 +1460,7 @@ impl Streaming {
|
||||
counts[1] += 1;
|
||||
} else {
|
||||
counts[2] += 1;
|
||||
if Self::region(world, key.0, key.1).is_some() {
|
||||
if self.light_region(world, key.0, key.1).is_some() {
|
||||
world.dirty_light.insert(key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -433,6 +433,12 @@ impl ChunkGenerator for VanillaTerrain {
|
||||
fn is_decorated(&self, proto: &Proto) -> bool {
|
||||
matches!(proto.downcast_ref::<VanillaProto>(), Some(VanillaProto::Ready(c)) if c.is_decorated())
|
||||
}
|
||||
fn light_view(&self, proto: &Proto) -> Option<Chunk> {
|
||||
match proto.downcast_ref::<VanillaProto>() {
|
||||
Some(VanillaProto::Ready(chunk)) => Some(self.column(chunk)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
fn saved_proto(&self, proto: &Proto) -> Option<SavedProto> {
|
||||
let Some(VanillaProto::Ready(chunk)) = proto.downcast_ref::<VanillaProto>() else {
|
||||
return None;
|
||||
|
||||
Reference in New Issue
Block a user