refactor(core): decompose Application::setupUICallbacks() into 7 domain handlers

Extract ~1,700 lines / 60+ inline [this]-capturing lambdas from the monolithic
Application::setupUICallbacks() into 7 focused callback handler classes following
the ToastManager/ChatPanel::setupCallbacks() pattern already in the codebase.

New handlers (include/core/ + src/core/):
  - NPCInteractionCallbackHandler  NPC greeting/farewell/vendor/aggro voice
  - AudioCallbackHandler           Music, positional sound, level-up, achievement, LFG
  - EntitySpawnCallbackHandler     Creature/player/GO spawn, despawn, move, state
  - AnimationCallbackHandler       Death, respawn, combat, emotes, charge, sprint, vehicle
  - TransportCallbackHandler       Mount, taxi, transport spawn/move
  - WorldEntryCallbackHandler      World entry, unstuck, hearthstone, bind point
  - UIScreenCallbackHandler        Auth, realm selection, char selection/creation/deletion

application.cpp:  4,462 → 2,791 lines  (−1,671)
setupUICallbacks: ~1,700 → ~50 lines (thin orchestrator)

Deduplication:
  resolveSoundEntryPath()   — was 3× copy-paste of SoundEntries.dbc lookup
  resolveNpcVoiceType()     — was 4× copy-paste of display-ID→voice detection
  precacheNearbyTiles()     — was 3× copy-paste of 17×17 tile loop
  4 helper lambdas          — promoted to private methods on WorldEntryCallbackHandler

State migration out of Application:
  charge* (6 vars)          → AnimationCallbackHandler
  hearth*/worldEntry*/taxi* → WorldEntryCallbackHandler
  pendingCreatedCharacterName_ → UIScreenCallbackHandler

Bug fixes:
  - Duplicate `namespace core {` in application.hpp caused wowee::std pollution
  - AppState forward decl in ui_screen_callback_handler.hpp was at wrong scope
  - world_loader.cpp accessed moved member vars directly via friend; now uses handler API
This commit is contained in:
Paul 2026-04-05 16:48:17 +03:00
parent a23c2172a8
commit 6dcc06697b
18 changed files with 2293 additions and 1765 deletions

View file

@ -0,0 +1,50 @@
#pragma once
#include <cstdint>
#include <glm/glm.hpp>
namespace wowee {
namespace rendering { class Renderer; }
namespace game { class GameHandler; }
namespace core { class EntitySpawner; }
namespace core {
/// Handles animation callbacks: death, respawn, swing, hit reaction, spell cast, emote,
/// stun, stealth, health, ghost, stand state, loot, sprint, vehicle, charge.
/// Owns charge rush state (interpolated in update).
class AnimationCallbackHandler {
public:
AnimationCallbackHandler(EntitySpawner& entitySpawner,
rendering::Renderer& renderer,
game::GameHandler& gameHandler);
void setupCallbacks();
/// Called each frame from Application::update() to drive charge interpolation.
/// Returns true if charge is active (player is externally driven).
bool updateCharge(float deltaTime);
// Charge state queries (used by Application::update for externallyDrivenMotion)
bool isCharging() const { return chargeActive_; }
// Reset charge state (logout/disconnect)
void resetChargeState();
private:
EntitySpawner& entitySpawner_;
rendering::Renderer& renderer_;
game::GameHandler& gameHandler_;
// Charge rush state (moved from Application)
bool chargeActive_ = false;
float chargeTimer_ = 0.0f;
float chargeDuration_ = 0.0f;
glm::vec3 chargeStartPos_{0.0f}; // Render coordinates
glm::vec3 chargeEndPos_{0.0f}; // Render coordinates
uint64_t chargeTargetGuid_ = 0;
};
} // namespace core
} // namespace wowee

View file

