TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MMAP::MMapManager Class Reference

#include <MMapManager.h>

Public Types

typedef std::unordered_map
< uint32, std::vector< uint32 > > 
PhaseChildMapContainer
 

Public Member Functions

 MMapManager ()
 
 ~MMapManager ()
 
void InitializeThreadUnsafe (std::unordered_map< uint32, std::vector< uint32 >> const &mapData)
 
bool loadMap (const std::string &basePath, uint32 mapId, int32 x, int32 y)
 
bool unloadMap (uint32 mapId, int32 x, int32 y)
 
bool unloadMap (uint32 mapId)
 
bool unloadMapInstance (uint32 mapId, uint32 instanceId)
 
dtNavMeshQuery constGetNavMeshQuery (uint32 mapId, uint32 instanceId, TerrainSet swaps)
 
dtNavMesh constGetNavMesh (uint32 mapId, TerrainSet swaps)
 
uint32 getLoadedTilesCount () const
 
uint32 getLoadedMapsCount () const
 
void LoadPhaseTiles (PhaseChildMapContainer::const_iterator phasedMapData, int32 x, int32 y)
 
void UnloadPhaseTile (PhaseChildMapContainer::const_iterator phasedMapData, int32 x, int32 y)
 
PhaseTileContainer constGetPhaseTileContainer (uint32 mapId) const
 

Private Member Functions

bool loadMapData (uint32 mapId)
 
uint32 packTileID (int32 x, int32 y)
 
MMapDataSet::const_iterator GetMMapData (uint32 mapId) const
 
PhasedTileLoadTile (uint32 mapId, int32 x, int32 y)
 

Private Attributes

MMapDataSet loadedMMaps
 
PhaseChildMapContainer phaseMapData
 
uint32 loadedTiles
 
bool thread_safe_environment
 
PhaseTileMap _phaseTiles
 

Member Typedef Documentation

typedef std::unordered_map<uint32, std::vector<uint32> > MMAP::MMapManager::PhaseChildMapContainer

Constructor & Destructor Documentation

MMAP::MMapManager::MMapManager ( )
inline
bool thread_safe_environment
Definition: MMapManager.h:131
uint32 loadedTiles
Definition: MMapManager.h:130
MMAP::MMapManager::~MMapManager ( )
31  {
32  for (MMapDataSet::iterator i = loadedMMaps.begin(); i != loadedMMaps.end(); ++i)
33  delete i->second;
34 
35  // by now we should not have maps loaded
36  // if we had, tiles in MMapData->mmapLoadedTiles, their actual data is lost!
37  }
MMapDataSet loadedMMaps
Definition: MMapManager.h:128

Member Function Documentation

uint32 MMAP::MMapManager::getLoadedMapsCount ( ) const
inline
110 { return uint32(loadedMMaps.size()); }
MMapDataSet loadedMMaps
Definition: MMapManager.h:128
uint32_t uint32
Definition: g3dmath.h:168

+ Here is the caller graph for this function:

uint32 MMAP::MMapManager::getLoadedTilesCount ( ) const
inline
109 { return loadedTiles; }
uint32 loadedTiles
Definition: MMapManager.h:130

+ Here is the caller graph for this function:

MMapDataSet::const_iterator MMAP::MMapManager::GetMMapData ( uint32  mapId) const
private
57  {
58  // return the iterator if found or end() if not found/NULL
59  MMapDataSet::const_iterator itr = loadedMMaps.find(mapId);
60  if (itr != loadedMMaps.cend() && !itr->second)
61  itr = loadedMMaps.cend();
62 
63  return itr;
64  }
MMapDataSet loadedMMaps
Definition: MMapManager.h:128

+ Here is the caller graph for this function:

