summaryrefslogtreecommitdiff
path: root/src/sim
diff options
context:
space:
mode:
Diffstat (limited to 'src/sim')
-rw-r--r--src/sim/chunk.rs2
-rw-r--r--src/sim/materials/mod.rs2
-rw-r--r--src/sim/sim.rs25
-rw-r--r--src/sim/world.rs10
4 files changed, 22 insertions, 17 deletions
diff --git a/src/sim/chunk.rs b/src/sim/chunk.rs
index cf4179a..1980932 100644
--- a/src/sim/chunk.rs
+++ b/src/sim/chunk.rs
@@ -6,6 +6,7 @@ use crate::{
pub struct Chunk {
pub cells: Box<[Cell; CELLS_IN_CHUNK as usize]>,
pub sleeping: bool,
+ pub needs_texture_update: bool,
}
impl Chunk {
@@ -22,6 +23,7 @@ impl Chunk {
Chunk {
cells: Box::new([Cell::void(); CELLS_IN_CHUNK]),
sleeping: true,
+ needs_texture_update: true,
}
}
}
diff --git a/src/sim/materials/mod.rs b/src/sim/materials/mod.rs
index 581ce31..d2d0e0e 100644
--- a/src/sim/materials/mod.rs
+++ b/src/sim/materials/mod.rs
@@ -24,7 +24,7 @@ pub struct MaterialDef {
static MATERIALS: [MaterialDef; 5] = [
MaterialDef {
name: "Void",
- color: (0xFF, 0xFF, 0x00, 0xFF),
+ color: (0x00, 0x00, 0x00, 0x00),
density: 0,
sim_update: None,
},
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);
diff --git a/src/sim/world.rs b/src/sim/world.rs
index 7775744..bdb1286 100644
--- a/src/sim/world.rs
+++ b/src/sim/world.rs
@@ -17,12 +17,12 @@ impl World {
(
(
// TODO is this cast expensive?
- x.div_euclid(CHUNK_SIZE as i32),
- y.div_euclid(CHUNK_SIZE as i32),
+ x.div_euclid(CHUNK_SIZE),
+ y.div_euclid(CHUNK_SIZE),
),
(
- x.rem_euclid(CHUNK_SIZE as i32) as u8,
- y.rem_euclid(CHUNK_SIZE as i32) as u8,
+ x.rem_euclid(CHUNK_SIZE) as u8,
+ y.rem_euclid(CHUNK_SIZE) as u8,
),
)
}
@@ -64,7 +64,7 @@ impl World {
};
for y in -10..10 {
- for x in -50..50 {
+ for x in -10..10 {
world.insert(x, y, Chunk::void());
}
}