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

#include <MMapManager.h>

Public Member Functions

 MMapData (dtNavMesh *mesh, uint32 mapId)
 
 ~MMapData ()
 
dtNavMeshGetNavMesh (TerrainSet swaps)
 

Public Attributes

NavMeshQuerySet navMeshQueries
 
dtNavMeshnavMesh
 
MMapTileSet loadedTileRefs
 
TerrainSetMap loadedPhasedTiles
 

Private Member Functions

void RemoveSwap (PhasedTile *ptile, uint32 swap, uint32 packedXY)
 
void AddSwap (PhasedTile *tile, uint32 swap, uint32 packedXY)
 

Private Attributes

uint32 _mapId
 
PhaseTileContainer _baseTiles
 
std::set< uint32_activeSwaps
 

Constructor & Destructor Documentation

MMAP::MMapData::MMapData ( dtNavMesh mesh,
uint32  mapId 
)
435  {
436  navMesh = mesh;
437  _mapId = mapId;
438  }
uint32 _mapId
Definition: MMapManager.h:81
dtNavMesh * navMesh
Definition: MMapManager.h:76
MMAP::MMapData::~MMapData ( )
441  {
442  for (NavMeshQuerySet::iterator i = navMeshQueries.begin(); i != navMeshQueries.end(); ++i)
443  dtFreeNavMeshQuery(i->second);
444 
446 
447  for (PhaseTileContainer::iterator i = _baseTiles.begin(); i != _baseTiles.end(); ++i)
448  {
449  delete (*i).second->data;
450  delete (*i).second;
451  }
452  }
void dtFreeNavMesh(dtNavMesh *navmesh)
Definition: DetourNavMesh.cpp:149
dtNavMesh * navMesh
Definition: MMapManager.h:76
PhaseTileContainer _baseTiles
Definition: MMapManager.h:82
NavMeshQuerySet navMeshQueries
Definition: MMapManager.h:74
void dtFreeNavMeshQuery(dtNavMeshQuery *query)
Definition: DetourNavMeshQuery.cpp:114

+ Here is the call graph for this function:

Member Function Documentation

