aboutsummaryrefslogtreecommitdiff
path: root/apps/fparkan-game/src/course_hud.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-02 00:14:54 +0300
committerValentin Popov <valentin@popov.link>2026-12-02 00:14:54 +0300
commit3efc5ba5d3389da168b00f8fe47d3478821e5d7f (patch)
tree8b222a05c28944eb05e815198872ae5f514db3b0 /apps/fparkan-game/src/course_hud.rs
parent752d34af83acf9a818e22c621fb034913079acff (diff)
downloadfparkan-3efc5ba5d3389da168b00f8fe47d3478821e5d7f.tar.xz
fparkan-3efc5ba5d3389da168b00f8fe47d3478821e5d7f.zip
feat(ui): restore the original cockpit radar dial
Use the mirrored source atlas halves and show the installed sensor range with the original font. The stock Fireline cockpit reads 300 and the Two Fortresses cockpit reads 400. The range query agrees with the original libraries for both inactive and missing devices.
Diffstat (limited to 'apps/fparkan-game/src/course_hud.rs')
-rw-r--r--apps/fparkan-game/src/course_hud.rs117
1 files changed, 0 insertions, 117 deletions
diff --git a/apps/fparkan-game/src/course_hud.rs b/apps/fparkan-game/src/course_hud.rs
deleted file mode 100644
index 7e436271..00000000
--- a/apps/fparkan-game/src/course_hud.rs
+++ /dev/null
@@ -1,117 +0,0 @@
-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),
- )
-}