# HG changeset patch # User alfadur # Date 1567544843 -10800 # Node ID 0ef770a40e758ed8cfac0ebe8daa1c4362ebcccb # Parent b387a51705ac9d0fedef50fde99411d9269c9791 add wind to physics processor diff -r b387a51705ac -r 0ef770a40e75 rust/hwphysics/src/data.rs --- a/rust/hwphysics/src/data.rs Tue Sep 03 23:57:06 2019 +0300 +++ b/rust/hwphysics/src/data.rs Wed Sep 04 00:07:23 2019 +0300 @@ -14,7 +14,7 @@ } impl TypeTuple for () { - fn get_types(types: &mut Vec) {} + fn get_types(_types: &mut Vec) {} } impl TypeTuple for &T { diff -r b387a51705ac -r 0ef770a40e75 rust/hwphysics/src/physics.rs --- a/rust/hwphysics/src/physics.rs Tue Sep 03 23:57:06 2019 +0300 +++ b/rust/hwphysics/src/physics.rs Wed Sep 04 00:07:23 2019 +0300 @@ -12,6 +12,8 @@ #[repr(transparent)] pub struct VelocityData(pub FPPoint); +pub struct AffectedByWind; + pub struct PositionUpdates { pub gear_ids: Vec, pub shifts: Vec<(FPPoint, FPPoint)>, @@ -46,6 +48,7 @@ pub struct PhysicsProcessor { gravity: FPNum, + wind: FPNum, position_updates: PositionUpdates, } @@ -53,22 +56,33 @@ pub fn register_components(data: &mut GearDataManager) { data.register::(); data.register::(); + data.register::(); } pub fn new() -> Self { Self { gravity: fp!(1 / 10), + wind: fp!(0), position_updates: PositionUpdates::new(64), } } 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 -= self.gravity; + vel.0 += gravity; pos.0 += vel.0; self.position_updates.push(gear_id, &old_pos, &pos.0) }, @@ -83,12 +97,21 @@ time_step: Millis, ) -> &PositionUpdates { let fp_step = time_step.to_fixed(); + let gravity = FPPoint::unit_y() * (self.gravity * fp_step); + let wind = FPPoint::unit_x() * (self.wind * fp_step); + 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 -= self.gravity * fp_step; + vel.0 += gravity; pos.0 += vel.0 * fp_step; self.position_updates.push(gear_id, &old_pos, &pos.0) },