diff options
Diffstat (limited to 'apps/fparkan-game')
| -rw-r--r-- | apps/fparkan-game/src/cockpit_dial.rs | 39 | ||||
| -rw-r--r-- | apps/fparkan-game/src/cockpit_vertical_gauge.rs (renamed from apps/fparkan-game/src/altimeter_hud.rs) | 89 | ||||
| -rw-r--r-- | apps/fparkan-game/src/main.rs | 2 | ||||
| -rw-r--r-- | apps/fparkan-game/src/mission_overlay.rs | 11 |
4 files changed, 102 insertions, 39 deletions
diff --git a/apps/fparkan-game/src/cockpit_dial.rs b/apps/fparkan-game/src/cockpit_dial.rs index 3bbb0131..ff422dea 100644 --- a/apps/fparkan-game/src/cockpit_dial.rs +++ b/apps/fparkan-game/src/cockpit_dial.rs @@ -1,5 +1,6 @@ use super::{ - altimeter_hud::AltimeterHud, append_environment_gradient_material, append_environment_range, + append_environment_gradient_material, append_environment_range, + cockpit_vertical_gauge::{GaugeLayout, VerticalGaugeHud}, environment_vertex, quad_indices, screen_tl_quad_vertices_pixels, world_pipeline_state, DirectoryVfs, EnvironmentGpuRange, LegacyBlendMode, LegacyDepthMode, StaticPreviewScene, VulkanSmokeRenderer, VulkanStaticMesh, VulkanStaticTexture, VulkanStaticVertex, @@ -7,7 +8,8 @@ use super::{ use fparkan_assets::{game_font::load_layout_font, ui_sprite::load_ui_page, RgbaImage}; use fparkan_render::cockpit_course::{bearing_markers, view_sector}; use fparkan_runtime::cockpit_altimeter::Altimeter; -use std::path::Path; +use fparkan_runtime::cockpit_speedometer::Speedometer; +use std::{path::Path, sync::Arc}; const MARKER_UVS: [[f32; 2]; 4] = [ [192.5 / 256.0, 154.5 / 256.0], @@ -20,7 +22,8 @@ const REAR: [f32; 3] = [225.0 / 255.0, 10.0 / 255.0, 10.0 / 255.0]; pub(super) struct CockpitDial { bezel: EnvironmentGpuRange, - altimeter: AltimeterHud, + altimeter: VerticalGaugeHud, + speedometer: VerticalGaugeHud, sector: EnvironmentGpuRange, markers: EnvironmentGpuRange, } @@ -51,7 +54,17 @@ impl CockpitDial { quad_indices(2)?, world_pipeline_state(LegacyBlendMode::SourceAlpha, LegacyDepthMode::Disabled), )?; - let altimeter = AltimeterHud::load(marker_page, icons, font, preview)?; + let marker_page = Arc::new(marker_page); + let font = Arc::new(font); + let altimeter = VerticalGaugeHud::load( + GaugeLayout::ALTITUDE, + marker_page.clone(), + &icons, + font.clone(), + preview, + )?; + let speedometer = + VerticalGaugeHud::load(GaugeLayout::SPEED, marker_page, &icons, font, preview)?; let sector_material = atlas_material(preview, sector_page)?; let sector = append_range(preview, sector_material, 3, vec![0, 1, 2])?; let markers = append_range( @@ -63,15 +76,17 @@ impl CockpitDial { Ok(Self { bezel, altimeter, + speedometer, sector, markers, }) } - pub(super) fn ranges(&self) -> [usize; 4] { + pub(super) fn ranges(&self) -> [usize; 5] { [ self.bezel.range_index, self.altimeter.range_index(), + self.speedometer.range_index(), self.sector.range_index, self.markers.range_index, ] @@ -84,8 +99,20 @@ impl CockpitDial { viewport: [f32; 2], view: Option<([f32; 2], f32)>, altitude: Option<Altimeter>, + speed: Option<Speedometer>, ) -> Result<(), String> { - self.altimeter.draw(renderer, mesh, viewport, altitude)?; + self.altimeter.draw( + renderer, + mesh, + viewport, + altitude.map(|state| (state.altitude, state.scale_top)), + )?; + self.speedometer.draw( + renderer, + mesh, + viewport, + speed.map(|state| (state.speed, state.scale_top)), + )?; for (range, count) in [(self.bezel, 12), (self.sector, 3), (self.markers, 12)] { renderer .set_draw_range_index_count( diff --git a/apps/fparkan-game/src/altimeter_hud.rs b/apps/fparkan-game/src/cockpit_vertical_gauge.rs index 9a7b4865..49a7314d 100644 --- a/apps/fparkan-game/src/altimeter_hud.rs +++ b/apps/fparkan-game/src/cockpit_vertical_gauge.rs @@ -5,28 +5,60 @@ use super::{ StaticPreviewScene, VulkanSmokeRenderer, VulkanStaticMesh, VulkanStaticTexture, }; use fparkan_assets::{game_font::BitmapFont, RgbaImage}; -use fparkan_runtime::cockpit_altimeter::Altimeter; +use std::sync::Arc; -const LEFT: u32 = 221; const TOP: u32 = 347; const WIDTH: u32 = 50; const HEIGHT: u32 = 110; +const SCALE_HEIGHT: u32 = 105; const WHITE: [u8; 3] = [255; 3]; const UV: [[f32; 2]; 4] = [[0.0, 0.0], [0.0, 1.0], [1.0, 1.0], [1.0, 0.0]]; -pub(super) struct AltimeterHud { +#[derive(Clone, Copy)] +pub(super) struct GaugeLayout { + left: u32, + icon_src: u32, + icon_left: u32, + number_left: u32, + strip_left: u32, + flip_strip: bool, +} + +impl GaugeLayout { + pub(super) const ALTITUDE: Self = Self { + left: 221, + icon_src: 215, + icon_left: 230, + number_left: 226, + strip_left: 240, + flip_strip: true, + }; + + pub(super) const SPEED: Self = Self { + left: 370, + icon_src: 199, + icon_left: 396, + number_left: 388, + strip_left: 370, + flip_strip: false, + }; +} + +pub(super) struct VerticalGaugeHud { range: EnvironmentGpuRange, backing: VulkanStaticTexture, - page: RgbaImage, - font: BitmapFont, - previous: Option<Altimeter>, + layout: GaugeLayout, + page: Arc<RgbaImage>, + font: Arc<BitmapFont>, + previous: Option<(i32, u32)>, } -impl AltimeterHud { +impl VerticalGaugeHud { pub(super) fn load( - page: RgbaImage, - icons: RgbaImage, - font: BitmapFont, + layout: GaugeLayout, + page: Arc<RgbaImage>, + icons: &RgbaImage, + font: Arc<BitmapFont>, preview: &mut StaticPreviewScene, ) -> Result<Self, String> { let mut backing = VulkanStaticTexture { @@ -35,12 +67,12 @@ impl AltimeterHud { rgba8: vec![0; (WIDTH * HEIGHT * 4) as usize], mip_levels: Vec::new(), }; - // iron3d+0x3f6a0 and +0x3ff00 select and position the altitude icon. + // iron3d+0x3f6a0 and +0x3ff00 select and position the icons. blit( &mut backing, - &icons, - [215, 0, 15, 28], - [230, 383], + icons, + [layout.icon_src, 0, 15, 28], + [layout.icon_left - layout.left, 383 - TOP], false, WHITE, ); @@ -59,6 +91,7 @@ impl AltimeterHud { Ok(Self { range, backing, + layout, page, font, previous: None, @@ -74,38 +107,32 @@ impl AltimeterHud { renderer: &mut VulkanSmokeRenderer, mesh: &mut VulkanStaticMesh, viewport: [f32; 2], - state: Option<Altimeter>, + state: Option<(i32, u32)>, ) -> Result<(), String> { renderer .set_draw_range_index_count(self.range_index(), if state.is_some() { 6 } else { 0 }) .map_err(|error| error.to_string())?; let Some(state) = state else { return Ok(()) }; if self.previous != Some(state) { + let (value, scale_top) = state; + let layout = self.layout; let mut sprite = self.backing.clone(); - let text = self - .font - .centered_line(&state.altitude.to_string(), 28, 11)?; + let text = self.font.centered_line(&value.to_string(), 28, 11)?; blit( &mut sprite, &text, [0, 0, text.width, text.height], - [226, 445], + [layout.number_left - layout.left, 445 - TOP], false, WHITE, ); - // iron3d+0x3fc18 crops the same rows from the texture and the screen; - // the lower end stays fixed and the top follows the indicated altitude. + // Both bars crop the same rows from the texture and screen. blit( &mut sprite, &self.page, - [ - 121, - state.scale_top, - 31, - Altimeter::SCALE_HEIGHT - state.scale_top, - ], - [240, TOP + state.scale_top], - true, + [121, scale_top, 31, SCALE_HEIGHT - scale_top], + [layout.strip_left - layout.left, scale_top], + layout.flip_strip, [0xff, 0xb4, 0x50], ); renderer @@ -118,7 +145,7 @@ impl AltimeterHud { let half_width = WIDTH as f32 * 0.5; let half_height = HEIGHT as f32 * 0.5; let center = [ - (LEFT as f32 + half_width) * sx, + (self.layout.left as f32 + half_width) * sx, (TOP as f32 + half_height) * sy, ]; let start = self.range.vertex_start; @@ -151,7 +178,7 @@ fn blit( for (channel, tint) in pixel.iter_mut().zip(tint) { *channel = ((u16::from(*channel) * u16::from(tint) + 127) / 255) as u8; } - let dst = (((top - TOP + row) * WIDTH + left - LEFT + col) * 4) as usize; + let dst = (((top + row) * WIDTH + left + col) * 4) as usize; source_over(&mut target.rgba8[dst..dst + 4], &pixel); } } diff --git a/apps/fparkan-game/src/main.rs b/apps/fparkan-game/src/main.rs index 4b677f59..35721de9 100644 --- a/apps/fparkan-game/src/main.rs +++ b/apps/fparkan-game/src/main.rs @@ -4,7 +4,6 @@ use fparkan_runtime::initial_component_node_times as static_preview_node_times; -mod altimeter_hud; mod camera_capture; mod chassis_animation; mod cockpit_dial; @@ -13,6 +12,7 @@ mod cockpit_geometry; mod cockpit_instrument; mod cockpit_radar_hud; mod cockpit_reticle; +mod cockpit_vertical_gauge; #[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 e8185f4a..fe646cc6 100644 --- a/apps/fparkan-game/src/mission_overlay.rs +++ b/apps/fparkan-game/src/mission_overlay.rs @@ -27,6 +27,7 @@ use super::{ use fparkan_assets::RgbaImage; use fparkan_runtime::{ cockpit_altimeter::cockpit_altimeter, + cockpit_speedometer::cockpit_speedometer, radar::{cockpit_radar_period, cockpit_range_readout}, AutoDemoCamera, Engine, StartingCockpit, }; @@ -526,7 +527,15 @@ impl StaticVulkanApp { }); let altitude = occupant.and_then(|(engine, cockpit)| cockpit_altimeter(engine, cockpit)); - dial.draw(renderer, &mut self.mesh, frame.viewport, view, altitude)?; + let speed = occupant.and_then(|(engine, cockpit)| cockpit_speedometer(engine, cockpit)); + dial.draw( + renderer, + &mut self.mesh, + frame.viewport, + view, + altitude, + speed, + )?; } if let Some(radar) = &mut self.overlay.radar { let period = |
