summaryrefslogtreecommitdiff
path: root/src/sim/cell_manager/chunk.rs
diff options
context:
space:
mode:
authorKai Stevenson <kai@kaistevenson.com>2026-08-22 15:00:35 -0700
committerKai Stevenson <kai@kaistevenson.com>2026-08-22 15:00:35 -0700
commit1a515237afb7ad09353a65f5fbc6e98a7c29ce8e (patch)
tree48cd4b4bcf8f8e357811f905f22607838d7c1f96 /src/sim/cell_manager/chunk.rs
parent6350e4ffca8ce1e46465284ef3d7559e0f40229b (diff)
sim manager refactor
Diffstat (limited to 'src/sim/cell_manager/chunk.rs')
-rw-r--r--src/sim/cell_manager/chunk.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/sim/cell_manager/chunk.rs b/src/sim/cell_manager/chunk.rs
new file mode 100644
index 0000000..3fe5056
--- /dev/null
+++ b/src/sim/cell_manager/chunk.rs
@@ -0,0 +1,47 @@
+use crate::{
+ config::{CELLS_IN_CHUNK, CHUNK_SIZE},
+ sim::{
+ cell::{cell::Cell, materials::MaterialForm},
+ lib::marching_squares::Marchable,
+ },
+};
+
+pub struct Chunk {
+ pub cells: Box<[Cell; CELLS_IN_CHUNK]>,
+ pub sleeping: bool,
+ pub needs_texture_update: bool,
+}
+
+impl Chunk {
+ #[inline]
+ pub fn get_cell_at_local_position(&self, x: u8, y: u8) -> Cell {
+ self.cells[x as usize + y as usize * CHUNK_SIZE as usize]
+ }
+ #[inline]
+ pub fn set_cell_at_local_position(&mut self, x: u8, y: u8, cell: Cell) {
+ self.cells[x as usize + y as usize * CHUNK_SIZE as usize] = cell;
+ }
+
+ pub fn void() -> Self {
+ Chunk {
+ cells: Box::new([Cell::void(); CELLS_IN_CHUNK]),
+ sleeping: true,
+ needs_texture_update: true,
+ }
+ }
+}
+
+impl Marchable for Chunk {
+ fn occupied(&self, x: i32, y: i32) -> bool {
+ if x < 0 || x >= CHUNK_SIZE || y < 0 || y >= CHUNK_SIZE {
+ false
+ } else {
+ // we only build a path for solid cells or settled powder cells
+ let cell = self.get_cell_at_local_position(x as u8, y as u8);
+ cell.material.def().form == MaterialForm::Solid || cell.settled() > 4
+ }
+ }
+ fn size(&self) -> (i32, i32) {
+ (CHUNK_SIZE, CHUNK_SIZE)
+ }
+}