summaryrefslogtreecommitdiff
path: root/src/sim/sim_manager/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/sim/sim_manager/mod.rs')
-rw-r--r--src/sim/sim_manager/mod.rs26
1 files changed, 10 insertions, 16 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 {