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/unit_patrol.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/unit_patrol.rs')
| -rw-r--r-- | crates/fparkan-runtime/src/unit_patrol.rs | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/crates/fparkan-runtime/src/unit_patrol.rs b/crates/fparkan-runtime/src/unit_patrol.rs index c25b309f..a22543b6 100644 --- a/crates/fparkan-runtime/src/unit_patrol.rs +++ b/crates/fparkan-runtime/src/unit_patrol.rs @@ -71,6 +71,7 @@ pub(super) struct PatrollingUnit { pub(super) struct PreparedPatrol { pub(super) state: UnitPatrol, poses: Vec<(ObjectHandle, TransformState, TransformState)>, + seconds: f32, } #[derive(Clone, Copy)] @@ -880,7 +881,11 @@ impl UnitPatrol { poses.push((unit.handle, before, after)); } } - Ok(PreparedPatrol { state, poses }) + Ok(PreparedPatrol { + state, + poses, + seconds, + }) } } @@ -1126,6 +1131,21 @@ fn choose_route( } impl PreparedPatrol { + pub(super) fn speed_of(&self, handle: ObjectHandle, can_fly: bool) -> f32 { + self.poses + .iter() + .find(|(moved, _, _)| *moved == handle) + .map_or(0.0, |(_, before, after)| { + let from = before.position.map(f32::from_bits); + let mut to = after.position.map(f32::from_bits); + if !can_fly { + // Ground support moves the root vertically without driving the chassis. + to[2] = from[2]; + } + crate::cockpit_speedometer::translation_speed(from, to, self.seconds) + }) + } + pub(super) fn apply_poses(&self, world: &mut World) -> Result<(), EngineError> { // These handles were read during preparation and the world has yet to step. for &(handle, _, after) in &self.poses { |
