From b3d2b95b8dd5e4578e2889845809fe7c21c5886b Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 2 Dec 2026 00:31:29 +0400 Subject: feat(ui): show cockpit altitude above mission sea level --- apps/fparkan-game/src/mission_overlay.rs | 46 +++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 4 deletions(-) (limited to 'apps/fparkan-game/src/mission_overlay.rs') diff --git a/apps/fparkan-game/src/mission_overlay.rs b/apps/fparkan-game/src/mission_overlay.rs index 6c87492c..a3b37d50 100644 --- a/apps/fparkan-game/src/mission_overlay.rs +++ b/apps/fparkan-game/src/mission_overlay.rs @@ -1,12 +1,31 @@ +use super::{ + altimeter_hud::AltimeterHud, satellite_map::SatelliteMap, StaticPreviewScene, StaticVulkanApp, +}; #[cfg(windows)] use super::{mission_hints::MissionHints, weapon_hud::WeaponHud}; -use super::{satellite_map::SatelliteMap, StaticPreviewScene, StaticVulkanApp}; -use fparkan_runtime::{Engine, StartingCockpit}; +use fparkan_runtime::{cockpit_altimeter::cockpit_altimeter, Engine, StartingCockpit}; use std::path::Path; +/// Source-over composition for original sprite texels and their alpha masks. +pub(super) fn source_over(pixel: &mut [u8], source: &[u8]) { + let alpha = u32::from(source[3]); + if alpha == 0 { + return; + } + let under = (u32::from(pixel[3]) * (255 - alpha) + 127) / 255; + let combined = alpha + under; + for index in 0..3 { + pixel[index] = + ((u32::from(source[index]) * alpha + u32::from(pixel[index]) * under + combined / 2) + / combined) as u8; + } + pixel[3] = combined as u8; +} + #[derive(Default)] pub(super) struct MissionOverlay { pub(super) satellite_map: Option, + altimeter: Option, #[cfg(windows)] pub(super) hints: Option, #[cfg(windows)] @@ -24,6 +43,15 @@ impl MissionOverlay { let Some(engine) = engine else { return Self::default(); }; + // The original draws the cockpit instruments before the satellite map. + let altimeter = cockpit.and_then(|_| { + AltimeterHud::load(root, preview) + .map(Some) + .unwrap_or_else(|error| { + eprintln!("altimeter_unavailable reason={error}"); + None + }) + }); #[cfg(windows)] let hints = MissionHints::load(root, mission, preview) .map(Some) @@ -45,10 +73,9 @@ impl MissionOverlay { None }) }); - #[cfg(not(windows))] - let _ = cockpit; Self { satellite_map, + altimeter, #[cfg(windows)] hints, #[cfg(windows)] @@ -72,6 +99,9 @@ impl MissionOverlay { remove(range, ranges, counts); } } + if let Some(altimeter) = &self.altimeter { + remove(altimeter.range_index(), ranges, counts); + } #[cfg(windows)] if let Some(hints) = &self.hints { remove(hints.range_index(), ranges, counts); @@ -96,6 +126,14 @@ impl StaticVulkanApp { .map(|(engine, cockpit)| (engine, cockpit, self.boarding_target)); map.draw(renderer, &mut self.mesh, frame.viewport, player)?; } + if let Some(altimeter) = &mut self.overlay.altimeter { + let state = self + .mission_engine + .as_ref() + .zip(self.cockpit) + .and_then(|(engine, cockpit)| cockpit_altimeter(engine, cockpit)); + altimeter.draw(renderer, &mut self.mesh, frame.viewport, state)?; + } #[cfg(windows)] if let Some(hints) = &mut self.overlay.hints { let outcome = self -- cgit v1.2.3