equal
deleted
inserted
replaced
33 |
33 |
34 fn len(&self) -> usize { |
34 fn len(&self) -> usize { |
35 self.gear_ids.len() |
35 self.gear_ids.len() |
36 } |
36 } |
37 |
37 |
38 fn push(&mut self, id: GearId, physics: PhysicsData) { |
38 fn push(&mut self, gear_id: GearId, physics: PhysicsData) { |
39 self.gear_ids.push(id); |
39 self.gear_ids.push(gear_id); |
40 self.positions.push(physics.position); |
40 self.positions.push(physics.position); |
41 self.velocities.push(physics.velocity); |
41 self.velocities.push(physics.velocity); |
|
42 } |
|
43 |
|
44 fn remove(&mut self, gear_id: GearId) { |
|
45 if let Some(index) = self.gear_ids.iter().position(|id| *id == gear_id) { |
|
46 self.gear_ids.swap_remove(index); |
|
47 self.positions.swap_remove(index); |
|
48 self.velocities.swap_remove(index); |
|
49 } |
42 } |
50 } |
43 |
51 |
44 fn iter_pos_update(&mut self) -> impl Iterator<Item = (GearId, (&mut FPPoint, &FPPoint))> { |
52 fn iter_pos_update(&mut self) -> impl Iterator<Item = (GearId, (&mut FPPoint, &FPPoint))> { |
45 self.gear_ids |
53 self.gear_ids |
46 .iter() |
54 .iter() |
63 } |
71 } |
64 |
72 |
65 fn push(&mut self, gear_id: GearId, physics: PhysicsData) { |
73 fn push(&mut self, gear_id: GearId, physics: PhysicsData) { |
66 self.gear_ids.push(gear_id); |
74 self.gear_ids.push(gear_id); |
67 self.positions.push(physics.position); |
75 self.positions.push(physics.position); |
|
76 } |
|
77 |
|
78 fn remove(&mut self, gear_id: GearId) { |
|
79 if let Some(index) = self.gear_ids.iter().position(|id| *id == gear_id) { |
|
80 self.gear_ids.swap_remove(index); |
|
81 self.positions.swap_remove(index); |
|
82 } |
68 } |
83 } |
69 } |
84 } |
70 |
85 |
71 pub struct PhysicsProcessor { |
86 pub struct PhysicsProcessor { |
72 dynamic_physics: DynamicPhysicsCollection, |
87 dynamic_physics: DynamicPhysicsCollection, |
147 self.static_physics.push(gear_id, gear_data); |
162 self.static_physics.push(gear_id, gear_data); |
148 } else { |
163 } else { |
149 self.dynamic_physics.push(gear_id, gear_data); |
164 self.dynamic_physics.push(gear_id, gear_data); |
150 } |
165 } |
151 } |
166 } |
|
167 |
|
168 fn remove(&mut self, gear_id: GearId) { |
|
169 self.static_physics.remove(gear_id); |
|
170 self.dynamic_physics.remove(gear_id) |
|
171 } |
152 } |
172 } |