equal
deleted
inserted
replaced
98 position: &FPPoint, |
98 position: &FPPoint, |
99 ) { |
99 ) { |
100 self.pairs.push((contact_gear_id1, contact_gear_id2)); |
100 self.pairs.push((contact_gear_id1, contact_gear_id2)); |
101 self.positions.push(fppoint_round(&position)); |
101 self.positions.push(fppoint_round(&position)); |
102 } |
102 } |
|
103 |
|
104 pub fn clear(&mut self) { |
|
105 self.pairs.clear(); |
|
106 self.positions.clear() |
|
107 } |
103 } |
108 } |
104 |
109 |
105 impl CollisionProcessor { |
110 impl CollisionProcessor { |
106 pub fn new(size: Size) -> Self { |
111 pub fn new(size: Size) -> Self { |
107 Self { |
112 Self { |
109 enabled_collisions: EnabledCollisionsCollection::new(), |
114 enabled_collisions: EnabledCollisionsCollection::new(), |
110 detected_collisions: DetectedCollisions::new(0), |
115 detected_collisions: DetectedCollisions::new(0), |
111 } |
116 } |
112 } |
117 } |
113 |
118 |
114 pub fn process(&mut self, land: &Land2D<u32>, updates: &crate::physics::PositionUpdates) { |
119 pub fn process( |
|
120 &mut self, |
|
121 land: &Land2D<u32>, |
|
122 updates: &crate::physics::PositionUpdates, |
|
123 ) -> &DetectedCollisions { |
|
124 self.detected_collisions.clear(); |
115 for (id, old_position, new_position) in updates.iter() { |
125 for (id, old_position, new_position) in updates.iter() { |
116 self.grid.update_position(id, old_position, new_position) |
126 self.grid.update_position(id, old_position, new_position) |
117 } |
127 } |
|
128 |
118 self.grid.check_collisions(&mut self.detected_collisions); |
129 self.grid.check_collisions(&mut self.detected_collisions); |
119 |
130 |
120 for (gear_id, collision) in self.enabled_collisions.iter() { |
131 for (gear_id, collision) in self.enabled_collisions.iter() { |
121 if collision |
132 if collision |
122 .bounds |
133 .bounds |
125 { |
136 { |
126 self.detected_collisions |
137 self.detected_collisions |
127 .push(gear_id, None, &collision.bounds.center) |
138 .push(gear_id, None, &collision.bounds.center) |
128 } |
139 } |
129 } |
140 } |
|
141 |
|
142 &self.detected_collisions |
130 } |
143 } |
131 } |
144 } |
132 |
145 |
133 impl GearDataProcessor<CollisionData> for CollisionProcessor { |
146 impl GearDataProcessor<CollisionData> for CollisionProcessor { |
134 fn add(&mut self, gear_id: GearId, gear_data: CollisionData) { |
147 fn add(&mut self, gear_id: GearId, gear_data: CollisionData) { |