void MMAP::MMapData::AddSwap ( PhasedTile tile,
uint32  swap,
uint32  packedXY 
)
private
492  {
493 
494  uint32 x = (packedXY >> 16);
495  uint32 y = (packedXY & 0x0000FFFF);
496 
497  if (loadedTileRefs.find(packedXY) == loadedTileRefs.end())
498  {
499  TC_LOG_DEBUG("phase", "MMapData::AddSwap: phased mmtile %04u[%02i, %02i] load skipped, due to not loaded base tile on map %u", swap, x, y, _mapId);
500  return;
501  }
502  if (loadedPhasedTiles[swap].find(packedXY) != loadedPhasedTiles[swap].end())
503  {
504  TC_LOG_DEBUG("phase", "MMapData::AddSwap: WARNING! phased mmtile %04u[%02i, %02i] load skipped, due to already loaded on map %u", swap, x, y, _mapId);
505  return;
506  }
507 
508 
509  dtMeshHeader* header = (dtMeshHeader*)ptile->data;
510 
511  const dtMeshTile* oldTile = navMesh->getTileByRef(loadedTileRefs[packedXY]);
512 
513  if (!oldTile)
514  {
515  TC_LOG_DEBUG("phase", "MMapData::AddSwap: phased mmtile %04u[%02i, %02i] load skipped, due to not loaded base tile ref on map %u", swap, x, y, _mapId);
516  return;
517  }
518 
519  // header xy is based on the swap map's tile set, wich doesn't have all the same tiles as root map, so copy the xy from the orignal header
520  header->x = oldTile->header->x;
521  header->y = oldTile->header->y;
522 
523  // the removed tile's data
524  PhasedTile* pt = new PhasedTile();
525  // remove old tile
526  if (dtStatusFailed(navMesh->removeTile(loadedTileRefs[packedXY], &pt->data, &pt->dataSize)))
527  {
528  TC_LOG_ERROR("phase", "MMapData::AddSwap: Could not unload %04u%02i%02i.mmtile from navmesh", _mapId, x, y);
529  delete pt;
530  }
531  else
532  {
533  TC_LOG_DEBUG("phase", "MMapData::AddSwap: Unloaded %04u%02i%02i.mmtile from navmesh", _mapId, x, y);
534 
535  // store the removed data first time, this is the origonal, non-phased tile
536  if (_baseTiles.find(packedXY) == _baseTiles.end())
537  _baseTiles[packedXY] = pt;
538 
539  _activeSwaps.insert(swap);
540  loadedPhasedTiles[swap].insert(packedXY);
541 
542  // add new swapped tile
543  if (dtStatusSucceed(navMesh->addTile(ptile->data, ptile->fileHeader.size, 0, 0, &loadedTileRefs[packedXY])))
544  {
545  TC_LOG_DEBUG("phase", "MMapData::AddSwap: Loaded phased mmtile %04u[%02i, %02i] into %04i[%02i, %02i]", swap, x, y, _mapId, header->x, header->y);
546  }
547  else
548  TC_LOG_ERROR("phase", "MMapData::AddSwap: Could not load %04u%02i%02i.mmtile to navmesh", swap, x, y);
549  }
550  }
std::set< uint32 > _activeSwaps
Definition: MMapManager.h:83
uint32 _mapId
Definition: MMapManager.h:81
dtStatus addTile(unsigned char *data, int dataSize, int flags, dtTileRef lastRef, dtTileRef *result)
Definition: DetourNavMesh.cpp:834
const dtMeshTile * getTileByRef(dtTileRef ref) const
Definition: DetourNavMesh.cpp:1078
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
dtNavMesh * navMesh
Definition: MMapManager.h:76
MMapTileSet loadedTileRefs
Definition: MMapManager.h:77
Definition: DetourNavMesh.h:247
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
bool dtStatusFailed(dtStatus status)
Definition: DetourStatus.h:47
TerrainSetMap loadedPhasedTiles
Definition: MMapManager.h:78
PhaseTileContainer _baseTiles
Definition: MMapManager.h:82
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
G3D::int16 x
Definition: Vector2int16.h:37
Definition: DetourNavMesh.h:279
int y
The y-position of the tile within the dtNavMesh tile grid. (x, y, layer)
Definition: DetourNavMesh.h:252
dtStatus removeTile(dtTileRef ref, unsigned char **data, int *dataSize)
Definition: DetourNavMesh.cpp:1156

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

