summaryrefslogtreecommitdiff
path: root/src/sim/cell_manager
diff options
context:
space:
mode:
authorKai Stevenson <kai@kaistevenson.com>2026-08-29 21:26:41 -0700
committerKai Stevenson <kai@kaistevenson.com>2026-08-29 21:26:41 -0700
commita57cb58602b323469861c0b06573c6e47db56f34 (patch)
treeef00d97d1843f35472473a0ed8a3dedbfa9b43b9 /src/sim/cell_manager
parente0feb1dc1821f3e1e3d6b9697cd4560b377988b8 (diff)
generating wood caves
Diffstat (limited to 'src/sim/cell_manager')
-rw-r--r--src/sim/cell_manager/manager.rs16
1 files changed, 10 insertions, 6 deletions
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());
}
}
}