equal
deleted
inserted
replaced
9 pub struct PositionData(pub FPPoint); |
9 pub struct PositionData(pub FPPoint); |
10 |
10 |
11 #[derive(PartialEq, Eq, Clone, Copy, Debug)] |
11 #[derive(PartialEq, Eq, Clone, Copy, Debug)] |
12 #[repr(transparent)] |
12 #[repr(transparent)] |
13 pub struct VelocityData(pub FPPoint); |
13 pub struct VelocityData(pub FPPoint); |
14 |
|
15 pub struct PhysicsProcessor { |
|
16 position_updates: PositionUpdates, |
|
17 } |
|
18 |
14 |
19 pub struct PositionUpdates { |
15 pub struct PositionUpdates { |
20 pub gear_ids: Vec<GearId>, |
16 pub gear_ids: Vec<GearId>, |
21 pub shifts: Vec<(FPPoint, FPPoint)>, |
17 pub shifts: Vec<(FPPoint, FPPoint)>, |
22 } |
18 } |
46 self.gear_ids.clear(); |
42 self.gear_ids.clear(); |
47 self.shifts.clear(); |
43 self.shifts.clear(); |
48 } |
44 } |
49 } |
45 } |
50 |
46 |
|
47 pub struct PhysicsProcessor { |
|
48 gravity: FPNum, |
|
49 position_updates: PositionUpdates, |
|
50 } |
|
51 |
51 impl PhysicsProcessor { |
52 impl PhysicsProcessor { |
52 pub fn register_components(data: &mut GearDataManager) { |
53 pub fn register_components(data: &mut GearDataManager) { |
53 data.register::<PositionData>(); |
54 data.register::<PositionData>(); |
54 data.register::<VelocityData>(); |
55 data.register::<VelocityData>(); |
55 } |
56 } |
56 |
57 |
57 pub fn new() -> Self { |
58 pub fn new() -> Self { |
58 Self { |
59 Self { |
|
60 gravity: fp!(100), |
59 position_updates: PositionUpdates::new(64), |
61 position_updates: PositionUpdates::new(64), |
60 } |
62 } |
61 } |
63 } |
62 |
64 |
63 pub fn process(&mut self, data: &mut GearDataManager, time_step: Millis) -> &PositionUpdates { |
65 pub fn process(&mut self, data: &mut GearDataManager, time_step: Millis) -> &PositionUpdates { |
66 |
68 |
67 data.iter_id( |
69 data.iter_id( |
68 |gear_id, (pos, vel): (&mut PositionData, &mut VelocityData)| { |
70 |gear_id, (pos, vel): (&mut PositionData, &mut VelocityData)| { |
69 if !vel.0.is_zero() { |
71 if !vel.0.is_zero() { |
70 let old_pos = pos.0; |
72 let old_pos = pos.0; |
|
73 vel.0 -= self.gravity * fp_step; |
71 pos.0 += vel.0 * fp_step; |
74 pos.0 += vel.0 * fp_step; |
72 self.position_updates.push(gear_id, &old_pos, &pos.0) |
75 self.position_updates.push(gear_id, &old_pos, &pos.0) |
73 } |
76 } |
74 }, |
77 }, |
75 ); |
78 ); |