diff options
| author | Valentin Popov <valentin@popov.link> | 2026-12-03 16:57:40 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-12-03 16:57:40 +0300 |
| commit | ca66e64b3995229ca7c8771b75ca26a60c3e344f (patch) | |
| tree | afd011b8db83dc5a7e3d0585631eae8135aefc94 /crates/fparkan-runtime/src/player_motion.rs | |
| parent | e8978cf0a7f66fd36a3f47c5a616fbfd3a9d20b0 (diff) | |
| download | fparkan-ca66e64b3995229ca7c8771b75ca26a60c3e344f.tar.xz fparkan-ca66e64b3995229ca7c8771b75ca26a60c3e344f.zip | |
feat(ui): show cockpit speed and Control limit
Diffstat (limited to 'crates/fparkan-runtime/src/player_motion.rs')
| -rw-r--r-- | crates/fparkan-runtime/src/player_motion.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/crates/fparkan-runtime/src/player_motion.rs b/crates/fparkan-runtime/src/player_motion.rs index 6733f921..a32be631 100644 --- a/crates/fparkan-runtime/src/player_motion.rs +++ b/crates/fparkan-runtime/src/player_motion.rs @@ -71,6 +71,7 @@ pub struct PlayerMotionStep { pub(super) pitch_bits: u32, flight_velocity: Option<[f32; 3]>, hero_walk_velocity: Option<[f32; 2]>, + movement_seconds: f32, hero_look: Option<HeroLook>, turret: Option<crate::TurretAim>, max_floor_clearance: f32, @@ -100,6 +101,20 @@ impl WalkingSurface { } impl PlayerMotionStep { + fn speed(self) -> f32 { + use crate::cockpit_speedometer::{length, translation_speed}; + + if let Some(velocity) = self.flight_velocity { + length(velocity) + } else if let Some([x, y]) = self.hero_walk_velocity { + length([x, y, 0.0]) + } else { + self.sweep.map_or(0.0, |[[x0, y0, _], [x1, y1, _]]| { + translation_speed([x0, y0, 0.0], [x1, y1, 0.0], self.movement_seconds) + }) + } + } + /// Uses the scene's terrain after foundation cuts and fills. #[must_use] pub fn with_scene_terrain( @@ -228,6 +243,7 @@ mod tests { pitch_bits: 0, flight_velocity: None, hero_walk_velocity: None, + movement_seconds: 0.0, hero_look: None, turret: None, max_floor_clearance: FLOOR_CLEARANCE, @@ -269,6 +285,7 @@ mod tests { pitch_bits: 0, flight_velocity: None, hero_walk_velocity: None, + movement_seconds: 0.0, hero_look: None, turret: None, max_floor_clearance: 1.25, @@ -295,6 +312,7 @@ mod tests { pitch_bits: 0, flight_velocity: None, hero_walk_velocity: None, + movement_seconds: 0.0, hero_look: None, turret: None, max_floor_clearance: FLOOR_CLEARANCE, @@ -657,6 +675,12 @@ pub(super) fn commit_motion_state( if let Some(look) = step.hero_look { mission.hero_look = look; } + if mission + .boarding + .is_none_or(|board| board.controls_chassis()) + { + mission.cockpit_speed = if blocked { 0.0 } else { step.speed() }; + } } if let Some(boarding) = &mut mission.boarding { if boarding.cockpit.handle != cockpit.handle { @@ -774,6 +798,7 @@ fn plan_motion( pitch_bits: pitch.to_bits(), flight_velocity, hero_walk_velocity: None, + movement_seconds: input.delta_seconds, hero_look: None, turret: None, max_floor_clearance: FLOOR_CLEARANCE, |
