From 1e5ba52b17a20cb66e52cd83b850da2dd6fb088f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=80lex=20Rom=C3=A0n?= Date: Sat, 29 Aug 2026 23:57:26 +0200 Subject: [PATCH] Use animation frame data where possible --- src/fighter/state/air_dodge.rs | 9 ++------- src/fighter/state/dash.rs | 11 +++-------- src/fighter/state/fall.rs | 3 +-- src/fighter/state/jump.rs | 4 +--- src/fighter/state/land.rs | 10 +++------- 5 files changed, 10 insertions(+), 27 deletions(-) diff --git a/src/fighter/state/air_dodge.rs b/src/fighter/state/air_dodge.rs index cf1f6e4..5263dc1 100644 --- a/src/fighter/state/air_dodge.rs +++ b/src/fighter/state/air_dodge.rs @@ -17,7 +17,6 @@ use crate::{ #[derive(Debug, Clone, Hash)] pub struct AirDodgeState { - pub duration_counter: u32, pub direction: FGVec2, } @@ -25,7 +24,7 @@ impl FighterStateImpl for AirDodgeState { const NAME: &'static str = "AirDodge"; fn check_interrupt(&self, state_context: &mut FighterStateContext) -> Option { - if self.duration_counter >= state_context.fighter_manifest.attributes.air_dodge_duration { + if state_context.is_current_animation_finished() { Some(FighterState::Fall(FallState)) } else { None @@ -33,8 +32,6 @@ impl FighterStateImpl for AirDodgeState { } fn update(&mut self, state_context: &mut FighterStateContext) { - self.duration_counter += 1; - state_context.velocity.0 *= state_context.fighter_manifest.attributes.air_dodge_decay; air::apply_air_motion( @@ -55,8 +52,7 @@ impl FighterStateImpl for AirDodgeState { current_line_id: res.line_id, }; Some(FighterState::Land(LandingState { - grounded_common, - duration_counter: 0, + grounded_common })) } else { None @@ -77,7 +73,6 @@ pub fn check_input(state_context: &FighterStateContext) -> Option .has_command(input::FighterCommands::Shield) .then(|| { FighterState::AirDodge(AirDodgeState { - duration_counter: 0, direction: state_context .input .get_last_frame() diff --git a/src/fighter/state/dash.rs b/src/fighter/state/dash.rs index 0d9a017..93da978 100644 --- a/src/fighter/state/dash.rs +++ b/src/fighter/state/dash.rs @@ -10,7 +10,6 @@ use crate::input::FighterCommands::{SmashMoveLeft, SmashMoveRight}; #[derive(Debug, Clone)] pub struct DashState { - frames_in_dash: u32, direction: FighterFacingDirection, ground_common: GroundedStateCommon, } @@ -18,14 +17,12 @@ pub struct DashState { impl std::hash::Hash for DashState { fn hash(&self, state: &mut H) { self.direction.hash(state); - self.frames_in_dash.hash(state); } } impl DashState { pub fn new(direction: FighterFacingDirection, ground_common: GroundedStateCommon) -> Self { Self { - frames_in_dash: 0, direction, ground_common, } @@ -52,13 +49,13 @@ impl FighterStateImpl for DashState { return Some(state); } - if self.frames_in_dash > attributes.dash_duration { + if ctx.is_current_animation_finished() { return run::check_input(ctx, ground) .or_else(|| walk::check_input(ctx, ground)) .or_else(|| wait::check_input(ctx, ground)); } - if self.frames_in_dash > attributes.dash_acceleration_duration { + if ctx.get_current_animation_frame() > attributes.dash_acceleration_duration { return run::check_input(ctx, ground); } @@ -90,9 +87,7 @@ impl FighterStateImpl for DashState { } fn update(&mut self, state_context: &mut FighterStateContext) { - self.frames_in_dash += 1; - - if self.frames_in_dash + if state_context.get_current_animation_frame() < state_context .fighter_manifest .attributes diff --git a/src/fighter/state/fall.rs b/src/fighter/state/fall.rs index 4dccf98..858d3ba 100644 --- a/src/fighter/state/fall.rs +++ b/src/fighter/state/fall.rs @@ -46,8 +46,7 @@ impl FighterStateImpl for FallState { current_line_id: res.line_id, }; Some(FighterState::Land(LandingState { - grounded_common, - duration_counter: 0, + grounded_common })) } else { None diff --git a/src/fighter/state/jump.rs b/src/fighter/state/jump.rs index 39a48b7..5ccf82e 100644 --- a/src/fighter/state/jump.rs +++ b/src/fighter/state/jump.rs @@ -68,7 +68,6 @@ impl FighterStateImpl for JumpSquatState { } Some(FighterState::AirDodge(AirDodgeState { - duration_counter: 0, direction: wavedash_dir.normalize_or_zero(), })) } else if self.duration_counter @@ -241,8 +240,7 @@ impl FighterStateImpl for JumpState { current_line_id: res.line_id, }; Some(FighterState::Land(LandingState { - grounded_common, - duration_counter: 0, + grounded_common })) } else { None diff --git a/src/fighter/state/land.rs b/src/fighter/state/land.rs index 1f3ad5f..f14ecc6 100644 --- a/src/fighter/state/land.rs +++ b/src/fighter/state/land.rs @@ -13,15 +13,13 @@ use crate::fighter::{ #[derive(Debug, Clone, Hash)] pub struct LandingState { - pub grounded_common: GroundedStateCommon, - pub duration_counter: u32, + pub grounded_common: GroundedStateCommon } impl LandingState { pub fn create(grounded_common: GroundedStateCommon) -> Self { Self { - grounded_common, - duration_counter: 0, + grounded_common } } } @@ -32,7 +30,7 @@ impl FighterStateImpl for LandingState { fn check_interrupt(&self, state_context: &mut FighterStateContext) -> Option { if state_context.is_current_animation_finished() { grounded_movement_standstill_common_interrupts(state_context, &self.grounded_common) - } else if self.duration_counter >= state_context.fighter_manifest.attributes.landing_iasa { + } else if state_context.get_current_animation_frame() >= state_context.fighter_manifest.attributes.landing_iasa { dash::check_input(state_context, &self.grounded_common).or_else(|| { ground::grounded_movement_common_interrupts(state_context, &self.grounded_common) .or_else(|| walk::check_input(state_context, &self.grounded_common)) @@ -43,8 +41,6 @@ impl FighterStateImpl for LandingState { } fn update(&mut self, state_context: &mut FighterStateContext) { - self.duration_counter += 1; - let friction = if state_context.velocity.x.abs() > state_context.fighter_manifest.attributes.max_walk_vel {