diff options
| author | Kai Stevenson <kai@kaistevenson.com> | 2026-08-22 15:00:35 -0700 |
|---|---|---|
| committer | Kai Stevenson <kai@kaistevenson.com> | 2026-08-22 15:00:35 -0700 |
| commit | 1a515237afb7ad09353a65f5fbc6e98a7c29ce8e (patch) | |
| tree | 48cd4b4bcf8f8e357811f905f22607838d7c1f96 /src/sim/rb_manager/rb_entity.rs | |
| parent | 6350e4ffca8ce1e46465284ef3d7559e0f40229b (diff) | |
sim manager refactor
Diffstat (limited to 'src/sim/rb_manager/rb_entity.rs')
| -rw-r--r-- | src/sim/rb_manager/rb_entity.rs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/sim/rb_manager/rb_entity.rs b/src/sim/rb_manager/rb_entity.rs new file mode 100644 index 0000000..18a6693 --- /dev/null +++ b/src/sim/rb_manager/rb_entity.rs @@ -0,0 +1,39 @@ +use rapier2d::prelude; + +use crate::sim::{ + cell::{cell::Cell, materials::MaterialId}, + lib::marching_squares::Marchable, +}; + +pub struct RbEntity { + pub id: u32, + pub width: i32, + pub height: i32, + pub cells: Vec<Cell>, + pub rb: prelude::RigidBodyHandle, + pub collider: Option<prelude::ColliderHandle>, +} + +impl RbEntity { + #[inline] + pub fn get_cell_at_local_position(&self, x: u8, y: u8) -> Cell { + 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 * 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) + } +} |
