diff options
Diffstat (limited to 'src/sim/sim_manager')
| -rw-r--r-- | src/sim/sim_manager/mod.rs | 26 | ||||
| -rw-r--r-- | src/sim/sim_manager/utils.rs | 7 |
2 files changed, 15 insertions, 18 deletions
diff --git a/src/sim/sim_manager/mod.rs b/src/sim/sim_manager/mod.rs index 855b398..97f542b 100644 --- a/src/sim/sim_manager/mod.rs +++ b/src/sim/sim_manager/mod.rs @@ -9,7 +9,7 @@ use crate::{ sim::{ cell::Cell, cell_manager::manager::CellManager, - entity::{Entity, EntityDef}, + entity::{Entity, EntityDef, EntityId}, particle_manager::ParticleManager, rb_manager::RbManager, sim_manager::utils::write_entity_to_world, @@ -35,7 +35,7 @@ pub struct SimManager { // entities // TODO entity manager? next_entity_id: u32, - pub entities: FxHashMap<u32, Entity>, + pub entities: FxHashMap<EntityId, Entity>, } pub struct SimCtx<'a> { @@ -45,7 +45,7 @@ pub struct SimCtx<'a> { } impl SimManager { - pub fn create_entity(&mut self, def: EntityDef) -> u32 { + pub fn create_entity(&mut self, def: EntityDef) -> EntityId { let (rb_h, collider_h) = if let Some(rb) = def.rb { let rb_h = self.rb_manager.physics_manager.world.insert_body(rb); @@ -70,21 +70,15 @@ impl SimManager { (None, None) }; - let entity = Entity::new( - self.next_entity_id, - rb_h, - collider_h, - def.cells, - def.behaviour, - ); + let id = EntityId(self.next_entity_id); + let entity = Entity::new(id, rb_h, collider_h, def.cells, def.behaviour); - let id = self.next_entity_id; self.entities.insert(id, entity); self.next_entity_id += 1; id } - pub fn destroy_entity(&mut self, id: u32) { + pub fn destroy_entity(&mut self, id: EntityId) { if let Some(entity) = self.entities.get(&id) { if let Some(rb_h) = entity.data.rb_h { self.rb_manager.physics_manager.world.remove_body(rb_h); @@ -102,8 +96,8 @@ impl SimManager { fn cell_update(&mut self, config: &Config, delta_time: f32) { // before we tick, write all the entities into the sim world // TODO optimize - let entity_ids: Vec<u32> = self.entities.keys().copied().collect(); - let mut cells_written_by_entity: Vec<(u32, Vec<(u8, u8, i32, i32)>)> = Vec::new(); + let entity_ids: Vec<EntityId> = self.entities.keys().copied().collect(); + let mut cells_written_by_entity: Vec<(EntityId, Vec<(u8, u8, i32, i32)>)> = Vec::new(); for entity_id in entity_ids { let cells_written = write_entity_to_world(self, entity_id, self.cell_manager.seqno); @@ -112,7 +106,7 @@ impl SimManager { self.cell_manager.tick(config.use_threading); - let entity_ids: Vec<u32> = self.entities.keys().cloned().collect(); + let entity_ids: Vec<EntityId> = self.entities.keys().cloned().collect(); for id in entity_ids { let entity = self.entities.get_mut(&id); let mut ctx = SimCtx { @@ -180,7 +174,7 @@ impl SimManager { } fn physics_update(&mut self, delta_time: f32) { - let entity_ids: Vec<u32> = self.entities.keys().cloned().collect(); + let entity_ids: Vec<EntityId> = self.entities.keys().cloned().collect(); for id in entity_ids { let entity = self.entities.get_mut(&id); let mut ctx = SimCtx { diff --git a/src/sim/sim_manager/utils.rs b/src/sim/sim_manager/utils.rs index b668359..13d7891 100644 --- a/src/sim/sim_manager/utils.rs +++ b/src/sim/sim_manager/utils.rs @@ -1,10 +1,13 @@ use glam::IVec2; -use crate::{content::materials::MaterialId, sim::sim_manager::SimManager}; +use crate::{ + content::materials::MaterialId, + sim::{entity::EntityId, sim_manager::SimManager}, +}; pub fn write_entity_to_world( sim: &mut SimManager, - entity_id: u32, + entity_id: EntityId, // make sure these cells will be simulated seqno: u64, // (entity_x, entity_y, cell_x, cell_y) |
