mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-04-13 08:03:51 +00:00
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).
79 lines
2.5 KiB
C++
79 lines
2.5 KiB
C++
#pragma once
|
|
|
|
#include "rendering/animation/anim_capability_set.hpp"
|
|
#include "rendering/animation/anim_event.hpp"
|
|
#include <cstdint>
|
|
|
|
namespace wowee {
|
|
namespace rendering {
|
|
|
|
// ============================================================================
|
|
// LocomotionFSM
|
|
//
|
|
// Pure logic state machine for movement animation. No renderer dependency.
|
|
// States: IDLE · WALK · RUN · JUMP_START · JUMP_MID · JUMP_END · SWIM_IDLE · SWIM
|
|
//
|
|
// Grace timer is internal — no external locomotionStopGraceTimer_ needed.
|
|
// ============================================================================
|
|
class LocomotionFSM {
|
|
public:
|
|
enum class State : uint8_t {
|
|
IDLE, WALK, RUN,
|
|
JUMP_START, JUMP_MID, JUMP_END,
|
|
SWIM_IDLE, SWIM,
|
|
};
|
|
|
|
struct Input {
|
|
bool moving = false;
|
|
bool movingForward = false;
|
|
bool sprinting = false;
|
|
bool movingBackward = false;
|
|
bool strafeLeft = false;
|
|
bool strafeRight = false;
|
|
bool grounded = true;
|
|
bool jumping = false;
|
|
bool swimming = false;
|
|
bool sitting = false;
|
|
bool sprintAura = false; // Sprint/Dash aura — use SPRINT anim
|
|
float deltaTime = 0.0f;
|
|
// Animation state for one-shot completion detection (jump start/end)
|
|
uint32_t currentAnimId = 0;
|
|
float currentAnimTime = 0.0f;
|
|
float currentAnimDuration = 0.0f;
|
|
bool haveAnimState = false;
|
|
};
|
|
|
|
/// Process event and update internal state.
|
|
void onEvent(AnimEvent event);
|
|
|
|
/// Evaluate current state against input and capabilities.
|
|
/// Returns AnimOutput with valid=false if no change needed (STAY policy).
|
|
AnimOutput resolve(const Input& in, const AnimCapabilitySet& caps);
|
|
|
|
State getState() const { return state_; }
|
|
void setState(State s) { state_ = s; }
|
|
void reset();
|
|
|
|
static constexpr uint8_t PRIORITY = 10;
|
|
|
|
private:
|
|
State state_ = State::IDLE;
|
|
|
|
// Grace timer: short delay before switching from WALK/RUN to IDLE
|
|
// to avoid flickering on network jitter
|
|
float graceTimer_ = 0.0f;
|
|
bool wasSprinting_ = false;
|
|
|
|
// One-shot tracking for jump start/end animations
|
|
bool jumpStartSeen_ = false;
|
|
bool jumpEndSeen_ = false;
|
|
|
|
static constexpr float kGraceSec = 0.12f;
|
|
|
|
/// Internal: update state transitions based on input.
|
|
void updateTransitions(const Input& in, const AnimCapabilitySet& caps);
|
|
bool oneShotComplete(const Input& in, uint32_t expectedAnimId) const;
|
|
};
|
|
|
|
} // namespace rendering
|
|
} // namespace wowee
|