mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-03-23 07:40:14 +00:00
- audio_engine.cpp: cache key was based on vector pointer address, not content — cache never hit since each asset load produces a new allocation. Replace with FNV-1a over head+tail bytes + size, giving correct content-based identity at O(1) cost. Add 256-entry cap with eviction to prevent unbounded growth over long sessions. - game_handler.hpp/cpp, spellbook_screen, game_screen: knownSpells was a std::vector with O(n) std::find lookups scattered across packet handlers and UI code. Switch to std::unordered_set for O(1) insert, erase, and membership checks. Update all push_back/erase-remove/find call sites to use set operations.
82 lines
2.7 KiB
C++
82 lines
2.7 KiB
C++
#pragma once
|
|
|
|
#include "game/game_handler.hpp"
|
|
#include <GL/glew.h>
|
|
#include <imgui.h>
|
|
#include <string>
|
|
#include <vector>
|
|
#include <map>
|
|
#include <unordered_map>
|
|
|
|
namespace wowee {
|
|
|
|
namespace pipeline { class AssetManager; }
|
|
|
|
namespace ui {
|
|
|
|
struct SpellInfo {
|
|
uint32_t spellId = 0;
|
|
std::string name;
|
|
std::string rank;
|
|
uint32_t iconId = 0; // SpellIconID
|
|
uint32_t attributes = 0; // Spell attributes (field 75)
|
|
bool isPassive() const { return (attributes & 0x40) != 0; }
|
|
};
|
|
|
|
struct SpellTabInfo {
|
|
std::string name;
|
|
std::vector<const SpellInfo*> spells;
|
|
};
|
|
|
|
class SpellbookScreen {
|
|
public:
|
|
void render(game::GameHandler& gameHandler, pipeline::AssetManager* assetManager);
|
|
bool isOpen() const { return open; }
|
|
void toggle() { open = !open; }
|
|
void setOpen(bool o) { open = o; }
|
|
|
|
// Drag-and-drop state for action bar assignment
|
|
bool isDraggingSpell() const { return draggingSpell_; }
|
|
uint32_t getDragSpellId() const { return dragSpellId_; }
|
|
void consumeDragSpell() { draggingSpell_ = false; dragSpellId_ = 0; dragSpellIconTex_ = 0; }
|
|
|
|
private:
|
|
bool open = false;
|
|
bool pKeyWasDown = false;
|
|
|
|
// Spell data (loaded from Spell.dbc)
|
|
bool dbcLoaded = false;
|
|
bool dbcLoadAttempted = false;
|
|
std::unordered_map<uint32_t, SpellInfo> spellData;
|
|
|
|
// Icon data (loaded from SpellIcon.dbc)
|
|
bool iconDbLoaded = false;
|
|
std::unordered_map<uint32_t, std::string> spellIconPaths; // SpellIconID -> path
|
|
std::unordered_map<uint32_t, GLuint> spellIconCache; // SpellIconID -> GL texture
|
|
|
|
// Skill line data (loaded from SkillLine.dbc + SkillLineAbility.dbc)
|
|
bool skillLineDbLoaded = false;
|
|
std::unordered_map<uint32_t, std::string> skillLineNames; // skillLineID -> name
|
|
std::unordered_map<uint32_t, uint32_t> skillLineCategories; // skillLineID -> categoryID
|
|
std::unordered_map<uint32_t, uint32_t> spellToSkillLine; // spellID -> skillLineID
|
|
|
|
// Categorized spell tabs (rebuilt when spell list changes)
|
|
// ordered map so tabs appear in consistent order
|
|
std::vector<SpellTabInfo> spellTabs;
|
|
size_t lastKnownSpellCount = 0;
|
|
|
|
// Drag-and-drop from spellbook to action bar
|
|
bool draggingSpell_ = false;
|
|
uint32_t dragSpellId_ = 0;
|
|
GLuint dragSpellIconTex_ = 0;
|
|
|
|
void loadSpellDBC(pipeline::AssetManager* assetManager);
|
|
void loadSpellIconDBC(pipeline::AssetManager* assetManager);
|
|
void loadSkillLineDBCs(pipeline::AssetManager* assetManager);
|
|
void categorizeSpells(const std::unordered_set<uint32_t>& knownSpells);
|
|
GLuint getSpellIcon(uint32_t iconId, pipeline::AssetManager* assetManager);
|
|
const SpellInfo* getSpellInfo(uint32_t spellId) const;
|
|
};
|
|
|
|
} // namespace ui
|
|
} // namespace wowee
|