diff options
| author | Valentin Popov <valentin@popov.link> | 2026-11-26 09:25:01 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-11-26 09:25:01 +0300 |
| commit | a1e8e2fd3be9a4c761fed1e8a40c322e2d7d42d2 (patch) | |
| tree | 1a80654b64ba3b674b72a02f915b1323fe039dc2 /crates/fparkan-runtime/src | |
| parent | 0fade3cf1100f9122d104f69d9cce2efc6306279 (diff) | |
| download | fparkan-a1e8e2fd3be9a4c761fed1e8a40c322e2d7d42d2.tar.xz fparkan-a1e8e2fd3be9a4c761fed1e8a40c322e2d7d42d2.zip | |
feat(render): animate player weapon tracks during firing
Sample the authored barrel tracks on the existing weapon clock before resolving the muzzle. Check Control phase interpolation against the original DLL and verify plasma rifle travel in a fixed-camera capture on the stock firing range.
Diffstat (limited to 'crates/fparkan-runtime/src')
| -rw-r--r-- | crates/fparkan-runtime/src/player_weapon.rs | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/crates/fparkan-runtime/src/player_weapon.rs b/crates/fparkan-runtime/src/player_weapon.rs index b95b0cb7..ffc488b1 100644 --- a/crates/fparkan-runtime/src/player_weapon.rs +++ b/crates/fparkan-runtime/src/player_weapon.rs @@ -41,8 +41,10 @@ pub struct PlayerWeapon { #[derive(Clone)] struct Barrel { muzzle: PreparedControlPoint, + row: PreparedControlTimelineRow, rate: f64, blend: f64, + from_blend: f64, } #[derive(Clone, PartialEq)] @@ -74,6 +76,40 @@ impl PlayerWeapons { &self.weapons } + /// Samples the barrel tracks after advancing the weapon bank on this frame. + pub fn apply_firing_pose(&self, component: usize, node_times: &mut [Option<f32>]) { + for weapon in self + .weapons + .iter() + .filter(|weapon| weapon.component_index == component) + { + for (index, barrel) in weapon.barrels.iter().enumerate() { + if barrel.row.flags & 4 != 0 { + continue; + } + let Some(time) = node_times.get_mut(barrel.row.node_index) else { + continue; + }; + let mut blend = barrel.blend; + if index == weapon.barrel_index + && matches!(weapon.phase, FirePhase::Shot | FirePhase::Finish) + { + let duration = weapon.phase_end_ms - weapon.phase_start_ms; + if duration > 0.0 { + let progress = + ((self.clock_ms - weapon.phase_start_ms) / duration).clamp(0.0, 1.0); + blend = barrel.from_blend + progress * (blend - barrel.from_blend); + } + } + let mut blend = blend as f32; + if barrel.row.flags & 2 != 0 { + blend = 1.0 - blend; + } + *time = Some((1.0 - blend) * barrel.row.frame_a + blend * barrel.row.frame_b); + } + } + } + /// Selects all weapons with zero, or one weapon by its one-based slot. pub fn select(&mut self, slot: usize) { match slot { @@ -197,6 +233,7 @@ impl PlayerWeapon { impl Barrel { fn travel_to(&mut self, blend: f64) -> f64 { let duration = (blend - self.blend).abs() * 1000.0 / self.rate; + self.from_blend = self.blend; self.blend = blend; duration } @@ -282,8 +319,10 @@ fn prepare_weapons( } Some(Barrel { muzzle: muzzle.clone(), + row: *row, rate: f64::from(rate), blend: f64::from(row.initial_blend), + from_blend: f64::from(row.initial_blend), }) }) .collect::<Option<Vec<_>>>()?; @@ -410,8 +449,18 @@ mod tests { direction: [0.0, 1.0, 0.0], name: [0; 32], }, + row: PreparedControlTimelineRow { + row_index: 0, + node_index: 0, + frame_a: 4.0, + frame_b: 8.0, + initial_blend: 0.0, + raw_parameters: [0; 4], + flags: 0, + }, rate: 50.0, blend: 0.0, + from_blend: 0.0, }], barrel_index: 0, rounds_remaining: Some(1), @@ -428,12 +477,23 @@ mod tests { cost: 4.0, amount: 8.0, }); + let mut node_times = [None]; assert!(weapons.fire(true, 0).next().is_none()); + assert!(weapons.fire(false, 5).next().is_none()); + weapons.apply_firing_pose(0, &mut node_times); + assert_eq!(node_times, [Some(5.0)]); assert!(weapons.fire(false, 10).next().is_none()); + weapons.apply_firing_pose(0, &mut node_times); + assert_eq!(node_times, [Some(6.0)]); assert_eq!(weapons.fire(false, 11).next().unwrap().0, 0); + assert!(weapons.fire(false, 16).next().is_none()); + weapons.apply_firing_pose(0, &mut node_times); + assert_eq!(node_times, [Some(7.0)]); assert_eq!(weapons.weapons()[0].rounds_remaining(), Some(1)); assert_eq!(weapons.weapons[0].charge.as_ref().unwrap().amount, 8.0); assert!(weapons.fire(false, 22).next().is_none()); + weapons.apply_firing_pose(0, &mut node_times); + assert_eq!(node_times, [Some(4.0)]); assert_eq!(weapons.weapons()[0].rounds_remaining(), Some(0)); assert_eq!(weapons.weapons[0].charge.as_ref().unwrap().amount, 4.0); assert!(weapons.fire(true, 100).next().is_none()); |
