# HG changeset patch # User alfadur # Date 1564061354 -10800 # Node ID b58f98bbc120ac3c35319e645e7c8608a9ec53f9 # Parent 07e909ba420344c0236eea4e78cc3a85ffba1097 clear intermediate result structures between iterations diff -r 07e909ba4203 -r b58f98bbc120 rust/hwphysics/src/collision.rs --- 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, updates: &crate::physics::PositionUpdates) { + pub fn process( + &mut self, + land: &Land2D, + 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 } } diff -r 07e909ba4203 -r b58f98bbc120 rust/hwphysics/src/lib.rs --- a/rust/hwphysics/src/lib.rs Thu Jul 25 15:18:00 2019 +0200 +++ b/rust/hwphysics/src/lib.rs Thu Jul 25 16:29:14 2019 +0300 @@ -48,7 +48,7 @@ pub fn step(&mut self, time_step: FPNum, land: &Land2D) { let updates = self.physics.process(time_step); - self.collision.process(land, &updates); + let collision = self.collision.process(land, &updates); } pub fn add_gear_data(&mut self, gear_id: GearId, data: T) diff -r 07e909ba4203 -r b58f98bbc120 rust/hwphysics/src/physics.rs --- a/rust/hwphysics/src/physics.rs Thu Jul 25 15:18:00 2019 +0200 +++ b/rust/hwphysics/src/physics.rs Thu Jul 25 16:29:14 2019 +0300 @@ -101,6 +101,11 @@ .zip(self.shifts.iter()) .map(|(id, (from, to))| (id, from, to)) } + + pub fn clear(&mut self) { + self.gear_ids.clear(); + self.shifts.clear(); + } } impl PhysicsProcessor { @@ -114,6 +119,7 @@ } pub fn process(&mut self, time_step: FPNum) -> &PositionUpdates { + self.position_updates.clear(); for (gear_id, (pos, vel)) in self.dynamic_physics.iter_pos_update() { let old_pos = *pos; *pos += *vel * time_step;