diff options
| author | Valentin Popov <valentin@popov.link> | 2026-11-26 05:40:09 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-11-26 05:40:09 +0300 |
| commit | 5a2aa6ff6b6f4ab2480eed5be90957377d00c9e2 (patch) | |
| tree | 158d1f3450a092797b4b87745eef56db1622c2bd /crates/fparkan-runtime/src/player_weapon.rs | |
| parent | 3837bebc873a32914139e8987a34716008da716c (diff) | |
| download | fparkan-5a2aa6ff6b6f4ab2480eed5be90957377d00c9e2.tar.xz fparkan-5a2aa6ff6b6f4ab2480eed5be90957377d00c9e2.zip | |
feat(combat): play spatial sounds for autonomous weapon shots
Carry the firing effect and muzzle position on the shot event. Resolve single-gun effects by their matching muzzle point when there is no node link. Play each one-shot as its simulation frame arrives.
Verified a stock gun sound enqueues a spatial voice with the flight starting position. AutoDemo ran with Vulkan validation clean and no playback errors. Comparison by ear with the original remains open.
Diffstat (limited to 'crates/fparkan-runtime/src/player_weapon.rs')
| -rw-r--r-- | crates/fparkan-runtime/src/player_weapon.rs | 66 |
1 files changed, 46 insertions, 20 deletions
diff --git a/crates/fparkan-runtime/src/player_weapon.rs b/crates/fparkan-runtime/src/player_weapon.rs index b301bc1a..48517342 100644 --- a/crates/fparkan-runtime/src/player_weapon.rs +++ b/crates/fparkan-runtime/src/player_weapon.rs @@ -1,6 +1,7 @@ use crate::{Engine, StartingCockpit}; use fparkan_assets::{ PreparedComponentControl, PreparedControlEffectSection, PreparedControlPoint, + PreparedControlTimelineRow, }; /// A unit's selectable weapon devices, in resource order. @@ -300,26 +301,7 @@ fn prepare_weapons( } else { return None; }; - let effect = match &control.effect_section { - PreparedControlEffectSection::Parsed(rows) => control - .node_effect_links - .iter() - .find(|&&(group, node, _)| { - Some(group) == control.initial_effect_group - && node as usize == row.node_index - }) - .and_then(|&(group, _, selector)| { - rows.iter() - .find(|row| row.table_index == group && row.selector == selector) - }) - .and_then(|row| { - Some(( - crate::bounded_ascii_c_string(&row.resource.archive)?, - crate::bounded_ascii_c_string(&row.resource.name)?, - )) - }), - _ => None, - }; + let effect = firing_effect(control, row); Some(PlayerWeapon { component_index, control_record_index, @@ -341,6 +323,50 @@ fn prepare_weapons( .collect() } +fn firing_effect( + control: &PreparedComponentControl, + muzzle: &PreparedControlTimelineRow, +) -> Option<(String, String)> { + let PreparedControlEffectSection::Parsed(rows) = &control.effect_section else { + return None; + }; + let group = control.initial_effect_group?; + let row = if let Some(&(_, _, selector)) = control + .node_effect_links + .iter() + .find(|&&(table, node, _)| table == group && node as usize == muzzle.node_index) + { + rows.iter() + .find(|row| row.table_index == group && row.selector == selector)? + } else { + // Separate gun meshes can have one firing record and an effect whose + // first control point is the same muzzle. Ambiguous rows stay unresolved. + if control + .typed_records + .iter() + .filter(|record| record.tag == 2) + .nth(1) + .is_some() + { + return None; + } + let mut candidates = rows.iter().filter(|row| { + row.table_index == group + && row.raw_condition == [0; 3] + && row.point_offsets[0] == muzzle.raw_parameters[1] + }); + let row = candidates.next()?; + if candidates.next().is_some() { + return None; + } + row + }; + Some(( + crate::bounded_ascii_c_string(&row.resource.archive)?, + crate::bounded_ascii_c_string(&row.resource.name)?, + )) +} + pub(super) fn prepare_unit_weapons(controls: &[Option<PreparedComponentControl>]) -> PlayerWeapons { PlayerWeapons { weapons: controls |
