From a57cb58602b323469861c0b06573c6e47db56f34 Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Sat, 29 Aug 2026 21:26:41 -0700 Subject: generating wood caves --- src/sim/cell_manager/manager.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/sim/cell_manager/manager.rs') diff --git a/src/sim/cell_manager/manager.rs b/src/sim/cell_manager/manager.rs index 64b97f1..c8015f7 100644 --- a/src/sim/cell_manager/manager.rs +++ b/src/sim/cell_manager/manager.rs @@ -48,10 +48,14 @@ impl CellManager { } } - pub fn insert(&mut self, x: i32, y: i32, chunk: Chunk) { - self.chunk_position_to_chunk_idx - .insert((x, y), self.chunks.len()); - self.chunks.push(chunk); + pub fn upsert(&mut self, x: i32, y: i32, chunk: Chunk) { + if let Some(&idx) = self.chunk_position_to_chunk_idx.get(&(x, y)) { + self.chunks[idx] = chunk; + } else { + self.chunk_position_to_chunk_idx + .insert((x, y), self.chunks.len()); + self.chunks.push(chunk); + } } pub fn tick(&mut self, use_threading: bool) { @@ -70,9 +74,9 @@ impl CellManager { for y in -10..1 { for x in -100..100 { if y == 0 { - world.insert(x, y, Chunk::floor()); + world.upsert(x, y, Chunk::floor()); } else { - world.insert(x, y, Chunk::void()); + world.upsert(x, y, Chunk::void()); } } } -- cgit v1.3.1