From 326b26c56483f6539229b98e626ec462327335d8 Mon Sep 17 00:00:00 2001 From: Kevin Reid Date: Tue, 28 Nov 2023 19:21:08 -0800 Subject: [PATCH] `Space::fill_uniform()` now properly notifies light update queue. --- all-is-cubes/src/space.rs | 15 ++++++++++----- all-is-cubes/src/space/light/updater.rs | 13 +++++++++++++ all-is-cubes/src/space/tests.rs | 12 +++++++++++- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/all-is-cubes/src/space.rs b/all-is-cubes/src/space.rs index ca856d883..a15ee8436 100644 --- a/all-is-cubes/src/space.rs +++ b/all-is-cubes/src/space.rs @@ -487,11 +487,16 @@ impl Space { }) } else if self.bounds() == region { // We're overwriting the entire space, so we might as well re-initialize it. - let linear = self.contents.as_linear_mut(); - let volume = linear.len(); - self.palette = Palette::new(block.clone(), volume); - linear.fill(/* block index = */ 0); - // TODO: also need to reset lighting and activate tick_action. + { + let linear = self.contents.as_linear_mut(); + let volume = linear.len(); + self.palette = Palette::new(block.clone(), volume); + linear.fill(/* block index = */ 0); + } + // TODO: if opaque, don't schedule updates + self.light + .light_needs_update_in_region(region, light::Priority::UNINIT); + // TODO: also need to activate tick_action if present. // And see if we can share more of the logic of this with new_from_builder(). self.change_notifier.notify(SpaceChange::EveryBlock); Ok(()) diff --git a/all-is-cubes/src/space/light/updater.rs b/all-is-cubes/src/space/light/updater.rs index fd4abe896..e873748c1 100644 --- a/all-is-cubes/src/space/light/updater.rs +++ b/all-is-cubes/src/space/light/updater.rs @@ -131,6 +131,19 @@ impl LightStorage { } } + pub(crate) fn light_needs_update_in_region(&mut self, region: GridAab, priority: Priority) { + let Some(region) = region.intersection(self.contents.bounds()) else { + return; + }; + if region.volume() > 400 { + self.light_update_queue.sweep(region, priority); + } else { + for cube in region.interior_iter() { + self.light_needs_update(cube, priority); + } + } + } + pub(in crate::space) fn modified_cube_needs_update( &mut self, uc: UpdateCtx<'_>, diff --git a/all-is-cubes/src/space/tests.rs b/all-is-cubes/src/space/tests.rs index e0302d732..c426158d3 100644 --- a/all-is-cubes/src/space/tests.rs +++ b/all-is-cubes/src/space/tests.rs @@ -336,13 +336,19 @@ fn fill_out_of_bounds() { /// Test filling an entire space with one block using [`Space::fill`]. #[test] fn fill_entire_space() { - let [block] = make_some_blocks(); + let block = Block::from(Rgba::new(0., 0., 0., 0.5)); // transparent so light gets involved let bounds = GridAab::from_lower_size([0, 3, 0], [25 * 16, 16, 2]); let mut space = Space::empty(bounds); + space.fill(bounds, |_| Some(&block)).unwrap(); + space.consistency_check(); for cube in bounds.interior_iter() { assert_eq!(&space[cube], &block); + assert!( + space.in_light_update_queue(cube), + "{cube:?} in light update queue" + ); } } @@ -362,6 +368,10 @@ fn fill_uniform_entire_space() { space.consistency_check(); for cube in bounds.interior_iter() { assert_eq!(&space[cube], &block); + assert!( + space.in_light_update_queue(cube), + "{cube:?} in light update queue" + ); } }