AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
MMAP::MMapMgr Class Reference

#include "MMapMgr.h"

Public Member Functions

 MMapMgr ()=default
 
 ~MMapMgr ()=default
 

Static Public Member Functions

static std::shared_ptr< dtNavMesh > LoadNavMesh (uint32 mapId)
 
static bool LoadTile (dtNavMesh *navMesh, uint32 mapId, int32 x, int32 y)
 
static ManagedNavMeshQuery CreateNavMeshQuery (dtNavMesh *navMesh)
 

Static Private Member Functions

static uint32 packTileID (int32 x, int32 y)
 

Detailed Description

Constructor & Destructor Documentation

◆ MMapMgr()

MMAP::MMapMgr::MMapMgr ( )
default

◆ ~MMapMgr()

MMAP::MMapMgr::~MMapMgr ( )
default

Member Function Documentation

◆ CreateNavMeshQuery()

ManagedNavMeshQuery MMAP::MMapMgr::CreateNavMeshQuery ( dtNavMesh *  navMesh)
static
125 {
126 // allocate mesh query
127 dtNavMeshQuery* query = dtAllocNavMeshQuery();
128 ASSERT(query);
129
130 if (dtStatusFailed(query->init(navMesh, 1024)))
131 {
132 dtFreeNavMeshQuery(query);
133 return nullptr;
134 }
135
136 ManagedNavMeshQuery navMeshQuery = ManagedNavMeshQuery(query);
137 return navMeshQuery;
138 }
#define ASSERT
Definition Errors.h:68
std::unique_ptr< dtNavMeshQuery, NavMeshQueryDeleter > ManagedNavMeshQuery
Definition MMapMgr.h:61

References ASSERT.

Referenced by MMapData::GetNavMeshQuery().

◆ LoadNavMesh()

std::shared_ptr< dtNavMesh > MMAP::MMapMgr::LoadNavMesh ( uint32  mapId)
static
28 {
29 // load and init dtNavMesh - read parameters from file
30 std::string fileName = Acore::StringFormat(MAP_FILE_NAME_FORMAT, sConfigMgr->GetOption<std::string>("DataDir", "."), mapId);
31
32 FILE* file = fopen(fileName.c_str(), "rb");
33 if (!file)
34 {
35 LOG_DEBUG("maps", "MMAP:loadMapData: Error: Could not open mmap file '{}'", fileName);
36 return nullptr;
37 }
38
39 dtNavMeshParams params;
40 uint32 count = uint32(fread(&params, sizeof(dtNavMeshParams), 1, file));
41 fclose(file);
42 if (count != 1)
43 {
44 LOG_DEBUG("maps", "MMAP:loadMapData: Error: Could not read params from file '{}'", fileName);
45 return nullptr;
46 }
47
48 dtNavMesh* mesh = dtAllocNavMesh();
49 ASSERT(mesh);
50 if (DT_SUCCESS != mesh->init(&params))
51 {
52 dtFreeNavMesh(mesh);
53 LOG_ERROR("maps", "MMAP:loadMapData: Failed to initialize dtNavMesh for mmap {:03} from file {}", mapId, fileName);
54 return nullptr;
55 }
56
57 LOG_DEBUG("maps", "MMAP:loadMapData: Loaded {:03}.mmap", mapId);
58
59 std::shared_ptr<dtNavMesh> navMesh = std::shared_ptr<dtNavMesh>(mesh, NavMeshDeleter());
60 return navMesh;
61 }
std::uint32_t uint32
Definition Define.h:107
#define LOG_ERROR(filterType__,...)
Definition Log.h:158
#define LOG_DEBUG(filterType__,...)
Definition Log.h:170
#define sConfigMgr
Definition Config.h:93
std::string StringFormat(FormatString< Args... > fmt, Args &&... args)
Default AC string format function.
Definition StringFormat.h:44
static char const *const MAP_FILE_NAME_FORMAT
Definition MMapMgr.h:48