dtNavMesh const * MMAP::MMapManager::GetNavMesh ( uint32  mapId,
TerrainSet  swaps 
)
400  {
401  MMapDataSet::const_iterator itr = GetMMapData(mapId);
402  if (itr == loadedMMaps.end())
403  return NULL;
404 
405  return itr->second->GetNavMesh(swaps);
406  }
arena_t NULL
Definition: jemalloc_internal.h:624
MMapDataSet::const_iterator GetMMapData(uint32 mapId) const
Definition: MMapManager.cpp:56
MMapDataSet loadedMMaps
Definition: MMapManager.h:128

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

dtNavMeshQuery const * MMAP::MMapManager::GetNavMeshQuery ( uint32  mapId,
uint32  instanceId,
TerrainSet  swaps 
)
409  {
410  MMapDataSet::const_iterator itr = GetMMapData(mapId);
411  if (itr == loadedMMaps.end())
412  return NULL;
413 
414  MMapData* mmap = itr->second;
415  if (mmap->navMeshQueries.find(instanceId) == mmap->navMeshQueries.end())
416  {
417  // allocate mesh query
419  ASSERT(query);
420  if (dtStatusFailed(query->init(mmap->GetNavMesh(swaps), 1024)))
421  {
422  dtFreeNavMeshQuery(query);
423  TC_LOG_ERROR("maps", "MMAP:GetNavMeshQuery: Failed to initialize dtNavMeshQuery for mapId %04u instanceId %u", mapId, instanceId);
424  return NULL;
425  }
426 
427  TC_LOG_DEBUG("maps", "MMAP:GetNavMeshQuery: created dtNavMeshQuery for mapId %04u instanceId %u", mapId, instanceId);
428  mmap->navMeshQueries.insert(std::pair<uint32, dtNavMeshQuery*>(instanceId, query));
429  }
430 
431  return mmap->navMeshQueries[instanceId];
432  }
arena_t NULL
Definition: jemalloc_internal.h:624
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
char * query(struct soap *soap)
Definition: httpget.cpp:244
MMapDataSet::const_iterator GetMMapData(uint32 mapId) const
Definition: MMapManager.cpp:56
bool dtStatusFailed(dtStatus status)
Definition: DetourStatus.h:47
MMapDataSet loadedMMaps
Definition: MMapManager.h:128
dtNavMeshQuery * dtAllocNavMeshQuery()
Definition: DetourNavMeshQuery.cpp:107
dtStatus init(const dtNavMesh *nav, const int maxNodes)
Definition: DetourNavMeshQuery.cpp:167
void dtFreeNavMeshQuery(dtNavMeshQuery *query)
Definition: DetourNavMeshQuery.cpp:114
#define ASSERT
Definition: Errors.h:55
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
Definition: DetourNavMeshQuery.h:153

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PhaseTileContainer const* MMAP::MMapManager::GetPhaseTileContainer ( uint32  mapId) const
inline
116  {
117  auto itr = _phaseTiles.find(mapId);
118  if (itr != _phaseTiles.end())
119  return &itr->second;
120  return nullptr;
121  }
PhaseTileMap _phaseTiles
Definition: MMapManager.h:134

+ Here is the caller graph for this function:

void MMAP::MMapManager::InitializeThreadUnsafe ( std::unordered_map< uint32, std::vector< uint32 >> const mapData)
40  {
41  // the caller must pass the list of all mapIds that will be used in the MMapManager lifetime
42  for (auto const& p : mapData)
43  {
44  loadedMMaps.insert(MMapDataSet::value_type(p.first, nullptr));
45  if (!p.second.empty())
46  {
47  phaseMapData[p.first] = p.second;
48  for (uint32 phasedMapId : p.second)
49  _phaseTiles.insert(PhaseTileMap::value_type(phasedMapId, PhaseTileContainer()));
50  }
51  }
52 
54  }
PhaseTileMap _phaseTiles
Definition: MMapManager.h:134
PhaseChildMapContainer phaseMapData
Definition: MMapManager.h:129
bool thread_safe_environment
Definition: MMapManager.h:131
std::unordered_map< uint32, PhasedTile * > PhaseTileContainer
Definition: MMapManager.h:59
uint32_t uint32
Definition: Define.h:150
MMapDataSet loadedMMaps
Definition: MMapManager.h:128

