1 use crate::common::{GearData, GearDataLookup, GearDataProcessor, GearId, LookupEntry, Millis}; |
1 use crate::common::{GearData, GearDataLookup, GearDataProcessor, GearId, Millis}; |
2 use fpnum::*; |
2 use fpnum::*; |
3 use integral_geometry::{GridIndex, Point, Size}; |
|
4 |
3 |
5 #[derive(PartialEq, Eq, Clone, Copy, Debug)] |
4 #[derive(PartialEq, Eq, Clone, Copy, Debug)] |
6 pub struct PhysicsData { |
5 pub struct PhysicsData { |
7 pub position: FPPoint, |
6 pub position: FPPoint, |
8 pub velocity: FPPoint, |
7 pub velocity: FPPoint, |
162 self.dynamic_physics.push(gear_id, gear_data) |
161 self.dynamic_physics.push(gear_id, gear_data) |
163 } else { |
162 } else { |
164 self.static_physics.push(gear_id, gear_data) |
163 self.static_physics.push(gear_id, gear_data) |
165 }; |
164 }; |
166 |
165 |
167 self.gear_lookup[gear_id] = LookupEntry::new(index, is_dynamic); |
166 self.gear_lookup.add(gear_id, index, is_dynamic); |
168 } |
167 } |
169 |
168 |
170 fn remove(&mut self, gear_id: GearId) { |
169 fn remove(&mut self, gear_id: GearId) { |
171 let location = self.gear_lookup[gear_id]; |
170 if let Some(entry) = self.gear_lookup.get(gear_id) { |
172 let relocated_gear_id = if location.value { |
171 let relocated_gear_id = if *entry.value() { |
173 self.dynamic_physics.remove(location.index as usize) |
172 self.dynamic_physics.remove(entry.index() as usize) |
|
173 } else { |
|
174 self.static_physics.remove(entry.index() as usize) |
|
175 }; |
|
176 |
|
177 if let Some(id) = relocated_gear_id { |
|
178 let index = entry.index(); |
|
179 self.gear_lookup[id].set_index(index); |
|
180 } |
|
181 } |
|
182 } |
|
183 |
|
184 fn get(&mut self, gear_id: GearId) -> Option<PhysicsData> { |
|
185 if let Some(entry) = self.gear_lookup.get(gear_id) { |
|
186 let data = if *entry.value() { |
|
187 PhysicsData { |
|
188 position: self.dynamic_physics.positions[entry.index() as usize], |
|
189 velocity: self.dynamic_physics.velocities[entry.index() as usize], |
|
190 } |
|
191 } else { |
|
192 PhysicsData { |
|
193 position: self.static_physics.positions[entry.index() as usize], |
|
194 velocity: FPPoint::zero(), |
|
195 } |
|
196 }; |
|
197 Some(data) |
174 } else { |
198 } else { |
175 self.static_physics.remove(location.index as usize) |
199 None |
176 }; |
200 } |
177 |
201 } |
178 if let Some(id) = relocated_gear_id { |
202 } |
179 self.gear_lookup[id].index = location.index; |
|
180 } |
|
181 } |
|
182 } |
|