summaryrefslogtreecommitdiff
path: root/src/sim/sim.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/sim/sim.rs')
-rw-r--r--src/sim/sim.rs52
1 files changed, 24 insertions, 28 deletions
diff --git a/src/sim/sim.rs b/src/sim/sim.rs
index 84c3126..b9f4b76 100644
--- a/src/sim/sim.rs
+++ b/src/sim/sim.rs
@@ -39,17 +39,13 @@ fn get_cell(chunks: &[Option<&mut Chunk>; 9], x: i32, y: i32) -> Option<Cell> {
let nc_x = x.rem_euclid(CHUNK_SIZE) as u8;
let nc_y = y.rem_euclid(CHUNK_SIZE) as u8;
- return if let Some(chunk) = &chunks[(dcx + 1 + (dcy + 1) * 3) as usize] {
- Some(chunk.get_cell_at_local_position(nc_x, nc_y))
- } else {
- None
- };
+ chunks[(dcx + 1 + (dcy + 1) * 3) as usize]
+ .as_ref()
+ .map(|chunk| chunk.get_cell_at_local_position(nc_x, nc_y))
} else {
- if let Some(target) = &chunks[4] {
- Some(target.get_cell_at_local_position(x as u8, y as u8))
- } else {
- None
- }
+ chunks[4]
+ .as_ref()
+ .map(|target| target.get_cell_at_local_position(x as u8, y as u8))
}
}
@@ -138,28 +134,28 @@ pub fn sim_tick_chunk(chunks: &mut [Option<&mut Chunk>; 9], seqno: u64) {
let mut cell = get_cell(chunks, x, y).unwrap();
let material = cell.material.def();
- if let Some(update) = material.sim_update {
- if cell.parity() == seqno_parity {
- cell.flip_parity();
- // apply the flipped parity in case the sim target doesn't
- set_cell(chunks, x, y, cell);
+ if let Some(update) = material.sim_update
+ && cell.parity() == seqno_parity
+ {
+ cell.flip_parity();
+ // apply the flipped parity in case the sim target doesn't
+ set_cell(chunks, x, y, cell);
- let mut update_ctx = UpdateCtx {
- chunks,
- seqno,
- seqno_parity,
+ let mut update_ctx = UpdateCtx {
+ chunks,
+ seqno,
+ seqno_parity,
- x,
- y,
- cell: &mut cell,
- material,
+ x,
+ y,
+ cell: &mut cell,
+ material,
- // TODO this is platform-dependent, will break for multiplayer
- rng: &mut rng,
- };
+ // TODO this is platform-dependent, will break for multiplayer
+ rng: &mut rng,
+ };
- update(&mut update_ctx);
- }
+ update(&mut update_ctx);
}
}
}