+ Here is the caller graph for this function:

bool MMAP::MMapManager::loadMap ( const std::string &  basePath,
uint32  mapId,
int32  x,
int32  y 
)
125  {
126  // make sure the mmap is loaded and ready to load tiles
127  if (!loadMapData(mapId))
128  return false;
129 
130  // get this mmap data
131  MMapData* mmap = loadedMMaps[mapId];
132  ASSERT(mmap->navMesh);
133 
134  // check if we already have this tile loaded
135  uint32 packedGridPos = packTileID(x, y);
136  if (mmap->loadedTileRefs.find(packedGridPos) != mmap->loadedTileRefs.end())
137  return false;
138 
139  // load this tile :: mmaps/MMMMXXYY.mmtile
140  std::string fileName = Trinity::StringFormat(TILE_FILE_NAME_FORMAT, sConfigMgr->GetStringDefault("DataDir", ".").c_str(), mapId, x, y);
141  FILE* file = fopen(fileName.c_str(), "rb");
142  if (!file)
143  {
144  TC_LOG_DEBUG("maps", "MMAP:loadMap: Could not open mmtile file '%s'", fileName.c_str());
145  return false;
146  }
147 
148  // read header
149  MmapTileHeader fileHeader;
150  if (fread(&fileHeader, sizeof(MmapTileHeader), 1, file) != 1 || fileHeader.mmapMagic != MMAP_MAGIC)
151  {
152  TC_LOG_ERROR("maps", "MMAP:loadMap: Bad header in mmap %04u%02i%02i.mmtile", mapId, x, y);
153  fclose(file);
154  return false;
155  }
156 
157  if (fileHeader.mmapVersion != MMAP_VERSION)
158  {
159  TC_LOG_ERROR("maps", "MMAP:loadMap: %04u%02i%02i.mmtile was built with generator v%i, expected v%i",
160  mapId, x, y, fileHeader.mmapVersion, MMAP_VERSION);
161  fclose(file);
162  return false;
163  }
164 
165  unsigned char* data = (unsigned char*)dtAlloc(fileHeader.size, DT_ALLOC_PERM);
166  ASSERT(data);
167 
168  size_t result = fread(data, fileHeader.size, 1, file);
169  if (!result)
170  {
171  TC_LOG_ERROR("maps", "MMAP:loadMap: Bad header or data in mmap %04u%02i%02i.mmtile", mapId, x, y);
172  fclose(file);
173  return false;
174  }
175 
176  fclose(file);
177 
178  dtMeshHeader* header = (dtMeshHeader*)data;
179  dtTileRef tileRef = 0;
180 
181  // memory allocated for data is now managed by detour, and will be deallocated when the tile is removed
182  if (dtStatusSucceed(mmap->navMesh->addTile(data, fileHeader.size, DT_TILE_FREE_DATA, 0, &tileRef)))
183  {
184  mmap->loadedTileRefs.insert(std::pair<uint32, dtTileRef>(packedGridPos, tileRef));
185  ++loadedTiles;
186  TC_LOG_DEBUG("maps", "MMAP:loadMap: Loaded mmtile %04i[%02i, %02i] into %04i[%02i, %02i]", mapId, x, y, mapId, header->x, header->y);
187 
188  PhaseChildMapContainer::const_iterator phasedMaps = phaseMapData.find(mapId);
189  if (phasedMaps != phaseMapData.end())
190  LoadPhaseTiles(phasedMaps, x, y);
191 
192  return true;
193  }
194 
195  TC_LOG_ERROR("maps", "MMAP:loadMap: Could not load %04u%02i%02i.mmtile into navmesh", mapId, x, y);
196  dtFree(data);
197  return false;
198  }
The navigation mesh owns the tile memory and is responsible for freeing it.
Definition: DetourNavMesh.h:104
void * dtAlloc(int size, dtAllocHint hint)
Definition: DetourAlloc.cpp:41
uint64_d dtTileRef
Definition: DetourNavMesh.h:53
uint32 mmapVersion
Definition: MapDefines.h:14
bool loadMapData(uint32 mapId)
Definition: MMapManager.cpp:66
uint32 mmapMagic
Definition: MapDefines.h:12
Memory persist after a function call.
Definition: DetourAlloc.h:26
#define sConfigMgr
Definition: Config.h:61
uint32 packTileID(int32 x, int32 y)
Definition: MMapManager.cpp:119
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
PhaseChildMapContainer phaseMapData
Definition: MMapManager.h:129
static char const *const TILE_FILE_NAME_FORMAT
Definition: MMapManager.cpp:27
Definition: DetourNavMesh.h:247
uint32 loadedTiles
Definition: MMapManager.h:130
int x
The x-position of the tile within the dtNavMesh tile grid. (x, y, layer)
Definition: DetourNavMesh.h:251
bool dtStatusSucceed(dtStatus status)
Definition: DetourStatus.h:41
uint32_t uint32
Definition: Define.h:150
G3D::int16 y
Definition: Vector2int16.h:38
MMapDataSet loadedMMaps
Definition: MMapManager.h:128
void LoadPhaseTiles(PhaseChildMapContainer::const_iterator phasedMapData, int32 x, int32 y)
Definition: MMapManager.cpp:249
Definition: MapDefines.h:10
std::string StringFormat(Format &&fmt, Args &&...args)
Default TC string format function.
Definition: StringFormat.h:28
#define ASSERT
Definition: Errors.h:55
uint32 size
Definition: MapDefines.h:15
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
const uint32 MMAP_MAGIC
Definition: MapDefines.h:7
G3D::int16 x
Definition: Vector2int16.h:37
int y
The y-position of the tile within the dtNavMesh tile grid. (x, y, layer)
Definition: DetourNavMesh.h:252
#define MMAP_VERSION
Definition: MapDefines.h:8
void dtFree(void *ptr)
Definition: DetourAlloc.cpp:46

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool MMAP::MMapManager::loadMapData ( uint32  mapId)
private
67  {
68  // we already have this map loaded?
69  MMapDataSet::iterator itr = loadedMMaps.find(mapId);
70  if (itr != loadedMMaps.end())
71  {
72  if (itr->second)
73  return true;
74  }
75  else
76  {
78  itr = loadedMMaps.insert(MMapDataSet::value_type(mapId, nullptr)).first;
79  else
80  ASSERT(false, "Invalid mapId %u passed to MMapManager after startup in thread unsafe environment", mapId);
81  }
82 
83  // load and init dtNavMesh - read parameters from file
84  std::string fileName = Trinity::StringFormat(MAP_FILE_NAME_FORMAT, sConfigMgr->GetStringDefault("DataDir", ".").c_str(), mapId);
85  FILE* file = fopen(fileName.c_str(), "rb");
86  if (!file)
87  {
88  TC_LOG_DEBUG("maps", "MMAP:loadMapData: Error: Could not open mmap file '%s'", fileName.c_str());
89  return false;
90  }
91 
93  uint32 count = uint32(fread(&params, sizeof(dtNavMeshParams), 1, file));
94  fclose(file);
95  if (count != 1)
96  {
97  TC_LOG_DEBUG("maps", "MMAP:loadMapData: Error: Could not read params from file '%s'", fileName.c_str());
98  return false;
99  }
100 
101  dtNavMesh* mesh = dtAllocNavMesh();
102  ASSERT(mesh);
103  if (dtStatusFailed(mesh->init(&params)))
104  {
105  dtFreeNavMesh(mesh);
106  TC_LOG_ERROR("maps", "MMAP:loadMapData: Failed to initialize dtNavMesh for mmap %04u from file %s", mapId, fileName.c_str());
107  return false;
108  }
109 
110  TC_LOG_DEBUG("maps", "MMAP:loadMapData: Loaded %04i.mmap", mapId);
111 
112  // store inside our map list
113  MMapData* mmap_data = new MMapData(mesh, mapId);
114 
115  itr->second = mmap_data;
116  return true;
117  }
dtStatus init(const dtNavMeshParams *params)
Definition: DetourNavMesh.cpp:222
static char const *const MAP_FILE_NAME_FORMAT
Definition: MMapManager.cpp:26
#define sConfigMgr
Definition: Config.h:61
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
void dtFreeNavMesh(dtNavMesh *navmesh)
Definition: DetourNavMesh.cpp:149
Definition: DetourNavMesh.h:323
bool thread_safe_environment
Definition: MMapManager.h:131
uint32_t uint32
Definition: Define.h:150
bool dtStatusFailed(dtStatus status)
Definition: DetourStatus.h:47
MMapDataSet loadedMMaps
Definition: MMapManager.h:128
std::string StringFormat(Format &&fmt, Args &&...args)
Default TC string format function.
Definition: StringFormat.h:28
Definition: DetourNavMesh.h:312
dtNavMesh * dtAllocNavMesh()
Definition: DetourNavMesh.cpp:138
#define ASSERT
Definition: Errors.h:55
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
uint32_t uint32
Definition: g3dmath.h:168
std::set< uint32 > params[2]
Definition: DisableMgr.cpp:45

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void MMAP::MMapManager::LoadPhaseTiles ( PhaseChildMapContainer::const_iterator  phasedMapData,
int32  x,
int32  y 
)
250  {
251  TC_LOG_DEBUG("phase", "MMAP:LoadPhaseTiles: Loading phased mmtiles for map %u, x: %i, y: %i", phasedMapData->first, x, y);
252 
253  uint32 packedGridPos = packTileID(x, y);
254 
255  for (uint32 phaseMapId : phasedMapData->second)
256  {
257  // only a few tiles have terrain swaps, do not write error for them
258  if (PhasedTile* data = LoadTile(phaseMapId, x, y))
259  {
260  TC_LOG_DEBUG("phase", "MMAP:LoadPhaseTiles: Loaded phased %04u%02i%02i.mmtile for root phase map %u", phaseMapId, x, y, phasedMapData->first);
261  _phaseTiles[phaseMapId][packedGridPos] = data;
262  }
263  }
264  }
PhaseTileMap _phaseTiles
Definition: MMapManager.h:134
PhasedTile * LoadTile(uint32 mapId, int32 x, int32 y)
Definition: MMapManager.cpp:200
uint32 packTileID(int32 x, int32 y)
Definition: MMapManager.cpp:119
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
uint32_t uint32
Definition: Define.h:150
G3D::int16 y
Definition: Vector2int16.h:38
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

