Some cleanup of add/remove to/from map.

This commit is contained in:
megamage
2011-11-11 17:50:26 -05:00
parent 3569f01adc
commit 07cf71fdd4
6 changed files with 44 additions and 43 deletions

View File

@@ -2277,7 +2277,7 @@ bool Player::TeleportTo(uint32 mapid, float x, float y, float z, float orientati
// remove from old map now
if (oldmap)
oldmap->RemoveFromMap(this, false);
oldmap->RemovePlayerFromMap(this, false);
// new final coordinates
float final_x = x;

View File

@@ -375,23 +375,22 @@ void Map::LoadGrid(float x, float y)
EnsureGridLoaded(Cell(x, y));
}
bool Map::AddToMap(Player* player)
bool Map::AddPlayerToMap(Player* player)
{
// Check if we are adding to correct map
ASSERT (player->GetMap() == this);
CellCoord p = Trinity::ComputeCellCoord(player->GetPositionX(), player->GetPositionY());
if (!p.IsCoordValid())
CellCoord cellCoord = Trinity::ComputeCellCoord(player->GetPositionX(), player->GetPositionY());
if (!cellCoord.IsCoordValid())
{
sLog->outError("Map::Add: Player (GUID: %u) has invalid coordinates X:%f Y:%f grid cell [%u:%u]", player->GetGUIDLow(), player->GetPositionX(), player->GetPositionY(), p.x_coord, p.y_coord);
sLog->outError("Map::Add: Player (GUID: %u) has invalid coordinates X:%f Y:%f grid cell [%u:%u]", player->GetGUIDLow(), player->GetPositionX(), player->GetPositionY(), cellCoord.x_coord, cellCoord.y_coord);
return false;
}
player->SetMap(this);
Cell cell(p);
Cell cell(cellCoord);
EnsureGridLoadedForActiveObject(cell, player);
AddToGrid(player, cell);
// Check if we are adding to correct map
ASSERT (player->GetMap() == this);
player->SetMap(this);
player->AddToWorld();
SendInitSelf(player);
@@ -416,38 +415,40 @@ void Map::InitializeObject(Creature* obj)
}
template<class T>
void
Map::AddToMap(T *obj)
void Map::AddToMap(T *obj)
{
CellCoord p = Trinity::ComputeCellCoord(obj->GetPositionX(), obj->GetPositionY());
if (!p.IsCoordValid())
{
sLog->outError("Map::Add: Object " UI64FMTD " has invalid coordinates X:%f Y:%f grid cell [%u:%u]", obj->GetGUID(), obj->GetPositionX(), obj->GetPositionY(), p.x_coord, p.y_coord);
return;
}
Cell cell(p);
if (obj->IsInWorld()) // need some clean up later
//TODO: Needs clean up. An object should not be added to map twice.
if (obj->IsInWorld())
{
ASSERT(obj->IsInGrid());
obj->UpdateObjectVisibility(true);
return;
}
CellCoord cellCoord = Trinity::ComputeCellCoord(obj->GetPositionX(), obj->GetPositionY());
if (!cellCoord.IsCoordValid())
{
sLog->outError("Map::Add: Object " UI64FMTD " has invalid coordinates X:%f Y:%f grid cell [%u:%u]", obj->GetGUID(), obj->GetPositionX(), obj->GetPositionY(), cellCoord.x_coord, cellCoord.y_coord);
return;
}
Cell cell(cellCoord);
if (obj->isActiveObject())
EnsureGridLoadedForActiveObject(cell, obj);
else
EnsureGridCreated(GridCoord(cell.GridX(), cell.GridY()));
AddToGrid(obj, cell);
sLog->outStaticDebug("Object %u enters grid[%u, %u]", GUID_LOPART(obj->GetGUID()), cell.GridX(), cell.GridY());
//Must already be set before AddToMap. Usually during obj->Create.
//obj->SetMap(this);
obj->AddToWorld();
InitializeObject(obj);
if (obj->isActiveObject())
AddToActive(obj);
sLog->outStaticDebug("Object %u enters grid[%u, %u]", GUID_LOPART(obj->GetGUID()), cell.GridX(), cell.GridY());
//something, such as vehicle, needs to be update immediately
//also, trigger needs to cast spell, if not update, cannot see visual
obj->UpdateObjectVisibility(true);
@@ -641,7 +642,7 @@ void Map::ProcessRelocationNotifies(const uint32 diff)
}
}
void Map::RemoveFromMap(Player* player, bool remove)
void Map::RemovePlayerFromMap(Player* player, bool remove)
{
player->RemoveFromWorld();
SendRemoveTransports(player);
@@ -2236,7 +2237,7 @@ bool InstanceMap::CanEnter(Player* player)
/*
Do map specific checks and add the player to the map if successful.
*/
bool InstanceMap::AddToMap(Player* player)
bool InstanceMap::AddPlayerToMap(Player* player)
{
// TODO: Not sure about checking player level: already done in HandleAreaTriggerOpcode
// GMs still can teleport player in instance.
@@ -2346,7 +2347,7 @@ bool InstanceMap::AddToMap(Player* player)
}
// this will acquire the same mutex so it cannot be in the previous block
Map::AddToMap(player);
Map::AddPlayerToMap(player);
if (i_data)
i_data->OnPlayerEnter(player);
@@ -2362,13 +2363,13 @@ void InstanceMap::Update(const uint32 t_diff)
i_data->Update(t_diff);
}
void InstanceMap::RemoveFromMap(Player* player, bool remove)
void InstanceMap::RemovePlayerFromMap(Player* player, bool remove)
{
sLog->outDetail("MAP: Removing player '%s' from instance '%u' of map '%s' before relocating to another map", player->GetName(), GetInstanceId(), GetMapName());
//if last player set unload timer
if (!m_unloadTimer && m_mapRefManager.getSize() == 1)
m_unloadTimer = m_unloadWhenEmpty ? MIN_UNLOAD_DELAY : std::max(sWorld->getIntConfig(CONFIG_INSTANCE_UNLOAD_DELAY), (uint32)MIN_UNLOAD_DELAY);
Map::RemoveFromMap(player, remove);
Map::RemovePlayerFromMap(player, remove);
// for normal instances schedule the reset after all players have left
SetResetSchedule(true);
}
@@ -2582,7 +2583,7 @@ bool BattlegroundMap::CanEnter(Player* player)
return Map::CanEnter(player);
}
bool BattlegroundMap::AddToMap(Player* player)
bool BattlegroundMap::AddPlayerToMap(Player* player)
{
{
TRINITY_GUARD(ACE_Thread_Mutex, Lock);
@@ -2592,13 +2593,13 @@ bool BattlegroundMap::AddToMap(Player* player)
// reset instance validity, battleground maps do not homebind
player->m_InstanceValid = true;
}
return Map::AddToMap(player);
return Map::AddPlayerToMap(player);
}
void BattlegroundMap::RemoveFromMap(Player* player, bool remove)
void BattlegroundMap::RemovePlayerFromMap(Player* player, bool remove)
{
sLog->outDetail("MAP: Removing player '%s' from bg '%u' of map '%s' before relocating to another map", player->GetName(), GetInstanceId(), GetMapName());
Map::RemoveFromMap(player, remove);
Map::RemovePlayerFromMap(player, remove);
}
void BattlegroundMap::SetUnload()

