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
|
|
@ -3,6 +3,7 @@
|
|||
#include "core/window.hpp"
|
||||
#include "core/input.hpp"
|
||||
#include "game/character.hpp"
|
||||
#include "game/game_services.hpp"
|
||||
#include "pipeline/blp_loader.hpp"
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
|
@ -126,6 +127,7 @@ private:
|
|||
|
||||
static Application* instance;
|
||||
|
||||
game::GameServices gameServices_;
|
||||
std::unique_ptr<Window> window;
|
||||
std::unique_ptr<rendering::Renderer> renderer;
|
||||
std::unique_ptr<ui::UIManager> uiManager;
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
#include "game/quest_handler.hpp"
|
||||
#include "game/movement_handler.hpp"
|
||||
#include "game/entity_controller.hpp"
|
||||
#include "game/game_services.hpp"
|
||||
#include "network/packet.hpp"
|
||||
#include <glm/glm.hpp>
|
||||
#include <memory>
|
||||
|
|
@ -130,9 +131,11 @@ public:
|
|||
using TalentEntry = game::TalentEntry;
|
||||
using TalentTabEntry = game::TalentTabEntry;
|
||||
|
||||
GameHandler();
|
||||
explicit GameHandler(GameServices& services);
|
||||
~GameHandler();
|
||||
|
||||
const GameServices& services() const { return services_; }
|
||||
|
||||
/** Access the active opcode table (wire ↔ logical mapping). */
|
||||
const OpcodeTable& getOpcodeTable() const { return opcodeTable_; }
|
||||
OpcodeTable& getOpcodeTable() { return opcodeTable_; }
|
||||
|
|
@ -2298,6 +2301,9 @@ private:
|
|||
float localOrientation);
|
||||
void clearTransportAttachment(uint64_t childGuid);
|
||||
|
||||
// Explicit service dependencies (owned by Application)
|
||||
GameServices& services_;
|
||||
|
||||
// Domain handlers — each manages a specific concern extracted from GameHandler
|
||||
std::unique_ptr<ChatHandler> chatHandler_;
|
||||
std::unique_ptr<MovementHandler> movementHandler_;
|
||||
|
|
|
|||
23
include/game/game_services.hpp
Normal file
23
include/game/game_services.hpp
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
namespace wowee {
|
||||
namespace rendering { class Renderer; }
|
||||
namespace pipeline { class AssetManager; }
|
||||
namespace game { class ExpansionRegistry; }
|
||||
|
||||
namespace game {
|
||||
|
||||
// Explicit service dependencies for game handlers.
|
||||
// Owned by Application, passed by reference to GameHandler at construction.
|
||||
// Replaces hidden Application::getInstance() singleton access.
|
||||
struct GameServices {
|
||||
rendering::Renderer* renderer = nullptr;
|
||||
pipeline::AssetManager* assetManager = nullptr;
|
||||
game::ExpansionRegistry* expansionRegistry = nullptr;
|
||||
uint32_t gryphonDisplayId = 0;
|
||||
uint32_t wyvernDisplayId = 0;
|
||||
};
|
||||
|
||||
} // namespace game
|
||||
} // namespace wowee
|
||||
Loading…
Add table
Add a link
Reference in a new issue