summaryrefslogtreecommitdiff
path: root/src/sim
diff options
context:
space:
mode:
Diffstat (limited to 'src/sim')
-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());
}
}
}