Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
13ee58ce17 | ||
|
|
ff78847512 | ||
|
|
ae8f7b5850 | ||
|
|
43ee6d8153 | ||
|
|
352c6fcb6c | ||
|
|
06d20c2d27 |
@@ -23,9 +23,9 @@ jobs:
|
||||
"$HOME/.cargo/bin/rustup" toolchain install nightly-2026-09-14 --profile minimal
|
||||
|
||||
- name: Cache Rust dependencies and build artifacts
|
||||
uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2.8.2
|
||||
uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
|
||||
with:
|
||||
prefix-key: v1-rust
|
||||
prefix-key: v2-rust
|
||||
shared-key: linux-nightly
|
||||
cache-bin: false
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ use crate::{
|
||||
FighterVelocity, Grounded,
|
||||
animation::FighterAnimationFrame,
|
||||
attack::{
|
||||
FighterDamage, FighterKnockbackVelocity, FighterPendingHitReaction,
|
||||
FighterReceivedAttacks, FighterSolvedHurtboxes, FighterStaleMoveQueue,
|
||||
FighterDamage, FighterKnockbackVelocity, FighterPendingHitReaction, FighterPendingHits,
|
||||
FighterSolvedHurtboxes, FighterStaleMoveQueue,
|
||||
},
|
||||
baked_animation::FighterBoneMatrices,
|
||||
state::FighterState,
|
||||
@@ -28,6 +28,7 @@ pub(super) struct DebugSaveState {
|
||||
struct Checkpoint {
|
||||
fighters: Vec<FighterCheckpoint>,
|
||||
stage_collision: StageCollision,
|
||||
pending_hits: FighterPendingHits,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -50,7 +51,6 @@ struct FighterCheckpoint {
|
||||
knockback_velocity: FighterKnockbackVelocity,
|
||||
stale_moves: FighterStaleMoveQueue,
|
||||
hitboxes: FighterHitboxes,
|
||||
received_attacks: FighterReceivedAttacks,
|
||||
solved_hurtboxes: FighterSolvedHurtboxes,
|
||||
bone_matrices: FighterBoneMatrices,
|
||||
grounded: bool,
|
||||
@@ -97,9 +97,11 @@ pub(super) fn save_or_restore(world: &mut World) {
|
||||
};
|
||||
checkpoint_fighters.push(checkpoint);
|
||||
}
|
||||
let pending_hits = world.resource::<FighterPendingHits>().clone();
|
||||
world.resource_mut::<DebugSaveState>().checkpoint = Some(Checkpoint {
|
||||
fighters: checkpoint_fighters,
|
||||
stage_collision,
|
||||
pending_hits,
|
||||
});
|
||||
info!("Saved debug game state");
|
||||
return;
|
||||
@@ -147,7 +149,6 @@ pub(super) fn save_or_restore(world: &mut World) {
|
||||
entity.insert(saved.knockback_velocity);
|
||||
entity.insert(saved.stale_moves.clone());
|
||||
entity.insert(saved.hitboxes.clone());
|
||||
entity.insert(saved.received_attacks.clone());
|
||||
entity.insert(saved.solved_hurtboxes.clone());
|
||||
entity.insert(saved.bone_matrices.clone());
|
||||
if saved.grounded {
|
||||
@@ -156,6 +157,7 @@ pub(super) fn save_or_restore(world: &mut World) {
|
||||
entity.remove::<Grounded>();
|
||||
}
|
||||
}
|
||||
world.insert_resource(checkpoint.pending_hits.clone());
|
||||
world.insert_resource(checkpoint.stage_collision);
|
||||
for mut match_camera in world.query::<&mut MatchCamera>().iter_mut(world) {
|
||||
match_camera.needs_snap = true;
|
||||
@@ -184,7 +186,6 @@ fn capture_fighter(world: &World, entity: Entity) -> Option<FighterCheckpoint> {
|
||||
knockback_velocity: *fighter.get::<FighterKnockbackVelocity>()?,
|
||||
stale_moves: fighter.get::<FighterStaleMoveQueue>()?.clone(),
|
||||
hitboxes: fighter.get::<FighterHitboxes>()?.clone(),
|
||||
received_attacks: fighter.get::<FighterReceivedAttacks>()?.clone(),
|
||||
solved_hurtboxes: fighter.get::<FighterSolvedHurtboxes>()?.clone(),
|
||||
bone_matrices: fighter.get::<FighterBoneMatrices>()?.clone(),
|
||||
grounded: fighter.contains::<Grounded>(),
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
use std::collections::{HashMap, VecDeque};
|
||||
|
||||
mod reaction;
|
||||
|
||||
use bevy::ecs::entity::{EntityMapper, MapEntities};
|
||||
use bevy::prelude::*;
|
||||
use bevy_ggrs::{Rollback, prelude::GgrsSchedule};
|
||||
use fixed_math::SinCos;
|
||||
use bevy_ggrs::{Rollback, RollbackApp, prelude::GgrsSchedule};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
fighter::{
|
||||
Fighter, FighterAttributes, FighterFacingDirection, FighterHitboxes, FighterHitstop,
|
||||
Fighter, FighterAttributes, FighterFacingDirection, FighterHitboxes,
|
||||
FighterPreviousFacingDirection, FighterPreviousTranslation, FighterRoster,
|
||||
FighterTranslation,
|
||||
animation::{AnimKind, FighterAnimationFrame},
|
||||
baked_animation::{FighterBoneIndexMap, FighterBoneMatrices, FixedMat4},
|
||||
errors::FighterErrors,
|
||||
hurtbox::{FixedAffineCapsule, FixedCapsule},
|
||||
manifest::FighterManifest,
|
||||
},
|
||||
@@ -432,15 +433,26 @@ pub struct FighterAttackScriptAssets {
|
||||
#[derive(Component, Clone, Debug, Default, Hash)]
|
||||
pub struct FighterSolvedHurtboxes(pub Vec<FighterSolvedHurtbox>);
|
||||
|
||||
#[derive(Component, Clone, Debug, Default, Hash, DerefMut, Deref)]
|
||||
pub struct FighterReceivedAttacks(
|
||||
pub Vec<(
|
||||
/* attacker */ Entity,
|
||||
Handle<FighterAttackScript>,
|
||||
AttackKind,
|
||||
/* hitbox_idx */ usize,
|
||||
)>,
|
||||
);
|
||||
#[derive(Clone, Debug, Hash)]
|
||||
pub struct FighterHit {
|
||||
pub attacker: Entity,
|
||||
pub defender: Entity,
|
||||
pub attack_script: Handle<FighterAttackScript>,
|
||||
pub attack_kind: AttackKind,
|
||||
pub hitbox_index: usize,
|
||||
}
|
||||
|
||||
#[derive(Resource, Clone, Debug, Default, Hash)]
|
||||
pub struct FighterPendingHits(pub Vec<FighterHit>);
|
||||
|
||||
impl MapEntities for FighterPendingHits {
|
||||
fn map_entities<M: EntityMapper>(&mut self, entity_mapper: &mut M) {
|
||||
for hit in &mut self.0 {
|
||||
hit.attacker = entity_mapper.get_mapped(hit.attacker);
|
||||
hit.defender = entity_mapper.get_mapped(hit.defender);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn solve_hurtboxes(
|
||||
mut query: Query<(
|
||||
@@ -498,19 +510,14 @@ pub fn intersect_attacks_with_hurtboxes(
|
||||
&Player,
|
||||
&FighterStaleMoveQueue,
|
||||
)>,
|
||||
mut query_attacked: Query<(
|
||||
Entity,
|
||||
&FighterSolvedHurtboxes,
|
||||
&Player,
|
||||
&Fighter,
|
||||
&mut FighterReceivedAttacks,
|
||||
)>,
|
||||
query_attacked: Query<(Entity, &FighterSolvedHurtboxes)>,
|
||||
mut pending_hits: ResMut<FighterPendingHits>,
|
||||
attack_scripts: Res<Assets<FighterAttackScript>>,
|
||||
) {
|
||||
pending_hits.0.clear();
|
||||
|
||||
for &entity_receiving in &roster.0 {
|
||||
let Ok((_, hurtboxes, _, _receiving_fighter, mut received_attacks)) =
|
||||
query_attacked.get_mut(entity_receiving)
|
||||
else {
|
||||
let Ok((_, hurtboxes)) = query_attacked.get(entity_receiving) else {
|
||||
continue;
|
||||
};
|
||||
|
||||
@@ -551,12 +558,13 @@ pub fn intersect_attacks_with_hurtboxes(
|
||||
continue;
|
||||
};
|
||||
|
||||
received_attacks.push((
|
||||
entity_hurting,
|
||||
active_attack.script.clone(),
|
||||
active_attack.kind,
|
||||
hitting_hitbox_idx,
|
||||
));
|
||||
pending_hits.0.push(FighterHit {
|
||||
attacker: entity_hurting,
|
||||
defender: entity_receiving,
|
||||
attack_script: active_attack.script.clone(),
|
||||
attack_kind: active_attack.kind,
|
||||
hitbox_index: hitting_hitbox_idx,
|
||||
});
|
||||
info!("Hit by hitbox {}!!!!", hitting_hitbox_idx);
|
||||
|
||||
active_attack.hit_fighters.push(entity_receiving);
|
||||
@@ -564,140 +572,21 @@ pub fn intersect_attacks_with_hurtboxes(
|
||||
}
|
||||
}
|
||||
|
||||
pub fn calculate_received_attacks_trajectories(
|
||||
mut attacker: Query<(
|
||||
&mut FighterStaleMoveQueue,
|
||||
&FighterFacingDirection,
|
||||
&FighterHitboxes,
|
||||
&Player,
|
||||
&mut FighterHitstop,
|
||||
)>,
|
||||
receiver: Query<(
|
||||
&mut FighterReceivedAttacks,
|
||||
&mut FighterDamage,
|
||||
&Fighter,
|
||||
&mut FighterPendingHitReaction,
|
||||
)>,
|
||||
attack_scripts: Res<Assets<FighterAttackScript>>,
|
||||
game_settings: Res<GameSettings>,
|
||||
fighter_manifests: Res<Assets<FighterManifest>>,
|
||||
) -> Result {
|
||||
for (mut received_attacks, mut receiver_damage, fighter, mut pending_reactions) in receiver {
|
||||
if received_attacks.is_empty() {
|
||||
continue;
|
||||
}
|
||||
|
||||
// we got attacked, time to calculate the total damage
|
||||
|
||||
let damage_data = received_attacks
|
||||
.iter()
|
||||
.filter_map(|(from_entity, attack_script, attack_kind, hitbox_idx)| {
|
||||
let Ok((stale_move_queue, facing_dir, _hitboxes, player, _attacker_hitstop)) =
|
||||
attacker.get(*from_entity)
|
||||
else {
|
||||
return None;
|
||||
};
|
||||
|
||||
let Some(attack_script) = attack_scripts.get(attack_script) else {
|
||||
return None;
|
||||
};
|
||||
|
||||
let hitbox = &attack_script.hitboxes[*hitbox_idx];
|
||||
|
||||
let damage_received =
|
||||
stale_move_queue.get_attack_damage_multiplier(*attack_kind) * hitbox.damage.0;
|
||||
|
||||
Some((
|
||||
from_entity,
|
||||
damage_received,
|
||||
hitbox,
|
||||
attack_script,
|
||||
matches!(facing_dir, FighterFacingDirection::Left),
|
||||
player.handle,
|
||||
))
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let total_damage_received_this_frame = damage_data
|
||||
.iter()
|
||||
.map(|(_, damage, ..)| damage)
|
||||
.sum::<FGi32>();
|
||||
|
||||
let fighter_manifest = fighter_manifests
|
||||
.get(&fighter.manifest)
|
||||
.ok_or(FighterErrors::FighterManifestNotFound)?;
|
||||
|
||||
let mut reactions = vec![];
|
||||
|
||||
for (attacker_entity, attack_damage, hitbox, _attack_script, facing_left, attacker_slot) in
|
||||
damage_data
|
||||
{
|
||||
let knockback = hitbox.calculate_knockback(
|
||||
&fighter_manifest.attributes,
|
||||
*receiver_damage,
|
||||
FighterDamage(total_damage_received_this_frame),
|
||||
false,
|
||||
false,
|
||||
);
|
||||
|
||||
let angle = match &hitbox.angle {
|
||||
AttackAngle::Normal(angle) => *angle,
|
||||
AttackAngle::Sakurai => FGi32::lit("32.0"),
|
||||
};
|
||||
|
||||
let launch_angle = if facing_left {
|
||||
FGi32::lit("180.0") - angle
|
||||
} else {
|
||||
angle
|
||||
};
|
||||
let (sin, cos) = launch_angle.sin_cos();
|
||||
let launch_direction = FGVec2::new(cos, sin);
|
||||
let hitstop = HitStop::calculate(FighterDamage(attack_damage), false);
|
||||
reactions.push((
|
||||
*attacker_entity,
|
||||
attacker_slot,
|
||||
FighterHitReaction {
|
||||
launch_velocity: launch_direction * knockback.get_launch_speed(&game_settings),
|
||||
hitstun_frames: knockback.get_hitstun_frames(&game_settings),
|
||||
hitstop_frames: hitstop,
|
||||
kind: HitReactionKind::Flinch,
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
receiver_damage.0 += total_damage_received_this_frame;
|
||||
|
||||
for (attacker_entity, _, reaction) in reactions.iter() {
|
||||
let Ok((.., mut hitstop)) = attacker.get_mut(*attacker_entity) else {
|
||||
continue;
|
||||
};
|
||||
|
||||
hitstop.remaining_frames = reaction.hitstop_frames.max(hitstop.remaining_frames);
|
||||
}
|
||||
|
||||
// Pick attack by port priority
|
||||
pending_reactions.0 = reactions
|
||||
.into_iter()
|
||||
.min_by(|(_, port_a, _), (_, port_b, _)| port_a.cmp(port_b))
|
||||
.map(|(_, _, reaction)| reaction);
|
||||
|
||||
received_attacks.clear();
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub struct FighterAttackPlugin;
|
||||
|
||||
impl Plugin for FighterAttackPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.init_resource::<FighterPendingHits>()
|
||||
.add_plugins(reaction::FighterReactionPlugin)
|
||||
.rollback_resource_with_clone::<FighterPendingHits>()
|
||||
.update_resource_with_map_entities::<FighterPendingHits>()
|
||||
.checksum_resource_with_hash::<FighterPendingHits>();
|
||||
app.add_systems(
|
||||
GgrsSchedule,
|
||||
(
|
||||
solve_hurtboxes,
|
||||
solve_hitboxes,
|
||||
intersect_attacks_with_hurtboxes,
|
||||
calculate_received_attacks_trajectories,
|
||||
)
|
||||
.chain()
|
||||
.after(crate::fighter::baked_animation::update_fighter_bone_matrices)
|
||||
@@ -0,0 +1,145 @@
|
||||
use bevy::prelude::*;
|
||||
use bevy_ggrs::prelude::GgrsSchedule;
|
||||
use fixed_math::SinCos;
|
||||
|
||||
use super::*;
|
||||
use crate::{
|
||||
fighter::{
|
||||
Fighter, FighterFacingDirection, FighterHitboxes, FighterHitstop,
|
||||
FighterPendingHitReaction, FighterStaleMoveQueue, errors::FighterErrors,
|
||||
manifest::FighterManifest,
|
||||
},
|
||||
game_settings::GameSettings,
|
||||
math::{int::FGi32, vec::FGVec2},
|
||||
player::Player,
|
||||
schedule::GameplaySet,
|
||||
scripting::FighterAttackScript,
|
||||
};
|
||||
|
||||
pub fn resolve_fighter_hits(
|
||||
mut pending_hits: ResMut<FighterPendingHits>,
|
||||
mut attacker: Query<(
|
||||
&FighterStaleMoveQueue,
|
||||
&FighterFacingDirection,
|
||||
&FighterHitboxes,
|
||||
&Player,
|
||||
&mut FighterHitstop,
|
||||
)>,
|
||||
mut receiver: Query<(&mut FighterDamage, &Fighter, &mut FighterPendingHitReaction)>,
|
||||
attack_scripts: Res<Assets<FighterAttackScript>>,
|
||||
game_settings: Res<GameSettings>,
|
||||
fighter_manifests: Res<Assets<FighterManifest>>,
|
||||
) -> Result {
|
||||
let hits = std::mem::take(&mut pending_hits.0);
|
||||
let mut hit_offset = 0;
|
||||
|
||||
while hit_offset < hits.len() {
|
||||
let defender = hits[hit_offset].defender;
|
||||
let next_defender = hits[hit_offset..]
|
||||
.iter()
|
||||
.position(|hit| hit.defender != defender)
|
||||
.map_or(hits.len(), |offset| hit_offset + offset);
|
||||
|
||||
let Ok((mut receiver_damage, fighter, mut pending_reaction)) = receiver.get_mut(defender)
|
||||
else {
|
||||
hit_offset = next_defender;
|
||||
continue;
|
||||
};
|
||||
|
||||
let damage_data = hits[hit_offset..next_defender]
|
||||
.iter()
|
||||
.filter_map(|hit| {
|
||||
let Ok((stale_move_queue, facing_dir, _hitboxes, player, _)) =
|
||||
attacker.get(hit.attacker)
|
||||
else {
|
||||
return None;
|
||||
};
|
||||
let attack_script = attack_scripts.get(&hit.attack_script)?;
|
||||
let hitbox = attack_script.hitboxes.get(hit.hitbox_index)?;
|
||||
let damage_received = stale_move_queue
|
||||
.get_attack_damage_multiplier(hit.attack_kind)
|
||||
* hitbox.damage.0;
|
||||
|
||||
Some((
|
||||
hit.attacker,
|
||||
damage_received,
|
||||
hitbox,
|
||||
matches!(facing_dir, FighterFacingDirection::Left),
|
||||
player.handle,
|
||||
))
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let total_damage_received_this_frame = damage_data
|
||||
.iter()
|
||||
.map(|(_, damage, ..)| damage)
|
||||
.sum::<FGi32>();
|
||||
let fighter_manifest = fighter_manifests
|
||||
.get(&fighter.manifest)
|
||||
.ok_or(FighterErrors::FighterManifestNotFound)?;
|
||||
let mut reactions = Vec::with_capacity(damage_data.len());
|
||||
|
||||
for (attacker_entity, attack_damage, hitbox, facing_left, attacker_slot) in damage_data {
|
||||
let knockback = hitbox.calculate_knockback(
|
||||
&fighter_manifest.attributes,
|
||||
*receiver_damage,
|
||||
FighterDamage(total_damage_received_this_frame),
|
||||
false,
|
||||
false,
|
||||
);
|
||||
let angle = match &hitbox.angle {
|
||||
AttackAngle::Normal(angle) => *angle,
|
||||
AttackAngle::Sakurai => FGi32::lit("32.0"),
|
||||
};
|
||||
let launch_angle = if facing_left {
|
||||
FGi32::lit("180.0") - angle
|
||||
} else {
|
||||
angle
|
||||
};
|
||||
let (sin, cos) = launch_angle.sin_cos();
|
||||
let launch_direction = FGVec2::new(cos, sin);
|
||||
let hitstop = HitStop::calculate(FighterDamage(attack_damage), false);
|
||||
reactions.push((
|
||||
attacker_entity,
|
||||
attacker_slot,
|
||||
FighterHitReaction {
|
||||
launch_velocity: launch_direction * knockback.get_launch_speed(&game_settings),
|
||||
hitstun_frames: knockback.get_hitstun_frames(&game_settings),
|
||||
hitstop_frames: hitstop,
|
||||
kind: HitReactionKind::Flinch,
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
receiver_damage.0 += total_damage_received_this_frame;
|
||||
|
||||
for (attacker_entity, _, reaction) in &reactions {
|
||||
let Ok((.., mut hitstop)) = attacker.get_mut(*attacker_entity) else {
|
||||
continue;
|
||||
};
|
||||
hitstop.remaining_frames = reaction.hitstop_frames.max(hitstop.remaining_frames);
|
||||
}
|
||||
|
||||
pending_reaction.0 = reactions
|
||||
.into_iter()
|
||||
.min_by(|(_, port_a, _), (_, port_b, _)| port_a.cmp(port_b))
|
||||
.map(|(_, _, reaction)| reaction);
|
||||
|
||||
hit_offset = next_defender;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub struct FighterReactionPlugin;
|
||||
|
||||
impl Plugin for FighterReactionPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(
|
||||
GgrsSchedule,
|
||||
resolve_fighter_hits
|
||||
.in_set(GameplaySet::Attacks)
|
||||
.after(super::intersect_attacks_with_hurtboxes),
|
||||
);
|
||||
}
|
||||
}
|
||||
+2
-5
@@ -37,8 +37,8 @@ use crate::{
|
||||
fighter::{
|
||||
attack::{
|
||||
AttackKind, FighterAttackPlugin, FighterAttackScriptAssets, FighterDamage,
|
||||
FighterKnockbackVelocity, FighterPendingHitReaction, FighterReceivedAttacks,
|
||||
FighterSolvedHurtboxes, FighterStaleMoveQueue,
|
||||
FighterKnockbackVelocity, FighterPendingHitReaction, FighterSolvedHurtboxes,
|
||||
FighterStaleMoveQueue,
|
||||
},
|
||||
baked_animation::{FighterBoneIndexMap, FighterBoneMatrices},
|
||||
manifest::FighterManifest,
|
||||
@@ -116,7 +116,6 @@ pub struct FighterVisual;
|
||||
|
||||
#[derive(Component)]
|
||||
#[require(
|
||||
FighterReceivedAttacks,
|
||||
FighterStaleMoveQueue,
|
||||
FighterDamage,
|
||||
FighterPendingHitReaction,
|
||||
@@ -199,8 +198,6 @@ impl Plugin for FighterPlugin {
|
||||
.checksum_component_with_hash::<FighterHitstop>()
|
||||
.rollback_component_with_copy::<FighterKnockbackVelocity>()
|
||||
.checksum_component_with_hash::<FighterKnockbackVelocity>()
|
||||
.rollback_component_with_clone::<FighterReceivedAttacks>()
|
||||
.checksum_component_with_hash::<FighterReceivedAttacks>()
|
||||
.rollback_resource_with_reflect::<StageCollision>()
|
||||
// Debug views.
|
||||
.add_systems(
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
use crate::fighter::state::ground::GroundedStateCommon;
|
||||
use crate::fighter::state::land::{LandingState, LandingType};
|
||||
use crate::fighter::state::{CollisionContext, FighterState};
|
||||
use crate::fighter::*;
|
||||
|
||||
pub fn integrate_gravity(velocity: &mut FighterVelocity, attributes: &FighterAttributes) {
|
||||
@@ -53,6 +56,27 @@ pub fn apply_air_motion(
|
||||
translation.0 += velocity.0;
|
||||
}
|
||||
|
||||
pub fn update_standard_motion(ctx: &mut crate::fighter::state::UpdateContext) {
|
||||
integrate_gravity(ctx.velocity, ctx.fighter_attributes);
|
||||
apply_air_drift(ctx.velocity, ctx.fighter_attributes, ctx.input);
|
||||
apply_air_motion(ctx.velocity, ctx.translation, ctx.prev_translation);
|
||||
}
|
||||
|
||||
pub fn collision_interrupt(
|
||||
ctx: &mut CollisionContext,
|
||||
landing_type: LandingType,
|
||||
) -> Option<FighterState> {
|
||||
let res = ctx.air_collide_with_stage()?;
|
||||
ctx.translation.0 = res.hit_position - ctx.ecb.get_bottom_point();
|
||||
let grounded_common = GroundedStateCommon {
|
||||
current_line_id: res.line_id,
|
||||
};
|
||||
Some(FighterState::Land(LandingState::create(
|
||||
grounded_common,
|
||||
landing_type,
|
||||
)))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
@@ -3,10 +3,7 @@ use crate::{
|
||||
animation::AnimKind,
|
||||
state::{
|
||||
CollisionContext, EnterContext, FighterState, FighterStateImpl, InterruptContext,
|
||||
UpdateContext, air,
|
||||
fall::FallState,
|
||||
ground::GroundedStateCommon,
|
||||
land::{LandingState, LandingType},
|
||||
UpdateContext, air, fall::FallState, land::LandingType,
|
||||
},
|
||||
},
|
||||
input,
|
||||
@@ -43,19 +40,7 @@ impl FighterStateImpl for AirDodgeState {
|
||||
&mut self,
|
||||
state_context: &mut CollisionContext,
|
||||
) -> Option<FighterState> {
|
||||
if let Some(res) = state_context.air_collide_with_stage() {
|
||||
// Adjust translation
|
||||
state_context.translation.0 = res.hit_position - state_context.ecb.get_bottom_point();
|
||||
let grounded_common = GroundedStateCommon {
|
||||
current_line_id: res.line_id,
|
||||
};
|
||||
Some(FighterState::Land(LandingState {
|
||||
grounded_common,
|
||||
landing_type: LandingType::Special,
|
||||
}))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
air::collision_interrupt(state_context, LandingType::Special)
|
||||
}
|
||||
|
||||
fn on_enter(&mut self, state_context: &mut EnterContext) {
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use std::hash::Hasher;
|
||||
|
||||
use super::{
|
||||
CollisionContext, EnterContext, FighterStateImpl, InterruptContext, UpdateContext, ground, run,
|
||||
wait, walk,
|
||||
@@ -7,22 +5,15 @@ use super::{
|
||||
use crate::fighter::FighterFacingDirection;
|
||||
use crate::fighter::animation::AnimKind;
|
||||
use crate::fighter::state::FighterState;
|
||||
use crate::fighter::state::fall::FallState;
|
||||
use crate::fighter::state::ground::{GroundedMotionResult, GroundedStateCommon};
|
||||
use crate::fighter::state::ground::GroundedStateCommon;
|
||||
use crate::input::FighterCommands::{SmashMoveLeft, SmashMoveRight};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, Hash)]
|
||||
pub struct DashState {
|
||||
direction: FighterFacingDirection,
|
||||
pub ground_common: GroundedStateCommon,
|
||||
}
|
||||
|
||||
impl std::hash::Hash for DashState {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
self.direction.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
impl DashState {
|
||||
pub fn new(direction: FighterFacingDirection, ground_common: GroundedStateCommon) -> Self {
|
||||
Self {
|
||||
@@ -115,13 +106,7 @@ impl FighterStateImpl for DashState {
|
||||
&mut self,
|
||||
state_context: &mut CollisionContext,
|
||||
) -> Option<FighterState> {
|
||||
if let GroundedMotionResult::InAir =
|
||||
ground::collide_with_stage_grounded(state_context, &mut self.ground_common, true)
|
||||
{
|
||||
Some(FighterState::Fall(FallState))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
ground::collision_interrupt(state_context, &mut self.ground_common, true)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
use super::{CollisionContext, EnterContext, FighterStateImpl, InterruptContext, UpdateContext};
|
||||
use crate::fighter::animation::AnimKind;
|
||||
use crate::fighter::state::ground::GroundedStateCommon;
|
||||
use crate::fighter::state::land::{LandingState, LandingType};
|
||||
use crate::fighter::state::{FighterState, air, jump};
|
||||
|
||||
#[derive(Debug, Clone, Copy, Hash)]
|
||||
@@ -18,36 +16,17 @@ impl FighterStateImpl for FallState {
|
||||
}
|
||||
|
||||
fn update(&mut self, state_context: &mut UpdateContext) {
|
||||
air::integrate_gravity(state_context.velocity, state_context.fighter_attributes);
|
||||
air::apply_air_drift(
|
||||
state_context.velocity,
|
||||
state_context.fighter_attributes,
|
||||
state_context.input,
|
||||
);
|
||||
air::apply_air_motion(
|
||||
state_context.velocity,
|
||||
state_context.translation,
|
||||
state_context.prev_translation,
|
||||
);
|
||||
air::update_standard_motion(state_context);
|
||||
}
|
||||
|
||||
fn check_collision_interrupt(
|
||||
&mut self,
|
||||
state_context: &mut CollisionContext,
|
||||
) -> Option<FighterState> {
|
||||
if let Some(res) = state_context.air_collide_with_stage() {
|
||||
// Adjust translation
|
||||
state_context.translation.0 = res.hit_position - state_context.ecb.get_bottom_point();
|
||||
let grounded_common = GroundedStateCommon {
|
||||
current_line_id: res.line_id,
|
||||
};
|
||||
Some(FighterState::Land(LandingState::create(
|
||||
grounded_common,
|
||||
LandingType::Normal,
|
||||
)))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
air::collision_interrupt(
|
||||
state_context,
|
||||
crate::fighter::state::land::LandingType::Normal,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
//! bit-for-bit deterministic for rollback.
|
||||
|
||||
use crate::fighter::state::{
|
||||
CollisionContext, FighterState, InterruptContext, dash, ground_attack, turn, wait, walk,
|
||||
CollisionContext, FighterState, InterruptContext, dash, fall, ground_attack, turn, wait, walk,
|
||||
};
|
||||
use crate::fighter::{
|
||||
FighterAttributes, FighterPreviousTranslation, FighterTranslation, FighterVelocity,
|
||||
@@ -163,6 +163,22 @@ pub fn apply_grounded_motion(
|
||||
translation.0 += FGVec2::new(velocity.0.x, FGi32::ZERO);
|
||||
}
|
||||
|
||||
pub fn update_friction_motion(ctx: &mut crate::fighter::state::UpdateContext) {
|
||||
let friction = if ctx.velocity.x.abs() > ctx.fighter_attributes.max_walk_vel {
|
||||
ctx.fighter_attributes.ground_friction
|
||||
* ctx
|
||||
.game_settings
|
||||
.fighter_common
|
||||
.ground_friction_over_walk_speed_multiplier
|
||||
} else {
|
||||
ctx.fighter_attributes.ground_friction
|
||||
};
|
||||
|
||||
let ground_velocity = ctx.velocity.x;
|
||||
ctx.velocity.x += apply_grounded_friction(friction, ground_velocity);
|
||||
apply_grounded_motion(ctx.velocity, ctx.translation, ctx.prev_translation);
|
||||
}
|
||||
|
||||
pub fn collide_with_stage_grounded(
|
||||
state_context: &mut CollisionContext,
|
||||
ground_common: &mut GroundedStateCommon,
|
||||
@@ -210,6 +226,17 @@ pub fn collide_with_stage_grounded(
|
||||
}
|
||||
}
|
||||
|
||||
pub fn collision_interrupt(
|
||||
ctx: &mut CollisionContext,
|
||||
common: &mut GroundedStateCommon,
|
||||
can_walk_off: bool,
|
||||
) -> Option<FighterState> {
|
||||
match collide_with_stage_grounded(ctx, common, can_walk_off) {
|
||||
GroundedMotionResult::InGround => None,
|
||||
GroundedMotionResult::InAir => Some(FighterState::Fall(fall::FallState)),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
@@ -6,8 +6,8 @@ use crate::{
|
||||
CollisionContext, EnterContext, ExitContext, FighterState, FighterStateImpl,
|
||||
InterruptContext, UpdateContext, air,
|
||||
fall::FallState,
|
||||
ground::{GroundedMotionResult, GroundedStateCommon, collide_with_stage_grounded},
|
||||
land::{LandingState, LandingType},
|
||||
ground::{GroundedStateCommon, collision_interrupt},
|
||||
land::LandingType,
|
||||
wait::WaitState,
|
||||
},
|
||||
},
|
||||
@@ -88,29 +88,10 @@ impl FighterStateImpl for HitstunState {
|
||||
) -> Option<FighterState> {
|
||||
match &mut self.hitstop_kind {
|
||||
HitstopStateKind::Grounded(grounded_state_common) => {
|
||||
if let GroundedMotionResult::InAir =
|
||||
collide_with_stage_grounded(state_context, grounded_state_common, true)
|
||||
{
|
||||
Some(FighterState::Fall(FallState {}))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
collision_interrupt(state_context, grounded_state_common, true)
|
||||
}
|
||||
HitstopStateKind::Airborne => {
|
||||
if let Some(res) = state_context.air_collide_with_stage() {
|
||||
// Adjust translation
|
||||
state_context.translation.0 =
|
||||
res.hit_position - state_context.ecb.get_bottom_point();
|
||||
let grounded_common = GroundedStateCommon {
|
||||
current_line_id: res.line_id,
|
||||
};
|
||||
Some(FighterState::Land(LandingState::create(
|
||||
grounded_common,
|
||||
LandingType::Normal,
|
||||
)))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
air::collision_interrupt(state_context, LandingType::Normal)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,7 @@ use crate::{
|
||||
CollisionContext, EnterContext, FighterState, FighterStateImpl, InterruptContext,
|
||||
UpdateContext, air,
|
||||
air_dodge::{self, AirDodgeState},
|
||||
fall::FallState,
|
||||
ground::{self, GroundedMotionResult, GroundedStateCommon},
|
||||
land::{LandingState, LandingType},
|
||||
ground::{self, GroundedStateCommon},
|
||||
},
|
||||
},
|
||||
input::FighterCommands,
|
||||
@@ -84,40 +82,14 @@ impl FighterStateImpl for JumpSquatState {
|
||||
|
||||
fn update(&mut self, state_context: &mut UpdateContext) {
|
||||
self.duration_counter += 1;
|
||||
|
||||
let friction =
|
||||
if state_context.velocity.x.abs() > state_context.fighter_attributes.max_walk_vel {
|
||||
state_context.fighter_attributes.ground_friction
|
||||
* state_context
|
||||
.game_settings
|
||||
.fighter_common
|
||||
.ground_friction_over_walk_speed_multiplier
|
||||
} else {
|
||||
state_context.fighter_attributes.ground_friction
|
||||
};
|
||||
|
||||
let ground_velocity = state_context.velocity.x;
|
||||
|
||||
state_context.velocity.x += ground::apply_grounded_friction(friction, ground_velocity);
|
||||
|
||||
ground::apply_grounded_motion(
|
||||
state_context.velocity,
|
||||
state_context.translation,
|
||||
state_context.prev_translation,
|
||||
);
|
||||
ground::update_friction_motion(state_context);
|
||||
}
|
||||
|
||||
fn check_collision_interrupt(
|
||||
&mut self,
|
||||
state_context: &mut CollisionContext,
|
||||
) -> Option<FighterState> {
|
||||
if let GroundedMotionResult::InAir =
|
||||
ground::collide_with_stage_grounded(state_context, &mut self.grounded_common, false)
|
||||
{
|
||||
Some(FighterState::Fall(FallState))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
ground::collision_interrupt(state_context, &mut self.grounded_common, false)
|
||||
}
|
||||
|
||||
fn on_enter(&mut self, state_context: &mut EnterContext) {
|
||||
@@ -139,17 +111,7 @@ impl FighterStateImpl for JumpState {
|
||||
}
|
||||
|
||||
fn update(&mut self, state_context: &mut UpdateContext) {
|
||||
air::integrate_gravity(state_context.velocity, state_context.fighter_attributes);
|
||||
air::apply_air_drift(
|
||||
state_context.velocity,
|
||||
state_context.fighter_attributes,
|
||||
state_context.input,
|
||||
);
|
||||
air::apply_air_motion(
|
||||
state_context.velocity,
|
||||
state_context.translation,
|
||||
state_context.prev_translation,
|
||||
);
|
||||
air::update_standard_motion(state_context);
|
||||
}
|
||||
|
||||
fn on_enter(&mut self, state_context: &mut EnterContext) {
|
||||
@@ -207,19 +169,10 @@ impl FighterStateImpl for JumpState {
|
||||
&mut self,
|
||||
state_context: &mut CollisionContext,
|
||||
) -> Option<FighterState> {
|
||||
if let Some(res) = state_context.air_collide_with_stage() {
|
||||
// Adjust translation
|
||||
state_context.translation.0 = res.hit_position - state_context.ecb.get_bottom_point();
|
||||
let grounded_common = GroundedStateCommon {
|
||||
current_line_id: res.line_id,
|
||||
};
|
||||
Some(FighterState::Land(LandingState::create(
|
||||
grounded_common,
|
||||
LandingType::Normal,
|
||||
)))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
air::collision_interrupt(
|
||||
state_context,
|
||||
crate::fighter::state::land::LandingType::Normal,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,11 +3,7 @@ use crate::fighter::{
|
||||
state::{
|
||||
CollisionContext, EnterContext, FighterState, FighterStateImpl, InterruptContext,
|
||||
UpdateContext, dash,
|
||||
fall::FallState,
|
||||
ground::{
|
||||
self, GroundedMotionResult, GroundedStateCommon,
|
||||
grounded_movement_standstill_common_interrupts,
|
||||
},
|
||||
ground::{self, GroundedStateCommon, grounded_movement_standstill_common_interrupts},
|
||||
walk,
|
||||
},
|
||||
};
|
||||
@@ -53,39 +49,14 @@ impl FighterStateImpl for LandingState {
|
||||
}
|
||||
|
||||
fn update(&mut self, state_context: &mut UpdateContext) {
|
||||
let friction =
|
||||
if state_context.velocity.x.abs() > state_context.fighter_attributes.max_walk_vel {
|
||||
state_context.fighter_attributes.ground_friction
|
||||
* state_context
|
||||
.game_settings
|
||||
.fighter_common
|
||||
.ground_friction_over_walk_speed_multiplier
|
||||
} else {
|
||||
state_context.fighter_attributes.ground_friction
|
||||
};
|
||||
|
||||
let ground_velocity = state_context.velocity.x;
|
||||
|
||||
state_context.velocity.x += ground::apply_grounded_friction(friction, ground_velocity);
|
||||
|
||||
ground::apply_grounded_motion(
|
||||
state_context.velocity,
|
||||
state_context.translation,
|
||||
state_context.prev_translation,
|
||||
);
|
||||
ground::update_friction_motion(state_context);
|
||||
}
|
||||
|
||||
fn check_collision_interrupt(
|
||||
&mut self,
|
||||
state_context: &mut CollisionContext,
|
||||
) -> Option<FighterState> {
|
||||
if let GroundedMotionResult::InAir =
|
||||
ground::collide_with_stage_grounded(state_context, &mut self.grounded_common, true)
|
||||
{
|
||||
Some(FighterState::Fall(FallState))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
ground::collision_interrupt(state_context, &mut self.grounded_common, true)
|
||||
}
|
||||
|
||||
fn on_enter(&mut self, state_context: &mut EnterContext) {
|
||||
|
||||
@@ -150,6 +150,7 @@ pub struct UpdateContext<'a> {
|
||||
pub fighter_attributes: &'a FighterAttributes,
|
||||
pub attack_scripts: &'a Assets<FighterAttackScript>,
|
||||
pub attack_script_assets: &'a FighterAttackScriptAssets,
|
||||
pub facing_direction: &'a FighterFacingDirection,
|
||||
}
|
||||
|
||||
impl UpdateContext<'_> {
|
||||
@@ -290,6 +291,7 @@ impl<'w, 's> FighterFrameQueryItem<'w, 's> {
|
||||
fighter_attributes: attributes,
|
||||
attack_scripts,
|
||||
attack_script_assets,
|
||||
facing_direction: &self.facing_direction
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,9 +6,7 @@ use super::{
|
||||
};
|
||||
use crate::fighter::animation::AnimKind;
|
||||
use crate::fighter::state::FighterState;
|
||||
use crate::fighter::state::fall::FallState;
|
||||
use crate::fighter::state::ground::{GroundedMotionResult, GroundedStateCommon};
|
||||
use crate::math::int::FGi32;
|
||||
use crate::fighter::state::ground::GroundedStateCommon;
|
||||
|
||||
#[derive(Component, Debug, Clone, Hash)]
|
||||
pub struct RunState {
|
||||
@@ -43,7 +41,7 @@ impl FighterStateImpl for RunState {
|
||||
let last_frame = state_context.input.get_last_frame();
|
||||
let (accel, target_vel) = state_context
|
||||
.fighter_attributes
|
||||
.get_accel_and_target_dashrun(&last_frame, FGi32::ONE);
|
||||
.get_accel_and_target_dashrun(&last_frame, state_context.facing_direction.to_sign());
|
||||
let accel = ground::compute_ground_accel(
|
||||
accel,
|
||||
target_vel,
|
||||
@@ -64,13 +62,7 @@ impl FighterStateImpl for RunState {
|
||||
&mut self,
|
||||
state_context: &mut CollisionContext,
|
||||
) -> Option<FighterState> {
|
||||
if let GroundedMotionResult::InAir =
|
||||
ground::collide_with_stage_grounded(state_context, &mut self.grounded_common, false)
|
||||
{
|
||||
Some(FighterState::Fall(FallState))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
ground::collision_interrupt(state_context, &mut self.grounded_common, true)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use super::{CollisionContext, EnterContext, FighterStateImpl, InterruptContext, UpdateContext};
|
||||
use crate::fighter::animation::AnimKind;
|
||||
use crate::fighter::state::fall::FallState;
|
||||
use crate::fighter::state::ground::{self, GroundedMotionResult, GroundedStateCommon};
|
||||
use crate::fighter::state::ground::{self, GroundedStateCommon};
|
||||
use crate::fighter::state::{FighterState, dash, jump, wait, walk};
|
||||
use crate::input::FighterCommands;
|
||||
|
||||
@@ -48,39 +47,14 @@ impl FighterStateImpl for TurnState {
|
||||
}
|
||||
|
||||
fn update(&mut self, state_context: &mut UpdateContext) {
|
||||
let friction =
|
||||
if state_context.velocity.x.abs() > state_context.fighter_attributes.max_walk_vel {
|
||||
state_context.fighter_attributes.ground_friction
|
||||
* state_context
|
||||
.game_settings
|
||||
.fighter_common
|
||||
.ground_friction_over_walk_speed_multiplier
|
||||
} else {
|
||||
state_context.fighter_attributes.ground_friction
|
||||
};
|
||||
|
||||
let ground_velocity = state_context.velocity.x;
|
||||
|
||||
state_context.velocity.x += ground::apply_grounded_friction(friction, ground_velocity);
|
||||
|
||||
ground::apply_grounded_motion(
|
||||
state_context.velocity,
|
||||
state_context.translation,
|
||||
state_context.prev_translation,
|
||||
);
|
||||
ground::update_friction_motion(state_context);
|
||||
}
|
||||
|
||||
fn check_collision_interrupt(
|
||||
&mut self,
|
||||
state_context: &mut CollisionContext,
|
||||
) -> Option<FighterState> {
|
||||
if let GroundedMotionResult::InAir =
|
||||
ground::collide_with_stage_grounded(state_context, &mut self.grounded_common, false)
|
||||
{
|
||||
Some(FighterState::Fall(FallState))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
ground::collision_interrupt(state_context, &mut self.grounded_common, false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,8 +3,7 @@ use super::{
|
||||
};
|
||||
use crate::fighter::animation::AnimKind;
|
||||
use crate::fighter::state::FighterState;
|
||||
use crate::fighter::state::fall::FallState;
|
||||
use crate::fighter::state::ground::{GroundedMotionResult, GroundedStateCommon};
|
||||
use crate::fighter::state::ground::GroundedStateCommon;
|
||||
|
||||
#[derive(Debug, Clone, Hash)]
|
||||
pub struct WaitState {
|
||||
@@ -38,39 +37,14 @@ impl FighterStateImpl for WaitState {
|
||||
}
|
||||
|
||||
fn update(&mut self, state_context: &mut UpdateContext) {
|
||||
let friction =
|
||||
if state_context.velocity.x.abs() > state_context.fighter_attributes.max_walk_vel {
|
||||
state_context.fighter_attributes.ground_friction
|
||||
* state_context
|
||||
.game_settings
|
||||
.fighter_common
|
||||
.ground_friction_over_walk_speed_multiplier
|
||||
} else {
|
||||
state_context.fighter_attributes.ground_friction
|
||||
};
|
||||
|
||||
let ground_velocity = state_context.velocity.x;
|
||||
|
||||
state_context.velocity.x += ground::apply_grounded_friction(friction, ground_velocity);
|
||||
|
||||
ground::apply_grounded_motion(
|
||||
state_context.velocity,
|
||||
state_context.translation,
|
||||
state_context.prev_translation,
|
||||
);
|
||||
ground::update_friction_motion(state_context);
|
||||
}
|
||||
|
||||
fn check_collision_interrupt(
|
||||
&mut self,
|
||||
state_context: &mut CollisionContext,
|
||||
) -> Option<FighterState> {
|
||||
if let GroundedMotionResult::InAir =
|
||||
ground::collide_with_stage_grounded(state_context, &mut self.grounded_common, false)
|
||||
{
|
||||
Some(FighterState::Fall(FallState))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
ground::collision_interrupt(state_context, &mut self.grounded_common, false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,7 @@ use super::{
|
||||
};
|
||||
use crate::fighter::animation::AnimKind;
|
||||
use crate::fighter::state::FighterState;
|
||||
use crate::fighter::state::fall::FallState;
|
||||
use crate::fighter::state::ground::{GroundedMotionResult, GroundedStateCommon};
|
||||
use crate::fighter::state::ground::GroundedStateCommon;
|
||||
|
||||
#[derive(Debug, Clone, Hash)]
|
||||
pub struct WalkState {
|
||||
@@ -55,13 +54,7 @@ impl FighterStateImpl for WalkState {
|
||||
&mut self,
|
||||
state_context: &mut CollisionContext,
|
||||
) -> Option<FighterState> {
|
||||
if let GroundedMotionResult::InAir =
|
||||
ground::collide_with_stage_grounded(state_context, &mut self.grounded_common, false)
|
||||
{
|
||||
Some(FighterState::Fall(FallState))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
ground::collision_interrupt(state_context, &mut self.grounded_common, false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user