diff options
| author | Kai Stevenson <kai@kaistevenson.com> | 2026-08-18 20:20:32 -0700 |
|---|---|---|
| committer | Kai Stevenson <kai@kaistevenson.com> | 2026-08-18 20:20:32 -0700 |
| commit | 92dd02d7cc4d9fc930760d26d81edbe2197a3fc0 (patch) | |
| tree | 6dfde8d306d20266c2185882c635360478a2b6ef /src/sim/rb_sim/rb_entity.rs | |
| parent | 5877fbf3991b1f35696bf86d9e1b3da3ece01f42 (diff) | |
marching rigid bodies
Diffstat (limited to 'src/sim/rb_sim/rb_entity.rs')
| -rw-r--r-- | src/sim/rb_sim/rb_entity.rs | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/src/sim/rb_sim/rb_entity.rs b/src/sim/rb_sim/rb_entity.rs index 50243bc..08813f6 100644 --- a/src/sim/rb_sim/rb_entity.rs +++ b/src/sim/rb_sim/rb_entity.rs @@ -1,24 +1,38 @@ use rapier2d::prelude; -use crate::{ - config::{CELLS_IN_CHUNK, CHUNK_SIZE}, - sim::cell::cell::Cell, +use crate::sim::{ + cell::{cell::Cell, materials::MaterialId}, + lib::marching_squares::Marchable, }; pub struct RbEntity { pub id: u32, - // TODO resizable - pub cells: Box<[Cell; CELLS_IN_CHUNK]>, + pub width: i32, + pub height: i32, + pub cells: Vec<Cell>, pub rb_parent: prelude::RigidBodyHandle, } impl RbEntity { #[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] + self.cells[x as usize + y as usize * self.width 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; + self.cells[x as usize + y as usize * self.width as usize] = cell; + } +} + +impl Marchable for RbEntity { + fn occupied(&self, x: i32, y: i32) -> bool { + if x < 0 || x >= self.width || y < 0 || y >= self.height { + false + } else { + self.get_cell_at_local_position(x as u8, y as u8).material != MaterialId::Void + } + } + fn size(&self) -> (i32, i32) { + (self.width, self.height) } } |
