fix: invalidate macro spell cache when spells are learned/removed

The macro primary spell cache stored 0 (no spell found) when a macro
referenced a spell the player hadn't learned yet. After learning the
spell from a trainer or leveling up, the cache was never refreshed,
so the macro button stayed broken. Now tracks the known spell count
and clears the cache when it changes, ensuring newly learned spells
are resolved on the next frame.
This commit is contained in:
Kelsi 2026-03-20 08:52:57 -07:00
parent 87e1ac7cdd
commit b960a1cdd5
2 changed files with 7 additions and 0 deletions

View file

@ -437,6 +437,7 @@ private:
// Macro cooldown cache: maps macro ID → resolved primary spell ID (0 = no spell found)
std::unordered_map<uint32_t, uint32_t> macroPrimarySpellCache_;
size_t macroCacheSpellCount_ = 0; // invalidates cache when spell list changes
uint32_t resolveMacroPrimarySpellId(uint32_t macroId, game::GameHandler& gameHandler);
// Death Knight rune bar: client-predicted fill (0.0=depleted, 1.0=ready) for smooth animation

View file

@ -8643,6 +8643,12 @@ VkDescriptorSet GameScreen::getSpellIcon(uint32_t spellId, pipeline::AssetManage
}
uint32_t GameScreen::resolveMacroPrimarySpellId(uint32_t macroId, game::GameHandler& gameHandler) {
// Invalidate cache when spell list changes (learning/unlearning spells)
size_t curSpellCount = gameHandler.getKnownSpells().size();
if (curSpellCount != macroCacheSpellCount_) {
macroPrimarySpellCache_.clear();
macroCacheSpellCount_ = curSpellCount;
}
auto cacheIt = macroPrimarySpellCache_.find(macroId);
if (cacheIt != macroPrimarySpellCache_.end()) return cacheIt->second;