Skip to content

Commit

Permalink
Space::fill_uniform() now properly notifies light update queue.
Browse files Browse the repository at this point in the history
  • Loading branch information
kpreid committed Nov 29, 2023
1 parent 51a9478 commit 326b26c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
15 changes: 10 additions & 5 deletions all-is-cubes/src/space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
13 changes: 13 additions & 0 deletions all-is-cubes/src/space/light/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<'_>,
Expand Down
12 changes: 11 additions & 1 deletion all-is-cubes/src/space/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
}
}

Expand All @@ -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"
);
}
}

Expand Down

0 comments on commit 326b26c

Please sign in to comment.