diff options
| author | Valentin Popov <valentin@popov.link> | 2026-11-26 19:09:41 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-11-26 19:09:41 +0300 |
| commit | 2e0a4571af587f28ba5ea580f177a225d0d352e2 (patch) | |
| tree | af456896c423edd6bc8b45666e64f46689cd7bcf /apps/fparkan-game/src/projectile_render.rs | |
| parent | 4367287f9e07aca6a173a5eaef641a75918d66e0 (diff) | |
| download | fparkan-2e0a4571af587f28ba5ea580f177a225d0d352e2.tar.xz fparkan-2e0a4571af587f28ba5ea580f177a225d0d352e2.zip | |
fix(audio): attach the engine loop to the player's missile
Prepare velocity-driven Op2 sounds with the projectile's CTL attachment.
Move their source with the active flight and stop it when the flight ends
or its slot is reused. Keep launch as a separate one-shot.
The GOG phase function confirms the missile's 0 to 1 phase range.
In the stock Firing Line window the engine loop began at the tail and
stopped on terrain contact.
Diffstat (limited to 'apps/fparkan-game/src/projectile_render.rs')
| -rw-r--r-- | apps/fparkan-game/src/projectile_render.rs | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/apps/fparkan-game/src/projectile_render.rs b/apps/fparkan-game/src/projectile_render.rs index 866d8c5b..a45b0c57 100644 --- a/apps/fparkan-game/src/projectile_render.rs +++ b/apps/fparkan-game/src/projectile_render.rs @@ -1,10 +1,13 @@ //! Prepare and populate the shared projectile body and trail draw pools. use super::{ - append_static_preview_component, fixed_effect_field, projectile_trail, shot_sound, - static_preview_component_materials, PreparedEffectMaterial, StaticPreviewScene, + append_static_preview_component, cross3, fixed_effect_field, normalize3, projectile_sound, + projectile_trail, shot_sound, static_preview_component_materials, PreparedEffectMaterial, + StaticPreviewScene, +}; +use fparkan_assets::{ + load_resource_entry_bytes_from_root, PreparedControlEffectRow, PreparedControlEffectSection, }; -use fparkan_assets::{load_resource_entry_bytes_from_root, PreparedControlEffectSection}; use fparkan_fx::{ambient_sound::Op2SoundCommand, decode_fxid, FxDocument}; use fparkan_render::LegacyIron3dEulerTransform; use fparkan_render_vulkan::{ @@ -23,12 +26,14 @@ pub(super) struct ProjectileDraw { pub(super) lifetime_ms: u32, pub(super) volume: Option<f32>, pub(super) launch_sounds: Vec<Op2SoundCommand>, + pub(super) engine_sounds: Vec<projectile_sound::EngineSound>, pub(super) local_vertices: Vec<VulkanStaticVertex>, pub(super) instances: Vec<ProjectileDrawSlot>, } pub(super) struct ProjectileDrawSlot { pub(super) flight: Option<PlayerProjectile>, + pub(super) sound_born_ms: Option<u32>, pub(super) shooter: Option<ObjectHandle>, pub(super) vertex_start: usize, pub(super) draw_ranges: Range<usize>, @@ -101,6 +106,7 @@ pub(super) fn prepare_projectile_draw( .collect::<Result<_, _>>()?; instances.push(ProjectileDrawSlot { flight: None, + sound_born_ms: None, shooter: None, vertex_start, draw_ranges, @@ -112,17 +118,24 @@ pub(super) fn prepare_projectile_draw( speed: projectile.speed, lifetime_ms: projectile.lifetime_ms, volume: projectile.volume, - launch_sounds: shot_sound::projectile_launch(effects.iter().map(|(_, effect)| effect)), + launch_sounds: shot_sound::projectile_launch(effects.iter().map(|effect| &effect.document)), + engine_sounds: projectile_sound::prepare(&projectile, &effects), local_vertices: geometry.vertices, instances, })) } -pub(super) fn initial_effects( +pub(super) struct ProjectileEffect<'a> { + pub(super) row: &'a PreparedControlEffectRow, + pub(super) resource: String, + pub(super) document: FxDocument, +} + +pub(super) fn initial_effects<'a>( root: &Path, - projectile: &ProjectileAssets, + projectile: &'a ProjectileAssets, name: &str, -) -> Vec<(String, FxDocument)> { +) -> Vec<ProjectileEffect<'a>> { let Some(control) = projectile.assets.object_component_controls[0][0].as_ref() else { return Vec::new(); }; @@ -142,7 +155,11 @@ pub(super) fn initial_effects( .map_err(|error| error.to_string()) .and_then(|bytes| decode_fxid(bytes).map_err(|error| error.to_string())); match effect { - Ok(effect) => Some((format!("{archive}/{fx}"), effect)), + Ok(document) => Some(ProjectileEffect { + row, + resource: format!("{archive}/{fx}"), + document, + }), Err(_) => { eprintln!("sim_coverage projectile_trail_resource_stub=1 projectile={name} effect={archive}/{fx}"); None @@ -152,6 +169,11 @@ pub(super) fn initial_effects( .collect() } +pub(super) fn flight_basis(forward: [f32; 3]) -> [[f32; 3]; 3] { + let right = normalize3(cross3(forward, [0.0, 0.0, 1.0])).unwrap_or([1.0, 0.0, 0.0]); + [right, forward, cross3(right, forward)] +} + pub(super) fn sample_autonomous(draws: &mut [Option<ProjectileDraw>], engine: &Engine) { for instance in draws .iter_mut() |