PhasedTile * MMAP::MMapManager::LoadTile ( uint32  mapId,
int32  x,
int32  y 
)
private
201  {
202  // load this tile :: mmaps/MMMXXYY.mmtile
203  std::string fileName = Trinity::StringFormat(TILE_FILE_NAME_FORMAT, sConfigMgr->GetStringDefault("DataDir", ".").c_str(), mapId, x, y);
204  FILE* file = fopen(fileName.c_str(), "rb");
205  if (!file)
206  {
207  // Not all tiles have phased versions, don't flood this msg
208  //TC_LOG_DEBUG("phase", "MMAP:LoadTile: Could not open mmtile file '%s'", fileName);
209  return NULL;
210  }
211 
212  PhasedTile* pTile = new PhasedTile();
213 
214  // read header
215  if (fread(&pTile->fileHeader, sizeof(MmapTileHeader), 1, file) != 1 || pTile->fileHeader.mmapMagic != MMAP_MAGIC)
216  {
217  TC_LOG_ERROR("phase", "MMAP:LoadTile: Bad header in mmap %04u%02i%02i.mmtile", mapId, x, y);
218  fclose(file);
219  delete pTile;
220  return nullptr;
221  }
222 
223  if (pTile->fileHeader.mmapVersion != MMAP_VERSION)
224  {
225  TC_LOG_ERROR("phase", "MMAP:LoadTile: %04u%02i%02i.mmtile was built with generator v%i, expected v%i",
226  mapId, x, y, pTile->fileHeader.mmapVersion, MMAP_VERSION);
227  fclose(file);
228  delete pTile;
229  return nullptr;
230  }
231 
232  pTile->data = (unsigned char*)dtAlloc(pTile->fileHeader.size, DT_ALLOC_PERM);
233  ASSERT(pTile->data);
234 
235  size_t result = fread(pTile->data, pTile->fileHeader.size, 1, file);
236  if (!result)
237  {
238  TC_LOG_ERROR("phase", "MMAP:LoadTile: Bad header or data in mmap %04u%02i%02i.mmtile", mapId, x, y);
239  fclose(file);
240  delete pTile;
241  return nullptr;
242  }
243 
244  fclose(file);
245 
246  return pTile;
247  }
void * dtAlloc(int size, dtAllocHint hint)
Definition: DetourAlloc.cpp:41
Memory persist after a function call.
Definition: DetourAlloc.h:26
#define sConfigMgr
Definition: Config.h:61
arena_t NULL
Definition: jemalloc_internal.h:624
static char const *const TILE_FILE_NAME_FORMAT
Definition: MMapManager.cpp:27
G3D::int16 y
Definition: Vector2int16.h:38
Definition: MapDefines.h:10
std::string StringFormat(Format &&fmt, Args &&...args)
Default TC string format function.
Definition: StringFormat.h:28
#define ASSERT
Definition: Errors.h:55
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
const uint32 MMAP_MAGIC
Definition: MapDefines.h:7
G3D::int16 x
Definition: Vector2int16.h:37
#define MMAP_VERSION
Definition: MapDefines.h:8

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

