1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
use super::{
initial_native_effect_phase, AmbientEffectGpuSlot, ControlEffectFrameSample,
ControlEffectInstanceKey, ControlEffectInstanceState, ControlEffectSlot, ControlSoundSlot,
MissionRenderRoot, SceneSampleId, StaticVulkanApp,
};
use fparkan_fx::clock::{FxInstanceClock, FxPhaseProvider};
use fparkan_runtime::{
loaded_mission_control_device_tables, AutoDemoCombatEvent, Engine, FiringEffectInstance,
};
use std::collections::{HashMap, HashSet};
pub(super) fn owner_control_capacity(
engine: &Engine,
roots: &[Option<MissionRenderRoot>],
index: usize,
) -> Option<(f32, f32)> {
let handle = roots.get(index)?.as_ref()?.handle;
let table = loaded_mission_control_device_tables(engine)?
.iter()
.find(|table| table.handle == handle)?;
Some((
f32::from_bits(table.node_provider_amount_bits?),
f32::from_bits(table.node_provider_maximum_amount_bits?),
))
}
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],
point_light_slots: &[ControlEffectSlot],
sound_slots: &[ControlSoundSlot],
sample_id: SceneSampleId,
control_clock_ms: u32,
manager_flag: bool,
owner_capacity: impl Fn(usize) -> Option<(f32, f32)>,
owner_motion: impl Fn(usize) -> Option<FxPhaseProvider>,
) -> HashMap<ControlEffectInstanceKey, ControlEffectFrameSample> {
let mut specifications = HashMap::new();
for slot in ambient_slots {
specifications.entry(slot.random_instance_key).or_insert((
slot.random_seed,
slot.header_flags,
slot.phase_jitter,
slot.random_shift,
slot.time_mode,
slot.duration_seconds,
));
}
for slot in point_light_slots
.iter()
.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,
slot.header_flags,
slot.phase_jitter,
slot.random_shift,
slot.time_mode,
slot.duration_seconds,
));
}
specifications
.into_iter()
.map(
|(key, (seed, flags, phase_jitter, random_shift, mode, duration))| {
let state = states.entry(key).or_insert_with(|| {
ControlEffectInstanceState::new(seed, flags, phase_jitter, random_shift)
});
if state.last_update_id == Some(sample_id) {
return (key, state.sample);
}
let idle = FxPhaseProvider::idle();
let mut provider = idle;
let mut resolved = false;
if mode == 14 {
let capacity = owner_capacity(key.object_index)
.and_then(|(remaining, capacity)| idle.with_control_capacity(remaining, capacity));
provider = capacity.unwrap_or(idle);
if state.clock.is_none() {
eprintln!("render_coverage control_damage_fx_activation_approx=1 (instance={key:?})");
if capacity.is_none() {
eprintln!("render_coverage control_fx_owner_state_stub=1 (missing Control capacity; instance={key:?} mode={mode})");
}
}
} else if matches!(mode, 5 | 15) {
if let Some(motion) = owner_motion(key.object_index) {
provider = motion;
resolved = true;
}
}
if mode != 14 && !resolved && state.clock.is_none() && fparkan_fx::fx_time_mode_requires_owner_state(mode) {
eprintln!("render_coverage control_fx_owner_state_stub=1 (idle provider; instance={key:?} mode={mode})");
}
let clock = state.clock.get_or_insert_with(|| {
// All static-preview instances are created at scene time zero.
FxInstanceClock::new(mode, flags, duration, 0.0)
.expect("prepared FX clock metadata")
});
let now_ms = control_clock_ms as f32;
let active = provider.control_effect_active(mode);
let phase = clock.update(now_ms).and_then(|()| {
clock.phase(now_ms, manager_flag, Some(&provider))
});
let instance_elapsed = clock.elapsed_seconds(now_ms).unwrap_or(0.0);
if phase.is_none() && state.last_update_id.is_none() {
eprintln!("render_coverage control_fx_clock_unsupported=1 (instance={key:?} mode={mode})");
}
let phase = phase.filter(|_| active);
let initial_phase = phase
.map(|phase| initial_native_effect_phase(flags, phase))
.unwrap_or(-1.0);
state.advance(sample_id, control_clock_ms, initial_phase);
state.sample.phase = phase;
state.sample.elapsed_seconds = instance_elapsed;
(key, state.sample)
},
)
.collect()
}
pub(super) fn activate_firing_flashes(
samples: &mut HashMap<ControlEffectInstanceKey, ControlEffectFrameSample>,
ambient_slots: &[AmbientEffectGpuSlot],
point_light_slots: &[ControlEffectSlot],
events: &[AutoDemoCombatEvent],
player_effects: Vec<FiringEffectInstance>,
) -> HashSet<ControlEffectInstanceKey> {
let autonomous_effects = events.iter().filter_map(|event| match *event {
AutoDemoCombatEvent::Shot {
effect_instance, ..
} => effect_instance,
_ => None,
});
player_effects
.into_iter()
.chain(autonomous_effects)
.filter_map(|effect| {
let key = ControlEffectInstanceKey::from(effect);
let has_external_flash = ambient_slots
.iter()
.any(|slot| slot.random_instance_key == key && slot.time_mode == 4)
|| point_light_slots
.iter()
.any(|slot| slot.random_instance_key == key && slot.time_mode == 4);
if !has_external_flash {
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;
Some(key)
})
.collect()
}
|