From 6f67586b8fc6efdb86d0c9a9744c546da97c4dab Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Tue, 11 Aug 2026 00:46:56 -0700 Subject: physics for sand and water --- src/sim/board.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/sim/board.rs') diff --git a/src/sim/board.rs b/src/sim/board.rs index 4cc5756..7af19be 100644 --- a/src/sim/board.rs +++ b/src/sim/board.rs @@ -1,24 +1,24 @@ -use crate::config::{PIXEL_BUFFER_HEIGHT, PIXEL_BUFFER_WIDTH}; - -type MaterialId = u16; +use crate::{ + config::{PIXEL_BUFFER_HEIGHT, PIXEL_BUFFER_WIDTH}, + sim::materials::MaterialId, +}; #[derive(Clone, Copy)] pub struct Cell { pub material: MaterialId, - pub velocity_x: i8, - pub velocity_y: i8, pub flags: u8, } impl Cell { - fn empty() -> Cell { + pub fn void() -> Cell { Cell { - material: 0, - velocity_x: 0, - velocity_y: 0, + material: MaterialId::Void, flags: 0, } } + pub fn from_material(material: MaterialId) -> Cell { + Cell { material, flags: 0 } + } } pub struct Board { @@ -40,8 +40,8 @@ impl Board { let idx = self.position_to_index(x, y).unwrap(); self.cells[idx] = c; } - pub fn cell_at_position(&self, x: i32, y: i32) -> Option<&Cell> { - Some(&self.cells[self.position_to_index(x, y)?]) + pub fn cell_at_position(&self, x: i32, y: i32) -> Option { + Some(self.cells[self.position_to_index(x, y)?]) } pub fn position_to_index(&self, x: i32, y: i32) -> Option { let board_x = x + self.size_x as i32 / 2; @@ -61,7 +61,7 @@ impl Board { pub fn empty() -> Board { let size_x = PIXEL_BUFFER_WIDTH * 2; let size_y = PIXEL_BUFFER_HEIGHT * 2; - let cells: Vec = vec![Cell::empty(); (size_x * size_y) as usize]; + let cells: Vec = vec![Cell::void(); (size_x * size_y) as usize]; Board { size_x, -- cgit v1.3.1