rust/hwphysics/src/collision.rs
changeset 15266 b58f98bbc120
parent 15263 24828281c9c5
child 15270 7446258fab98
--- a/rust/hwphysics/src/collision.rs	Thu Jul 25 15:18:00 2019 +0200
+++ b/rust/hwphysics/src/collision.rs	Thu Jul 25 16:29:14 2019 +0300
@@ -100,6 +100,11 @@
         self.pairs.push((contact_gear_id1, contact_gear_id2));
         self.positions.push(fppoint_round(&position));
     }
+
+    pub fn clear(&mut self) {
+        self.pairs.clear();
+        self.positions.clear()
+    }
 }
 
 impl CollisionProcessor {
@@ -111,10 +116,16 @@
         }
     }
 
-    pub fn process(&mut self, land: &Land2D<u32>, updates: &crate::physics::PositionUpdates) {
+    pub fn process(
+        &mut self,
+        land: &Land2D<u32>,
+        updates: &crate::physics::PositionUpdates,
+    ) -> &DetectedCollisions {
+        self.detected_collisions.clear();
         for (id, old_position, new_position) in updates.iter() {
             self.grid.update_position(id, old_position, new_position)
         }
+
         self.grid.check_collisions(&mut self.detected_collisions);
 
         for (gear_id, collision) in self.enabled_collisions.iter() {
@@ -127,6 +138,8 @@
                     .push(gear_id, None, &collision.bounds.center)
             }
         }
+
+        &self.detected_collisions
     }
 }