aboutsummaryrefslogtreecommitdiff
path: root/apps/fparkan-game/src
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-01 23:45:44 +0300
committerValentin Popov <valentin@popov.link>2026-12-01 23:45:44 +0300
commit029297446ec0b235602b4f4d9197786a3466a6fe (patch)
treecf0371e18391f19879999452d11182e98f01a473 /apps/fparkan-game/src
parentb3d2b95b8dd5e4578e2889845809fe7c21c5886b (diff)
downloadfparkan-029297446ec0b235602b4f4d9197786a3466a6fe.tar.xz
fparkan-029297446ec0b235602b4f4d9197786a3466a6fe.zip
feat(ui): display cockpit view bearings and aperture
Read the visible cockpit camera to draw the original front and rear markers and field-of-view sector from the installed UI atlases. Check the indicator on a stock Fireline start and a separate Shift look with the weapon aim held.
Diffstat (limited to 'apps/fparkan-game/src')
-rw-r--r--apps/fparkan-game/src/course_hud.rs117
-rw-r--r--apps/fparkan-game/src/main.rs1
-rw-r--r--apps/fparkan-game/src/mission_overlay.rs25
3 files changed, 142 insertions, 1 deletions
diff --git a/apps/fparkan-game/src/course_hud.rs b/apps/fparkan-game/src/course_hud.rs
new file mode 100644
index 00000000..7e436271
--- /dev/null
+++ b/apps/fparkan-game/src/course_hud.rs
@@ -0,0 +1,117 @@
+use super::{
+ append_environment_gradient_material, append_environment_range, environment_vertex,
+ world_pipeline_state, DirectoryVfs, EnvironmentGpuRange, LegacyBlendMode, LegacyDepthMode,
+ StaticPreviewScene, VulkanSmokeRenderer, VulkanStaticMesh, VulkanStaticTexture,
+ VulkanStaticVertex,
+};
+use fparkan_assets::{ui_sprite::load_ui_page, RgbaImage};
+use fparkan_render::cockpit_course::{bearing_markers, view_sector};
+use std::path::Path;
+
+const MARKER_UVS: [[f32; 2]; 4] = [
+ [192.5 / 256.0, 154.5 / 256.0],
+ [192.5 / 256.0, 165.0 / 256.0],
+ [201.0 / 256.0, 154.5 / 256.0],
+ [201.0 / 256.0, 165.0 / 256.0],
+];
+const FRONT: [f32; 3] = [10.0 / 255.0, 10.0 / 255.0, 225.0 / 255.0];
+const REAR: [f32; 3] = [225.0 / 255.0, 10.0 / 255.0, 10.0 / 255.0];
+
+pub(super) struct CourseHud {
+ sector: EnvironmentGpuRange,
+ markers: EnvironmentGpuRange,
+}
+
+impl CourseHud {
+ pub(super) fn load(root: &Path, preview: &mut StaticPreviewScene) -> Result<Self, String> {
+ let vfs = DirectoryVfs::new(root);
+ let sector_page = load_ui_page(&vfs, "page7")?;
+ let marker_page = load_ui_page(&vfs, "page6")?;
+ if [
+ sector_page.width,
+ sector_page.height,
+ marker_page.width,
+ marker_page.height,
+ ] != [256; 4]
+ {
+ return Err("unexpected native course atlas dimensions".into());
+ }
+ let sector = append_range(preview, sector_page, 3, vec![0, 1, 2])?;
+ let markers = append_range(
+ preview,
+ marker_page,
+ 8,
+ vec![0, 1, 2, 2, 1, 3, 4, 5, 6, 6, 5, 7],
+ )?;
+ Ok(Self { sector, markers })
+ }
+
+ pub(super) fn ranges(&self) -> [usize; 2] {
+ [self.sector.range_index, self.markers.range_index]
+ }
+
+ pub(super) fn draw(
+ &self,
+ renderer: &mut VulkanSmokeRenderer,
+ mesh: &mut VulkanStaticMesh,
+ view: Option<([f32; 2], f32)>,
+ ) -> Result<(), String> {
+ for (range, count) in self.ranges().into_iter().zip([3, 12]) {
+ renderer
+ .set_draw_range_index_count(range, if view.is_some() { count } else { 0 })
+ .map_err(|error| error.to_string())?;
+ }
+ let Some((forward, fov)) = view else {
+ return Ok(());
+ };
+
+ let start = self.sector.vertex_start;
+ mesh.vertices[start..start + 3]
+ .copy_from_slice(&view_sector(fov).map(|(point, uv)| vertex(point, uv, [1.0; 3])));
+ let start = self.markers.vertex_start;
+ for ((corners, color), vertices) in bearing_markers(forward)
+ .into_iter()
+ .zip([FRONT, REAR])
+ .zip(mesh.vertices[start..start + 8].chunks_exact_mut(4))
+ {
+ for ((point, uv), output) in corners.into_iter().zip(MARKER_UVS).zip(vertices) {
+ *output = vertex(point, uv, color);
+ }
+ }
+ Ok(())
+ }
+}
+
+fn vertex([x, y]: [f32; 2], uv: [f32; 2], color: [f32; 3]) -> VulkanStaticVertex {
+ // Scaling the design coordinates and the viewport by the same factors
+ // cancels out when converting the original TL positions to NDC.
+ environment_vertex(
+ [x * (2.0 / 640.0) - 1.0, y * (2.0 / 480.0) - 1.0, 0.999],
+ color,
+ uv,
+ )
+}
+
+fn append_range(
+ preview: &mut StaticPreviewScene,
+ page: RgbaImage,
+ vertex_count: usize,
+ indices: Vec<u32>,
+) -> Result<EnvironmentGpuRange, String> {
+ let material = append_environment_gradient_material(&mut preview.materials)?;
+ preview.materials[material].screen_tl = true;
+ preview.materials[material].sky_far_depth = false;
+ preview.materials[material].texture = VulkanStaticTexture {
+ width: page.width,
+ height: page.height,
+ rgba8: page.rgba8,
+ mip_levels: Vec::new(),
+ };
+ append_environment_range(
+ &mut preview.mesh,
+ material,
+ vec![environment_vertex([0.0; 3], [1.0; 3], [0.0; 2]); vertex_count],
+ indices,
+ world_pipeline_state(LegacyBlendMode::SourceAlpha, LegacyDepthMode::Disabled),
+ )
+}
diff --git a/apps/fparkan-game/src/main.rs b/apps/fparkan-game/src/main.rs
index 4e044abe..c226d0da 100644
--- a/apps/fparkan-game/src/main.rs
+++ b/apps/fparkan-game/src/main.rs
@@ -10,6 +10,7 @@ mod chassis_animation;
mod cockpit_geometry;
#[cfg(windows)]
mod control_effects;
+mod course_hud;
#[cfg(test)]
use control_effects::advance_control_effect_instances;
mod damage_visibility;
diff --git a/apps/fparkan-game/src/mission_overlay.rs b/apps/fparkan-game/src/mission_overlay.rs
index a3b37d50..fb669e8d 100644
--- a/apps/fparkan-game/src/mission_overlay.rs
+++ b/apps/fparkan-game/src/mission_overlay.rs
@@ -1,5 +1,6 @@
use super::{
- altimeter_hud::AltimeterHud, satellite_map::SatelliteMap, StaticPreviewScene, StaticVulkanApp,
+ altimeter_hud::AltimeterHud, course_hud::CourseHud, horizontal_fov,
+ satellite_map::SatelliteMap, StaticPreviewScene, StaticVulkanApp,
};
#[cfg(windows)]
use super::{mission_hints::MissionHints, weapon_hud::WeaponHud};
@@ -25,6 +26,7 @@ pub(super) fn source_over(pixel: &mut [u8], source: &[u8]) {
#[derive(Default)]
pub(super) struct MissionOverlay {
pub(super) satellite_map: Option<SatelliteMap>,
+ course: Option<CourseHud>,
altimeter: Option<AltimeterHud>,
#[cfg(windows)]
pub(super) hints: Option<MissionHints>,
@@ -44,6 +46,14 @@ impl MissionOverlay {
return Self::default();
};
// The original draws the cockpit instruments before the satellite map.
+ let course = cockpit.and_then(|_| {
+ CourseHud::load(root, preview)
+ .map(Some)
+ .unwrap_or_else(|error| {
+ eprintln!("course_hud_unavailable reason={error}");
+ None
+ })
+ });
let altimeter = cockpit.and_then(|_| {
AltimeterHud::load(root, preview)
.map(Some)
@@ -75,6 +85,7 @@ impl MissionOverlay {
});
Self {
satellite_map,
+ course,
altimeter,
#[cfg(windows)]
hints,
@@ -102,6 +113,11 @@ impl MissionOverlay {
if let Some(altimeter) = &self.altimeter {
remove(altimeter.range_index(), ranges, counts);
}
+ if let Some(course) = &self.course {
+ for range in course.ranges() {
+ remove(range, ranges, counts);
+ }
+ }
#[cfg(windows)]
if let Some(hints) = &self.hints {
remove(hints.range_index(), ranges, counts);
@@ -134,6 +150,13 @@ impl StaticVulkanApp {
.and_then(|(engine, cockpit)| cockpit_altimeter(engine, cockpit));
altimeter.draw(renderer, &mut self.mesh, frame.viewport, state)?;
}
+ if let Some(course) = &self.overlay.course {
+ let view = self.cockpit.map(|_| {
+ let [x, y, _] = frame.camera.forward();
+ ([x, y], horizontal_fov(&frame.camera, frame.aspect))
+ });
+ course.draw(renderer, &mut self.mesh, view)?;
+ }
#[cfg(windows)]
if let Some(hints) = &mut self.overlay.hints {
let outcome = self