aboutsummaryrefslogtreecommitdiff
path: root/apps/fparkan-game/src
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-02 00:24:00 +0300
committerValentin Popov <valentin@popov.link>2026-12-02 00:24:00 +0300
commit72eff35e96ea0c9029248d8403c0a37f63642b79 (patch)
tree3aeda01bd2ccbe9940e2e6caab44e2435129a13d /apps/fparkan-game/src
parent3efc5ba5d3389da168b00f8fe47d3478821e5d7f (diff)
downloadfparkan-72eff35e96ea0c9029248d8403c0a37f63642b79.tar.xz
fparkan-72eff35e96ea0c9029248d8403c0a37f63642b79.zip
feat(ui): animate and sound the original radar sweep
Draw the native 20-segment outline over the cockpit dial and under its contacts. Read the installed radar period and restart only after two periods, playing the configured RADAR cue independently of mission speech. Check the growing and reset sweep on the stock Fireline start.
Diffstat (limited to 'apps/fparkan-game/src')
-rw-r--r--apps/fparkan-game/src/audio.rs50
-rw-r--r--apps/fparkan-game/src/cockpit_radar_hud.rs78
-rw-r--r--apps/fparkan-game/src/mission_overlay.rs19
3 files changed, 137 insertions, 10 deletions
diff --git a/apps/fparkan-game/src/audio.rs b/apps/fparkan-game/src/audio.rs
index 90ddd6d7..4e180ba2 100644
--- a/apps/fparkan-game/src/audio.rs
+++ b/apps/fparkan-game/src/audio.rs
@@ -638,6 +638,8 @@ pub(crate) struct GameAudio {
music: Player,
variations: Player,
mission_voice: Player,
+ radar: Player,
+ radar_sample: Option<SoundAsset>,
vehicle_capture_voice: capture_voice::VehicleCaptureVoice,
mission_cfg: NormalizedPath,
weather_loop: NativeSpatialPlayer,
@@ -676,6 +678,7 @@ impl GameAudio {
let music = Player::connect_new(stream.mixer());
let variations = Player::connect_new(stream.mixer());
let mission_voice = Player::connect_new(stream.mixer());
+ let radar = Player::connect_new(stream.mixer());
let listener = Listener::default();
let (left, right) = ear_positions(listener)?;
let weather_loop =
@@ -686,6 +689,8 @@ impl GameAudio {
music,
variations,
mission_voice,
+ radar,
+ radar_sample: None,
vehicle_capture_voice: capture_voice::VehicleCaptureVoice::new(random_seed()),
mission_cfg,
weather_loop,
@@ -699,6 +704,15 @@ impl GameAudio {
weather_volume: 1.0,
weather_position: listener.position,
};
+ audio.radar_sample = audio
+ .game_sound_resource("RADAR")
+ .and_then(|(archive, file)| {
+ audio
+ .dynamic_sound(&archive, &file)
+ .map_err(|error| error.to_string())
+ })
+ .map_err(|error| eprintln!("radar_audio_unavailable reason={error}"))
+ .ok();
audio.start_theme()?;
audio.play_music_track(DEFAULT_MUSIC_TRACK)?;
Ok(audio)
@@ -954,6 +968,7 @@ impl GameAudio {
&self.music,
&self.variations,
&self.mission_voice,
+ &self.radar,
] {
if paused {
player.pause();
@@ -988,6 +1003,7 @@ impl GameAudio {
self.music.stop();
self.variations.stop();
self.mission_voice.stop();
+ self.radar.stop();
self.weather_loop.stop();
for player in self.control_sounds.values() {
player.stop();
@@ -1028,6 +1044,11 @@ impl GameAudio {
}
pub(crate) fn queue_game_voice(&mut self, symbol: &str) -> Result<String, String> {
+ let (archive, file) = self.game_sound_resource(symbol)?;
+ self.queue_voice_asset(&archive, &file)
+ }
+
+ fn game_sound_resource(&self, symbol: &str) -> Result<(String, String), String> {
let path = normalize_relative(b"ui/game_resources.cfg", PathPolicy::StrictLegacy)
.expect("valid game resources path");
let bytes = self
@@ -1035,9 +1056,24 @@ impl GameAudio {
.vfs
.read(&path)
.map_err(|error| error.to_string())?;
- let (archive, file) = voice_resource(&bytes, symbol)?
- .ok_or_else(|| format!("voice resource {symbol} is missing in {}", path.as_str()))?;
- self.queue_voice_asset(&archive, &file)
+ voice_resource(&bytes, symbol)?
+ .ok_or_else(|| format!("sound {symbol} is missing in {}", path.as_str()))
+ }
+
+ /// Plays the original non-positional radar pulse alongside mission speech.
+ pub(crate) fn play_radar_pulse(&mut self) -> Result<(), AudioError> {
+ if self.paused {
+ return Ok(());
+ }
+ let Some(sample) = self.radar_sample.take() else {
+ return Ok(());
+ };
+ let source = decoder_for(&sample)?;
+ self.radar.clear();
+ self.radar.append(source);
+ self.radar.play();
+ self.radar_sample = Some(sample);
+ Ok(())
}
fn queue_voice_asset(&mut self, archive: &str, file: &str) -> Result<String, String> {
@@ -1968,6 +2004,13 @@ mod tests {
let vfs: Arc<dyn Vfs> = Arc::new(fparkan_vfs::DirectoryVfs::new(&root));
let mut audio =
GameAudio::new(vfs, "MISSIONS/Autodemo.00/data.tma").expect("open original game audio");
+ let radar_sample = audio.radar_sample.as_ref().expect("original radar sample");
+ assert_eq!(radar_sample.resource_name(), "sounds.lib:i_radar.wav");
+ audio
+ .play_radar_pulse()
+ .expect("play original radar sample");
+ assert!(!audio.radar.empty());
+ assert!(audio.mission_voice.empty());
audio
.handle_sound_event(&SoundEvent {
archive: "sounds.lib".to_string(),
@@ -2014,6 +2057,7 @@ mod tests {
assert!(audio.control_sound_is_playing(ControlSoundId::Effect(1)));
assert!(!audio.weather_loop.empty());
audio.set_paused(true);
+ assert!(audio.radar.is_paused());
assert!(audio
.control_sounds
.values()
diff --git a/apps/fparkan-game/src/cockpit_radar_hud.rs b/apps/fparkan-game/src/cockpit_radar_hud.rs
index 53161ec2..832d126d 100644
--- a/apps/fparkan-game/src/cockpit_radar_hud.rs
+++ b/apps/fparkan-game/src/cockpit_radar_hud.rs
@@ -1,11 +1,14 @@
use super::{
append_environment_gradient_material, append_environment_range, environment_vertex,
- quad_indices, screen_tl_quad_vertices_pixels, world_pipeline_state, DirectoryVfs,
- EnvironmentGpuRange, LegacyBlendMode, LegacyDepthMode, StaticPreviewScene,
- VulkanDynamicDrawRange, VulkanSmokeRenderer, VulkanStaticMesh, VulkanStaticTexture,
+ environment_vertex_with_alpha, quad_indices, screen_tl_quad_vertices_pixels,
+ world_pipeline_state, DirectoryVfs, EnvironmentGpuRange, LegacyBlendMode, LegacyDepthMode,
+ StaticPreviewScene, VulkanDynamicDrawRange, VulkanSmokeRenderer, VulkanStaticMesh,
+ VulkanStaticTexture,
};
use fparkan_assets::game_font::{load_layout_font, BitmapFont};
-use fparkan_render::cockpit_radar::{contact_pixel, mark_rectangles};
+use fparkan_render::cockpit_radar::{
+ contact_pixel, mark_rectangles, sweep_outline, RadarSweep, SWEEP_EDGES,
+};
use fparkan_runtime::{radar::cockpit_contacts, Engine, StartingCockpit};
use fparkan_world::ObjectHandle;
use std::path::Path;
@@ -13,6 +16,8 @@ use std::path::Path;
const LABEL_SIZE: [u32; 2] = [37, 11];
pub(super) struct CockpitRadarHud {
+ sweep: EnvironmentGpuRange,
+ sweep_clock: RadarSweep,
contacts: usize,
label: EnvironmentGpuRange,
font: BitmapFont,
@@ -25,6 +30,13 @@ impl CockpitRadarHud {
let material = append_environment_gradient_material(&mut preview.materials)?;
preview.materials[material].screen_tl = true;
preview.materials[material].sky_far_depth = false;
+ let sweep = append_environment_range(
+ &mut preview.mesh,
+ material,
+ vec![environment_vertex([0.0; 3], [1.0; 3], [0.0; 2]); SWEEP_EDGES * 4],
+ quad_indices(SWEEP_EDGES)?,
+ world_pipeline_state(LegacyBlendMode::SourceAlpha, LegacyDepthMode::Disabled),
+ )?;
let range = append_environment_range(
&mut preview.mesh,
material,
@@ -61,6 +73,8 @@ impl CockpitRadarHud {
world_pipeline_state(LegacyBlendMode::SourceAlpha, LegacyDepthMode::Disabled),
)?;
Ok(Self {
+ sweep,
+ sweep_clock: RadarSweep::default(),
contacts: range.range_index,
label,
font,
@@ -68,8 +82,60 @@ impl CockpitRadarHud {
})
}
- pub(super) fn ranges(&self) -> [usize; 2] {
- [self.contacts, self.label.range_index]
+ pub(super) fn ranges(&self) -> [usize; 3] {
+ [
+ self.sweep.range_index,
+ self.contacts,
+ self.label.range_index,
+ ]
+ }
+
+ /// Whether a new sweep began and the HUD should play its original sound.
+ pub(super) fn draw_sweep(
+ &mut self,
+ renderer: &mut VulkanSmokeRenderer,
+ mesh: &mut VulkanStaticMesh,
+ viewport: [f32; 2],
+ now_ms: u32,
+ period_ms: Option<f32>,
+ ) -> Result<bool, String> {
+ let (radius, restarted) =
+ period_ms.map_or((0, false), |period| self.sweep_clock.sample(now_ms, period));
+ renderer
+ .set_draw_range_index_count(
+ self.sweep.range_index,
+ if radius == 0 {
+ 0
+ } else {
+ (SWEEP_EDGES * 6) as u32
+ },
+ )
+ .map_err(|error| error.to_string())?;
+ if radius > 0 {
+ let outline = sweep_outline(radius, viewport);
+ let vertex = |[x, y]: [f32; 2]| {
+ environment_vertex_with_alpha(
+ [
+ x * (2.0 / viewport[0]) - 1.0,
+ y * (2.0 / viewport[1]) - 1.0,
+ 0.999,
+ ],
+ [0.0, 155.0 / 255.0, 0.0],
+ 140.0 / 255.0,
+ [0.0; 2],
+ )
+ };
+ let start = self.sweep.vertex_start;
+ for (i, vertices) in mesh.vertices[start..start + SWEEP_EDGES * 4]
+ .chunks_exact_mut(4)
+ .enumerate()
+ {
+ let [outer, inner] = outline[i];
+ let [next_outer, next_inner] = outline[(i + 1) % SWEEP_EDGES];
+ vertices.copy_from_slice(&[outer, inner, next_outer, next_inner].map(vertex));
+ }
+ }
+ Ok(restarted)
}
pub(super) fn draw_readout(
diff --git a/apps/fparkan-game/src/mission_overlay.rs b/apps/fparkan-game/src/mission_overlay.rs
index 7eec86b2..f46983c4 100644
--- a/apps/fparkan-game/src/mission_overlay.rs
+++ b/apps/fparkan-game/src/mission_overlay.rs
@@ -5,7 +5,9 @@ use super::{
#[cfg(windows)]
use super::{mission_hints::MissionHints, weapon_hud::WeaponHud};
use fparkan_runtime::{
- cockpit_altimeter::cockpit_altimeter, radar::cockpit_range_readout, Engine, StartingCockpit,
+ cockpit_altimeter::cockpit_altimeter,
+ radar::{cockpit_radar_period, cockpit_range_readout},
+ Engine, StartingCockpit,
};
use std::path::Path;
@@ -157,6 +159,21 @@ impl StaticVulkanApp {
dial.draw(renderer, &mut self.mesh, frame.viewport, view, altitude)?;
}
if let Some(radar) = &mut self.overlay.radar {
+ let period =
+ occupant.and_then(|(engine, cockpit)| cockpit_radar_period(engine, cockpit));
+ if radar.draw_sweep(
+ renderer,
+ &mut self.mesh,
+ frame.viewport,
+ frame.clock.time_ms,
+ period,
+ )? {
+ if let Some(audio) = &mut self.audio {
+ if let Err(error) = audio.play_radar_pulse() {
+ eprintln!("radar_audio_unavailable reason={error}");
+ }
+ }
+ }
radar.draw_readout(
renderer,
occupant.map(|(engine, cockpit)| cockpit_range_readout(engine, cockpit)),