From 077bead07a76908ac4e0e2b84de3940256cf6fd1 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 2 Dec 2026 19:23:04 +0400 Subject: feat(ui): draw the cockpit reticle from the original atlas Use the native page9 crops, mirrored scales and hull-relative heading marker. Match the geometry against the original and run the stock Constructor cockpit with and without the satellite map under Vulkan validation. --- apps/fparkan-game/src/cockpit_reticle.rs | 87 ++++++++++++++++++++++++++++++++ apps/fparkan-game/src/main.rs | 1 + apps/fparkan-game/src/mission_overlay.rs | 32 ++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 apps/fparkan-game/src/cockpit_reticle.rs (limited to 'apps') diff --git a/apps/fparkan-game/src/cockpit_reticle.rs b/apps/fparkan-game/src/cockpit_reticle.rs new file mode 100644 index 00000000..4a2710c7 --- /dev/null +++ b/apps/fparkan-game/src/cockpit_reticle.rs @@ -0,0 +1,87 @@ +use super::{ + dot3, mission_overlay::add_overlay_sprite, screen_tl_quad_vertices_pixels, DirectoryVfs, + EnvironmentGpuRange, StaticPreviewScene, VulkanSmokeRenderer, VulkanStaticMesh, +}; +use fparkan_assets::{cockpit_reticle, RgbaImage}; +use fparkan_render::LegacyIron3dEulerTransform; +use std::path::Path; + +const MARKER_COLOR: [f32; 3] = [0.0, 1.0, 0.0]; +const MARKER_UV: [[f32; 2]; 4] = [[0.0, 0.0], [0.0, 1.0], [1.0, 1.0], [1.0, 0.0]]; + +pub(super) struct CockpitReticle { + scales: EnvironmentGpuRange, + marker: EnvironmentGpuRange, +} + +impl CockpitReticle { + pub(super) fn load(root: &Path, preview: &mut StaticPreviewScene) -> Result { + let image = cockpit_reticle::load(&DirectoryVfs::new(root))?; + let scales = add_overlay_sprite( + preview, + image, + cockpit_reticle::BOUNDS.map(|bound| bound as f32), + [1.0; 3], + 1.0, + )?; + let marker = add_overlay_sprite( + preview, + RgbaImage { + width: 1, + height: 1, + rgba8: vec![255; 4], + }, + [0.0; 4], + MARKER_COLOR, + 1.0, + )?; + Ok(Self { scales, marker }) + } + + pub(super) fn ranges(&self) -> [usize; 2] { + [self.scales.range_index, self.marker.range_index] + } + + pub(super) fn draw( + &self, + renderer: &mut VulkanSmokeRenderer, + mesh: &mut VulkanStaticMesh, + orientation: Option<[u32; 3]>, + camera_forward: [f32; 3], + ) -> Result<(), String> { + let hull = orientation.and_then(|orientation| { + LegacyIron3dEulerTransform { + translation: [0.0; 3], + orientation_radians: orientation.map(f32::from_bits), + } + .try_row_major() + }); + for range in self.ranges() { + renderer + .set_draw_range_index_count(range, if hull.is_some() { 6 } else { 0 }) + .map_err(|error| error.to_string())?; + } + let Some(hull) = hull else { + return Ok(()); + }; + let local = [0, 1].map(|column| { + dot3( + camera_forward, + [hull[column], hull[column + 4], hull[column + 8]], + ) + }); + let [left, top, right, bottom] = cockpit_reticle::heading_marker(local); + let vertices = screen_tl_quad_vertices_pixels( + [(left + right) * 0.5, (top + bottom) * 0.5], + (right - left) * 0.5, + (bottom - top) * 0.5, + [640.0, 480.0], + MARKER_COLOR, + 1.0, + MARKER_UV, + ); + let first = self.marker.vertex_start; + mesh.vertices[first..first + vertices.len()].copy_from_slice(&vertices); + Ok(()) + } +} diff --git a/apps/fparkan-game/src/main.rs b/apps/fparkan-game/src/main.rs index a95b4879..2dee309c 100644 --- a/apps/fparkan-game/src/main.rs +++ b/apps/fparkan-game/src/main.rs @@ -10,6 +10,7 @@ mod chassis_animation; mod cockpit_dial; mod cockpit_geometry; mod cockpit_radar_hud; +mod cockpit_reticle; #[cfg(windows)] mod control_effects; #[cfg(test)] diff --git a/apps/fparkan-game/src/mission_overlay.rs b/apps/fparkan-game/src/mission_overlay.rs index d253a074..f7b99c3a 100644 --- a/apps/fparkan-game/src/mission_overlay.rs +++ b/apps/fparkan-game/src/mission_overlay.rs @@ -2,6 +2,7 @@ use super::{ append_environment_gradient_material, append_environment_range, cockpit_dial::CockpitDial, cockpit_radar_hud::CockpitRadarHud, + cockpit_reticle::CockpitReticle, factory_menu::FactoryProjectPanel, horizontal_fov, quad_indices, satellite_map::SatelliteMap, @@ -44,6 +45,7 @@ pub(super) struct MissionOverlay { #[cfg(windows)] strategic_tooltip: Option, dial: Option, + reticle: Option, pub(super) factory_projects: Option, pub(super) radar: Option, #[cfg(windows)] @@ -84,6 +86,11 @@ impl MissionOverlay { None }) }); + let reticle = cockpit.and_then(|_| { + CockpitReticle::load(root, preview) + .inspect_err(|error| eprintln!("cockpit_reticle_unavailable reason={error}")) + .ok() + }); // iron3d+0x2cbb0 draws the AutoDemo balance rows under its top-aligned map. #[cfg(windows)] let strategy_balance = (autodemo || cockpit.is_some()) @@ -198,6 +205,7 @@ impl MissionOverlay { #[cfg(windows)] strategic_tooltip, dial, + reticle, factory_projects, radar, #[cfg(windows)] @@ -233,6 +241,11 @@ impl MissionOverlay { remove(range, ranges, counts); } } + if let Some(reticle) = &self.reticle { + for range in reticle.ranges() { + remove(range, ranges, counts); + } + } #[cfg(windows)] if let Some(balance) = &self.strategy_balance { remove(balance.range_index(), ranges, counts); @@ -443,6 +456,25 @@ impl StaticVulkanApp { }; let cockpit = self.cockpit.filter(|_| self.command_view.is_none()); let occupant = self.mission_engine.as_ref().zip(cockpit); + if let Some(reticle) = &self.overlay.reticle { + let orientation = + cockpit + .zip(self.mission_frame.as_ref()) + .and_then(|(cockpit, frame)| { + frame + .snapshot + .transforms + .iter() + .find(|(handle, _)| *handle == cockpit.handle) + .map(|(_, pose)| pose.orientation) + }); + reticle.draw( + renderer, + &mut self.mesh, + orientation, + frame.camera.forward(), + )?; + } if let Some(dial) = &mut self.overlay.dial { let view = cockpit.map(|_| { let [x, y, _] = frame.camera.forward(); -- cgit v1.2.3