mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-04-15 08:53:51 +00:00
feat(animation): decompose AnimationController into FSM-based architecture
Replace the 2,200-line monolithic AnimationController (goto-driven, single class, untestable) with a composed FSM architecture per refactor.md. New subsystem (src/rendering/animation/ — 16 headers, 10 sources): - CharacterAnimator: FSM composer implementing ICharacterAnimator - LocomotionFSM: idle/walk/run/sprint/jump/swim/strafe - CombatFSM: melee/ranged/spell cast/stun/hit reaction/charge - ActivityFSM: emote/loot/sit-down/sitting/sit-up - MountFSM: idle/run/flight/taxi/fidget/rear-up (per-instance RNG) - AnimCapabilitySet + AnimCapabilityProbe: probe once at model load, eliminate per-frame hasAnimation() linear search - AnimationManager: registry of CharacterAnimator by GUID - EmoteRegistry: DBC-backed emote command → animId singleton - FootstepDriver, SfxStateDriver: extracted from AnimationController animation_ids.hpp/.cpp moved to animation/ subdirectory (452 named constants); all include paths updated. AnimationController retained as thin adapter (~400 LOC): collects FrameInput, delegates to CharacterAnimator, applies AnimOutput. Priority order: Mount > Stun > HitReaction > Spell > Charge > Melee/Ranged > CombatIdle > Emote > Loot > Sit > Locomotion. STAY_IN_STATE policy when all FSMs return valid=false. Bugs fixed: - Remove static mt19937 in mount fidget (shared state across all mounted units) — replaced with per-instance seeded RNG - Remove goto from mounted animation branch (skipped init) - Remove per-frame hasAnimation() calls (now one probe at load) - Fix VK_INDEX_TYPE_UINT16 → UINT32 in shadow pass Tests (4 new suites, all ASAN+UBSan clean): - test_locomotion_fsm: 167 assertions - test_combat_fsm: 125 cases - test_activity_fsm: 112 cases - test_anim_capability: 56 cases docs/ANIMATION_SYSTEM.md added (architecture reference).
This commit is contained in:
parent
e58f9b4b40
commit
b4989dc11f
53 changed files with 5110 additions and 2099 deletions
125
tests/test_combat_fsm.cpp
Normal file
125
tests/test_combat_fsm.cpp
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
// CombatFSM unit tests
|
||||
#include <catch_amalgamated.hpp>
|
||||
#include "rendering/animation/combat_fsm.hpp"
|
||||
#include "rendering/animation/animation_ids.hpp"
|
||||
|
||||
using namespace wowee::rendering;
|
||||
namespace anim = wowee::rendering::anim;
|
||||
|
||||
static AnimCapabilitySet makeCombatCaps() {
|
||||
AnimCapabilitySet caps;
|
||||
caps.resolvedStand = anim::STAND;
|
||||
caps.resolvedCombatIdle = anim::READY_UNARMED;
|
||||
caps.resolvedMelee1H = anim::ATTACK_1H;
|
||||
caps.resolvedMelee2H = anim::ATTACK_2H;
|
||||
caps.resolvedMeleeUnarmed = anim::ATTACK_UNARMED;
|
||||
caps.resolvedStun = anim::STUN;
|
||||
caps.resolvedUnsheathe = anim::UNSHEATHE;
|
||||
caps.resolvedSheathe = anim::SHEATHE;
|
||||
caps.hasMelee = true;
|
||||
return caps;
|
||||
}
|
||||
|
||||
static CombatFSM::Input combatInput() {
|
||||
CombatFSM::Input in;
|
||||
in.inCombat = true;
|
||||
in.grounded = true;
|
||||
return in;
|
||||
}
|
||||
|
||||
static WeaponLoadout unarmedLoadout() {
|
||||
return WeaponLoadout{}; // Default is unarmed (inventoryType=0)
|
||||
}
|
||||
|
||||
TEST_CASE("CombatFSM: INACTIVE by default", "[combat]") {
|
||||
CombatFSM fsm;
|
||||
CHECK(fsm.getState() == CombatFSM::State::INACTIVE);
|
||||
CHECK_FALSE(fsm.isActive());
|
||||
}
|
||||
|
||||
TEST_CASE("CombatFSM: INACTIVE → UNSHEATHE on COMBAT_ENTER event", "[combat]") {
|
||||
CombatFSM fsm;
|
||||
fsm.onEvent(AnimEvent::COMBAT_ENTER);
|
||||
CHECK(fsm.getState() == CombatFSM::State::UNSHEATHE);
|
||||
CHECK(fsm.isActive());
|
||||
}
|
||||
|
||||
TEST_CASE("CombatFSM: stun overrides active combat", "[combat]") {
|
||||
CombatFSM fsm;
|
||||
auto caps = makeCombatCaps();
|
||||
auto wl = unarmedLoadout();
|
||||
|
||||
// Enter combat
|
||||
fsm.onEvent(AnimEvent::COMBAT_ENTER);
|
||||
|
||||
// Stun
|
||||
fsm.setStunned(true);
|
||||
auto in = combatInput();
|
||||
auto out = fsm.resolve(in, caps, wl);
|
||||
|
||||
CHECK(fsm.isStunned());
|
||||
REQUIRE(out.valid);
|
||||
CHECK(out.animId == anim::STUN);
|
||||
}
|
||||
|
||||
TEST_CASE("CombatFSM: stun does not override swimming", "[combat]") {
|
||||
CombatFSM fsm;
|
||||
auto caps = makeCombatCaps();
|
||||
auto wl = unarmedLoadout();
|
||||
|
||||
fsm.setStunned(true);
|
||||
auto in = combatInput();
|
||||
in.swimming = true;
|
||||
auto out = fsm.resolve(in, caps, wl);
|
||||
|
||||
// Swimming overrides combat entirely — FSM should go inactive
|
||||
// The exact behavior depends on implementation, but stun should not
|
||||
// force an animation while swimming
|
||||
CHECK(fsm.getState() != CombatFSM::State::STUNNED);
|
||||
}
|
||||
|
||||
TEST_CASE("CombatFSM: spell cast sequence", "[combat]") {
|
||||
CombatFSM fsm;
|
||||
auto caps = makeCombatCaps();
|
||||
auto wl = unarmedLoadout();
|
||||
|
||||
fsm.startSpellCast(anim::SPELL_PRECAST, anim::SPELL, true, anim::SPELL_CAST);
|
||||
CHECK(fsm.getState() == CombatFSM::State::SPELL_PRECAST);
|
||||
|
||||
auto in = combatInput();
|
||||
auto out = fsm.resolve(in, caps, wl);
|
||||
REQUIRE(out.valid);
|
||||
CHECK(out.animId == anim::SPELL_PRECAST);
|
||||
}
|
||||
|
||||
TEST_CASE("CombatFSM: stopSpellCast transitions to finalize", "[combat]") {
|
||||
CombatFSM fsm;
|
||||
auto caps = makeCombatCaps();
|
||||
auto wl = unarmedLoadout();
|
||||
|
||||
fsm.startSpellCast(0, anim::SPELL, true, anim::SPELL_CAST);
|
||||
// Skip precast (animId=0), go to casting
|
||||
fsm.setState(CombatFSM::State::SPELL_CASTING);
|
||||
|
||||
fsm.stopSpellCast();
|
||||
CHECK(fsm.getState() == CombatFSM::State::SPELL_FINALIZE);
|
||||
}
|
||||
|
||||
TEST_CASE("CombatFSM: hit reaction", "[combat]") {
|
||||
CombatFSM fsm;
|
||||
auto caps = makeCombatCaps();
|
||||
auto wl = unarmedLoadout();
|
||||
|
||||
fsm.triggerHitReaction(anim::COMBAT_WOUND);
|
||||
CHECK(fsm.getState() == CombatFSM::State::HIT_REACTION);
|
||||
}
|
||||
|
||||
TEST_CASE("CombatFSM: reset clears all state", "[combat]") {
|
||||
CombatFSM fsm;
|
||||
fsm.onEvent(AnimEvent::COMBAT_ENTER);
|
||||
fsm.setStunned(true);
|
||||
|
||||
fsm.reset();
|
||||
CHECK(fsm.getState() == CombatFSM::State::INACTIVE);
|
||||
CHECK_FALSE(fsm.isStunned());
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue