summaryrefslogtreecommitdiff
path: root/src/sim/sim.rs
diff options
context:
space:
mode:
authorKai Stevenson <kai@kaistevenson.com>2026-08-15 14:17:28 -0700
committerKai Stevenson <kai@kaistevenson.com>2026-08-15 14:17:28 -0700
commitc94749cc88080ef7fef7b285f9072ea26d18e1eb (patch)
treeba20a6e1fe918934c94a4e5c3f7370d6c6ce97d8 /src/sim/sim.rs
parentb510f5fcf5335c5e26d65ca96d7ec16c2f050f5d (diff)
wip, working with native resolution
Diffstat (limited to 'src/sim/sim.rs')
-rw-r--r--src/sim/sim.rs25
1 files changed, 14 insertions, 11 deletions
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<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;
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<Cell> {
}
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);