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 /apps/fparkan-game/src/audio.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 'apps/fparkan-game/src/audio.rs')
| -rw-r--r-- | apps/fparkan-game/src/audio.rs | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/apps/fparkan-game/src/audio.rs b/apps/fparkan-game/src/audio.rs index f70f36c2..c0af0418 100644 --- a/apps/fparkan-game/src/audio.rs +++ b/apps/fparkan-game/src/audio.rs @@ -1871,6 +1871,68 @@ mod tests { #[test] #[ignore = "requires installed GOG assets and a usable OS audio output"] + fn stock_autonomous_shot_starts_a_spatial_voice_at_its_muzzle() { + use fparkan_runtime::{ + autonomous_weapon_effects, create, frame, load_gameplay_mission, AutoDemoCombatEvent, + EngineServices, MissionMode, MissionRequest, MissionStartupInput, + }; + const MISSION: &str = "MISSIONS/Autodemo.00/data.tma"; + let root = std::env::var_os("FPARKAN_GAME_ROOT") + .map(std::path::PathBuf::from) + .unwrap_or_else(|| std::path::PathBuf::from(r"C:\GOG Games\Parkan - Iron Strategy")); + let vfs: Arc<dyn Vfs> = Arc::new(fparkan_vfs::DirectoryVfs::new(&root)); + let mut engine = create(EngineServices::new(vfs.clone())).unwrap(); + load_gameplay_mission( + &mut engine, + MissionRequest { + key: MISSION.into(), + mode: MissionMode::AutoDemo, + }, + MissionStartupInput { + queue_time_ms: 0, + research_creation_gate: false, + }, + None, + ) + .unwrap(); + let sounds: Vec<_> = autonomous_weapon_effects(&engine) + .iter() + .map(|(archive, name)| crate::shot_sound::load(&root, archive, name)) + .collect(); + for now in (0..=60_000).step_by(50) { + let frame = frame(&mut engine, now).unwrap(); + for event in &frame.autodemo_combat_events { + let AutoDemoCombatEvent::Shot { + effect: Some(effect), + muzzle_bits, + .. + } = *event + else { + continue; + }; + if sounds[effect].is_none() { + continue; + } + let mut audio = GameAudio::new(vfs, MISSION).expect("open game audio"); + audio.set_paused(true); + crate::shot_sound::play_autonomous( + &sounds, + std::slice::from_ref(event), + &mut audio, + ); + let voice = audio.one_shots.last().expect("queued spatial weapon sound"); + assert_eq!( + voice.player.state.lock().unwrap().emitter_position, + muzzle_bits.map(f32::from_bits) + ); + return; + } + } + panic!("no stock autonomous shot selected a supported sound effect"); + } + + #[test] + #[ignore = "requires installed GOG assets and a usable OS audio output"] fn starts_pauses_and_drops_gog_audio() { let root = std::env::var_os("FPARKAN_GAME_ROOT") .map(std::path::PathBuf::from) |