uint32 MMAP::MMapManager::packTileID ( int32  x,
int32  y 
)
private
120  {
121  return uint32(x << 16 | y);
122  }
G3D::int16 y
Definition: Vector2int16.h:38
uint32_t uint32
Definition: g3dmath.h:168
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the caller graph for this function:

bool MMAP::MMapManager::unloadMap ( uint32  mapId,
int32  x,
int32  y 
)
290  {
291  // check if we have this map loaded
292  MMapDataSet::const_iterator itr = GetMMapData(mapId);
293  if (itr == loadedMMaps.end())
294  {
295  // file may not exist, therefore not loaded
296  TC_LOG_DEBUG("maps", "MMAP:unloadMap: Asked to unload not loaded navmesh map. %04u%02i%02i.mmtile", mapId, x, y);
297  return false;
298  }
299 
300  MMapData* mmap = itr->second;
301 
302  // check if we have this tile loaded
303  uint32 packedGridPos = packTileID(x, y);
304  if (mmap->loadedTileRefs.find(packedGridPos) == mmap->loadedTileRefs.end())
305  {
306  // file may not exist, therefore not loaded
307  TC_LOG_DEBUG("maps", "MMAP:unloadMap: Asked to unload not loaded navmesh tile. %04u%02i%02i.mmtile", mapId, x, y);
308  return false;
309  }
310 
311  dtTileRef tileRef = mmap->loadedTileRefs[packedGridPos];
312 
313  // unload, and mark as non loaded
314  if (dtStatusFailed(mmap->navMesh->removeTile(tileRef, NULL, NULL)))
315  {
316  // this is technically a memory leak
317  // if the grid is later reloaded, dtNavMesh::addTile will return error but no extra memory is used
318  // we cannot recover from this error - assert out
319  TC_LOG_ERROR("maps", "MMAP:unloadMap: Could not unload %04u%02i%02i.mmtile from navmesh", mapId, x, y);
320  ABORT();
321  }
322  else
323  {
324  mmap->loadedTileRefs.erase(packedGridPos);
325  --loadedTiles;
326  TC_LOG_DEBUG("maps", "MMAP:unloadMap: Unloaded mmtile %03i[%02i, %02i] from %04i", mapId, x, y, mapId);
327 
328  PhaseChildMapContainer::const_iterator phasedMaps = phaseMapData.find(mapId);
329  if (phasedMaps != phaseMapData.end())
330  UnloadPhaseTile(phasedMaps, x, y);
331  return true;
332  }
333 
334  return false;
335  }
uint64_d dtTileRef
Definition: DetourNavMesh.h:53
uint32 packTileID(int32 x, int32 y)
Definition: MMapManager.cpp:119
arena_t NULL
Definition: jemalloc_internal.h:624
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
PhaseChildMapContainer phaseMapData
Definition: MMapManager.h:129
void UnloadPhaseTile(PhaseChildMapContainer::const_iterator phasedMapData, int32 x, int32 y)
Definition: MMapManager.cpp:266
MMapDataSet::const_iterator GetMMapData(uint32 mapId) const
Definition: MMapManager.cpp:56
uint32 loadedTiles
Definition: MMapManager.h:130
uint32_t uint32
Definition: Define.h:150
G3D::int16 y
Definition: Vector2int16.h:38
bool dtStatusFailed(dtStatus status)
Definition: DetourStatus.h:47
MMapDataSet loadedMMaps
Definition: MMapManager.h:128
#define ABORT
Definition: Errors.h:56
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool MMAP::MMapManager::unloadMap ( uint32  mapId)
338  {
339  MMapDataSet::iterator itr = loadedMMaps.find(mapId);
340  if (itr == loadedMMaps.end() || !itr->second)
341  {
342  // file may not exist, therefore not loaded
343  TC_LOG_DEBUG("maps", "MMAP:unloadMap: Asked to unload not loaded navmesh map %04u", mapId);
344  return false;
345  }
346 
347  // unload all tiles from given map
348  MMapData* mmap = itr->second;
349  for (MMapTileSet::iterator i = mmap->loadedTileRefs.begin(); i != mmap->loadedTileRefs.end(); ++i)
350  {
351  uint32 x = (i->first >> 16);
352  uint32 y = (i->first & 0x0000FFFF);
353  if (dtStatusFailed(mmap->navMesh->removeTile(i->second, NULL, NULL)))
354  TC_LOG_ERROR("maps", "MMAP:unloadMap: Could not unload %04u%02i%02i.mmtile from navmesh", mapId, x, y);
355  else
356  {
357  PhaseChildMapContainer::const_iterator phasedMaps = phaseMapData.find(mapId);
358  if (phasedMaps != phaseMapData.end())
359  UnloadPhaseTile(phasedMaps, x, y);
360  --loadedTiles;
361  TC_LOG_DEBUG("maps", "MMAP:unloadMap: Unloaded mmtile %04i[%02i, %02i] from %04i", mapId, x, y, mapId);
362  }
363  }
364 
365  delete mmap;
366  itr->second = nullptr;
367  TC_LOG_DEBUG("maps", "MMAP:unloadMap: Unloaded %04i.mmap", mapId);
368 
369  return true;
370  }
arena_t NULL
Definition: jemalloc_internal.h:624
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
PhaseChildMapContainer phaseMapData
Definition: MMapManager.h:129
void UnloadPhaseTile(PhaseChildMapContainer::const_iterator phasedMapData, int32 x, int32 y)
Definition: MMapManager.cpp:266
uint32 loadedTiles
Definition: MMapManager.h:130
uint32_t uint32
Definition: Define.h:150
G3D::int16 y
Definition: Vector2int16.h:38
bool dtStatusFailed(dtStatus status)
Definition: DetourStatus.h:47
MMapDataSet loadedMMaps
Definition: MMapManager.h:128
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the call graph for this function:

