76 position_updates: PositionUpdates, |
76 position_updates: PositionUpdates, |
77 } |
77 } |
78 |
78 |
79 pub struct PositionUpdates { |
79 pub struct PositionUpdates { |
80 pub gear_ids: Vec<GearId>, |
80 pub gear_ids: Vec<GearId>, |
81 pub positions: Vec<FPPoint>, |
81 pub shifts: Vec<(FPPoint, FPPoint)>, |
82 } |
82 } |
83 |
83 |
84 impl PositionUpdates { |
84 impl PositionUpdates { |
85 pub fn new(capacity: usize) -> Self { |
85 pub fn new(capacity: usize) -> Self { |
86 Self { |
86 Self { |
87 gear_ids: Vec::with_capacity(capacity), |
87 gear_ids: Vec::with_capacity(capacity), |
88 positions: Vec::with_capacity(capacity), |
88 shifts: Vec::with_capacity(capacity), |
89 } |
89 } |
90 } |
90 } |
91 |
91 |
92 pub fn push(&mut self, gear_id: GearId, position: &FPPoint) { |
92 pub fn push(&mut self, gear_id: GearId, old_position: &FPPoint, new_position: &FPPoint) { |
93 self.gear_ids.push(gear_id); |
93 self.gear_ids.push(gear_id); |
94 self.positions.push(*position); |
94 self.shifts.push((*old_position, *new_position)); |
95 } |
95 } |
96 } |
96 } |
97 |
97 |
98 impl PhysicsProcessor { |
98 impl PhysicsProcessor { |
99 pub fn new() -> Self { |
99 pub fn new() -> Self { |
105 } |
105 } |
106 } |
106 } |
107 |
107 |
108 pub fn process(&mut self, time_step: FPNum) -> &PositionUpdates { |
108 pub fn process(&mut self, time_step: FPNum) -> &PositionUpdates { |
109 for (gear_id, (pos, vel)) in self.dynamic_physics.iter_pos_update() { |
109 for (gear_id, (pos, vel)) in self.dynamic_physics.iter_pos_update() { |
|
110 let old_pos = *pos; |
110 *pos += *vel * time_step; |
111 *pos += *vel * time_step; |
111 if !vel.is_zero() { |
112 if !vel.is_zero() { |
112 self.position_updates.push(gear_id, pos) |
113 self.position_updates.push(gear_id, &old_pos, pos) |
113 } else { |
114 } else { |
114 self.physics_cleanup.push(gear_id) |
115 self.physics_cleanup.push(gear_id) |
115 } |
116 } |
116 } |
117 } |
117 &self.position_updates |
118 &self.position_updates |