dtNavMesh * MMAP::MMapData::GetNavMesh ( TerrainSet  swaps)
553  {
554  std::set<uint32> activeSwaps = _activeSwaps; // _activeSwaps is modified inside RemoveSwap
555  for (uint32 swap : activeSwaps)
556  {
557  if (!swaps.count(swap)) // swap not active
558  {
560  for (PhaseTileContainer::const_iterator itr = ptc->begin(); itr != ptc->end(); ++itr)
561  RemoveSwap(itr->second, swap, itr->first); // remove swap
562  }
563  }
564 
565  // for each of the calling unit's terrain swaps
566  for (uint32 swap : swaps)
567  {
568  if (!_activeSwaps.count(swap)) // swap not active
569  {
570  // for each of the terrain swap's xy tiles
572  for (PhaseTileContainer::const_iterator itr = ptc->begin(); itr != ptc->end(); ++itr)
573  AddSwap(itr->second, swap, itr->first); // add swap
574  }
575  }
576 
577  return navMesh;
578  }
std::set< uint32 > _activeSwaps
Definition: MMapManager.h:83
dtNavMesh * navMesh
Definition: MMapManager.h:76
void RemoveSwap(PhasedTile *ptile, uint32 swap, uint32 packedXY)
Definition: MMapManager.cpp:454
std::unordered_map< uint32, PhasedTile * > PhaseTileContainer
Definition: MMapManager.h:59
uint32_t uint32
Definition: Define.h:150
void AddSwap(PhasedTile *tile, uint32 swap, uint32 packedXY)
Definition: MMapManager.cpp:491
static MMapManager * createOrGetMMapManager()
Definition: MMapFactory.cpp:28
PhaseTileContainer const * GetPhaseTileContainer(uint32 mapId) const
Definition: MMapManager.h:115

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void MMAP::MMapData::RemoveSwap ( PhasedTile ptile,
uint32  swap,
uint32  packedXY 
)
private
455  {
456  uint32 x = (packedXY >> 16);
457  uint32 y = (packedXY & 0x0000FFFF);
458 
459  if (loadedPhasedTiles[swap].find(packedXY) == loadedPhasedTiles[swap].end())
460  {
461  TC_LOG_DEBUG("phase", "MMapData::RemoveSwap: mmtile %04u[%02i, %02i] unload skipped, due to not loaded", swap, x, y);
462  return;
463  }
464  dtMeshHeader* header = (dtMeshHeader*)ptile->data;
465 
466  // remove old tile
468  TC_LOG_ERROR("phase", "MMapData::RemoveSwap: Could not unload phased %04u%02i%02i.mmtile from navmesh", swap, x, y);
469  else
470  {
471  TC_LOG_DEBUG("phase", "MMapData::RemoveSwap: Unloaded phased %04u%02i%02i.mmtile from navmesh", swap, x, y);
472 
473  // restore base tile
474  if (dtStatusSucceed(navMesh->addTile(_baseTiles[packedXY]->data, _baseTiles[packedXY]->dataSize, 0, 0, &loadedTileRefs[packedXY])))
475  {
476  TC_LOG_DEBUG("phase", "MMapData::RemoveSwap: Loaded base mmtile %04u[%02i, %02i] into %04i[%02i, %02i]", _mapId, x, y, _mapId, header->x, header->y);
477  }
478  else
479  TC_LOG_ERROR("phase", "MMapData::RemoveSwap: Could not load base %04u%02i%02i.mmtile to navmesh", _mapId, x, y);
480  }
481 
482  loadedPhasedTiles[swap].erase(packedXY);
483 
484  if (loadedPhasedTiles[swap].empty())
485  {
486  _activeSwaps.erase(swap);
487  TC_LOG_DEBUG("phase", "MMapData::RemoveSwap: Fully removed swap %u from map %u", swap, _mapId);
488  }
489  }
std::set< uint32 > _activeSwaps
Definition: MMapManager.h:83
uint32 _mapId
Definition: MMapManager.h:81
arena_t NULL
Definition: jemalloc_internal.h:624
dtStatus addTile(unsigned char *data, int dataSize, int flags, dtTileRef lastRef, dtTileRef *result)
Definition: DetourNavMesh.cpp:834
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
dtNavMesh * navMesh
Definition: MMapManager.h:76
MMapTileSet loadedTileRefs
Definition: MMapManager.h:77
Definition: DetourNavMesh.h:247
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
bool dtStatusFailed(dtStatus status)
Definition: DetourStatus.h:47
TerrainSetMap loadedPhasedTiles
Definition: MMapManager.h:78
PhaseTileContainer _baseTiles
Definition: MMapManager.h:82
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
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
dtStatus removeTile(dtTileRef ref, unsigned char **data, int *dataSize)
Definition: DetourNavMesh.cpp:1156

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

std::set<uint32> MMAP::MMapData::_activeSwaps
private
PhaseTileContainer MMAP::MMapData::_baseTiles
private
uint32 MMAP::MMapData::_mapId
private
TerrainSetMap MMAP::MMapData::loadedPhasedTiles
MMapTileSet MMAP::MMapData::loadedTileRefs
dtNavMesh* MMAP::MMapData::navMesh
NavMeshQuerySet MMAP::MMapData::navMeshQueries

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