aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src/player_weapon.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-01 10:43:57 +0300
committerValentin Popov <valentin@popov.link>2026-12-01 10:43:57 +0300
commitbf991ad728dd6cdc02168b4d6552f0e7e85181a2 (patch)
tree20f796e1fd77ec39a63f2f25a9a42f491dd9ce55 /crates/fparkan-runtime/src/player_weapon.rs
parent6bd2930a1805ee27b32f9329fa8d9aeb16479da9 (diff)
downloadfparkan-bf991ad728dd6cdc02168b4d6552f0e7e85181a2.tar.xz
fparkan-bf991ad728dd6cdc02168b4d6552f0e7e85181a2.zip
fix(render): drive warbot muzzle flashes with firing phases
Use the first CPT node when the effect has no explicit override. Feed the autonomous weapon banks into the same phase sampling path as manual weapons. Confirm the effect constructor and phase reads in the original DLLs, and compare the two cannon flashes in a live AutoDemo window at the same clock sample.
Diffstat (limited to 'crates/fparkan-runtime/src/player_weapon.rs')
-rw-r--r--crates/fparkan-runtime/src/player_weapon.rs36
1 files changed, 25 insertions, 11 deletions
diff --git a/crates/fparkan-runtime/src/player_weapon.rs b/crates/fparkan-runtime/src/player_weapon.rs
index 421f0e7a..d46c0943 100644
--- a/crates/fparkan-runtime/src/player_weapon.rs
+++ b/crates/fparkan-runtime/src/player_weapon.rs
@@ -101,18 +101,21 @@ impl PlayerWeapons {
.flat_map(move |weapon| weapon.windup_sounds(object_index))
}
- /// Current blends of the model nodes explicitly linked to firing effects.
+ /// Current blends of the model nodes driving firing effects.
pub fn firing_effect_phases(
&self,
object_index: usize,
) -> impl Iterator<Item = (FiringEffectInstance, f32)> + '_ {
self.weapons.iter().filter_map(move |weapon| {
+ if weapon.destroyed {
+ return None;
+ }
let node = weapon.effect_node?;
let blend = self
.weapons
.iter()
.rev()
- .filter(|track| track.component_index == weapon.component_index)
+ .filter(|track| !track.destroyed && track.component_index == weapon.component_index)
.find_map(|track| {
let index = track.barrels.iter().rposition(|barrel| {
barrel.row.node_index == node && barrel.row.flags & 4 == 0
@@ -477,15 +480,21 @@ fn prepare_weapons(
return None;
};
let effect_row = firing_effect_row(control, row);
- let effect_node = effect_row
- .filter(|effect| {
- control.node_effect_links.contains(&(
- effect.table_index,
- row.node_index as u32,
- effect.selector,
- ))
- })
- .map(|_| row.node_index);
+ let effect_node = effect_row.and_then(|effect| {
+ if let Some(&(_, node, _)) =
+ control
+ .node_effect_links
+ .iter()
+ .rfind(|&&(table, _, selector)| {
+ table == effect.table_index && selector == effect.selector
+ })
+ {
+ return Some(node as usize);
+ }
+ // Control opcode 4 binds mode 4 to the effect's first CPT point.
+ let point = points.points.get(effect.point_offsets[0] as usize)?;
+ usize::try_from(point.raw_signed_field_04).ok()
+ });
let effect = effect_row.and_then(|row| {
Some((
crate::bounded_ascii_c_string(&row.resource.archive)?,
@@ -618,6 +627,11 @@ mod tests {
(point.raw_signed_field_04, point.raw_signed_field_08),
(3, 2)
);
+ let effect = cannon.firing_effect(12).expect("medium cannon flash");
+ assert_eq!(cannon.effect_node, Some(3));
+ assert!(bank
+ .firing_effect_phases(12)
+ .any(|(candidate, phase)| candidate == effect && phase == 0.0));
for (index, projectile, tube_count) in [(12, "br_l_01", 16), (14, "br_b_01", 9)] {
let (_, bank) = prepared_warbot_weapons(&engine)