diff options
| author | Valentin Popov <valentin@popov.link> | 2026-11-27 01:41:33 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-11-27 01:41:33 +0300 |
| commit | 5a29afc412a129d9b8d3bd8e6840cc3250921952 (patch) | |
| tree | 33034062ac069bf4361b1282fb1bd85a3026beea /apps/fparkan-game/src | |
| parent | fa8b449bf66997506feeef9d85e07e89bc7c20b4 (diff) | |
| download | fparkan-5a29afc412a129d9b8d3bd8e6840cc3250921952.tar.xz fparkan-5a29afc412a129d9b8d3bd8e6840cc3250921952.zip | |
fix(render): drive manual firing flashes from linked barrel nodes
Use the current authored barrel blend as Effect mode 4 input when Control links the effect to that node. Leave projectile release and direct shot audio on their existing clocks.
Verified the bound node and phase flags against GOG AniMesh and Effect, covered the stock Constructor cannon, and compared the flash at two phases in a validation-clean mission window.
Diffstat (limited to 'apps/fparkan-game/src')
| -rw-r--r-- | apps/fparkan-game/src/control_effects.rs | 76 | ||||
| -rw-r--r-- | apps/fparkan-game/src/main.rs | 41 |
2 files changed, 85 insertions, 32 deletions
diff --git a/apps/fparkan-game/src/control_effects.rs b/apps/fparkan-game/src/control_effects.rs index 735a0975..910bba81 100644 --- a/apps/fparkan-game/src/control_effects.rs +++ b/apps/fparkan-game/src/control_effects.rs @@ -9,7 +9,7 @@ use fparkan_runtime::{ }; use std::collections::{HashMap, HashSet}; -pub(super) fn owner_control_capacity( +fn owner_control_capacity( engine: &Engine, roots: &[Option<MissionRenderRoot>], index: usize, @@ -36,6 +36,62 @@ impl From<FiringEffectInstance> for ControlEffectInstanceKey { } impl StaticVulkanApp { + pub(super) fn sample_control_effects( + &mut self, + sample_id: SceneSampleId, + clock_ms: u32, + manager_flag: bool, + player_shots: Vec<FiringEffectInstance>, + ) -> ( + HashMap<ControlEffectInstanceKey, ControlEffectFrameSample>, + HashSet<ControlEffectInstanceKey>, + ) { + let weapon_phases: HashMap<_, _> = self + .cockpit + .and_then(|cockpit| { + let weapons = self.player_weapon_banks.get(&cockpit.handle)?; + Some(weapons.firing_effect_phases(cockpit.object_index)) + }) + .into_iter() + .flatten() + .map(|(effect, phase)| (effect.into(), phase)) + .collect(); + let mut samples = advance_control_effect_instances( + &mut self.control_effect_instance_states, + &self.ambient_effect_slots, + &self.control_point_light_slots, + &self.control_sound_slots, + sample_id, + clock_ms, + manager_flag, + |index| { + owner_control_capacity( + self.mission_engine.as_ref()?, + &self.mission_render_roots, + index, + ) + }, + |index| self.motion_effects.provider(index), + |key| weapon_phases.get(&key).copied(), + ); + let mut direct_shot_sounds = activate_firing_flashes( + &mut samples, + &self.ambient_effect_slots, + &self.control_point_light_slots, + self.mission_frame + .as_ref() + .map_or(&[][..], |frame| &frame.autodemo_combat_events), + player_shots, + &weapon_phases, + ); + // Manual weapon audio is already emitted with the projectile. + direct_shot_sounds.extend(self.control_sound_slots.iter().filter_map(|sound| { + let key = sound.effect.random_instance_key; + (sound.effect.time_mode == 4 && weapon_phases.contains_key(&key)).then_some(key) + })); + (samples, direct_shot_sounds) + } + pub(super) fn start_windup_sounds( &mut self, control_clock_ms: u32, @@ -103,6 +159,7 @@ pub(super) fn advance_control_effect_instances( manager_flag: bool, owner_capacity: impl Fn(usize) -> Option<(f32, f32)>, owner_motion: impl Fn(usize) -> Option<FxPhaseProvider>, + owner_effect_phase: impl Fn(ControlEffectInstanceKey) -> Option<f32>, ) -> HashMap<ControlEffectInstanceKey, ControlEffectFrameSample> { let mut specifications = HashMap::new(); for slot in ambient_slots { @@ -155,6 +212,11 @@ pub(super) fn advance_control_effect_instances( eprintln!("render_coverage control_fx_owner_state_stub=1 (missing Control capacity; instance={key:?} mode={mode})"); } } + } else if mode == 4 { + if let Some(phase) = owner_effect_phase(key) { + provider.effect_value = phase; + resolved = true; + } } else if matches!(mode, 5 | 15) { if let Some(motion) = owner_motion(key.object_index) { provider = motion; @@ -191,12 +253,13 @@ pub(super) fn advance_control_effect_instances( .collect() } -pub(super) fn activate_firing_flashes( +fn activate_firing_flashes( samples: &mut HashMap<ControlEffectInstanceKey, ControlEffectFrameSample>, ambient_slots: &[AmbientEffectGpuSlot], point_light_slots: &[ControlEffectSlot], events: &[AutoDemoCombatEvent], player_effects: Vec<FiringEffectInstance>, + weapon_phases: &HashMap<ControlEffectInstanceKey, f32>, ) -> HashSet<ControlEffectInstanceKey> { let autonomous_effects = events.iter().filter_map(|event| match *event { AutoDemoCombatEvent::Shot { @@ -219,10 +282,11 @@ pub(super) fn activate_firing_flashes( return None; } let sample = samples.get_mut(&key)?; - // shortcut: the release occurs at the midpoint of the weapon cycle. - // Keep the flash to this snapshot until the full effect phase is wired. - sample.phase = Some(0.5); - sample.elapsed_seconds = 0.0; + if !weapon_phases.contains_key(&key) { + // shortcut: a shot supplies one visual sample when the bound node is unavailable. + sample.phase = Some(0.5); + sample.elapsed_seconds = 0.0; + } Some(key) }) .collect() diff --git a/apps/fparkan-game/src/main.rs b/apps/fparkan-game/src/main.rs index b479d3c3..8d5c0c68 100644 --- a/apps/fparkan-game/src/main.rs +++ b/apps/fparkan-game/src/main.rs @@ -9,16 +9,15 @@ mod chassis_animation; mod cockpit_geometry; #[cfg(windows)] mod control_effects; +#[cfg(test)] +use control_effects::advance_control_effect_instances; mod damage_visibility; mod debris; mod destruction_effects; -mod motion_effects; -use control_effects::{ - activate_firing_flashes, advance_control_effect_instances, owner_control_capacity, -}; mod mission_hints; mod mission_notices; mod mission_pause; +mod motion_effects; mod player_collision; mod player_fire; mod player_footsteps; @@ -11446,32 +11445,12 @@ impl StaticVulkanApp { None }; self.start_windup_sounds(control_clock_ms, weapon_windup_sounds); - let mut control_effect_random_samples = advance_control_effect_instances( - &mut self.control_effect_instance_states, - &self.ambient_effect_slots, - &self.control_point_light_slots, - &self.control_sound_slots, + let (control_effect_random_samples, direct_shot_sounds) = self.sample_control_effects( clock.id, control_clock_ms, environment .as_ref() .is_some_and(|frame| frame.control_effect_manager_flag), - |index| { - owner_control_capacity( - self.mission_engine.as_ref()?, - &self.mission_render_roots, - index, - ) - }, - |index| self.motion_effects.provider(index), - ); - let firing_flashes = activate_firing_flashes( - &mut control_effect_random_samples, - &self.ambient_effect_slots, - &self.control_point_light_slots, - self.mission_frame - .as_ref() - .map_or(&[][..], |frame| &frame.autodemo_combat_events), player_firing_effects, ); let control_point_lights = update_control_point_lights( @@ -11715,7 +11694,7 @@ impl StaticVulkanApp { continue; } // The same firing event starts its one-shot directly. - if firing_flashes.contains(&slot.random_instance_key) { + if direct_shot_sounds.contains(&slot.random_instance_key) { continue; } if slot.owner_component_is_mounted { @@ -19290,6 +19269,7 @@ mod tests { false, |_| None, |_| None, + |_| None, ); assert!(update_control_point_lights( &mut [inactive], @@ -19311,6 +19291,7 @@ mod tests { false, |_| None, |_| None, + |_| None, ); let lights = update_control_point_lights( std::slice::from_mut(&mut slot), @@ -19357,6 +19338,7 @@ mod tests { false, |_| None, |_| None, + |_| None, ); assert_eq!(first.len(), 1); let key = slot.random_instance_key; @@ -19385,6 +19367,7 @@ mod tests { false, |_| None, |_| None, + |_| None, )[&key], first_sample, "a repeated read of the same captured update reuses the shared sample" @@ -19399,6 +19382,7 @@ mod tests { false, |_| None, |_| None, + |_| None, ); let expected = expected_state.advance(SceneSampleId::Replay(8), 500, 1.0); assert_eq!(second[&key].phase_jitter, expected.phase_jitter); @@ -19425,6 +19409,7 @@ mod tests { false, |_| None, |_| None, + |_| None, ); assert_eq!(later[&key].phase, Some(1.0)); assert_eq!(later[&key].elapsed_seconds, 0.5); @@ -19438,6 +19423,7 @@ mod tests { false, |_| None, |_| None, + |_| None, ); assert_eq!(restarted[&key].phase, Some(0.0)); assert_eq!(restarted[&key].elapsed_seconds, 0.0); @@ -19477,6 +19463,7 @@ mod tests { daylight, |_| None, |_| None, + |_| None, ); assert_eq!(samples[&key].phase, Some(expected)); } @@ -19494,6 +19481,7 @@ mod tests { false, |_| None, |_| None, + |_| None, ); assert_eq!( samples[&key].phase, @@ -19518,6 +19506,7 @@ mod tests { false, |_| Some((remaining, 100.0)), |_| None, + |_| None, ); assert_eq!(samples[&key].phase, expected); if expected.is_none() { |
