aboutsummaryrefslogtreecommitdiff
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
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.
-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
-rw-r--r--crates/fparkan-render/src/cockpit_radar.rs81
-rw-r--r--crates/fparkan-runtime/src/radar.rs32
-rw-r--r--docs/appendices/knowledge-boundaries.md2
-rw-r--r--docs/appendices/ui-shell.md12
-rw-r--r--docs/reference/original-binaries.md1
8 files changed, 256 insertions, 19 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)),
diff --git a/crates/fparkan-render/src/cockpit_radar.rs b/crates/fparkan-render/src/cockpit_radar.rs
index f14fe3c6..e9043362 100644
--- a/crates/fparkan-render/src/cockpit_radar.rs
+++ b/crates/fparkan-render/src/cockpit_radar.rs
@@ -3,6 +3,59 @@
use crate::cockpit_course::CENTER;
use std::f64::consts::FRAC_PI_2;
+pub const SWEEP_EDGES: usize = 20;
+
+/// Clock state held by the cockpit radar panel.
+#[derive(Default)]
+pub struct RadarSweep {
+ start_ms: Option<u32>,
+}
+
+impl RadarSweep {
+ /// Returns the native design radius and whether this paint starts a new sweep.
+ /// `radar_period_ms` is the positive period supplied by Control.
+ pub fn sample(&mut self, now_ms: u32, radar_period_ms: f32) -> (u32, bool) {
+ let duration = f64::from(radar_period_ms * 0.002);
+ if let Some(start_ms) = self.start_ms {
+ let elapsed = f64::from(now_ms.wrapping_sub(start_ms)) * f64::from(0.001_f32);
+ if elapsed <= duration {
+ let radius = (60.0 / duration * f64::from(elapsed as f32)).round_ties_even();
+ return (radius as u32, false);
+ }
+ }
+ self.start_ms = Some(now_ms);
+ (0, true)
+ }
+}
+
+/// The 20 native line segments, expanded to a one-pixel stroke in screen space.
+/// The caller omits the degenerate outline at radius zero.
+pub fn sweep_outline(radius: u32, viewport: [f32; 2]) -> [[[f32; 2]; 2]; SWEEP_EDGES] {
+ let [sx, sy] = [viewport[0] / 640.0, viewport[1] / 480.0];
+ let points: [[f32; 2]; SWEEP_EDGES] = std::array::from_fn(|index| {
+ let angle = index as f32 * (std::f32::consts::TAU / SWEEP_EDGES as f32);
+ let (sin, cos) = angle.sin_cos();
+ let r = radius as f32;
+ [(CENTER[0] + r * cos) * sx, (CENTER[1] + r * sin) * sy]
+ });
+ let normal = |[ax, ay]: [f32; 2], [bx, by]: [f32; 2]| {
+ let [dx, dy] = [bx - ax, by - ay];
+ let length = dx.hypot(dy);
+ [dy / length, -dx / length]
+ };
+ std::array::from_fn(|i| {
+ let point = points[i];
+ let [nx, ny] = normal(points[(i + SWEEP_EDGES - 1) % SWEEP_EDGES], point);
+ let [mx, my] = normal(point, points[(i + 1) % SWEEP_EDGES]);
+ let scale = 0.5 / (1.0 + nx * mx + ny * my);
+ let [dx, dy] = [(nx + mx) * scale, (ny + my) * scale];
+ [
+ [point[0] + dx, point[1] + dy],
+ [point[0] - dx, point[1] - dy],
+ ]
+ })
+}
+
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum ContactMark {
Building,
@@ -83,6 +136,34 @@ mod tests {
use super::*;
#[test]
+ fn sweep_restarts_only_after_the_native_strict_boundary() {
+ let mut sweep = RadarSweep::default();
+ assert_eq!(sweep.sample(0, 750.0), (0, true));
+ assert_eq!(sweep.sample(775, 750.0), (31, false));
+ assert_eq!(sweep.sample(1500, 750.0), (60, false));
+ assert_eq!(sweep.sample(1501, 750.0), (0, true));
+ assert_eq!(sweep.sample(1501, 750.0), (0, false));
+ assert_eq!(sweep.sample(5100, 750.0), (0, true));
+ }
+
+ #[test]
+ fn sweep_polygon_matches_native_800_by_600_vertices() {
+ let outline = sweep_outline(31, [800.0, 600.0]);
+ for (index, native) in [
+ (0, [438.75, 495.0]),
+ (1, [436.85345, 506.97446]),
+ (5, [400.0, 533.75]),
+ (13, [377.22327, 463.65067]),
+ ] {
+ let [outer, inner] = outline[index];
+ for axis in 0..2 {
+ let center = (outer[axis] + inner[axis]) * 0.5;
+ assert!((center - native[axis]).abs() < 0.001);
+ }
+ }
+ }
+
+ #[test]
fn cockpit_radar_rotates_with_view_and_maps_range_to_sixty_design_pixels() {
let viewport = [800.0, 600.0];
assert_eq!(
diff --git a/crates/fparkan-runtime/src/radar.rs b/crates/fparkan-runtime/src/radar.rs
index a6cb9f78..677c3348 100644
--- a/crates/fparkan-runtime/src/radar.rs
+++ b/crates/fparkan-runtime/src/radar.rs
@@ -41,14 +41,30 @@ pub struct CockpitContact {
/// The range printed on the cockpit dial, even when the antenna is unpowered.
#[must_use]
pub fn cockpit_range_readout(engine: &Engine, cockpit: StartingCockpit) -> i32 {
- let range = engine.loaded.as_ref().and_then(|mission| {
- let table = mission
- .control_device_tables
- .iter()
- .find(|table| table.handle == cockpit.handle)?;
- Some(f32::from_bits(radar_device(table)?.coefficient_bits?[3]))
- });
- range_readout(range)
+ range_readout(cockpit_radar_coefficient(engine, cockpit, 3))
+}
+
+/// The installed radar's period for the HUD sweep, from Control selector 0xa9.
+#[must_use]
+pub fn cockpit_radar_period(engine: &Engine, cockpit: StartingCockpit) -> Option<f32> {
+ cockpit_radar_coefficient(engine, cockpit, 4)
+ .filter(|period| period.is_finite() && *period > 0.0)
+}
+
+fn cockpit_radar_coefficient(
+ engine: &Engine,
+ cockpit: StartingCockpit,
+ index: usize,
+) -> Option<f32> {
+ let table = engine
+ .loaded
+ .as_ref()?
+ .control_device_tables
+ .iter()
+ .find(|table| table.handle == cockpit.handle)?;
+ Some(f32::from_bits(
+ radar_device(table)?.coefficient_bits?[index],
+ ))
}
fn range_readout(range: Option<f32>) -> i32 {
diff --git a/docs/appendices/knowledge-boundaries.md b/docs/appendices/knowledge-boundaries.md
index 968c3e08..e5260571 100644
--- a/docs/appendices/knowledge-boundaries.md
+++ b/docs/appendices/knowledge-boundaries.md
@@ -1424,7 +1424,7 @@ layout или glyph drawing. `menu_resources.cfg` и шесть варианто
semantics, focus/navigation и HUD state machine.
В нижнем радаре рамка следует за целью, выбранной для пересадки. Ещё открыты
-полный выбор цели оригинала, отметки группы, импульс радара, спидометр и
+полный выбор цели оригинала, отметки группы, спидометр и
кнопки на рамке прибора.
Закрывающий эксперимент: сопоставить оставшиеся детали `shell_ctrls.cfg`,
diff --git a/docs/appendices/ui-shell.md b/docs/appendices/ui-shell.md
index e291666a..27fdeca4 100644
--- a/docs/appendices/ui-shell.md
+++ b/docs/appendices/ui-shell.md
@@ -319,6 +319,18 @@ Control. Оружейный цикл в `Control.dll` по RVA `0x29ca0` разÐ
в строке от `x=303` до `x=340` при `y=467`.
[Хеш сборки iron3d.dll](../reference/original-binaries.md).
+Импульс радара идёт от центра к краю шкалы. `iron3d.dll` по RVA `0x403ed`
+запрашивает период датчика через Control `0xa9` и удваивает его. Например,
+при периоде датчика 750 мс круг доходит до радиуса 60 за 1,5 секунды.
+Радиус округляется перед выводом. На первом кадре, где время строго больше
+двух периодов, радиус сбрасывается и звучит `RADAR` из `ui/game_resources.cfg`.
+При пропуске кадров начинается один новый круг. Засечки на круге по-прежнему
+обновляет скан датчика по собственному периоду.
+
+`services.dll` по RVA `0x1910` рисует импульс ломаной из 20 отрезков. Центр
+совпадает с центром прибора, цвет имеет ARGB `0x8c009b00`. Засечки рисуются
+после импульса и перекрывают его. [Хеши сборок](../reference/original-binaries.md).
+
## Контракт новой реализации
UI scene хранит корневые widgets, focus, viewport/clip rectangles и modal
diff --git a/docs/reference/original-binaries.md b/docs/reference/original-binaries.md
index 0c1d2e7e..49a35567 100644
--- a/docs/reference/original-binaries.md
+++ b/docs/reference/original-binaries.md
@@ -26,6 +26,7 @@ Part 1/Part 2 builds remain listed separately above.
| `Control.dll` | 299008 | `bcb86318089028548a178b03a21accdce15df0cc85ddd91674cf3c2f55012c6e` |
| `Effect.dll` | 163840 | `386a3e8db1ce23f61957825d633c7dae1ed40c25cab0cf10a534385fd7cee789` |
| `iron3d.dll` | 1175552 | `d1dc4ea8535e2069b0a05c9e8be2724dd438ba44cca7a83007d8b2e50f9e35fa` |
+| `services.dll` | 311296 | `d3619deeb4d598b16099e0263e15f9c3213f0faa7208dc093328cfba93fdc0ea` |
| `Terrain.dll` | 499712 | `af87d1b2e728a0be73c52be3b44cc196ab46da7799f25a15d40f8c9b0b425ead` |
## Различающиеся модули