aboutsummaryrefslogtreecommitdiff
path: root/apps/fparkan-game/src
diff options
context:
space:
mode:
Diffstat (limited to 'apps/fparkan-game/src')
-rw-r--r--apps/fparkan-game/src/control_effects.rs87
-rw-r--r--apps/fparkan-game/src/main.rs33
-rw-r--r--apps/fparkan-game/src/player_fire.rs20
-rw-r--r--apps/fparkan-game/src/shot_sound.rs9
4 files changed, 126 insertions, 23 deletions
diff --git a/apps/fparkan-game/src/control_effects.rs b/apps/fparkan-game/src/control_effects.rs
index 8007ea9f..3bc8331b 100644
--- a/apps/fparkan-game/src/control_effects.rs
+++ b/apps/fparkan-game/src/control_effects.rs
@@ -1,10 +1,12 @@
use super::{
initial_native_effect_phase, AmbientEffectGpuSlot, ControlEffectFrameSample,
ControlEffectInstanceKey, ControlEffectInstanceState, ControlEffectSlot, ControlSoundSlot,
- MissionRenderRoot, SceneSampleId,
+ MissionRenderRoot, SceneSampleId, StaticVulkanApp,
};
use fparkan_fx::clock::{FxInstanceClock, FxPhaseProvider};
-use fparkan_runtime::{loaded_mission_control_device_tables, AutoDemoCombatEvent, Engine};
+use fparkan_runtime::{
+ loaded_mission_control_device_tables, AutoDemoCombatEvent, Engine, FiringEffectInstance,
+};
use std::collections::{HashMap, HashSet};
pub(super) fn owner_control_capacity(
@@ -22,6 +24,75 @@ pub(super) fn owner_control_capacity(
))
}
+impl From<FiringEffectInstance> for ControlEffectInstanceKey {
+ fn from(effect: FiringEffectInstance) -> Self {
+ Self {
+ object_index: effect.object_index,
+ component_index: effect.component_index,
+ table_index: effect.table_index,
+ row_index: effect.row_index,
+ }
+ }
+}
+
+impl StaticVulkanApp {
+ pub(super) fn start_windup_sounds(
+ &mut self,
+ control_clock_ms: u32,
+ manual: Vec<FiringEffectInstance>,
+ ) {
+ if self.audio.is_none() {
+ return;
+ }
+ let autonomous = self.mission_frame.iter().flat_map(|frame| {
+ frame
+ .autodemo_combat_events
+ .iter()
+ .filter_map(|event| match event {
+ AutoDemoCombatEvent::WindupSound(sound) => Some(*sound),
+ _ => None,
+ })
+ });
+ let keys: HashSet<_> = manual
+ .into_iter()
+ .chain(autonomous)
+ .map(ControlEffectInstanceKey::from)
+ .collect();
+ if keys.is_empty() {
+ return;
+ }
+ for sound in &self.control_sound_slots {
+ let slot = &sound.effect;
+ if !sound.waits_for_windup || !keys.contains(&slot.random_instance_key) {
+ continue;
+ }
+ let state = self
+ .control_effect_instance_states
+ .entry(slot.random_instance_key)
+ .or_insert_with(|| {
+ ControlEffectInstanceState::new(
+ slot.random_seed,
+ slot.header_flags,
+ slot.phase_jitter,
+ slot.random_shift,
+ )
+ });
+ let now = control_clock_ms as f32;
+ // Opcode 10 immediately sets the origin and selects mode 1 on this instance.
+ let clock = state.clock.get_or_insert_with(|| {
+ FxInstanceClock::new(
+ slot.time_mode,
+ slot.header_flags,
+ slot.duration_seconds,
+ now,
+ )
+ .expect("prepared FX clock metadata")
+ });
+ clock.set_time(now, 1).expect("positive wind-up duration");
+ }
+ }
+}
+
pub(super) fn advance_control_effect_instances(
states: &mut HashMap<ControlEffectInstanceKey, ControlEffectInstanceState>,
ambient_slots: &[AmbientEffectGpuSlot],
@@ -46,7 +117,10 @@ pub(super) fn advance_control_effect_instances(
}
for slot in point_light_slots
.iter()
- .chain(sound_slots.iter().map(|slot| &slot.effect))
+ .chain(sound_slots.iter().filter_map(|slot| {
+ (!slot.waits_for_windup || states.contains_key(&slot.effect.random_instance_key))
+ .then_some(&slot.effect)
+ }))
{
specifications.entry(slot.random_instance_key).or_insert((
slot.random_seed,
@@ -133,12 +207,7 @@ pub(super) fn activate_firing_flashes(
else {
return None;
};
- let key = ControlEffectInstanceKey {
- object_index: effect.object_index,
- component_index: effect.component_index,
- table_index: effect.table_index,
- row_index: effect.row_index,
- };
+ let key = ControlEffectInstanceKey::from(effect);
let has_external_flash = ambient_slots
.iter()
.any(|slot| slot.random_instance_key == key && slot.time_mode == 4)
diff --git a/apps/fparkan-game/src/main.rs b/apps/fparkan-game/src/main.rs
index dd186207..8005faa7 100644
--- a/apps/fparkan-game/src/main.rs
+++ b/apps/fparkan-game/src/main.rs
@@ -939,6 +939,7 @@ struct ControlEffectSlot {
#[derive(Clone, Debug)]
struct ControlSoundSlot {
effect: ControlEffectSlot,
+ waits_for_windup: bool,
command: Op2SoundCommand,
state: Op2SoundState,
}
@@ -5704,6 +5705,12 @@ fn append_initial_control_effect_slots(
let group_index = row.table_index;
let archive = fixed_effect_field(&row.resource.archive);
let name = fixed_effect_field(&row.resource.name);
+ let windup = row.opcode == 3
+ && control.typed_records.iter().any(|record| {
+ control
+ .weapon_windup_sound_rows(record)
+ .any(|sound| sound.row_index == row.row_index)
+ });
let points = if row.opcode == 4 {
let Some(point_list) = point_list else {
continue;
@@ -5715,8 +5722,8 @@ fn append_initial_control_effect_slots(
)
})?)
} else {
- // The root-node path covers the authored chassis engine loops.
- if row.point_offsets[0] != 0 {
+ // Chassis engine loops use the root. Weapon sounds use their authored node.
+ if !windup && row.point_offsets[0] != 0 {
continue;
}
None
@@ -5746,7 +5753,7 @@ fn append_initial_control_effect_slots(
.get(&key)
.ok_or_else(|| format!("Control FX {key} was not cached"))?;
let header = document.header();
- if row.opcode == 3 && !matches!(header.time_mode, 5 | 15) {
+ if row.opcode == 3 && !windup && !matches!(header.time_mode, 5 | 15) {
continue;
}
let sound_commands = document
@@ -5767,7 +5774,7 @@ fn append_initial_control_effect_slots(
continue;
}
if !matches!(header.time_mode, 0..=17)
- || (matches!(header.time_mode, 1..=3) && duration_seconds <= 0.0)
+ || ((windup || matches!(header.time_mode, 1..=3)) && duration_seconds <= 0.0)
{
*unsupported_sounds += sound_commands;
record_skip(
@@ -5781,7 +5788,9 @@ fn append_initial_control_effect_slots(
let owner_node_index = usize::try_from(
points
.as_ref()
- .map_or(0, |points| points[0].raw_signed_field_04),
+ .map_or(row.point_offsets[0] as i32, |points| {
+ points[0].raw_signed_field_04
+ }),
)
.ok()
.filter(|owner_node| {
@@ -5869,6 +5878,7 @@ fn append_initial_control_effect_slots(
if let Some(sound) = Op2SoundCommand::from_command(command) {
sound_slots.push(ControlSoundSlot {
effect: slot,
+ waits_for_windup: windup,
command: sound,
state: Op2SoundState::default(),
});
@@ -9659,7 +9669,11 @@ fn run_static_vulkan_mode(
};
projectile_draws.push(draw);
}
- shot_sound::report_missing_player_sounds(&player_weapon_layouts, &projectile_draws);
+ shot_sound::report_missing_player_sounds(
+ &player_weapon_layouts,
+ &projectile_draws,
+ &preview.control_sound_slots,
+ );
}
let autodemo_draws = mission_engine.as_ref().map_or_else(Vec::new, |engine| {
fparkan_runtime::autodemo_projectile_types(engine).iter().map(|kind| {
@@ -10611,8 +10625,9 @@ impl StaticVulkanApp {
"mission_ai"
};
for event in &frame.autodemo_combat_events {
- use fparkan_runtime::AutoDemoCombatEvent::{BuildingHit, Destroyed, Shot};
+ use fparkan_runtime::AutoDemoCombatEvent::{BuildingHit, Destroyed, Shot, WindupSound};
match *event {
+ WindupSound(_) => {}
Shot { shooter, target, projectile, .. } => eprintln!(
"{combat}_shot shooter={} target={} projectile={projectile} queue_time_ms={clock_ms}", shooter.slot, target.slot
),
@@ -11261,7 +11276,7 @@ impl StaticVulkanApp {
}
}
}
- let player_shots = self.sample_player_fire(control_clock_ms);
+ let (player_shots, weapon_windup_sounds) = self.sample_player_fire(control_clock_ms);
let effect_elapsed_seconds = control_clock_ms as f32 / 1000.0;
// CTLD's validated NDP defaults seed the native query gate. This
// preview does not process mission Action1 updates, so it retains that
@@ -11396,6 +11411,7 @@ impl StaticVulkanApp {
} else {
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,
@@ -14404,6 +14420,7 @@ mod tests {
effect_section: PreparedControlEffectSection::Absent,
initial_effect_group: None,
node_effect_links: Vec::new(),
+ effect_modes: Vec::new(),
point_list: None,
}
}
diff --git a/apps/fparkan-game/src/player_fire.rs b/apps/fparkan-game/src/player_fire.rs
index 870dfe2f..b1be6551 100644
--- a/apps/fparkan-game/src/player_fire.rs
+++ b/apps/fparkan-game/src/player_fire.rs
@@ -3,25 +3,30 @@ use super::{
LegacyIron3dEulerTransform, PlayerProjectile, PreparedControlPoint, StaticVulkanApp,
};
+use fparkan_runtime::FiringEffectInstance;
+
impl StaticVulkanApp {
pub(super) fn sample_player_fire(
&mut self,
clock_ms: u32,
- ) -> Vec<(usize, PreparedControlPoint)> {
+ ) -> (
+ Vec<(usize, PreparedControlPoint)>,
+ Vec<FiringEffectInstance>,
+ ) {
let trigger = self.player_fire_held || self.player_fire_pressed;
self.player_fire_pressed = false;
let Some(cockpit) = self.cockpit else {
- return Vec::new();
+ return (Vec::new(), Vec::new());
};
if self.mission_frame.is_none()
|| !self
.player_weapon_layouts
.contains_key(&cockpit.object_index)
{
- return Vec::new();
+ return (Vec::new(), Vec::new());
}
let Some(weapons) = self.player_weapon_banks.get_mut(&cockpit.handle) else {
- return Vec::new();
+ return (Vec::new(), Vec::new());
};
if let Some(engine) = &self.mission_engine {
weapons.read_control_energy(engine, cockpit.handle);
@@ -33,7 +38,12 @@ impl StaticVulkanApp {
if let Some(engine) = &mut self.mission_engine {
weapons.publish_control_energy(engine, cockpit.handle);
}
- shots
+ (
+ shots,
+ weapons
+ .started_windup_sounds(cockpit.object_index)
+ .collect(),
+ )
}
pub(super) fn emit_player_shots(
diff --git a/apps/fparkan-game/src/shot_sound.rs b/apps/fparkan-game/src/shot_sound.rs
index 893b3a14..02c561ee 100644
--- a/apps/fparkan-game/src/shot_sound.rs
+++ b/apps/fparkan-game/src/shot_sound.rs
@@ -32,6 +32,7 @@ pub(super) fn projectile_launch<'a>(
pub(super) fn report_missing_player_sounds(
layouts: &std::collections::HashMap<usize, super::PlayerWeaponLayout>,
projectiles: &[Option<super::ProjectileDraw>],
+ control_sounds: &[super::ControlSoundSlot],
) {
for (&object, layout) in layouts {
for (weapon, (pool, sound)) in layout.weapons.weapons().iter().zip(&layout.slots) {
@@ -39,7 +40,13 @@ pub(super) fn report_missing_player_sounds(
.get(*pool)
.and_then(Option::as_ref)
.is_some_and(|draw| !draw.launch_sounds.is_empty());
- if sound.is_none() && !has_launch_sound {
+ let has_windup_sound = weapon.windup_sounds(object).any(|effect| {
+ let key = super::ControlEffectInstanceKey::from(effect);
+ control_sounds
+ .iter()
+ .any(|slot| slot.effect.random_instance_key == key)
+ });
+ if sound.is_none() && !has_launch_sound && !has_windup_sound {
eprintln!(
"sim_coverage player_weapon_sound_stub=1 object={object} projectile={}",
weapon.projectile