From ca66e64b3995229ca7c8771b75ca26a60c3e344f Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Thu, 3 Dec 2026 17:57:40 +0400 Subject: feat(ui): show cockpit speed and Control limit --- crates/fparkan-runtime/src/player_motion.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'crates/fparkan-runtime/src/player_motion.rs') 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, turret: Option, 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, -- cgit v1.2.3