diff -r bfd185ad03e7 -r 42b710b0f883 rust/hwphysics/src/physics.rs --- a/rust/hwphysics/src/physics.rs Thu Jul 25 21:59:20 2019 +0300 +++ b/rust/hwphysics/src/physics.rs Thu Jul 25 22:31:24 2019 +0300 @@ -35,12 +35,20 @@ self.gear_ids.len() } - fn push(&mut self, id: GearId, physics: PhysicsData) { - self.gear_ids.push(id); + fn push(&mut self, gear_id: GearId, physics: PhysicsData) { + self.gear_ids.push(gear_id); self.positions.push(physics.position); self.velocities.push(physics.velocity); } + fn remove(&mut self, gear_id: GearId) { + if let Some(index) = self.gear_ids.iter().position(|id| *id == gear_id) { + self.gear_ids.swap_remove(index); + self.positions.swap_remove(index); + self.velocities.swap_remove(index); + } + } + fn iter_pos_update(&mut self) -> impl Iterator { self.gear_ids .iter() @@ -66,6 +74,13 @@ self.gear_ids.push(gear_id); self.positions.push(physics.position); } + + fn remove(&mut self, gear_id: GearId) { + if let Some(index) = self.gear_ids.iter().position(|id| *id == gear_id) { + self.gear_ids.swap_remove(index); + self.positions.swap_remove(index); + } + } } pub struct PhysicsProcessor { @@ -149,4 +164,9 @@ self.dynamic_physics.push(gear_id, gear_data); } } + + fn remove(&mut self, gear_id: GearId) { + self.static_physics.remove(gear_id); + self.dynamic_physics.remove(gear_id) + } }