From c94749cc88080ef7fef7b285f9072ea26d18e1eb Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Sat, 15 Aug 2026 14:17:28 -0700 Subject: wip, working with native resolution --- src/sim/sim.rs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'src/sim/sim.rs') diff --git a/src/sim/sim.rs b/src/sim/sim.rs index 6e0029e..ef2fc80 100644 --- a/src/sim/sim.rs +++ b/src/sim/sim.rs @@ -41,12 +41,12 @@ pub struct UpdateCtx<'a, 'b, 'c> { } fn get_cell(chunks: &[Option<&mut Chunk>; 9], x: i32, y: i32) -> Option { - let dcx = x.div_euclid(CHUNK_SIZE as i32); - let dcy = y.div_euclid(CHUNK_SIZE as i32); + let dcx = x.div_euclid(CHUNK_SIZE); + let dcy = y.div_euclid(CHUNK_SIZE); if dcx != 0 || dcy != 0 { // in a different chunk - let nc_x = x.rem_euclid(CHUNK_SIZE as i32) as u8; - let nc_y = y.rem_euclid(CHUNK_SIZE as i32) as u8; + 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)) @@ -63,19 +63,21 @@ fn get_cell(chunks: &[Option<&mut Chunk>; 9], x: i32, y: i32) -> Option { } pub fn set_cell(chunks: &mut [Option<&mut Chunk>; 9], x: i32, y: i32, cell: Cell) { - let dcx = x.div_euclid(CHUNK_SIZE as i32); - let dcy = y.div_euclid(CHUNK_SIZE as i32); + let dcx = x.div_euclid(CHUNK_SIZE); + let dcy = y.div_euclid(CHUNK_SIZE); if dcx != 0 || dcy != 0 { // in a different chunk - let nc_x = x.rem_euclid(CHUNK_SIZE as i32) as u8; - let nc_y = y.rem_euclid(CHUNK_SIZE as i32) as u8; + let nc_x = x.rem_euclid(CHUNK_SIZE) as u8; + let nc_y = y.rem_euclid(CHUNK_SIZE) as u8; if let Some(chunk) = &mut chunks[(dcx + 1 + (dcy + 1) * 3) as usize] { chunk.set_cell_at_local_position(nc_x, nc_y, cell); + chunk.needs_texture_update = true; } } else { if let Some(target) = &mut chunks[4] { target.set_cell_at_local_position(x as u8, y as u8, cell); + target.needs_texture_update = true; } } } @@ -118,12 +120,12 @@ pub fn sim_tick_chunk(chunks: &mut [Option<&mut Chunk>; 9], seqno: u64) { let seqno_parity = (seqno as u8) & 0b1; if chunks[4].is_some() { - for y in (0..CHUNK_SIZE as i32).rev() { - for i in 0..CHUNK_SIZE as i32 { + for y in (0..CHUNK_SIZE).rev() { + for i in 0..CHUNK_SIZE { let x = if seqno_parity == 0 { i } else { - (CHUNK_SIZE as i32) - i - 1 + (CHUNK_SIZE) - i - 1 }; let mut cell = get_cell(chunks, x, y).unwrap(); @@ -213,6 +215,7 @@ pub fn sim_tick(world: &mut World, seqno: u64, use_threading: bool) { }; if use_threading { + // TODO use forte color.par_iter().for_each(chunk_closure); } else { color.iter().for_each(chunk_closure); -- cgit v1.3.1