From 4367287f9e07aca6a173a5eaef641a75918d66e0 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Thu, 26 Nov 2026 20:02:16 +0400 Subject: fix(audio): start node-attached laser sounds during wind-up Use the weapon descriptor's Control group to select the mode-1 sound rows. Update them through the existing FX clock and spatial Op2 playback for both manual and autonomous weapons. The GOG Control/Effect entry points confirm the selector, epoch and phase threshold, including retriggering after a sample at the exact phase peak. The stock Two Fortresses helicopter started the original sound at both weapon nodes in a Vulkan window. --- crates/fparkan-runtime/src/player_weapon.rs | 49 ++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'crates/fparkan-runtime/src/player_weapon.rs') diff --git a/crates/fparkan-runtime/src/player_weapon.rs b/crates/fparkan-runtime/src/player_weapon.rs index cfec0524..0ab0613f 100644 --- a/crates/fparkan-runtime/src/player_weapon.rs +++ b/crates/fparkan-runtime/src/player_weapon.rs @@ -1,4 +1,4 @@ -use crate::{Engine, StartingCockpit}; +use crate::{Engine, FiringEffectInstance, StartingCockpit}; use fparkan_assets::{ PreparedComponentControl, PreparedControlEffectRow, PreparedControlEffectSection, PreparedControlPoint, PreparedControlTimelineRow, @@ -29,6 +29,8 @@ pub struct PlayerWeapon { /// Optional type-4 effect started by this weapon. pub effect: Option<(String, String)>, pub(super) effect_row: Option<(usize, usize)>, + windup_sound_rows: Vec<(usize, usize)>, + windup_started: bool, barrels: Vec, barrel_index: usize, rounds_remaining: Option, @@ -77,6 +79,17 @@ impl PlayerWeapons { &self.weapons } + /// Control sound instances whose wind-up began on this sample. + pub fn started_windup_sounds( + &self, + object_index: usize, + ) -> impl Iterator + '_ { + self.weapons + .iter() + .filter(|weapon| weapon.windup_started) + .flat_map(move |weapon| weapon.windup_sounds(object_index)) + } + /// Samples the barrel tracks after advancing the weapon bank on this frame. pub fn apply_firing_pose(&self, component: usize, node_times: &mut [Option]) { for weapon in self @@ -155,6 +168,7 @@ impl PlayerWeapons { impl PlayerWeapon { fn sample_fire(&mut self, trigger: bool, now: f64) -> Option { let mut shot = None; + self.windup_started = false; while now > self.phase_end_ms || self.phase == FirePhase::Idle { // shortcut: leave a second overdue shot pending until the next simulation sample. if self.phase == FirePhase::Shot && shot.is_some() { @@ -186,6 +200,7 @@ impl PlayerWeapon { break; } self.phase = FirePhase::Shot; + self.windup_started = true; barrel.travel_to(0.5) } FirePhase::Shot => { @@ -215,6 +230,21 @@ impl PlayerWeapon { shot } + /// Prepared node-attached sound rows belonging to this device. + pub fn windup_sounds( + &self, + object_index: usize, + ) -> impl Iterator + '_ { + self.windup_sound_rows + .iter() + .map(move |&(table_index, row_index)| FiringEffectInstance { + object_index, + component_index: self.component_index, + table_index, + row_index, + }) + } + /// Remaining shots, or `None` for an unlimited weapon. pub fn rounds_remaining(&self) -> Option { self.rounds_remaining @@ -360,6 +390,11 @@ fn prepare_weapons( projectile_archive, effect, effect_row: effect_row.map(|row| (row.table_index, row.row_index)), + windup_sound_rows: control + .weapon_windup_sound_rows(record) + .map(|row| (row.table_index, row.row_index)) + .collect(), + windup_started: false, barrels, barrel_index: 0, rounds_remaining, @@ -443,6 +478,8 @@ mod tests { projectile_archive: String::from("test.rlb"), effect: None, effect_row: None, + windup_sound_rows: vec![(0, 1)], + windup_started: false, barrels: vec![Barrel { muzzle: PreparedControlPoint { raw_flags: 0, @@ -482,7 +519,17 @@ mod tests { }); let mut node_times = [None]; assert!(weapons.fire(true, 0).next().is_none()); + assert_eq!( + weapons.started_windup_sounds(7).collect::>(), + [FiringEffectInstance { + object_index: 7, + component_index: 0, + table_index: 0, + row_index: 1, + }] + ); assert!(weapons.fire(false, 5).next().is_none()); + assert!(weapons.started_windup_sounds(7).next().is_none()); weapons.apply_firing_pose(0, &mut node_times); assert_eq!(node_times, [Some(5.0)]); assert!(weapons.fire(false, 10).next().is_none()); -- cgit v1.2.3