Clean up very some confusing MapManager functions (create/find map/base map).

This commit is contained in:
megamage
2011-11-23 12:45:59 -05:00
parent b3fef1e280
commit 98be413ce0
6 changed files with 25 additions and 30 deletions
+5 -5
View File
@@ -940,7 +940,7 @@ bool Player::Create(uint32 guidlow, CharacterCreateInfo* createInfo)
return false; return false;
} }
SetMap(sMapMgr->CreateMap(info->mapId, this, 0)); SetMap(sMapMgr->CreateMap(info->mapId, this));
uint8 powertype = cEntry->powerType; uint8 powertype = cEntry->powerType;
@@ -2205,7 +2205,7 @@ bool Player::TeleportTo(uint32 mapid, float x, float y, float z, float orientati
if (!sMapMgr->CanPlayerEnter(mapid, this, false)) if (!sMapMgr->CanPlayerEnter(mapid, this, false))
return false; return false;
Map* map = sMapMgr->CreateMap(mapid, this, 0); Map* map = sMapMgr->CreateMap(mapid, this);
if (!map || map->CanEnter(this)) if (!map || map->CanEnter(this))
{ {
//lets reset near teleport flag if it wasn't reset during chained teleports //lets reset near teleport flag if it wasn't reset during chained teleports
@@ -16790,7 +16790,7 @@ bool Player::LoadFromDB(uint32 guid, SQLQueryHolder *holder)
// NOW player must have valid map // NOW player must have valid map
// load the player's map here if it's not already loaded // load the player's map here if it's not already loaded
Map* map = sMapMgr->CreateMap(mapId, this, instanceId); Map* map = sMapMgr->CreateMap(mapId, this);
if (!map) if (!map)
{ {
@@ -16808,14 +16808,14 @@ bool Player::LoadFromDB(uint32 guid, SQLQueryHolder *holder)
RelocateToHomebind(); RelocateToHomebind();
} }
map = sMapMgr->CreateMap(mapId, this, 0); map = sMapMgr->CreateMap(mapId, this);
if (!map) if (!map)
{ {
PlayerInfo const* info = sObjectMgr->GetPlayerInfo(getRace(), getClass()); PlayerInfo const* info = sObjectMgr->GetPlayerInfo(getRace(), getClass());
mapId = info->mapId; mapId = info->mapId;
Relocate(info->positionX, info->positionY, info->positionZ, 0.0f); Relocate(info->positionX, info->positionY, info->positionZ, 0.0f);
sLog->outError("Player (guidlow %d) have invalid coordinates (X: %f Y: %f Z: %f O: %f). Teleport to default race/class locations.", guid, GetPositionX(), GetPositionY(), GetPositionZ(), GetOrientation()); sLog->outError("Player (guidlow %d) have invalid coordinates (X: %f Y: %f Z: %f O: %f). Teleport to default race/class locations.", guid, GetPositionX(), GetPositionY(), GetPositionZ(), GetOrientation());
map = sMapMgr->CreateMap(mapId, this, 0); map = sMapMgr->CreateMap(mapId, this);
if (!map) if (!map)
{ {
sLog->outError("Player (guidlow %d) has invalid default map coordinates (X: %f Y: %f Z: %f O: %f). or instance couldn't be created", guid, GetPositionX(), GetPositionY(), GetPositionZ(), GetOrientation()); sLog->outError("Player (guidlow %d) has invalid default map coordinates (X: %f Y: %f Z: %f O: %f). or instance couldn't be created", guid, GetPositionX(), GetPositionY(), GetPositionZ(), GetOrientation());
@@ -98,7 +98,7 @@ void MapManager::LoadTransports()
m_TransportsByMap[*i].insert(t); m_TransportsByMap[*i].insert(t);
//If we someday decide to use the grid to track transports, here: //If we someday decide to use the grid to track transports, here:
t->SetMap(sMapMgr->CreateMap(mapid, t, 0)); t->SetMap(sMapMgr->CreateBaseMap(mapid));
t->AddToWorld(); t->AddToWorld();
++count; ++count;
@@ -494,7 +494,7 @@ void Transport::TeleportTransport(uint32 newMapid, float x, float y, float z)
RemoveFromWorld(); RemoveFromWorld();
ResetMap(); ResetMap();
Map* newMap = sMapMgr->CreateMap(newMapid, this, 0); Map* newMap = sMapMgr->CreateBaseMap(newMapid);
SetMap(newMap); SetMap(newMap);
ASSERT (GetMap()); ASSERT (GetMap());
AddToWorld(); AddToWorld();
+7 -9
View File
@@ -95,9 +95,9 @@ void MapManager::checkAndCorrectGridStatesArray()
++i_GridStateErrorCount; ++i_GridStateErrorCount;
} }
Map* MapManager::_createBaseMap(uint32 id) Map* MapManager::CreateBaseMap(uint32 id)
{ {
Map* m = _findMap(id); Map* m = FindBaseMap(id);
if (m == NULL) if (m == NULL)
{ {
@@ -119,21 +119,19 @@ Map* MapManager::_createBaseMap(uint32 id)
return m; return m;
} }
Map* MapManager::CreateMap(uint32 id, const WorldObject* obj, uint32 /*instanceId*/) Map* MapManager::CreateMap(uint32 id, Player* player)
{ {
ASSERT(obj); Map* m = CreateBaseMap(id);
//if (!obj->IsInWorld()) sLog->outError("GetMap: called for map %d with object (typeid %d, guid %d, mapid %d, instanceid %d) who is not in world!", id, obj->GetTypeId(), obj->GetGUIDLow(), obj->GetMapId(), obj->GetInstanceId());
Map* m = _createBaseMap(id);
if (m && obj->GetTypeId() == TYPEID_PLAYER && m->Instanceable()) if (m && m->Instanceable())
m = ((MapInstanced*)m)->CreateInstanceForPlayer(id, (Player*)obj); m = ((MapInstanced*)m)->CreateInstanceForPlayer(id, player);
return m; return m;
} }
Map* MapManager::FindMap(uint32 mapid, uint32 instanceId) const Map* MapManager::FindMap(uint32 mapid, uint32 instanceId) const
{ {
Map* map = _findMap(mapid); Map* map = FindBaseMap(mapid);
if (!map) if (!map)
return NULL; return NULL;
+9 -12
View File
@@ -35,14 +35,18 @@ class MapManager
friend class ACE_Singleton<MapManager, ACE_Thread_Mutex>; friend class ACE_Singleton<MapManager, ACE_Thread_Mutex>;
public: public:
Map* CreateBaseMap(uint32 mapId);
Map* CreateMap(uint32, const WorldObject* obj, uint32 instanceId); Map* FindBaseMap(uint32 mapId) const
Map const* CreateBaseMap(uint32 id) const { return const_cast<MapManager*>(this)->_createBaseMap(id); } {
Map* FindMap(uint32 mapid, uint32 instanceId = 0) const; MapMapType::const_iterator iter = i_maps.find(mapId);
return (iter == i_maps.end() ? NULL : iter->second);
}
Map* CreateMap(uint32 mapId, Player* player);
Map* FindMap(uint32 mapId, uint32 instanceId) const;
uint16 GetAreaFlag(uint32 mapid, float x, float y, float z) const uint16 GetAreaFlag(uint32 mapid, float x, float y, float z) const
{ {
Map const* m = CreateBaseMap(mapid); Map const* m = const_cast<MapManager*>(this)->CreateBaseMap(mapid);
return m->GetAreaFlag(x, y, z); return m->GetAreaFlag(x, y, z);
} }
uint32 GetAreaId(uint32 mapid, float x, float y, float z) const uint32 GetAreaId(uint32 mapid, float x, float y, float z) const
@@ -163,13 +167,6 @@ class MapManager
MapManager(const MapManager &); MapManager(const MapManager &);
MapManager& operator=(const MapManager &); MapManager& operator=(const MapManager &);
Map* _createBaseMap(uint32 id);
Map* _findMap(uint32 id) const
{
MapMapType::const_iterator iter = i_maps.find(id);
return (iter == i_maps.end() ? NULL : iter->second);
}
ACE_Thread_Mutex Lock; ACE_Thread_Mutex Lock;
uint32 i_gridCleanUpDelay; uint32 i_gridCleanUpDelay;
MapMapType i_maps; MapMapType i_maps;
@@ -351,7 +351,7 @@ void FlightPathMovementGenerator::InitEndGridInfo()
void FlightPathMovementGenerator::PreloadEndGrid() void FlightPathMovementGenerator::PreloadEndGrid()
{ {
// used to preload the final grid where the flightmaster is // used to preload the final grid where the flightmaster is
Map* endMap = sMapMgr->FindMap(m_endMapId); Map* endMap = sMapMgr->FindBaseMap(m_endMapId);
// Load the grid // Load the grid
if (endMap) if (endMap)
@@ -72,7 +72,7 @@ void WorldSession::HandleMoveWorldportAckOpcode()
} }
// relocate the player to the teleport destination // relocate the player to the teleport destination
Map* newMap = sMapMgr->CreateMap(loc.GetMapId(), GetPlayer(), 0); Map* newMap = sMapMgr->CreateMap(loc.GetMapId(), GetPlayer());
// the CanEnter checks are done in TeleporTo but conditions may change // the CanEnter checks are done in TeleporTo but conditions may change
// while the player is in transit, for example the map may get full // while the player is in transit, for example the map may get full
if (!newMap || !newMap->CanEnter(GetPlayer())) if (!newMap || !newMap->CanEnter(GetPlayer()))