# HG changeset patch # User alfadur # Date 1616533909 -10800 # Node ID f4b563a9ac5e32a853e39552e6a3e51b73302e0e # Parent 50315e39d7055bb94970331f87d42c9627fabd82 add const generics to physics step diff -r 50315e39d705 -r f4b563a9ac5e rust/hwphysics/src/common.rs --- a/rust/hwphysics/src/common.rs Mon Mar 15 15:57:19 2021 -0400 +++ b/rust/hwphysics/src/common.rs Wed Mar 24 00:11:49 2021 +0300 @@ -9,12 +9,12 @@ impl Millis { #[inline] - pub fn new(value: u32) -> Self { + pub const fn new(value: u32) -> Self { Self(value) } #[inline] - pub fn get(self) -> u32 { + pub const fn get(self) -> u32 { self.0 } diff -r 50315e39d705 -r f4b563a9ac5e rust/hwphysics/src/lib.rs --- a/rust/hwphysics/src/lib.rs Mon Mar 15 15:57:19 2021 -0400 +++ b/rust/hwphysics/src/lib.rs Wed Mar 24 00:11:49 2021 +0300 @@ -48,12 +48,7 @@ } pub fn step(&mut self, time_step: Millis, land: &Land2D) { - let updates = if time_step == Millis::new(1) { - self.physics.process_single_tick(&mut self.data) - } else { - self.physics - .process_multiple_ticks(&mut self.data, time_step) - }; + let updates = self.physics.process(&mut self.data, time_step); let collisions = self.collision.process(land, &updates); } diff -r 50315e39d705 -r f4b563a9ac5e rust/hwphysics/src/physics.rs --- 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::(data, time_step) + } else { + self.process_impl::(data, time_step) + } + } + + fn process_impl( + &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) }, );