Skip to content

Commit

Permalink
Don't recompute neigbors pointlessly when updating litter state (Leaf…
Browse files Browse the repository at this point in the history
  • Loading branch information
alice-i-cecile authored May 27, 2023
1 parent 2ca244e commit 20a41e7
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions emergence_lib/src/geometry/indexing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,17 +549,24 @@ impl MapGeometry {

/// Updates the passability of the provided `tile_pos` based on the state of the litter at that location.
pub(crate) fn update_litter_state(&mut self, tile_pos: TilePos, litter_state: InventoryState) {
match litter_state {
InventoryState::Empty | InventoryState::Partial => {
self.impassable_litter_tiles.remove(&tile_pos);
let current_litter_state = self.impassable_litter_tiles.contains(&tile_pos);

match current_litter_state {
true => {
if litter_state != InventoryState::Full {
self.impassable_litter_tiles.remove(&tile_pos);
self.recompute_passable_neighbors(tile_pos);
self.recompute_reachable_neighbors(tile_pos);
}
}
InventoryState::Full => {
self.impassable_litter_tiles.insert(tile_pos);
false => {
if litter_state == InventoryState::Full {
self.impassable_litter_tiles.insert(tile_pos);
self.recompute_passable_neighbors(tile_pos);
self.recompute_reachable_neighbors(tile_pos);
}
}
}

self.recompute_passable_neighbors(tile_pos);
self.recompute_reachable_neighbors(tile_pos);
}

/// Returns an iterator over all of the tiles that are ocean tiles.
Expand Down

0 comments on commit 20a41e7

Please sign in to comment.