diff -r 44b49f255e31 -r d5e6c8c92d87 rust/hwphysics/src/lib.rs --- a/rust/hwphysics/src/lib.rs Thu Jan 27 03:51:13 2022 +0300 +++ b/rust/hwphysics/src/lib.rs Fri Jan 28 02:33:44 2022 +0300 @@ -6,7 +6,10 @@ use integral_geometry::PotSize; use land2d::Land2D; +use std::any::{Any, TypeId}; +use crate::collision::CollisionData; +use crate::physics::VelocityData; use crate::{ collision::CollisionProcessor, common::{GearAllocator, GearId, Millis}, @@ -52,9 +55,20 @@ let collisions = self.collision.process(land, &updates); } - #[inline] pub fn add_gear_data(&mut self, gear_id: GearId, data: &T) { self.data.add(gear_id, data); + if TypeId::of::() == TypeId::of::() { + self.collision.remove(gear_id); + } + } + + pub fn remove_gear_data(&mut self, gear_id: GearId) { + self.data.remove::(gear_id); + if TypeId::of::() == TypeId::of::() { + if let Some(collision_data) = self.data.get::(gear_id) { + self.collision.add(gear_id, *collision_data); + } + } } #[inline] @@ -72,12 +86,12 @@ World, }; use fpnum::{fp, FPNum, FPPoint}; - use integral_geometry::PotSize; + use integral_geometry::{PotSize, Size}; use land2d::Land2D; #[test] fn data_flow() { - let world_size = PotSize::new(2048, 2048).unwrap; + let world_size = PotSize::new(2048, 2048).unwrap(); let mut world = World::new(world_size); let gear_id = world.new_gear().unwrap(); @@ -95,7 +109,10 @@ }, ); - let land = Land2D::new(Size::new(world_size.width - 2, world_size.height - 2), 0); + let land = Land2D::new( + Size::new(world_size.width() - 2, world_size.height() - 2), + 0, + ); world.step(Millis::new(1), &land); }