rust/hwphysics/src/collision.rs
changeset 15385 6e3e5be8b2e2
parent 15287 478d5372eb4a
--- a/rust/hwphysics/src/collision.rs	Wed Aug 28 22:53:40 2019 +0300
+++ b/rust/hwphysics/src/collision.rs	Wed Aug 28 23:06:34 2019 +0300
@@ -1,9 +1,6 @@
 use std::ops::RangeInclusive;
 
-use crate::{
-    common::{GearData, GearDataProcessor, GearId},
-    grid::Grid,
-};
+use crate::{common::GearId, data::GearDataManager, grid::Grid};
 
 use fpnum::*;
 use integral_geometry::{Point, Size};
@@ -37,16 +34,12 @@
     pub bounds: CircleBounds,
 }
 
-impl GearData for CollisionData {}
-
 #[derive(PartialEq, Eq, Clone, Copy, Debug)]
 pub struct ContactData {
     pub elasticity: FPNum,
     pub friction: FPNum,
 }
 
-impl GearData for ContactData {}
-
 struct EnabledCollisionsCollection {
     gear_ids: Vec<GearId>,
     collisions: Vec<CollisionData>,
@@ -107,6 +100,11 @@
 }
 
 impl CollisionProcessor {
+    pub fn register_components(data: &mut GearDataManager) {
+        data.register::<CollisionData>();
+        data.register::<ContactData>();
+    }
+
     pub fn new(size: Size) -> Self {
         Self {
             grid: Grid::new(size),
@@ -115,6 +113,18 @@
         }
     }
 
+    pub fn add(&mut self, gear_id: GearId, gear_data: CollisionData) {
+        self.grid.insert_static(gear_id, &gear_data.bounds);
+    }
+
+    pub fn remove(&mut self, gear_id: GearId) {
+        self.grid.remove(gear_id);
+    }
+
+    pub fn get(&mut self, gear_id: GearId) -> Option<CollisionData> {
+        None
+    }
+
     pub fn process(
         &mut self,
         land: &Land2D<u32>,
@@ -141,17 +151,3 @@
         &self.detected_collisions
     }
 }
-
-impl GearDataProcessor<CollisionData> for CollisionProcessor {
-    fn add(&mut self, gear_id: GearId, gear_data: CollisionData) {
-        self.grid.insert_static(gear_id, &gear_data.bounds);
-    }
-
-    fn remove(&mut self, gear_id: GearId) {
-        self.grid.remove(gear_id);
-    }
-
-    fn get(&mut self, gear_id: GearId) -> Option<CollisionData> {
-        None
-    }
-}