View File

@@ -244,8 +244,8 @@ class Map : public GridRefManager<NGridType>
return false;
}
virtual bool AddToMap(Player*);
virtual void RemoveFromMap(Player*, bool);
virtual bool AddPlayerToMap(Player*);
virtual void RemovePlayerFromMap(Player*, bool);
template<class T> void AddToMap(T *);
template<class T> void RemoveFromMap(T *, bool);
@@ -567,8 +567,8 @@ class InstanceMap : public Map
public:
InstanceMap(uint32 id, time_t, uint32 InstanceId, uint8 SpawnMode, Map* _parent);
~InstanceMap();
bool AddToMap(Player*);
void RemoveFromMap(Player*, bool);
bool AddPlayerToMap(Player*);
void RemovePlayerFromMap(Player*, bool);
void Update(const uint32);
void CreateInstanceData(bool load);
bool Reset(uint8 method);
@@ -597,8 +597,8 @@ class BattlegroundMap : public Map
BattlegroundMap(uint32 id, time_t, uint32 InstanceId, Map* _parent, uint8 spawnMode);
~BattlegroundMap();
bool AddToMap(Player*);
void RemoveFromMap(Player*, bool);
bool AddPlayerToMap(Player*);
void RemovePlayerFromMap(Player*, bool);
bool CanEnter(Player* player);
void SetUnload();
//void UnloadAll(bool pForce);

View File

@@ -920,7 +920,7 @@ void WorldSession::HandlePlayerLogin(LoginQueryHolder * holder)
}
}
if (!pCurrChar->GetMap()->AddToMap(pCurrChar) || !pCurrChar->CheckInstanceLoginValid())
if (!pCurrChar->GetMap()->AddPlayerToMap(pCurrChar) || !pCurrChar->CheckInstanceLoginValid())
{
AreaTrigger const* at = sObjectMgr->GetGoBackTrigger(pCurrChar->GetMapId());
if (at)

View File

@@ -68,7 +68,7 @@ void WorldSession::HandleMoveWorldportAckOpcode()
if (GetPlayer()->IsInWorld())
{
sLog->outCrash("Player (Name %s) is still in world when teleported from map %u to new map %u", GetPlayer()->GetName(), oldMap->GetId(), loc.GetMapId());
oldMap->RemoveFromMap(GetPlayer(), false);
oldMap->RemovePlayerFromMap(GetPlayer(), false);
}
// relocate the player to the teleport destination
@@ -88,7 +88,7 @@ void WorldSession::HandleMoveWorldportAckOpcode()
GetPlayer()->SetMap(newMap);
GetPlayer()->SendInitialPacketsBeforeAddToMap();
if (!GetPlayer()->GetMap()->AddToMap(GetPlayer()))
if (!GetPlayer()->GetMap()->AddPlayerToMap(GetPlayer()))
{
sLog->outError("WORLD: failed to teleport player %s (%d) to map %d because of unknown reason!", GetPlayer()->GetName(), GetPlayer()->GetGUIDLow(), loc.GetMapId());
GetPlayer()->ResetMap();

View File

@@ -494,7 +494,7 @@ void WorldSession::LogoutPlayer(bool Save)
_player->CleanupsBeforeDelete();
sLog->outChar("Account: %d (IP: %s) Logout Character:[%s] (GUID: %u)", GetAccountId(), GetRemoteAddress().c_str(), _player->GetName(), _player->GetGUIDLow());
Map* _map = _player->GetMap();
_map->RemoveFromMap(_player, true);
_map->RemovePlayerFromMap(_player, true);
SetPlayer(NULL); // deleted in Remove call
///- Send the 'logout complete' packet to the client