mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-04-07 05:33:51 +00:00
Add animation_ids.hpp/cpp with all 452 WoW animation ID constants (anim::STAND, anim::RUN, anim::FIRE_BOW, ... anim::FLY_BACKWARDS, etc.), nameFromId() O(1) lookup, and flyVariant() compact 218-element ground→FLY_* resolver. Expand AnimationController into a full state machine with 20+ named states: spell cast (directed→omni→cast fallback chain, instant one-shot release), hit reactions (WOUND/CRIT/DODGE/BLOCK/SHIELD_BLOCK), stun, wounded idle, stealth animation substitution, loot, fishing channel, sit/sleep/kneel down→loop→up transitions, sheathe/unsheathe combat enter/exit, ranged weapons (BOW/GUN/CROSSBOW/THROWN with reload states), game object OPEN/CLOSE/DESTROY, vehicle enter/exit, mount flight directionals (FLY_LEFT/RIGHT/UP/DOWN/BACKWARDS), emote state variants, off-hand/pierce/dual-wield alternation, NPC birth/spawn/drown/rise, sprint aura override, totem idle, NPC greeting/farewell. Add spell_defines.hpp with SpellEffect (~45 constants) and SpellMissInfo (12 constants) namespaces; replace all magic numbers in spell_handler.cpp. Add GAMEOBJECT_BYTES_1 to update field table (all 4 expansion JSONs) and wire GameObjectStateCallback. Add DBC cross-validation on world entry. Expand tools/_ANIM_NAMES from ~35 to 452 entries in m2_viewer.py and asset_pipeline_gui.py. Add tests/test_animation_ids.cpp. Bug fixes included: - Stand state 1 was animating READY_2H(27) — fixed to SITTING(97) - Spell casts ended freeze-frame — add one-shot release animation - NPC 2H swing probe chain missing ATTACK_2H_LOOSE (polearm/staff) - Chair sits (states 2/4/5/6) incorrectly played floor-sit transition - STOP(3) used for all spell casts — replaced with model-aware chain
184 lines
7.1 KiB
C++
184 lines
7.1 KiB
C++
// Animation ID validation tests — covers nameFromId() and validateAgainstDBC()
|
|
#include <catch_amalgamated.hpp>
|
|
#include "rendering/animation_ids.hpp"
|
|
#include "pipeline/dbc_loader.hpp"
|
|
#include <cstring>
|
|
#include <vector>
|
|
|
|
using wowee::pipeline::DBCFile;
|
|
namespace anim = wowee::rendering::anim;
|
|
|
|
// Build a synthetic AnimationData.dbc in memory.
|
|
// AnimationData.dbc layout: each record has at least 1 field (the animation ID).
|
|
// We use numFields=2 (id + dummy) to mirror the real DBC which has multiple fields.
|
|
static std::vector<uint8_t> buildAnimationDBC(const std::vector<uint32_t>& animIds) {
|
|
const uint32_t numRecords = static_cast<uint32_t>(animIds.size());
|
|
const uint32_t numFields = 2; // id + a dummy field
|
|
const uint32_t recordSize = numFields * 4;
|
|
const uint32_t stringBlockSize = 1; // single null byte
|
|
|
|
std::vector<uint8_t> data;
|
|
data.reserve(20 + numRecords * recordSize + stringBlockSize);
|
|
|
|
// Magic "WDBC"
|
|
data.push_back('W'); data.push_back('D'); data.push_back('B'); data.push_back('C');
|
|
|
|
auto writeU32 = [&](uint32_t v) {
|
|
data.push_back(static_cast<uint8_t>(v & 0xFF));
|
|
data.push_back(static_cast<uint8_t>((v >> 8) & 0xFF));
|
|
data.push_back(static_cast<uint8_t>((v >> 16) & 0xFF));
|
|
data.push_back(static_cast<uint8_t>((v >> 24) & 0xFF));
|
|
};
|
|
|
|
writeU32(numRecords);
|
|
writeU32(numFields);
|
|
writeU32(recordSize);
|
|
writeU32(stringBlockSize);
|
|
|
|
// Records: [animId, 0]
|
|
for (uint32_t id : animIds) {
|
|
writeU32(id);
|
|
writeU32(0);
|
|
}
|
|
|
|
// String block: single null
|
|
data.push_back('\0');
|
|
|
|
return data;
|
|
}
|
|
|
|
// ── nameFromId tests ────────────────────────────────────────────────────────
|
|
|
|
TEST_CASE("nameFromId returns correct names for known IDs", "[animation]") {
|
|
REQUIRE(std::string(anim::nameFromId(anim::STAND)) == "STAND");
|
|
REQUIRE(std::string(anim::nameFromId(anim::DEATH)) == "DEATH");
|
|
REQUIRE(std::string(anim::nameFromId(anim::WALK)) == "WALK");
|
|
REQUIRE(std::string(anim::nameFromId(anim::RUN)) == "RUN");
|
|
REQUIRE(std::string(anim::nameFromId(anim::ATTACK_UNARMED)) == "ATTACK_UNARMED");
|
|
REQUIRE(std::string(anim::nameFromId(anim::ATTACK_1H)) == "ATTACK_1H");
|
|
REQUIRE(std::string(anim::nameFromId(anim::ATTACK_2H)) == "ATTACK_2H");
|
|
REQUIRE(std::string(anim::nameFromId(anim::ATTACK_2H_LOOSE)) == "ATTACK_2H_LOOSE");
|
|
REQUIRE(std::string(anim::nameFromId(anim::SPELL_CAST_DIRECTED)) == "SPELL_CAST_DIRECTED");
|
|
REQUIRE(std::string(anim::nameFromId(anim::SPELL_CAST_OMNI)) == "SPELL_CAST_OMNI");
|
|
REQUIRE(std::string(anim::nameFromId(anim::READY_1H)) == "READY_1H");
|
|
REQUIRE(std::string(anim::nameFromId(anim::READY_2H)) == "READY_2H");
|
|
REQUIRE(std::string(anim::nameFromId(anim::READY_2H_LOOSE)) == "READY_2H_LOOSE");
|
|
REQUIRE(std::string(anim::nameFromId(anim::READY_UNARMED)) == "READY_UNARMED");
|
|
REQUIRE(std::string(anim::nameFromId(anim::EMOTE_DANCE)) == "EMOTE_DANCE");
|
|
}
|
|
|
|
TEST_CASE("nameFromId returns UNKNOWN for out-of-range IDs", "[animation]") {
|
|
REQUIRE(std::string(anim::nameFromId(anim::ANIM_COUNT)) == "UNKNOWN");
|
|
REQUIRE(std::string(anim::nameFromId(anim::ANIM_COUNT + 1)) == "UNKNOWN");
|
|
REQUIRE(std::string(anim::nameFromId(9999)) == "UNKNOWN");
|
|
REQUIRE(std::string(anim::nameFromId(UINT32_MAX)) == "UNKNOWN");
|
|
}
|
|
|
|
TEST_CASE("nameFromId covers first and last IDs", "[animation]") {
|
|
REQUIRE(std::string(anim::nameFromId(0)) == "STAND");
|
|
REQUIRE(std::string(anim::nameFromId(anim::ANIM_COUNT - 1)) == "FLY_GUILD_CHAMPION_2");
|
|
}
|
|
|
|
// ── validateAgainstDBC tests ────────────────────────────────────────────────
|
|
|
|
TEST_CASE("validateAgainstDBC handles null DBC", "[animation][dbc]") {
|
|
// Should not crash — just logs a warning
|
|
anim::validateAgainstDBC(nullptr);
|
|
}
|
|
|
|
TEST_CASE("validateAgainstDBC handles unloaded DBC", "[animation][dbc]") {
|
|
auto dbc = std::make_shared<DBCFile>();
|
|
REQUIRE_FALSE(dbc->isLoaded());
|
|
// Should not crash — just logs a warning
|
|
anim::validateAgainstDBC(dbc);
|
|
}
|
|
|
|
TEST_CASE("validateAgainstDBC with perfect match", "[animation][dbc]") {
|
|
// Build a DBC containing IDs 0..ANIM_COUNT-1 (exact match)
|
|
std::vector<uint32_t> allIds;
|
|
for (uint32_t i = 0; i < anim::ANIM_COUNT; ++i) {
|
|
allIds.push_back(i);
|
|
}
|
|
auto data = buildAnimationDBC(allIds);
|
|
|
|
auto dbc = std::make_shared<DBCFile>();
|
|
REQUIRE(dbc->load(data));
|
|
REQUIRE(dbc->getRecordCount() == anim::ANIM_COUNT);
|
|
|
|
// Should complete without crashing — all IDs match
|
|
anim::validateAgainstDBC(dbc);
|
|
}
|
|
|
|
TEST_CASE("validateAgainstDBC with missing IDs in DBC", "[animation][dbc]") {
|
|
// DBC only contains a subset of IDs — misses many
|
|
std::vector<uint32_t> partialIds = {0, 1, 2, 4, 5};
|
|
auto data = buildAnimationDBC(partialIds);
|
|
|
|
auto dbc = std::make_shared<DBCFile>();
|
|
REQUIRE(dbc->load(data));
|
|
REQUIRE(dbc->getRecordCount() == 5);
|
|
|
|
// Should log warnings for missing IDs but not crash
|
|
anim::validateAgainstDBC(dbc);
|
|
}
|
|
|
|
TEST_CASE("validateAgainstDBC with extra IDs beyond range", "[animation][dbc]") {
|
|
// DBC has some IDs beyond ANIM_COUNT
|
|
std::vector<uint32_t> extraIds = {0, 1, 500, 600, 1000};
|
|
auto data = buildAnimationDBC(extraIds);
|
|
|
|
auto dbc = std::make_shared<DBCFile>();
|
|
REQUIRE(dbc->load(data));
|
|
REQUIRE(dbc->getRecordCount() == 5);
|
|
|
|
// Should log info about extra DBC-only IDs but not crash
|
|
anim::validateAgainstDBC(dbc);
|
|
}
|
|
|
|
TEST_CASE("validateAgainstDBC with empty DBC", "[animation][dbc]") {
|
|
// DBC with zero records
|
|
auto data = buildAnimationDBC({});
|
|
|
|
auto dbc = std::make_shared<DBCFile>();
|
|
REQUIRE(dbc->load(data));
|
|
REQUIRE(dbc->getRecordCount() == 0);
|
|
|
|
// Should log warnings for all ANIM_COUNT missing IDs but not crash
|
|
anim::validateAgainstDBC(dbc);
|
|
}
|
|
|
|
TEST_CASE("validateAgainstDBC with single ID", "[animation][dbc]") {
|
|
// DBC with just STAND (id=0)
|
|
auto data = buildAnimationDBC({0});
|
|
|
|
auto dbc = std::make_shared<DBCFile>();
|
|
REQUIRE(dbc->load(data));
|
|
REQUIRE(dbc->getRecordCount() == 1);
|
|
|
|
anim::validateAgainstDBC(dbc);
|
|
}
|
|
|
|
TEST_CASE("ANIM_COUNT matches expected value", "[animation]") {
|
|
REQUIRE(anim::ANIM_COUNT == 452);
|
|
}
|
|
|
|
TEST_CASE("Animation constant IDs are unique and sequential from documentation", "[animation]") {
|
|
// Verify key animation ID values match WoW's AnimationData.dbc layout
|
|
REQUIRE(anim::STAND == 0);
|
|
REQUIRE(anim::DEATH == 1);
|
|
REQUIRE(anim::SPELL == 2);
|
|
REQUIRE(anim::ATTACK_UNARMED == 16);
|
|
REQUIRE(anim::ATTACK_1H == 17);
|
|
REQUIRE(anim::ATTACK_2H == 18);
|
|
REQUIRE(anim::ATTACK_2H_LOOSE == 19);
|
|
REQUIRE(anim::READY_UNARMED == 25);
|
|
REQUIRE(anim::READY_1H == 26);
|
|
REQUIRE(anim::READY_2H == 27);
|
|
REQUIRE(anim::READY_2H_LOOSE == 28);
|
|
REQUIRE(anim::SPELL_CAST == 32);
|
|
REQUIRE(anim::SPELL_CAST_DIRECTED == 53);
|
|
REQUIRE(anim::SPELL_CAST_OMNI == 54);
|
|
REQUIRE(anim::CHANNEL_CAST_DIRECTED == 124);
|
|
REQUIRE(anim::CHANNEL_CAST_OMNI == 125);
|
|
REQUIRE(anim::EMOTE_DANCE == 69);
|
|
}
|