mirror of
https://github.com/mangosfour/server.git
synced 2025-12-26 07:37:02 +00:00
[10727] Map system re-engineered. Special thanks to Blueboy for tests.
Signed-off-by: Ambal <pogrebniak@gala.net>
This commit is contained in:
parent
f5e40a5fda
commit
f67d89f109
43 changed files with 1254 additions and 1128 deletions
|
|
@ -23,16 +23,15 @@
|
|||
#include "Log.h"
|
||||
#include "Transports.h"
|
||||
#include "GridDefines.h"
|
||||
#include "MapInstanced.h"
|
||||
#include "DestinationHolderImp.h"
|
||||
#include "World.h"
|
||||
#include "CellImpl.h"
|
||||
#include "Corpse.h"
|
||||
#include "ObjectMgr.h"
|
||||
|
||||
#define CLASS_LOCK MaNGOS::ClassLevelLockable<MapManager, ACE_Thread_Mutex>
|
||||
#define CLASS_LOCK MaNGOS::ClassLevelLockable<MapManager, ACE_Recursive_Thread_Mutex>
|
||||
INSTANTIATE_SINGLETON_2(MapManager, CLASS_LOCK);
|
||||
INSTANTIATE_CLASS_MUTEX(MapManager, ACE_Thread_Mutex);
|
||||
INSTANTIATE_CLASS_MUTEX(MapManager, ACE_Recursive_Thread_Mutex);
|
||||
|
||||
MapManager::MapManager()
|
||||
: i_gridCleanUpDelay(sWorld.getConfig(CONFIG_UINT32_INTERVAL_GRIDCLEAN))
|
||||
|
|
@ -88,60 +87,64 @@ void MapManager::InitializeVisibilityDistanceInfo()
|
|||
(*iter).second->InitVisibilityDistance();
|
||||
}
|
||||
|
||||
Map*
|
||||
MapManager::_createBaseMap(uint32 id)
|
||||
{
|
||||
Map *m = _findMap(id);
|
||||
|
||||
if( m == NULL )
|
||||
{
|
||||
Guard guard(*this);
|
||||
|
||||
const MapEntry* entry = sMapStore.LookupEntry(id);
|
||||
if (entry && entry->Instanceable())
|
||||
{
|
||||
m = new MapInstanced(id, i_gridCleanUpDelay);
|
||||
}
|
||||
else
|
||||
{
|
||||
m = new Map(id, i_gridCleanUpDelay, 0, REGULAR_DIFFICULTY);
|
||||
}
|
||||
i_maps[id] = m;
|
||||
}
|
||||
|
||||
MANGOS_ASSERT(m != NULL);
|
||||
return m;
|
||||
}
|
||||
|
||||
Map* MapManager::CreateMap(uint32 id, const WorldObject* obj)
|
||||
{
|
||||
MANGOS_ASSERT(obj);
|
||||
//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);
|
||||
Guard _guard(*this);
|
||||
|
||||
Map * m = NULL;
|
||||
|
||||
if (m && (obj->GetTypeId() == TYPEID_PLAYER) && m->Instanceable())
|
||||
m = ((MapInstanced*)m)->CreateInstance((Player*)obj);
|
||||
const MapEntry* entry = sMapStore.LookupEntry(id);
|
||||
if(!entry)
|
||||
return NULL;
|
||||
|
||||
if(entry->Instanceable())
|
||||
{
|
||||
MANGOS_ASSERT(obj->GetTypeId() == TYPEID_PLAYER);
|
||||
//create InstanceMap object
|
||||
if(obj->GetTypeId() == TYPEID_PLAYER)
|
||||
m = CreateInstance(id, (Player*)obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
//create regular Continent map
|
||||
m = FindMap(id);
|
||||
if( m == NULL )
|
||||
{
|
||||
m = new Map(id, i_gridCleanUpDelay, 0, REGULAR_DIFFICULTY);
|
||||
//add map into container
|
||||
i_maps[MapID(id)] = m;
|
||||
}
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
Map* MapManager::CreateBgMap(uint32 mapid, BattleGround* bg)
|
||||
{
|
||||
Map *m = _createBaseMap(mapid);
|
||||
((MapInstanced*)m)->CreateBattleGroundMap(sObjectMgr.GenerateLowGuid(HIGHGUID_INSTANCE), bg);
|
||||
return m;
|
||||
TerrainInfo * pData = sTerrainMgr.LoadTerrain(mapid);
|
||||
|
||||
Guard _guard(*this);
|
||||
return CreateBattleGroundMap(mapid, sObjectMgr.GenerateLowGuid(HIGHGUID_INSTANCE), bg);
|
||||
}
|
||||
|
||||
Map* MapManager::FindMap(uint32 mapid, uint32 instanceId) const
|
||||
{
|
||||
Map *map = _findMap(mapid);
|
||||
if(!map)
|
||||
Guard guard(*this);
|
||||
|
||||
MapMapType::const_iterator iter = i_maps.find(MapID(mapid, instanceId));
|
||||
if(iter == i_maps.end())
|
||||
return NULL;
|
||||
|
||||
//this is a small workaround for transports
|
||||
if(instanceId == 0 && iter->second->Instanceable())
|
||||
{
|
||||
assert(false);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(!map->Instanceable())
|
||||
return instanceId == 0 ? map : NULL;
|
||||
|
||||
return ((MapInstanced*)map)->FindMap(instanceId);
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -233,9 +236,20 @@ bool MapManager::CanPlayerEnter(uint32 mapid, Player* player)
|
|||
|
||||
void MapManager::DeleteInstance(uint32 mapid, uint32 instanceId)
|
||||
{
|
||||
Map *m = _createBaseMap(mapid);
|
||||
if (m && m->Instanceable())
|
||||
((MapInstanced*)m)->DestroyInstance(instanceId);
|
||||
Guard _guard(*this);
|
||||
|
||||
MapMapType::iterator iter = i_maps.find(MapID(mapid, instanceId));
|
||||
if(iter != i_maps.end())
|
||||
{
|
||||
Map * pMap = iter->second;
|
||||
if (pMap->Instanceable())
|
||||
{
|
||||
i_maps.erase(iter);
|
||||
|
||||
pMap->UnloadAll(true);
|
||||
delete pMap;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -251,6 +265,23 @@ MapManager::Update(uint32 diff)
|
|||
for (TransportSet::iterator iter = m_Transports.begin(); iter != m_Transports.end(); ++iter)
|
||||
(*iter)->Update((uint32)i_timer.GetCurrent());
|
||||
|
||||
//remove all maps which can be unloaded
|
||||
MapMapType::iterator iter = i_maps.begin();
|
||||
while(iter != i_maps.end())
|
||||
{
|
||||
Map * pMap = iter->second;
|
||||
//check if map can be unloaded
|
||||
if(pMap->CanUnload((uint32)i_timer.GetCurrent()))
|
||||
{
|
||||
pMap->UnloadAll(true);
|
||||
delete pMap;
|
||||
|
||||
i_maps.erase(iter++);
|
||||
}
|
||||
else
|
||||
++iter;
|
||||
}
|
||||
|
||||
i_timer.SetCurrent(0);
|
||||
}
|
||||
|
||||
|
|
@ -287,6 +318,8 @@ void MapManager::UnloadAll()
|
|||
delete i_maps.begin()->second;
|
||||
i_maps.erase(i_maps.begin());
|
||||
}
|
||||
|
||||
TerrainManager::Instance().UnloadAll();
|
||||
}
|
||||
|
||||
uint32 MapManager::GetNumInstances()
|
||||
|
|
@ -295,10 +328,8 @@ uint32 MapManager::GetNumInstances()
|
|||
for(MapMapType::iterator itr = i_maps.begin(); itr != i_maps.end(); ++itr)
|
||||
{
|
||||
Map *map = itr->second;
|
||||
if(!map->Instanceable()) continue;
|
||||
MapInstanced::InstancedMaps &maps = ((MapInstanced *)map)->GetInstancedMaps();
|
||||
for(MapInstanced::InstancedMaps::iterator mitr = maps.begin(); mitr != maps.end(); ++mitr)
|
||||
if(mitr->second->IsDungeon()) ret++;
|
||||
if(!map->IsDungeon()) continue;
|
||||
ret += 1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -309,11 +340,103 @@ uint32 MapManager::GetNumPlayersInInstances()
|
|||
for(MapMapType::iterator itr = i_maps.begin(); itr != i_maps.end(); ++itr)
|
||||
{
|
||||
Map *map = itr->second;
|
||||
if(!map->Instanceable()) continue;
|
||||
MapInstanced::InstancedMaps &maps = ((MapInstanced *)map)->GetInstancedMaps();
|
||||
for(MapInstanced::InstancedMaps::iterator mitr = maps.begin(); mitr != maps.end(); ++mitr)
|
||||
if(mitr->second->IsDungeon())
|
||||
ret += ((InstanceMap*)mitr->second)->GetPlayers().getSize();
|
||||
if(!map->IsDungeon()) continue;
|
||||
ret += map->GetPlayers().getSize();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
///// returns a new or existing Instance
|
||||
///// in case of battlegrounds it will only return an existing map, those maps are created by bg-system
|
||||
Map* MapManager::CreateInstance(uint32 id, Player * player)
|
||||
{
|
||||
Map* map = NULL;
|
||||
Map * pNewMap = NULL;
|
||||
uint32 NewInstanceId = 0; // instanceId of the resulting map
|
||||
const MapEntry* entry = sMapStore.LookupEntry(id);
|
||||
|
||||
if(entry->IsBattleGroundOrArena())
|
||||
{
|
||||
// find existing bg map for player
|
||||
NewInstanceId = player->GetBattleGroundId();
|
||||
MANGOS_ASSERT(NewInstanceId);
|
||||
map = FindMap(id, NewInstanceId);
|
||||
MANGOS_ASSERT(map);
|
||||
}
|
||||
else if (InstanceSave* pSave = player->GetBoundInstanceSaveForSelfOrGroup(id))
|
||||
{
|
||||
// solo/perm/group
|
||||
NewInstanceId = pSave->GetInstanceId();
|
||||
map = FindMap(id, NewInstanceId);
|
||||
// it is possible that the save exists but the map doesn't
|
||||
if (!map)
|
||||
pNewMap = CreateInstanceMap(id, NewInstanceId, pSave->GetDifficulty(), pSave);
|
||||
}
|
||||
else
|
||||
{
|
||||
// if no instanceId via group members or instance saves is found
|
||||
// the instance will be created for the first time
|
||||
NewInstanceId = sObjectMgr.GenerateLowGuid(HIGHGUID_INSTANCE);
|
||||
|
||||
Difficulty diff = player->GetGroup() ? player->GetGroup()->GetDifficulty(entry->IsRaid()) : player->GetDifficulty(entry->IsRaid());
|
||||
pNewMap = CreateInstanceMap(id, NewInstanceId, diff);
|
||||
}
|
||||
|
||||
//add a new map object into the registry
|
||||
if(pNewMap)
|
||||
{
|
||||
i_maps[MapID(id, NewInstanceId)] = pNewMap;
|
||||
map = pNewMap;
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
InstanceMap* MapManager::CreateInstanceMap(uint32 id, uint32 InstanceId, Difficulty difficulty, InstanceSave *save)
|
||||
{
|
||||
// make sure we have a valid map id
|
||||
if (!sMapStore.LookupEntry(id))
|
||||
{
|
||||
sLog.outError("CreateInstanceMap: no entry for map %d", id);
|
||||
MANGOS_ASSERT(false);
|
||||
}
|
||||
if (!ObjectMgr::GetInstanceTemplate(id))
|
||||
{
|
||||
sLog.outError("CreateInstanceMap: no instance template for map %d", id);
|
||||
MANGOS_ASSERT(false);
|
||||
}
|
||||
|
||||
// some instances only have one difficulty
|
||||
if (!GetMapDifficultyData(id, difficulty))
|
||||
difficulty = DUNGEON_DIFFICULTY_NORMAL;
|
||||
|
||||
DEBUG_LOG("MapInstanced::CreateInstanceMap: %s map instance %d for %d created with difficulty %d", save?"":"new ", InstanceId, id, difficulty);
|
||||
|
||||
InstanceMap *map = new InstanceMap(id, i_gridCleanUpDelay, InstanceId, difficulty);
|
||||
MANGOS_ASSERT(map->IsDungeon());
|
||||
|
||||
bool load_data = save != NULL;
|
||||
map->CreateInstanceData(load_data);
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
BattleGroundMap* MapManager::CreateBattleGroundMap(uint32 id, uint32 InstanceId, BattleGround* bg)
|
||||
{
|
||||
DEBUG_LOG("MapInstanced::CreateBattleGroundMap: instance:%d for map:%d and bgType:%d created.", InstanceId, id, bg->GetTypeID());
|
||||
|
||||
PvPDifficultyEntry const* bracketEntry = GetBattlegroundBracketByLevel(bg->GetMapId(),bg->GetMinLevel());
|
||||
|
||||
uint8 spawnMode = bracketEntry ? bracketEntry->difficulty : REGULAR_DIFFICULTY;
|
||||
|
||||
BattleGroundMap *map = new BattleGroundMap(id, i_gridCleanUpDelay, InstanceId, spawnMode);
|
||||
MANGOS_ASSERT(map->IsBattleGroundOrArena());
|
||||
map->SetBG(bg);
|
||||
bg->SetBgMap(map);
|
||||
|
||||
//add map into map container
|
||||
i_maps[MapID(id, InstanceId)] = map;
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue