refactor(game): extract EntityController from GameHandler (step 1.3)

Moves entity lifecycle, name/creature/game-object caches, transport GUID
tracking, and the entire update-object pipeline out of GameHandler into a
new EntityController class (friend-class pattern, same as CombatHandler
et al.).

What moved:
- applyUpdateObjectBlock() — 1,520-line core of all entity creation,
  field updates, and movement application
- processOutOfRangeObjects() / finalizeUpdateObjectBatch()
- handleUpdateObject() / handleCompressedUpdateObject() / handleDestroyObject()
- handleNameQueryResponse() / handleCreatureQueryResponse()
- handleGameObjectQueryResponse() / handleGameObjectPageText()
- handlePageTextQueryResponse()
- enqueueUpdateObjectWork() / processPendingUpdateObjectWork()
- playerNameCache, playerClassRaceCache_, pendingNameQueries
- creatureInfoCache, pendingCreatureQueries
- gameObjectInfoCache_, pendingGameObjectQueries_
- transportGuids_, serverUpdatedTransportGuids_
- EntityManager (accessed by other handlers via getEntityManager())

8 opcodes re-registered by EntityController::registerOpcodes():
  SMSG_UPDATE_OBJECT, SMSG_COMPRESSED_UPDATE_OBJECT, SMSG_DESTROY_OBJECT,
  SMSG_NAME_QUERY_RESPONSE, SMSG_CREATURE_QUERY_RESPONSE,
  SMSG_GAMEOBJECT_QUERY_RESPONSE, SMSG_GAMEOBJECT_PAGETEXT,
  SMSG_PAGE_TEXT_QUERY_RESPONSE

Other handler files (combat, movement, social, spell, inventory, quest,
chat) updated to access EntityManager via getEntityManager() and the
name cache via getPlayerNameCache() — no logic changes.

Also included:
- .clang-tidy: add modernize-use-nodiscard,
  modernize-use-designated-initializers; set -std=c++20 in ExtraArgs
- test.sh: prepend clang's own resource include dir before GCC's to
  silence xmmintrin.h / ia32intrin.h conflicts during clang-tidy runs

Line counts:
  entity_controller.hpp  147 lines  (new)
  entity_controller.cpp  2172 lines (new)
  game_handler.cpp       8095 lines (was 10143, −2048)

Build: 0 errors, 0 warnings.
This commit is contained in:
Paul 2026-03-29 08:21:27 +03:00
parent 4f2a4e5520
commit f5757aca83
15 changed files with 2497 additions and 2260 deletions

View file

@ -1180,7 +1180,7 @@ void MovementHandler::handleOtherPlayerMovement(network::Packet& packet) {
}
}
auto entity = owner_.entityManager.getEntity(moverGuid);
auto entity = owner_.getEntityManager().getEntity(moverGuid);
if (!entity) {
return;
}
@ -1539,7 +1539,7 @@ void MovementHandler::handleMonsterMove(network::Packet& packet) {
}
}
auto entity = owner_.entityManager.getEntity(data.guid);
auto entity = owner_.getEntityManager().getEntity(data.guid);
if (!entity) {
return;
}
@ -1552,7 +1552,7 @@ void MovementHandler::handleMonsterMove(network::Packet& packet) {
if (data.moveType == 4) {
orientation = core::coords::serverToCanonicalYaw(data.facingAngle);
} else if (data.moveType == 3) {
auto target = owner_.entityManager.getEntity(data.facingTarget);
auto target = owner_.getEntityManager().getEntity(data.facingTarget);
if (target) {
float dx = target->getX() - entity->getX();
float dy = target->getY() - entity->getY();
@ -1613,7 +1613,7 @@ void MovementHandler::handleMonsterMove(network::Packet& packet) {
posCanonical.x, posCanonical.y, posCanonical.z, 0);
}
} else if (data.moveType == 3 && data.facingTarget != 0) {
auto target = owner_.entityManager.getEntity(data.facingTarget);
auto target = owner_.getEntityManager().getEntity(data.facingTarget);
if (target) {
float dx = target->getX() - entity->getX();
float dy = target->getY() - entity->getY();
@ -1635,7 +1635,7 @@ void MovementHandler::handleMonsterMoveTransport(network::Packet& packet) {
float localY = packet.readFloat();
float localZ = packet.readFloat();
auto entity = owner_.entityManager.getEntity(moverGuid);
auto entity = owner_.getEntityManager().getEntity(moverGuid);
if (!entity) return;
if (packet.getReadPos() + 5 > packet.getSize()) {
@ -1674,7 +1674,7 @@ void MovementHandler::handleMonsterMoveTransport(network::Packet& packet) {
} else if (moveType == 3) {
if (packet.getReadPos() + 8 > packet.getSize()) return;
uint64_t tgtGuid = packet.readUInt64();
if (auto tgt = owner_.entityManager.getEntity(tgtGuid)) {
if (auto tgt = owner_.getEntityManager().getEntity(tgtGuid)) {
float dx = tgt->getX() - entity->getX();
float dy = tgt->getY() - entity->getY();
if (std::abs(dx) > 0.01f || std::abs(dy) > 0.01f)
@ -1922,7 +1922,7 @@ void MovementHandler::handleNewWorld(network::Packet& packet) {
owner_.mountCallback_(0);
}
for (const auto& [guid, entity] : owner_.entityManager.getEntities()) {
for (const auto& [guid, entity] : owner_.getEntityManager().getEntities()) {
if (guid == owner_.playerGuid) continue;
if (entity->getType() == ObjectType::UNIT && owner_.creatureDespawnCallback_) {
owner_.creatureDespawnCallback_(guid);
@ -1938,7 +1938,7 @@ void MovementHandler::handleNewWorld(network::Packet& packet) {
owner_.unitCastStates_.clear();
owner_.unitAurasCache_.clear();
owner_.clearCombatText();
owner_.entityManager.clear();
owner_.getEntityManager().clear();
owner_.clearHostileAttackers();
owner_.worldStates_.clear();
owner_.gossipPois_.clear();
@ -2278,7 +2278,7 @@ void MovementHandler::startClientTaxiPath(const std::vector<uint32_t>& pathNodes
movementInfo.orientation = initialOrientation;
sanitizeMovementForTaxi();
auto playerEntity = owner_.entityManager.getEntity(owner_.playerGuid);
auto playerEntity = owner_.getEntityManager().getEntity(owner_.playerGuid);
if (playerEntity) {
playerEntity->setPosition(start.x, start.y, start.z, initialOrientation);
}
@ -2293,7 +2293,7 @@ void MovementHandler::startClientTaxiPath(const std::vector<uint32_t>& pathNodes
void MovementHandler::updateClientTaxi(float deltaTime) {
if (!taxiClientActive_ || taxiClientPath_.size() < 2) return;
auto playerEntity = owner_.entityManager.getEntity(owner_.playerGuid);
auto playerEntity = owner_.getEntityManager().getEntity(owner_.playerGuid);
auto finishTaxiFlight = [&]() {
if (!taxiClientPath_.empty()) {
@ -2820,7 +2820,7 @@ void MovementHandler::updateAttachedTransportChildren(float /*deltaTime*/) {
stale.reserve(8);
for (const auto& [childGuid, attachment] : owner_.transportAttachments_) {
auto entity = owner_.entityManager.getEntity(childGuid);
auto entity = owner_.getEntityManager().getEntity(childGuid);
if (!entity) {
stale.push_back(childGuid);
continue;