mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-02 15: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
|
|
@ -1,4 +1,4 @@
|
|||
# Phase 0: Unit test infrastructure using Catch2 v3 (amalgamated)
|
||||
# Unit test infrastructure using Catch2 v3 (amalgamated)
|
||||
|
||||
# Catch2 amalgamated as a library target
|
||||
add_library(catch2_main STATIC
|
||||
|
|
@ -139,7 +139,7 @@ register_test_target(test_frustum)
|
|||
add_executable(test_animation_ids
|
||||
test_animation_ids.cpp
|
||||
${TEST_COMMON_SOURCES}
|
||||
${CMAKE_SOURCE_DIR}/src/rendering/animation_ids.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/rendering/animation/animation_ids.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/pipeline/dbc_loader.cpp
|
||||
)
|
||||
target_include_directories(test_animation_ids PRIVATE ${TEST_INCLUDE_DIRS})
|
||||
|
|
@ -148,6 +148,55 @@ target_link_libraries(test_animation_ids PRIVATE catch2_main)
|
|||
add_test(NAME animation_ids COMMAND test_animation_ids)
|
||||
register_test_target(test_animation_ids)
|
||||
|
||||
# ── test_locomotion_fsm ──────────────────────────────────────
|
||||
add_executable(test_locomotion_fsm
|
||||
test_locomotion_fsm.cpp
|
||||
${TEST_COMMON_SOURCES}
|
||||
${CMAKE_SOURCE_DIR}/src/rendering/animation/locomotion_fsm.cpp
|
||||
)
|
||||
target_include_directories(test_locomotion_fsm PRIVATE ${TEST_INCLUDE_DIRS})
|
||||
target_include_directories(test_locomotion_fsm SYSTEM PRIVATE ${TEST_SYSTEM_INCLUDE_DIRS})
|
||||
target_link_libraries(test_locomotion_fsm PRIVATE catch2_main)
|
||||
add_test(NAME locomotion_fsm COMMAND test_locomotion_fsm)
|
||||
register_test_target(test_locomotion_fsm)
|
||||
|
||||
# ── test_combat_fsm ──────────────────────────────────────────
|
||||
add_executable(test_combat_fsm
|
||||
test_combat_fsm.cpp
|
||||
${TEST_COMMON_SOURCES}
|
||||
${CMAKE_SOURCE_DIR}/src/rendering/animation/combat_fsm.cpp
|
||||
)
|
||||
target_include_directories(test_combat_fsm PRIVATE ${TEST_INCLUDE_DIRS})
|
||||
target_include_directories(test_combat_fsm SYSTEM PRIVATE ${TEST_SYSTEM_INCLUDE_DIRS})
|
||||
target_link_libraries(test_combat_fsm PRIVATE catch2_main)
|
||||
add_test(NAME combat_fsm COMMAND test_combat_fsm)
|
||||
register_test_target(test_combat_fsm)
|
||||
|
||||
# ── test_activity_fsm ────────────────────────────────────────
|
||||
add_executable(test_activity_fsm
|
||||
test_activity_fsm.cpp
|
||||
${TEST_COMMON_SOURCES}
|
||||
${CMAKE_SOURCE_DIR}/src/rendering/animation/activity_fsm.cpp
|
||||
)
|
||||
target_include_directories(test_activity_fsm PRIVATE ${TEST_INCLUDE_DIRS})
|
||||
target_include_directories(test_activity_fsm SYSTEM PRIVATE ${TEST_SYSTEM_INCLUDE_DIRS})
|
||||
target_link_libraries(test_activity_fsm PRIVATE catch2_main)
|
||||
add_test(NAME activity_fsm COMMAND test_activity_fsm)
|
||||
register_test_target(test_activity_fsm)
|
||||
|
||||
# NPC animator tests removed — NpcAnimator replaced by generic CharacterAnimator
|
||||
|
||||
# ── test_anim_capability ─────────────────────────────────────
|
||||
# Header-only struct tests — no source files needed
|
||||
add_executable(test_anim_capability
|
||||
test_anim_capability.cpp
|
||||
)
|
||||
target_include_directories(test_anim_capability PRIVATE ${TEST_INCLUDE_DIRS})
|
||||
target_include_directories(test_anim_capability SYSTEM PRIVATE ${TEST_SYSTEM_INCLUDE_DIRS})
|
||||
target_link_libraries(test_anim_capability PRIVATE catch2_main)
|
||||
add_test(NAME anim_capability COMMAND test_anim_capability)
|
||||
register_test_target(test_anim_capability)
|
||||
|
||||
# ── ASAN / UBSan for test targets ────────────────────────────
|
||||
if(WOWEE_ENABLE_ASAN AND NOT MSVC)
|
||||
foreach(_t IN LISTS ALL_TEST_TARGETS)
|
||||
|
|
|
|||
112
tests/test_activity_fsm.cpp
Normal file
112
tests/test_activity_fsm.cpp
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
// ActivityFSM unit tests
|
||||
#include <catch_amalgamated.hpp>
|
||||
#include "rendering/animation/activity_fsm.hpp"
|
||||
#include "rendering/animation/animation_ids.hpp"
|
||||
|
||||
using namespace wowee::rendering;
|
||||
namespace anim = wowee::rendering::anim;
|
||||
|
||||
static AnimCapabilitySet makeActivityCaps() {
|
||||
AnimCapabilitySet caps;
|
||||
caps.resolvedStand = anim::STAND;
|
||||
caps.resolvedSitDown = anim::SIT_GROUND_DOWN;
|
||||
caps.resolvedSitLoop = anim::SITTING;
|
||||
caps.resolvedSitUp = anim::SIT_GROUND_UP;
|
||||
caps.resolvedKneel = anim::KNEEL_LOOP;
|
||||
caps.resolvedLoot = anim::LOOT;
|
||||
return caps;
|
||||
}
|
||||
|
||||
static ActivityFSM::Input idleInput() {
|
||||
ActivityFSM::Input in;
|
||||
in.grounded = true;
|
||||
return in;
|
||||
}
|
||||
|
||||
TEST_CASE("ActivityFSM: NONE by default", "[activity]") {
|
||||
ActivityFSM fsm;
|
||||
CHECK(fsm.getState() == ActivityFSM::State::NONE);
|
||||
CHECK_FALSE(fsm.isActive());
|
||||
}
|
||||
|
||||
TEST_CASE("ActivityFSM: emote starts and returns valid output", "[activity]") {
|
||||
ActivityFSM fsm;
|
||||
auto caps = makeActivityCaps();
|
||||
|
||||
fsm.startEmote(anim::EMOTE_WAVE, false);
|
||||
CHECK(fsm.getState() == ActivityFSM::State::EMOTE);
|
||||
CHECK(fsm.isEmoteActive());
|
||||
|
||||
auto in = idleInput();
|
||||
auto out = fsm.resolve(in, caps);
|
||||
REQUIRE(out.valid);
|
||||
CHECK(out.animId == anim::EMOTE_WAVE);
|
||||
CHECK(out.loop == false);
|
||||
}
|
||||
|
||||
TEST_CASE("ActivityFSM: emote cancelled by movement", "[activity]") {
|
||||
ActivityFSM fsm;
|
||||
auto caps = makeActivityCaps();
|
||||
|
||||
fsm.startEmote(anim::EMOTE_WAVE, false);
|
||||
|
||||
auto in = idleInput();
|
||||
in.moving = true;
|
||||
auto out = fsm.resolve(in, caps);
|
||||
|
||||
// After movement, emote should be cancelled
|
||||
CHECK_FALSE(fsm.isEmoteActive());
|
||||
CHECK(fsm.getState() == ActivityFSM::State::NONE);
|
||||
}
|
||||
|
||||
TEST_CASE("ActivityFSM: looting starts and stops", "[activity]") {
|
||||
ActivityFSM fsm;
|
||||
auto caps = makeActivityCaps();
|
||||
|
||||
fsm.startLooting();
|
||||
CHECK(fsm.getState() == ActivityFSM::State::LOOTING);
|
||||
|
||||
auto in = idleInput();
|
||||
auto out = fsm.resolve(in, caps);
|
||||
REQUIRE(out.valid);
|
||||
|
||||
// stopLooting transitions through LOOT_END (KNEEL_END one-shot) before NONE
|
||||
fsm.stopLooting();
|
||||
CHECK(fsm.getState() == ActivityFSM::State::LOOT_END);
|
||||
}
|
||||
|
||||
TEST_CASE("ActivityFSM: sit stand state triggers sit down", "[activity]") {
|
||||
ActivityFSM fsm;
|
||||
auto caps = makeActivityCaps();
|
||||
|
||||
fsm.setStandState(ActivityFSM::STAND_STATE_SIT);
|
||||
CHECK(fsm.getState() == ActivityFSM::State::SIT_DOWN);
|
||||
|
||||
auto in = idleInput();
|
||||
in.sitting = true;
|
||||
auto out = fsm.resolve(in, caps);
|
||||
REQUIRE(out.valid);
|
||||
}
|
||||
|
||||
TEST_CASE("ActivityFSM: cancel emote explicitly", "[activity]") {
|
||||
ActivityFSM fsm;
|
||||
auto caps = makeActivityCaps();
|
||||
|
||||
fsm.startEmote(anim::EMOTE_DANCE, true);
|
||||
CHECK(fsm.isEmoteActive());
|
||||
CHECK(fsm.getEmoteAnimId() == anim::EMOTE_DANCE);
|
||||
|
||||
fsm.cancelEmote();
|
||||
CHECK_FALSE(fsm.isEmoteActive());
|
||||
CHECK(fsm.getState() == ActivityFSM::State::NONE);
|
||||
}
|
||||
|
||||
TEST_CASE("ActivityFSM: reset clears all state", "[activity]") {
|
||||
ActivityFSM fsm;
|
||||
fsm.startEmote(anim::EMOTE_WAVE, false);
|
||||
CHECK(fsm.isActive());
|
||||
|
||||
fsm.reset();
|
||||
CHECK(fsm.getState() == ActivityFSM::State::NONE);
|
||||
CHECK_FALSE(fsm.isActive());
|
||||
}
|
||||
56
tests/test_anim_capability.cpp
Normal file
56
tests/test_anim_capability.cpp
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
// AnimCapabilitySet unit tests
|
||||
#include <catch_amalgamated.hpp>
|
||||
#include "rendering/animation/anim_capability_set.hpp"
|
||||
|
||||
using namespace wowee::rendering;
|
||||
|
||||
TEST_CASE("AnimCapabilitySet: default-constructed has all zero IDs", "[capability]") {
|
||||
AnimCapabilitySet caps;
|
||||
|
||||
CHECK(caps.resolvedStand == 0);
|
||||
CHECK(caps.resolvedWalk == 0);
|
||||
CHECK(caps.resolvedRun == 0);
|
||||
CHECK(caps.resolvedSprint == 0);
|
||||
CHECK(caps.resolvedJumpStart == 0);
|
||||
CHECK(caps.resolvedJump == 0);
|
||||
CHECK(caps.resolvedJumpEnd == 0);
|
||||
CHECK(caps.resolvedSwimIdle == 0);
|
||||
CHECK(caps.resolvedSwim == 0);
|
||||
CHECK(caps.resolvedCombatIdle == 0);
|
||||
CHECK(caps.resolvedMelee1H == 0);
|
||||
CHECK(caps.resolvedMelee2H == 0);
|
||||
CHECK(caps.resolvedStun == 0);
|
||||
CHECK(caps.resolvedMount == 0);
|
||||
CHECK(caps.resolvedStealthIdle == 0);
|
||||
CHECK(caps.resolvedLoot == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("AnimCapabilitySet: default-constructed has all flags false", "[capability]") {
|
||||
AnimCapabilitySet caps;
|
||||
|
||||
CHECK_FALSE(caps.hasStand);
|
||||
CHECK_FALSE(caps.hasWalk);
|
||||
CHECK_FALSE(caps.hasRun);
|
||||
CHECK_FALSE(caps.hasSprint);
|
||||
CHECK_FALSE(caps.hasWalkBackwards);
|
||||
CHECK_FALSE(caps.hasJump);
|
||||
CHECK_FALSE(caps.hasSwim);
|
||||
CHECK_FALSE(caps.hasMelee);
|
||||
CHECK_FALSE(caps.hasStealth);
|
||||
CHECK_FALSE(caps.hasDeath);
|
||||
CHECK_FALSE(caps.hasMount);
|
||||
}
|
||||
|
||||
TEST_CASE("AnimOutput::ok creates valid output", "[capability]") {
|
||||
auto out = AnimOutput::ok(42, true);
|
||||
CHECK(out.valid);
|
||||
CHECK(out.animId == 42);
|
||||
CHECK(out.loop == true);
|
||||
}
|
||||
|
||||
TEST_CASE("AnimOutput::stay creates invalid output", "[capability]") {
|
||||
auto out = AnimOutput::stay();
|
||||
CHECK_FALSE(out.valid);
|
||||
CHECK(out.animId == 0);
|
||||
CHECK(out.loop == false);
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// Animation ID validation tests — covers nameFromId() and validateAgainstDBC()
|
||||
#include <catch_amalgamated.hpp>
|
||||
#include "rendering/animation_ids.hpp"
|
||||
#include "rendering/animation/animation_ids.hpp"
|
||||
#include "pipeline/dbc_loader.hpp"
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
|
|
|||
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());
|
||||
}
|
||||
167
tests/test_locomotion_fsm.cpp
Normal file
167
tests/test_locomotion_fsm.cpp
Normal file
|
|
@ -0,0 +1,167 @@
|
|||
// LocomotionFSM unit tests
|
||||
#include <catch_amalgamated.hpp>
|
||||
#include "rendering/animation/locomotion_fsm.hpp"
|
||||
#include "rendering/animation/animation_ids.hpp"
|
||||
|
||||
using namespace wowee::rendering;
|
||||
namespace anim = wowee::rendering::anim;
|
||||
|
||||
// Helper: create a capability set with basic locomotion resolved
|
||||
static AnimCapabilitySet makeLocoCaps() {
|
||||
AnimCapabilitySet caps;
|
||||
caps.resolvedStand = anim::STAND;
|
||||
caps.resolvedWalk = anim::WALK;
|
||||
caps.resolvedRun = anim::RUN;
|
||||
caps.resolvedSprint = anim::SPRINT;
|
||||
caps.resolvedWalkBackwards = anim::WALK_BACKWARDS;
|
||||
caps.resolvedStrafeLeft = anim::SHUFFLE_LEFT;
|
||||
caps.resolvedStrafeRight = anim::SHUFFLE_RIGHT;
|
||||
caps.resolvedJumpStart = anim::JUMP_START;
|
||||
caps.resolvedJump = anim::JUMP;
|
||||
caps.resolvedJumpEnd = anim::JUMP_END;
|
||||
caps.resolvedSwimIdle = anim::SWIM_IDLE;
|
||||
caps.resolvedSwim = anim::SWIM;
|
||||
caps.hasStand = true;
|
||||
caps.hasWalk = true;
|
||||
caps.hasRun = true;
|
||||
caps.hasSprint = true;
|
||||
caps.hasWalkBackwards = true;
|
||||
caps.hasJump = true;
|
||||
caps.hasSwim = true;
|
||||
return caps;
|
||||
}
|
||||
|
||||
static LocomotionFSM::Input idle() {
|
||||
LocomotionFSM::Input in;
|
||||
in.deltaTime = 0.016f;
|
||||
return in;
|
||||
}
|
||||
|
||||
TEST_CASE("LocomotionFSM: IDLE → WALK on move start (non-sprinting)", "[locomotion]") {
|
||||
LocomotionFSM fsm;
|
||||
auto caps = makeLocoCaps();
|
||||
|
||||
auto in = idle();
|
||||
in.moving = true;
|
||||
auto out = fsm.resolve(in, caps);
|
||||
|
||||
REQUIRE(out.valid);
|
||||
REQUIRE(out.animId == anim::WALK);
|
||||
REQUIRE(out.loop == true);
|
||||
CHECK(fsm.getState() == LocomotionFSM::State::WALK);
|
||||
}
|
||||
|
||||
TEST_CASE("LocomotionFSM: IDLE → RUN on move start (sprinting)", "[locomotion]") {
|
||||
LocomotionFSM fsm;
|
||||
auto caps = makeLocoCaps();
|
||||
|
||||
auto in = idle();
|
||||
in.moving = true;
|
||||
in.sprinting = true;
|
||||
auto out = fsm.resolve(in, caps);
|
||||
|
||||
REQUIRE(out.valid);
|
||||
REQUIRE(out.animId == anim::RUN);
|
||||
CHECK(fsm.getState() == LocomotionFSM::State::RUN);
|
||||
}
|
||||
|
||||
TEST_CASE("LocomotionFSM: WALK → IDLE on move stop (after grace)", "[locomotion]") {
|
||||
LocomotionFSM fsm;
|
||||
auto caps = makeLocoCaps();
|
||||
|
||||
// Start walking
|
||||
auto in = idle();
|
||||
in.moving = true;
|
||||
fsm.resolve(in, caps);
|
||||
CHECK(fsm.getState() == LocomotionFSM::State::WALK);
|
||||
|
||||
// Stop moving — grace timer keeps walk for a bit
|
||||
in.moving = false;
|
||||
in.deltaTime = 0.2f; // > grace period (0.12s)
|
||||
auto out = fsm.resolve(in, caps);
|
||||
|
||||
CHECK(fsm.getState() == LocomotionFSM::State::IDLE);
|
||||
}
|
||||
|
||||
TEST_CASE("LocomotionFSM: WALK → JUMP_START on jump", "[locomotion]") {
|
||||
LocomotionFSM fsm;
|
||||
auto caps = makeLocoCaps();
|
||||
|
||||
// Start walking
|
||||
auto in = idle();
|
||||
in.moving = true;
|
||||
fsm.resolve(in, caps);
|
||||
|
||||
// Jump
|
||||
in.jumping = true;
|
||||
in.grounded = false;
|
||||
auto out = fsm.resolve(in, caps);
|
||||
|
||||
REQUIRE(out.valid);
|
||||
REQUIRE(out.animId == anim::JUMP_START);
|
||||
CHECK(fsm.getState() == LocomotionFSM::State::JUMP_START);
|
||||
}
|
||||
|
||||
TEST_CASE("LocomotionFSM: SWIM_IDLE → SWIM on move start while swimming", "[locomotion]") {
|
||||
LocomotionFSM fsm;
|
||||
auto caps = makeLocoCaps();
|
||||
|
||||
// Enter swim idle
|
||||
auto in = idle();
|
||||
in.swimming = true;
|
||||
fsm.resolve(in, caps);
|
||||
CHECK(fsm.getState() == LocomotionFSM::State::SWIM_IDLE);
|
||||
|
||||
// Start swimming
|
||||
in.moving = true;
|
||||
auto out = fsm.resolve(in, caps);
|
||||
|
||||
REQUIRE(out.valid);
|
||||
REQUIRE(out.animId == anim::SWIM);
|
||||
CHECK(fsm.getState() == LocomotionFSM::State::SWIM);
|
||||
}
|
||||
|
||||
TEST_CASE("LocomotionFSM: backward walking resolves WALK_BACKWARDS", "[locomotion]") {
|
||||
LocomotionFSM fsm;
|
||||
auto caps = makeLocoCaps();
|
||||
|
||||
auto in = idle();
|
||||
in.moving = true;
|
||||
in.movingBackward = true;
|
||||
auto out = fsm.resolve(in, caps);
|
||||
|
||||
REQUIRE(out.valid);
|
||||
// Should use WALK_BACKWARDS when available
|
||||
CHECK(out.animId == anim::WALK_BACKWARDS);
|
||||
}
|
||||
|
||||
TEST_CASE("LocomotionFSM: STAY when WALK_BACKWARDS missing from caps", "[locomotion]") {
|
||||
LocomotionFSM fsm;
|
||||
AnimCapabilitySet caps;
|
||||
caps.resolvedStand = anim::STAND;
|
||||
caps.resolvedWalk = anim::WALK;
|
||||
caps.hasStand = true;
|
||||
caps.hasWalk = true;
|
||||
// No WALK_BACKWARDS in caps
|
||||
|
||||
auto in = idle();
|
||||
in.moving = true;
|
||||
in.movingBackward = true;
|
||||
auto out = fsm.resolve(in, caps);
|
||||
|
||||
// Should still resolve something — falls back to walk
|
||||
REQUIRE(out.valid);
|
||||
}
|
||||
|
||||
TEST_CASE("LocomotionFSM: reset restores IDLE", "[locomotion]") {
|
||||
LocomotionFSM fsm;
|
||||
auto caps = makeLocoCaps();
|
||||
|
||||
auto in = idle();
|
||||
in.moving = true;
|
||||
fsm.resolve(in, caps);
|
||||
CHECK(fsm.getState() == LocomotionFSM::State::WALK);
|
||||
|
||||
fsm.reset();
|
||||
CHECK(fsm.getState() == LocomotionFSM::State::IDLE);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue