From 63897d56d75ce8dcf03ec5b458e92d059ab5fd5b Mon Sep 17 00:00:00 2001 From: XTZGZoReX Date: Thu, 1 Oct 2009 18:58:08 +0400 Subject: [PATCH] Move visibility update functions to more appropriate classes. Signed-off-by: VladimirMangos --- src/game/Creature.cpp | 6 +++--- src/game/GameObject.cpp | 2 +- src/game/NPCHandler.cpp | 4 ++-- src/game/Object.cpp | 11 ++++++++++- src/game/Object.h | 2 ++ src/game/ObjectAccessor.cpp | 30 ------------------------------ src/game/ObjectAccessor.h | 2 -- src/game/Player.cpp | 30 ++++++++++++++++++++++++++---- src/game/Player.h | 2 ++ src/game/SpellAuras.cpp | 2 +- 10 files changed, 47 insertions(+), 44 deletions(-) diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp index 7e72e2b4d..35da7f57c 100644 --- a/src/game/Creature.cpp +++ b/src/game/Creature.cpp @@ -159,7 +159,7 @@ void Creature::RemoveCorpse() m_deathTimer = 0; setDeathState(DEAD); - ObjectAccessor::UpdateObjectVisibility(this); + UpdateObjectVisibility(); loot.clear(); uint32 respawnDelay = m_respawnDelay; if (AI()) @@ -1585,9 +1585,9 @@ void Creature::Respawn() // forced recreate creature object at clients UnitVisibility currentVis = GetVisibility(); SetVisibility(VISIBILITY_RESPAWN); - ObjectAccessor::UpdateObjectVisibility(this); + UpdateObjectVisibility(); SetVisibility(currentVis); // restore visibility state - ObjectAccessor::UpdateObjectVisibility(this); + UpdateObjectVisibility(); if(getDeathState()==DEAD) { diff --git a/src/game/GameObject.cpp b/src/game/GameObject.cpp index 57da43f75..c0e0299c4 100644 --- a/src/game/GameObject.cpp +++ b/src/game/GameObject.cpp @@ -449,7 +449,7 @@ void GameObject::Update(uint32 /*p_time*/) if(sWorld.getConfig(CONFIG_SAVE_RESPAWN_TIME_IMMEDIATLY)) SaveRespawnTime(); - ObjectAccessor::UpdateObjectVisibility(this); + UpdateObjectVisibility(); break; } diff --git a/src/game/NPCHandler.cpp b/src/game/NPCHandler.cpp index 8bb0be9b9..33ba8538d 100644 --- a/src/game/NPCHandler.cpp +++ b/src/game/NPCHandler.cpp @@ -372,11 +372,11 @@ void WorldSession::SendSpiritResurrect() _player->TeleportTo(corpseGrave->map_id, corpseGrave->x, corpseGrave->y, corpseGrave->z, _player->GetOrientation()); // or update at original position else - ObjectAccessor::UpdateVisibilityForPlayer(_player); + _player->UpdateVisibilityForPlayer(); } // or update at original position else - ObjectAccessor::UpdateVisibilityForPlayer(_player); + _player->UpdateVisibilityForPlayer(); _player->SaveToDB(); } diff --git a/src/game/Object.cpp b/src/game/Object.cpp index 72ba05930..152c16b9e 100644 --- a/src/game/Object.cpp +++ b/src/game/Object.cpp @@ -1852,7 +1852,7 @@ void WorldObject::SetPhaseMask(uint32 newPhaseMask, bool update) m_phaseMask = newPhaseMask; if(update && IsInWorld()) - ObjectAccessor::UpdateObjectVisibility(this); + UpdateObjectVisibility(); } void WorldObject::PlayDistanceSound( uint32 sound_id, Player* target /*= NULL*/ ) @@ -1875,3 +1875,12 @@ void WorldObject::PlayDirectSound( uint32 sound_id, Player* target /*= NULL*/ ) else SendMessageToSet( &data, true ); } + +void WorldObject::UpdateObjectVisibility() +{ + CellPair p = MaNGOS::ComputeCellPair(GetPositionX(), GetPositionY()); + Cell cell(p); + + GetMap()->UpdateObjectVisibility(this, cell, p); +} + diff --git a/src/game/Object.h b/src/game/Object.h index adb23924c..80044ef76 100644 --- a/src/game/Object.h +++ b/src/game/Object.h @@ -474,6 +474,8 @@ class MANGOS_DLL_SPEC WorldObject : public Object virtual void SaveRespawnTime() {} void AddObjectToRemoveList(); + void UpdateObjectVisibility(); + // main visibility check function in normal case (ignore grey zone distance check) bool isVisibleFor(Player const* u, WorldObject const* viewPoint) const { return isVisibleForInState(u,viewPoint,false); } diff --git a/src/game/ObjectAccessor.cpp b/src/game/ObjectAccessor.cpp index 1ceb156ce..cd6a3ffb3 100644 --- a/src/game/ObjectAccessor.cpp +++ b/src/game/ObjectAccessor.cpp @@ -442,36 +442,6 @@ ObjectAccessor::WorldObjectChangeAccumulator::Visit(PlayerMapType &m) ObjectAccessor::_buildPacket(iter->getSource(), &i_object, i_updateDatas); } -void -ObjectAccessor::UpdateObjectVisibility(WorldObject *obj) -{ - CellPair p = MaNGOS::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY()); - Cell cell(p); - - obj->GetMap()->UpdateObjectVisibility(obj, cell, p); -} - -void ObjectAccessor::UpdateVisibilityForPlayer( Player* player ) -{ - WorldObject const* viewPoint = player->GetViewPoint(); - Map* m = player->GetMap(); - - CellPair p(MaNGOS::ComputeCellPair(player->GetPositionX(), player->GetPositionY())); - Cell cell(p); - - m->UpdatePlayerVisibility(player, cell, p); - - if (player!=viewPoint) - { - CellPair pView(MaNGOS::ComputeCellPair(viewPoint->GetPositionX(), viewPoint->GetPositionY())); - Cell cellView(pView); - - m->UpdateObjectsVisibilityFor(player, cellView, pView); - } - else - m->UpdateObjectsVisibilityFor(player, cell, p); -} - /// Define the static member of HashMapHolder template UNORDERED_MAP< uint64, T* > HashMapHolder::m_objectMap; diff --git a/src/game/ObjectAccessor.h b/src/game/ObjectAccessor.h index 14154817a..fb42d97a1 100644 --- a/src/game/ObjectAccessor.h +++ b/src/game/ObjectAccessor.h @@ -202,8 +202,6 @@ class MANGOS_DLL_DECL ObjectAccessor : public MaNGOS::SingletonUpdatePlayerVisibility(this, cell, p); + + if (this != viewPoint) + { + CellPair pView(MaNGOS::ComputeCellPair(viewPoint->GetPositionX(), viewPoint->GetPositionY())); + Cell cellView(pView); + + m->UpdateObjectsVisibilityFor(this, cellView, pView); + } + else + m->UpdateObjectsVisibilityFor(this, cell, p); +} + diff --git a/src/game/Player.h b/src/game/Player.h index 89a6421d3..6bb046765 100644 --- a/src/game/Player.h +++ b/src/game/Player.h @@ -1033,6 +1033,8 @@ class MANGOS_DLL_SPEC Player : public Unit bool CanInteractWithNPCs(bool alive = true) const; GameObject* GetGameObjectIfCanInteractWith(uint64 guid, GameobjectTypes type) const; + void UpdateVisibilityForPlayer(); + bool ToggleAFK(); bool ToggleDND(); bool isAFK() const { return HasFlag(PLAYER_FLAGS,PLAYER_FLAGS_AFK); }; diff --git a/src/game/SpellAuras.cpp b/src/game/SpellAuras.cpp index 278edf214..663d91a41 100644 --- a/src/game/SpellAuras.cpp +++ b/src/game/SpellAuras.cpp @@ -3910,7 +3910,7 @@ void Aura::HandleInvisibilityDetect(bool apply, bool Real) m_target->m_detectInvisibilityMask |= (1 << m_modifier.m_miscvalue); } if(Real && m_target->GetTypeId()==TYPEID_PLAYER) - ObjectAccessor::UpdateVisibilityForPlayer((Player*)m_target); + ((Player*)m_target)->UpdateVisibilityForPlayer(); } void Aura::HandleAuraModRoot(bool apply, bool Real)