References ASSERT, LOG_DEBUG, LOG_ERROR, MMAP::MAP_FILE_NAME_FORMAT, sConfigMgr, and Acore::StringFormat().

Referenced by MapCollisionData::MapCollisionData().

◆ LoadTile()

bool MMAP::MMapMgr::LoadTile ( dtNavMesh *  navMesh,
uint32  mapId,
int32  x,
int32  y 
)
static
69 {
70 // load this tile :: mmaps/MMMXXYY.mmtile
71 std::string fileName = Acore::StringFormat(TILE_FILE_NAME_FORMAT, sConfigMgr->GetOption<std::string>("DataDir", "."), mapId, x, y);
72 FILE* file = fopen(fileName.c_str(), "rb");
73 if (!file)
74 {
75 LOG_DEBUG("maps", "MMAP:loadMap: Could not open mmtile file '{}'", fileName);
76 return false;
77 }
78
79 // read header
80 MmapTileHeader fileHeader;
81 if (fread(&fileHeader, sizeof(MmapTileHeader), 1, file) != 1 || fileHeader.mmapMagic != MMAP_MAGIC)
82 {
83 LOG_ERROR("maps", "MMAP:loadMap: Bad header in mmap {:03}{:02}{:02}.mmtile", mapId, x, y);
84 fclose(file);
85 return false;
86 }
87
88 if (fileHeader.mmapVersion != MMAP_VERSION)
89 {
90 LOG_ERROR("maps", "MMAP:loadMap: {:03}{:02}{:02}.mmtile was built with generator v{}, expected v{}",
91 mapId, x, y, fileHeader.mmapVersion, MMAP_VERSION);
92 fclose(file);
93 return false;
94 }
95
96 unsigned char* data = (unsigned char*)dtAlloc(fileHeader.size, DT_ALLOC_PERM);
97 ASSERT(data);
98
99 std::size_t result = fread(data, fileHeader.size, 1, file);
100 if (!result)
101 {
102 LOG_ERROR("maps", "MMAP:loadMap: Bad header or data in mmap {:03}{:02}{:02}.mmtile", mapId, x, y);
103 fclose(file);
104 return false;
105 }
106
107 fclose(file);
108
109 dtTileRef tileRef = 0;
110
111 // memory allocated for data is now managed by detour, and will be deallocated when the tile is removed
112 if (dtStatusSucceed(navMesh->addTile(data, fileHeader.size, DT_TILE_FREE_DATA, 0, &tileRef)))
113 {
114 dtMeshHeader* header = (dtMeshHeader*)data;
115 LOG_DEBUG("maps", "MMAP:loadMap: Loaded mmtile {:03}[{:02},{:02}] into {:03}[{:02},{:02}]", mapId, x, y, mapId, header->x, header->y);
116 return true;
117 }
118
119 LOG_ERROR("maps", "MMAP:loadMap: Could not load {:03}{:02}{:02}.mmtile into navmesh", mapId, x, y);
120 dtFree(data);
121 return false;
122 }
#define MMAP_VERSION
Definition MapDefines.h:29
#define MMAP_MAGIC
Definition MapDefines.h:28
static char const *const TILE_FILE_NAME_FORMAT
Definition MMapMgr.h:49
Definition MapDefines.h:65
uint32 mmapVersion
Definition MapDefines.h:68
uint32 size
Definition MapDefines.h:69
uint32 mmapMagic
Definition MapDefines.h:66

References ASSERT, LOG_DEBUG, LOG_ERROR, MMAP_MAGIC, MMAP_VERSION, MmapTileHeader::mmapMagic, MmapTileHeader::mmapVersion, sConfigMgr, MmapTileHeader::size, Acore::StringFormat(), and MMAP::TILE_FILE_NAME_FORMAT.

Referenced by MapCollisionData::LoadMMapTile().

◆ packTileID()

uint32 MMAP::MMapMgr::packTileID ( int32  x,
int32  y 
)
staticprivate
64 {
65 return uint32(x << 16 | y);
66 }

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