@ -34,6 +34,15 @@ namespace addons { class AddonManager; }
namespace core {
// Handler forward declarations
class NPCInteractionCallbackHandler;
class AudioCallbackHandler;
class EntitySpawnCallbackHandler;
class AnimationCallbackHandler;
class TransportCallbackHandler;
class WorldEntryCallbackHandler;
class UIScreenCallbackHandler;
enum class AppState {
AUTHENTICATION,
REALM_SELECTION,
@ -134,9 +143,17 @@ private:
std::unique_ptr<WorldLoader> worldLoader_;
std::unique_ptr<audio::AudioCoordinator> audioCoordinator_;
// Callback handlers (extracted from setupUICallbacks)
std::unique_ptr<NPCInteractionCallbackHandler> npcInteractionCallbacks_;
std::unique_ptr<AudioCallbackHandler> audioCallbacks_;
std::unique_ptr<EntitySpawnCallbackHandler> entitySpawnCallbacks_;
std::unique_ptr<AnimationCallbackHandler> animationCallbacks_;
std::unique_ptr<TransportCallbackHandler> transportCallbacks_;
std::unique_ptr<WorldEntryCallbackHandler> worldEntryCallbacks_;
std::unique_ptr<UIScreenCallbackHandler> uiScreenCallbacks_;
AppState state = AppState::AUTHENTICATION;
bool running = false;
std::string pendingCreatedCharacterName_; // Auto-select after character creation
bool playerCharacterSpawned = false;
bool npcsSpawned = false;
bool spawnSnapToGround = true;
@ -154,27 +171,11 @@ private:
static inline const std::string emptyString_;
static inline const std::vector<std::string> emptyStringVec_;
bool lastTaxiFlight_ = false;
float taxiLandingClampTimer_ = 0.0f;
float worldEntryMovementGraceTimer_ = 0.0f;
// Hearth teleport: freeze player until terrain loads at destination
bool hearthTeleportPending_ = false;
glm::vec3 hearthTeleportPos_{0.0f}; // render coords
float hearthTeleportTimer_ = 0.0f; // timeout safety
float facingSendCooldown_ = 0.0f; // Rate-limits MSG_MOVE_SET_FACING
float lastSentCanonicalYaw_ = 1000.0f; // Sentinel — triggers first send
float taxiStreamCooldown_ = 0.0f;
bool idleYawned_ = false;
// Charge rush state
bool chargeActive_ = false;
float chargeTimer_ = 0.0f;
float chargeDuration_ = 0.0f;
glm::vec3 chargeStartPos_{0.0f}; // Render coordinates
glm::vec3 chargeEndPos_{0.0f}; // Render coordinates
uint64_t chargeTargetGuid_ = 0;
bool wasAutoAttacking_ = false;
// Quest marker billboard sprites (above NPCs)

View file

@ -0,0 +1,40 @@
#pragma once
#include <cstdint>
#include <string>
#include <optional>
namespace wowee {
namespace rendering { class Renderer; }
namespace game { class GameHandler; }
namespace audio { class AudioCoordinator; }
namespace pipeline { class AssetManager; }
namespace ui { class UIManager; }
namespace core {
/// Handles audio-related callbacks: music, sound effects, level-up, achievement, LFG.
class AudioCallbackHandler {
public:
AudioCallbackHandler(pipeline::AssetManager& assetManager,
audio::AudioCoordinator* audioCoordinator,
rendering::Renderer* renderer,
ui::UIManager* uiManager,
game::GameHandler& gameHandler);
void setupCallbacks();
private:
/// Resolve SoundEntries.dbc → file path for a given soundId (eliminates 3x copy-paste)
std::optional<std::string> resolveSoundEntryPath(uint32_t soundId) const;
pipeline::AssetManager& assetManager_;
audio::AudioCoordinator* audioCoordinator_;
rendering::Renderer* renderer_;
ui::UIManager* uiManager_;
game::GameHandler& gameHandler_;
};
} // namespace core
} // namespace wowee

View file

@ -0,0 +1,34 @@
#pragma once
#include <cstdint>
#include <array>
#include <functional>
namespace wowee {
namespace rendering { class Renderer; }
namespace game { class GameHandler; }
namespace core { class EntitySpawner; }
namespace core {
/// Handles entity spawn/despawn callbacks: creatures, players, game objects.
class EntitySpawnCallbackHandler {
public:
/// @param isLocalPlayerGuid Returns true if the given GUID is the local player (to skip self-spawn)
EntitySpawnCallbackHandler(EntitySpawner& entitySpawner,
rendering::Renderer& renderer,
game::GameHandler& gameHandler,
std::function<bool(uint64_t)> isLocalPlayerGuid);
void setupCallbacks();
private:
EntitySpawner& entitySpawner_;
rendering::Renderer& renderer_;
game::GameHandler& gameHandler_;
std::function<bool(uint64_t)> isLocalPlayerGuid_;
};
} // namespace core
} // namespace wowee

View file

@ -0,0 +1,37 @@
#pragma once
#include <cstdint>
#include <glm/glm.hpp>
#include "audio/npc_voice_manager.hpp"
namespace wowee {
namespace rendering { class Renderer; }
namespace game { class GameHandler; }
namespace audio { class AudioCoordinator; }
namespace core { class EntitySpawner; }
namespace core {
/// Handles NPC interaction callbacks: greeting, farewell, vendor, aggro voice lines.
class NPCInteractionCallbackHandler {
public:
NPCInteractionCallbackHandler(EntitySpawner& entitySpawner,
rendering::Renderer* renderer,
game::GameHandler& gameHandler,
audio::AudioCoordinator* audioCoordinator);
void setupCallbacks();
private:
/// Resolve NPC voice type from GUID (eliminates 4x copy-paste of display-ID lookup)
audio::VoiceType resolveNpcVoiceType(uint64_t guid) const;
EntitySpawner& entitySpawner_;
rendering::Renderer* renderer_;
game::GameHandler& gameHandler_;
audio::AudioCoordinator* audioCoordinator_;
};
} // namespace core
} // namespace wowee

View file

@ -0,0 +1,33 @@
#pragma once
#include <cstdint>
#include <vector>
#include <glm/glm.hpp>
namespace wowee {
namespace rendering { class Renderer; }
namespace game { class GameHandler; }
namespace core { class EntitySpawner; class WorldLoader; }
namespace core {
/// Handles transport-related callbacks: transport spawn/move, taxi, mount.
class TransportCallbackHandler {
public:
TransportCallbackHandler(EntitySpawner& entitySpawner,
rendering::Renderer& renderer,
game::GameHandler& gameHandler,
WorldLoader* worldLoader);
void setupCallbacks();
private:
EntitySpawner& entitySpawner_;
rendering::Renderer& renderer_;
game::GameHandler& gameHandler_;
WorldLoader* worldLoader_;
};
} // namespace core
} // namespace wowee

View file

@ -0,0 +1,46 @@
#pragma once
#include <cstdint>
#include <functional>
#include <string>
namespace wowee {
namespace ui { class UIManager; }
namespace game { class GameHandler; class ExpansionRegistry; }
namespace auth { class AuthHandler; }
namespace pipeline { class AssetManager; }
namespace core {
// Forward-declared in application.hpp
enum class AppState;
/// Handles authentication, realm selection, character selection/creation UI callbacks.
/// Owns pendingCreatedCharacterName_.
class UIScreenCallbackHandler {
public:
using SetStateFn = std::function<void(AppState)>;
UIScreenCallbackHandler(ui::UIManager& uiManager,
game::GameHandler& gameHandler,
auth::AuthHandler& authHandler,
game::ExpansionRegistry* expansionRegistry,
pipeline::AssetManager* assetManager,
SetStateFn setState);
void setupCallbacks();
private:
ui::UIManager& uiManager_;
game::GameHandler& gameHandler_;
auth::AuthHandler& authHandler_;
game::ExpansionRegistry* expansionRegistry_;
pipeline::AssetManager* assetManager_;
SetStateFn setState_;
std::string pendingCreatedCharacterName_; // Auto-select after character creation
};
} // namespace core
} // namespace wowee

View file

@ -0,0 +1,78 @@
#pragma once
#include <cstdint>
#include <optional>
#include <glm/glm.hpp>
namespace wowee {
namespace rendering { class Renderer; }
namespace game { class GameHandler; }
namespace pipeline { class AssetManager; }
namespace audio { class AudioCoordinator; }
namespace core { class EntitySpawner; class WorldLoader; }
namespace core {
/// Handles world entry, unstuck, hearthstone, and bind point callbacks.
/// Owns hearth-teleport state and worldEntryMovementGraceTimer.
class WorldEntryCallbackHandler {
public:
WorldEntryCallbackHandler(rendering::Renderer& renderer,
game::GameHandler& gameHandler,
WorldLoader* worldLoader,
EntitySpawner* entitySpawner,
audio::AudioCoordinator* audioCoordinator,
pipeline::AssetManager* assetManager);
void setupCallbacks();
/// Called each frame from Application::update() to manage hearth-teleport freeze/thaw.
void update(float deltaTime);
// State queries (used by Application::update)
float getWorldEntryMovementGraceTimer() const { return worldEntryMovementGraceTimer_; }
void setWorldEntryMovementGraceTimer(float t) { worldEntryMovementGraceTimer_ = t; }
bool isHearthTeleportPending() const { return hearthTeleportPending_; }
// Reset state (logout/disconnect)
void resetState();
// Taxi state (managed by Application::update, but tracked here for clarity)
bool getLastTaxiFlight() const { return lastTaxiFlight_; }
void setLastTaxiFlight(bool v) { lastTaxiFlight_ = v; }
float getTaxiLandingClampTimer() const { return taxiLandingClampTimer_; }
void setTaxiLandingClampTimer(float t) { taxiLandingClampTimer_ = t; }
private:
/// Sample best floor height at (x, y) from terrain, WMO, and M2 (eliminates 3x duplication)
std::optional<float> sampleBestFloorAt(float x, float y, float probeZ) const;
/// Clear stuck movement state on player
void clearStuckMovement();
/// Sync teleported render position to server
void syncTeleportedPositionToServer(const glm::vec3& renderPos);
/// Force server-side teleport via GM command
void forceServerTeleportCommand(const glm::vec3& renderPos);
rendering::Renderer& renderer_;
game::GameHandler& gameHandler_;
WorldLoader* worldLoader_;
EntitySpawner* entitySpawner_;
audio::AudioCoordinator* audioCoordinator_;
pipeline::AssetManager* assetManager_;
// Hearth teleport: freeze player until terrain loads at destination (moved from Application)
bool hearthTeleportPending_ = false;
glm::vec3 hearthTeleportPos_{0.0f}; // render coords
float hearthTeleportTimer_ = 0.0f; // timeout safety
float worldEntryMovementGraceTimer_ = 0.0f;
bool lastTaxiFlight_ = false;
float taxiLandingClampTimer_ = 0.0f;
};
} // namespace core
} // namespace wowee