mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-04-03 20:03:50 +00:00
[refactor] Break Application::getInstance() from GameHandler
Introduce `GameServices` struct — an explicit dependency bundle that `Application` populates and passes to `GameHandler` at construction time. Eliminates all 47 hidden `Application::getInstance()` calls in `src/game/*.cpp`, completing SOLID-D (dependency-inversion) cleanup. Changes: - New `include/game/game_services.hpp` — `struct GameServices` carrying pointers to `Renderer`, `AssetManager`, `ExpansionRegistry`, and two taxi-mount display IDs - `GameHandler(GameServices&)` replaces default constructor; exposes `services() const` accessor for domain handlers - `Application` holds `game::GameServices gameServices_`; populates it after all subsystems are created, then constructs `GameHandler` (fixes latent init-order bug: `GameHandler` was previously created before `AssetManager` / `ExpansionRegistry`) - `game_handler.cpp`: duplicate `isActiveExpansion` / `isClassicLikeExpansion` / `isPreWotlk` anonymous-namespace helpers removed; `game_utils.hpp` included instead - All domain handlers (`InventoryHandler`, `SpellHandler`, `MovementHandler`, `CombatHandler`, `QuestHandler`, `SocialHandler`, `WardenHandler`) replace `Application::getInstance().getXxx()` with `owner_.services().xxx`
This commit is contained in:
parent
c1c28d4216
commit
a86efaaa18
12 changed files with 92 additions and 68 deletions
|
|
@ -1,4 +1,5 @@
|
|||
#include "game/game_handler.hpp"
|
||||
#include "game/game_utils.hpp"
|
||||
#include "game/chat_handler.hpp"
|
||||
#include "game/movement_handler.hpp"
|
||||
#include "game/combat_handler.hpp"
|
||||
|
|
@ -92,23 +93,6 @@ bool isAuthCharPipelineOpcode(LogicalOpcode op) {
|
|||
|
||||
namespace {
|
||||
|
||||
bool isActiveExpansion(const char* expansionId) {
|
||||
auto& app = core::Application::getInstance();
|
||||
auto* registry = app.getExpansionRegistry();
|
||||
if (!registry) return false;
|
||||
auto* profile = registry->getActive();
|
||||
if (!profile) return false;
|
||||
return profile->id == expansionId;
|
||||
}
|
||||
|
||||
bool isClassicLikeExpansion() {
|
||||
return isActiveExpansion("classic") || isActiveExpansion("turtle");
|
||||
}
|
||||
|
||||
bool isPreWotlk() {
|
||||
return isClassicLikeExpansion() || isActiveExpansion("tbc");
|
||||
}
|
||||
|
||||
bool envFlagEnabled(const char* key, bool defaultValue = false) {
|
||||
const char* raw = std::getenv(key);
|
||||
if (!raw || !*raw) return defaultValue;
|
||||
|
|
@ -615,7 +599,7 @@ static QuestQueryRewards tryParseQuestRewards(const std::vector<uint8_t>& data,
|
|||
|
||||
template<typename ManagerGetter, typename Callback>
|
||||
void GameHandler::withSoundManager(ManagerGetter getter, Callback cb) {
|
||||
if (auto* renderer = core::Application::getInstance().getRenderer()) {
|
||||
if (auto* renderer = services_.renderer) {
|
||||
if (auto* mgr = (renderer->*getter)()) cb(mgr);
|
||||
}
|
||||
}
|
||||
|
|
@ -639,7 +623,8 @@ void GameHandler::registerWorldHandler(LogicalOpcode op, void (GameHandler::*han
|
|||
};
|
||||
}
|
||||
|
||||
GameHandler::GameHandler() {
|
||||
GameHandler::GameHandler(GameServices& services)
|
||||
: services_(services) {
|
||||
LOG_DEBUG("GameHandler created");
|
||||
|
||||
setActiveOpcodeTable(&opcodeTable_);
|
||||
|
|
@ -819,7 +804,7 @@ void GameHandler::resetDbcCaches() {
|
|||
// Clear the AssetManager DBC file cache so that expansion-specific DBCs
|
||||
// (CharSections, ItemDisplayInfo, etc.) are reloaded from the new expansion's
|
||||
// MPQ files instead of returning stale data from a previous session/expansion.
|
||||
auto* am = core::Application::getInstance().getAssetManager();
|
||||
auto* am = services_.assetManager;
|
||||
if (am) {
|
||||
am->clearDBCCache();
|
||||
}
|
||||
|
|
@ -1213,7 +1198,7 @@ void GameHandler::updateTimers(float deltaTime) {
|
|||
}
|
||||
if (!alreadyAnnounced && pendingLootMoneyAmount_ > 0) {
|
||||
addSystemChatMessage("Looted: " + formatCopperAmount(pendingLootMoneyAmount_));
|
||||
auto* renderer = core::Application::getInstance().getRenderer();
|
||||
auto* renderer = services_.renderer;
|
||||
if (renderer) {
|
||||
if (auto* sfx = renderer->getUiSoundManager()) {
|
||||
if (pendingLootMoneyAmount_ >= 10000) {
|
||||
|
|
@ -3099,7 +3084,7 @@ void GameHandler::registerOpcodeHandlers() {
|
|||
uint64_t impTargetGuid = packet.readUInt64();
|
||||
uint32_t impVisualId = packet.readUInt32();
|
||||
if (impVisualId == 0) return;
|
||||
auto* renderer = core::Application::getInstance().getRenderer();
|
||||
auto* renderer = services_.renderer;
|
||||
if (!renderer) return;
|
||||
glm::vec3 spawnPos;
|
||||
if (impTargetGuid == playerGuid) {
|
||||
|
|
@ -7249,7 +7234,7 @@ void GameHandler::loadTitleNameCache() const {
|
|||
if (titleNameCacheLoaded_) return;
|
||||
titleNameCacheLoaded_ = true;
|
||||
|
||||
auto* am = core::Application::getInstance().getAssetManager();
|
||||
auto* am = services_.assetManager;
|
||||
if (!am || !am->isInitialized()) return;
|
||||
|
||||
auto dbc = am->loadDBC("CharTitles.dbc");
|
||||
|
|
@ -7301,7 +7286,7 @@ void GameHandler::loadAchievementNameCache() {
|
|||
if (achievementNameCacheLoaded_) return;
|
||||
achievementNameCacheLoaded_ = true;
|
||||
|
||||
auto* am = core::Application::getInstance().getAssetManager();
|
||||
auto* am = services_.assetManager;
|
||||
if (!am || !am->isInitialized()) return;
|
||||
|
||||
auto dbc = am->loadDBC("Achievement.dbc");
|
||||
|
|
@ -7386,7 +7371,7 @@ void GameHandler::loadFactionNameCache() const {
|
|||
if (factionNameCacheLoaded_) return;
|
||||
factionNameCacheLoaded_ = true;
|
||||
|
||||
auto* am = core::Application::getInstance().getAssetManager();
|
||||
auto* am = services_.assetManager;
|
||||
if (!am || !am->isInitialized()) return;
|
||||
|
||||
auto dbc = am->loadDBC("Faction.dbc");
|
||||
|
|
@ -7487,7 +7472,7 @@ void GameHandler::loadAreaNameCache() const {
|
|||
if (areaNameCacheLoaded_) return;
|
||||
areaNameCacheLoaded_ = true;
|
||||
|
||||
auto* am = core::Application::getInstance().getAssetManager();
|
||||
auto* am = services_.assetManager;
|
||||
if (!am || !am->isInitialized()) return;
|
||||
|
||||
auto dbc = am->loadDBC("WorldMapArea.dbc");
|
||||
|
|
@ -7522,7 +7507,7 @@ void GameHandler::loadMapNameCache() const {
|
|||
if (mapNameCacheLoaded_) return;
|
||||
mapNameCacheLoaded_ = true;
|
||||
|
||||
auto* am = core::Application::getInstance().getAssetManager();
|
||||
auto* am = services_.assetManager;
|
||||
if (!am || !am->isInitialized()) return;
|
||||
|
||||
auto dbc = am->loadDBC("Map.dbc");
|
||||
|
|
@ -7555,7 +7540,7 @@ void GameHandler::loadLfgDungeonDbc() const {
|
|||
if (lfgDungeonNameCacheLoaded_) return;
|
||||
lfgDungeonNameCacheLoaded_ = true;
|
||||
|
||||
auto* am = core::Application::getInstance().getAssetManager();
|
||||
auto* am = services_.assetManager;
|
||||
if (!am || !am->isInitialized()) return;
|
||||
|
||||
auto dbc = am->loadDBC("LFGDungeons.dbc");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue