aboutsummaryrefslogtreecommitdiff
path: root/apps/fparkan-game/src/mission_overlay.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-01 23:31:29 +0300
committerValentin Popov <valentin@popov.link>2026-12-01 23:31:29 +0300
commitb3d2b95b8dd5e4578e2889845809fe7c21c5886b (patch)
tree97c106a587c350cb82f05fc20c477c3e89f6aba9 /apps/fparkan-game/src/mission_overlay.rs
parentc3e2add9a189879b5e800344e07645af591a2cbd (diff)
downloadfparkan-b3d2b95b8dd5e4578e2889845809fe7c21c5886b.tar.xz
fparkan-b3d2b95b8dd5e4578e2889845809fe7c21c5886b.zip
feat(ui): show cockpit altitude above mission sea level
Diffstat (limited to 'apps/fparkan-game/src/mission_overlay.rs')
-rw-r--r--apps/fparkan-game/src/mission_overlay.rs46
1 files changed, 42 insertions, 4 deletions
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<SatelliteMap>,
+ altimeter: Option<AltimeterHud>,
#[cfg(windows)]
pub(super) hints: Option<MissionHints>,
#[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