--- a/rust/hwphysics/src/physics.rs Mon Mar 15 15:57:19 2021 -0400
+++ b/rust/hwphysics/src/physics.rs Wed Mar 24 00:11:49 2021 +0300
@@ -67,36 +67,28 @@
}
}
- pub fn process_single_tick(&mut self, data: &mut GearDataManager) -> &PositionUpdates {
- let gravity = FPPoint::unit_y() * self.gravity;
- let wind = FPPoint::unit_x() * self.wind;
-
- self.position_updates.clear();
-
- data.iter()
- .with_tags::<&AffectedByWind>()
- .run(|(vel,): (&mut VelocityData,)| {
- vel.0 += wind;
- });
-
- data.iter().run_id(
- |gear_id, (pos, vel): (&mut PositionData, &mut VelocityData)| {
- let old_pos = pos.0;
- vel.0 += gravity;
- pos.0 += vel.0;
- self.position_updates.push(gear_id, &old_pos, &pos.0)
- },
- );
-
- &self.position_updates
- }
-
- pub fn process_multiple_ticks(
+ pub fn process(
&mut self,
data: &mut GearDataManager,
time_step: Millis,
) -> &PositionUpdates {
- let fp_step = time_step.to_fixed();
+ if time_step == Millis::new(1) {
+ self.process_impl::<true>(data, time_step)
+ } else {
+ self.process_impl::<false>(data, time_step)
+ }
+ }
+
+ fn process_impl<const SINGLE_TICK: bool>(
+ &mut self,
+ data: &mut GearDataManager,
+ time_step: Millis,
+ ) -> &PositionUpdates {
+ let fp_step = if SINGLE_TICK {
+ fp!(1)
+ } else {
+ time_step.to_fixed()
+ };
let gravity = FPPoint::unit_y() * (self.gravity * fp_step);
let wind = FPPoint::unit_x() * (self.wind * fp_step);
@@ -112,7 +104,7 @@
|gear_id, (pos, vel): (&mut PositionData, &mut VelocityData)| {
let old_pos = pos.0;
vel.0 += gravity;
- pos.0 += vel.0 * fp_step;
+ pos.0 += if SINGLE_TICK { vel.0 } else { vel.0 * fp_step };
self.position_updates.push(gear_id, &old_pos, &pos.0)
},
);