bool MMAP::MMapManager::unloadMapInstance ( uint32  mapId,
uint32  instanceId 
)
373  {
374  // check if we have this map loaded
375  MMapDataSet::const_iterator itr = GetMMapData(mapId);
376  if (itr == loadedMMaps.end())
377  {
378  // file may not exist, therefore not loaded
379  TC_LOG_DEBUG("maps", "MMAP:unloadMapInstance: Asked to unload not loaded navmesh map %04u", mapId);
380  return false;
381  }
382 
383  MMapData* mmap = itr->second;
384  if (mmap->navMeshQueries.find(instanceId) == mmap->navMeshQueries.end())
385  {
386  TC_LOG_DEBUG("maps", "MMAP:unloadMapInstance: Asked to unload not loaded dtNavMeshQuery mapId %04u instanceId %u", mapId, instanceId);
387  return false;
388  }
389 
390  dtNavMeshQuery* query = mmap->navMeshQueries[instanceId];
391 
392  dtFreeNavMeshQuery(query);
393  mmap->navMeshQueries.erase(instanceId);
394  TC_LOG_DEBUG("maps", "MMAP:unloadMapInstance: Unloaded mapId %04u instanceId %u", mapId, instanceId);
395 
396  return true;
397  }
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
char * query(struct soap *soap)
Definition: httpget.cpp:244
MMapDataSet::const_iterator GetMMapData(uint32 mapId) const
Definition: MMapManager.cpp:56
MMapDataSet loadedMMaps
Definition: MMapManager.h:128
void dtFreeNavMeshQuery(dtNavMeshQuery *query)
Definition: DetourNavMeshQuery.cpp:114
Definition: DetourNavMeshQuery.h:153

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void MMAP::MMapManager::UnloadPhaseTile ( PhaseChildMapContainer::const_iterator  phasedMapData,
int32  x,
int32  y 
)
267  {
268  TC_LOG_DEBUG("phase", "MMAP:UnloadPhaseTile: Unloading phased mmtile for map %u, x: %i, y: %i", phasedMapData->first, x, y);
269 
270  uint32 packedGridPos = packTileID(x, y);
271 
272  for (uint32 phaseMapId : phasedMapData->second)
273  {
274  auto phasedTileItr = _phaseTiles.find(phaseMapId);
275  if (phasedTileItr == _phaseTiles.end())
276  continue;
277 
278  auto dataItr = phasedTileItr->second.find(packedGridPos);
279  if (dataItr != phasedTileItr->second.end())
280  {
281  TC_LOG_DEBUG("phase", "MMAP:UnloadPhaseTile: Unloaded phased %04u%02i%02i.mmtile for root phase map %u", phaseMapId, x, y, phasedMapData->first);
282  delete dataItr->second->data;
283  delete dataItr->second;
284  phasedTileItr->second.erase(dataItr);
285  }
286  }
287  }
PhaseTileMap _phaseTiles
Definition: MMapManager.h:134
uint32 packTileID(int32 x, int32 y)
Definition: MMapManager.cpp:119
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
uint32_t uint32
Definition: Define.h:150
G3D::int16 y
Definition: Vector2int16.h:38
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

PhaseTileMap MMAP::MMapManager::_phaseTiles
private
MMapDataSet MMAP::MMapManager::loadedMMaps
private
uint32 MMAP::MMapManager::loadedTiles
private
PhaseChildMapContainer MMAP::MMapManager::phaseMapData
private
bool MMAP::MMapManager::thread_safe_environment
private

The documentation for this class was generated from the following files: