AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
VMAP::VMapMgr2 Class Reference

#include "VMapMgr2.h"

Inheritance diagram for VMAP::VMapMgr2:
VMAP::IVMapMgr

Public Types

typedef uint32(* GetLiquidFlagsFn) (uint32 liquidType)
 
typedef bool(* IsVMAPDisabledForFn) (uint32 entry, uint8 flags)
 

Public Member Functions

G3D::Vector3 convertPositionToInternalRep (float x, float y, float z) const
 
 VMapMgr2 ()
 
 ~VMapMgr2 () override
 
void InitializeThreadUnsafe (const std::vector< uint32 > &mapIds)
 
int loadMap (const char *pBasePath, unsigned int mapId, int x, int y) override
 
void unloadMap (unsigned int mapId, int x, int y) override
 
void unloadMap (unsigned int mapId) override
 
bool isInLineOfSight (unsigned int mapId, float x1, float y1, float z1, float x2, float y2, float z2, ModelIgnoreFlags ignoreFlags) override
 
bool GetObjectHitPos (unsigned int mapId, float x1, float y1, float z1, float x2, float y2, float z2, float &rx, float &ry, float &rz, float modifyDist) override
 
float getHeight (unsigned int mapId, float x, float y, float z, float maxSearchDist) override
 
bool processCommand (char *) override
 
bool GetAreaAndLiquidData (uint32 mapId, float x, float y, float z, Optional< uint8 > reqLiquidType, AreaAndLiquidData &data) const override
 
WorldModelacquireModelInstance (const std::string &basepath, const std::string &filename, uint32 flags)
 
void releaseModelInstance (const std::string &filename)
 
std::string getDirFileName (unsigned int mapId, int, int) const override
 
LoadResult existsMap (const char *basePath, unsigned int mapId, int x, int y) override
 
void GetInstanceMapTree (InstanceTreeMap &instanceMapTree)
 
- Public Member Functions inherited from VMAP::IVMapMgr
 IVMapMgr ()
 
virtual ~IVMapMgr ()=default
 
void setEnableLineOfSightCalc (bool pVal)
 
void setEnableHeightCalc (bool pVal)
 
bool isLineOfSightCalcEnabled () const
 
bool isHeightCalcEnabled () const
 
bool isMapLoadingEnabled () const
 

Static Public Member Functions

static std::string getMapFileName (unsigned int mapId)
 

Public Attributes

GetLiquidFlagsFn GetLiquidFlagsPtr
 
IsVMAPDisabledForFn IsVMAPDisabledForPtr
 

Protected Member Functions

bool _loadMap (uint32 mapId, const std::string &basePath, uint32 tileX, uint32 tileY)
 
InstanceTreeMap::const_iterator GetMapTree (uint32 mapId) const
 

Static Protected Member Functions

static uint32 GetLiquidFlagsDummy (uint32)
 
static bool IsVMAPDisabledForDummy (uint32, uint8)
 

Protected Attributes

ModelFileMap iLoadedModelFiles
 
InstanceTreeMap iInstanceMapTrees
 
bool thread_safe_environment
 
std::mutex LoadedModelFilesLock
 

Detailed Description

Member Typedef Documentation

◆ GetLiquidFlagsFn

typedef uint32(* VMAP::VMapMgr2::GetLiquidFlagsFn) (uint32 liquidType)

◆ IsVMAPDisabledForFn

typedef bool(* VMAP::VMapMgr2::IsVMAPDisabledForFn) (uint32 entry, uint8 flags)

Constructor & Destructor Documentation

◆ VMapMgr2()

VMAP::VMapMgr2::VMapMgr2 ( )
35 {
39 }
static uint32 GetLiquidFlagsDummy(uint32)
Definition VMapMgr2.h:89
IsVMAPDisabledForFn IsVMAPDisabledForPtr
Definition VMapMgr2.h:135
static bool IsVMAPDisabledForDummy(uint32, uint8)
Definition VMapMgr2.h:90
bool thread_safe_environment
Definition VMapMgr2.h:81
GetLiquidFlagsFn GetLiquidFlagsPtr
Definition VMapMgr2.h:132

References GetLiquidFlagsDummy(), GetLiquidFlagsPtr, IsVMAPDisabledForDummy(), IsVMAPDisabledForPtr, and thread_safe_environment.

◆ ~VMapMgr2()

VMAP::VMapMgr2::~VMapMgr2 ( )
override
42 {
43 for (InstanceTreeMap::iterator i = iInstanceMapTrees.begin(); i != iInstanceMapTrees.end(); ++i)
44 {
45 delete i->second;
46 }
47
48 for (ModelFileMap::iterator i = iLoadedModelFiles.begin(); i != iLoadedModelFiles.end(); ++i)
49 {
50 delete i->second.getModel();
51 }
52 }
InstanceTreeMap iInstanceMapTrees
Definition VMapMgr2.h:80
ModelFileMap iLoadedModelFiles
Definition VMapMgr2.h:79

References iInstanceMapTrees, and iLoadedModelFiles.

Member Function Documentation

◆ _loadMap()

bool VMAP::VMapMgr2::_loadMap ( uint32  mapId,
const std::string &  basePath,
uint32  tileX,
uint32  tileY 
)
protected
118 {
119 InstanceTreeMap::iterator instanceTree = iInstanceMapTrees.find(mapId);
120 if (instanceTree == iInstanceMapTrees.end())
121 {
123 {
124 instanceTree = iInstanceMapTrees.insert(InstanceTreeMap::value_type(mapId, nullptr)).first;
125 }
126 else
127 ABORT("Invalid mapId {} tile [{}, {}] passed to VMapMgr2 after startup in thread unsafe environment",
128 mapId, tileX, tileY);
129 }
130
131 if (!instanceTree->second)
132 {
133 std::string mapFileName = getMapFileName(mapId);
134 StaticMapTree* newTree = new StaticMapTree(mapId, basePath);
135 if (!newTree->InitMap(mapFileName, this))
136 {
137 delete newTree;
138 return false;
139 }
140 instanceTree->second = newTree;
141 }
142
143 return instanceTree->second->LoadMapTile(tileX, tileY, this);
144 }
#define ABORT
Definition Errors.h:76
static std::string getMapFileName(unsigned int mapId)
Definition VMapMgr2.cpp:89

References ABORT, getMapFileName(), iInstanceMapTrees, VMAP::StaticMapTree::InitMap(), VMAP::StaticMapTree::LoadMapTile(), and thread_safe_environment.

Referenced by loadMap().

◆ acquireModelInstance()

WorldModel * VMAP::VMapMgr2::acquireModelInstance ( const std::string &  basepath,
const std::string &  filename,
uint32  flags 
)

Critical section, thread safe access to iLoadedModelFiles

285 {
287 std::lock_guard<std::mutex> lock(LoadedModelFilesLock);
288
289 ModelFileMap::iterator model = iLoadedModelFiles.find(filename);
290 if (model == iLoadedModelFiles.end())
291 {
292 WorldModel* worldmodel = new WorldModel();
293 if (!worldmodel->readFile(basepath + filename + ".vmo"))
294 {
295 LOG_ERROR("maps", "VMapMgr2: could not load '{}{}.vmo'", basepath, filename);
296 delete worldmodel;
297 return nullptr;
298 }
299 LOG_DEBUG("maps", "VMapMgr2: loading file '{}{}'", basepath, filename);
300
301 worldmodel->Flags = flags;
302
303 model = iLoadedModelFiles.insert(std::pair<std::string, ManagedModel>(filename, ManagedModel())).first;
304 model->second.setModel(worldmodel);
305 }
306
307 return model->second.getModel();
308 }
#define LOG_ERROR(filterType__,...)
Definition Log.h:158
#define LOG_DEBUG(filterType__,...)
Definition Log.h:170
std::mutex LoadedModelFilesLock
Definition VMapMgr2.h:84

References VMAP::WorldModel::Flags, iLoadedModelFiles, LoadedModelFilesLock, LOG_DEBUG, LOG_ERROR, and VMAP::WorldModel::readFile().

Referenced by GameObjectModel::initialize(), VMAP::StaticMapTree::InitMap(), and VMAP::StaticMapTree::LoadMapTile().

◆ convertPositionToInternalRep()

Vector3 VMAP::VMapMgr2::convertPositionToInternalRep ( float  x,
float  y,
float  z 
) const
66 {
67 Vector3 pos;
68 const float mid = 0.5f * MAX_NUMBER_OF_GRIDS * SIZE_OF_GRIDS;
69 pos.x = mid - x;
70 pos.y = mid - y;
71 pos.z = z;
72
73 return pos;
74 }
#define SIZE_OF_GRIDS
Definition MapDefines.h:26
#define MAX_NUMBER_OF_GRIDS
Definition MapDefines.h:24

References MAX_NUMBER_OF_GRIDS, and SIZE_OF_GRIDS.

Referenced by GetAreaAndLiquidData(), getHeight(), GetObjectHitPos(), and isInLineOfSight().

◆ existsMap()

LoadResult VMAP::VMapMgr2::existsMap ( const char *  basePath,
unsigned int  mapId,
int  x,
int  y 
)
overridevirtual

Implements VMAP::IVMapMgr.

330 {
331 return StaticMapTree::CanLoadMap(std::string(basePath), mapId, x, y);
332 }
static LoadResult CanLoadMap(const std::string &basePath, uint32 mapID, uint32 tileX, uint32 tileY)
Definition MapTree.cpp:215

References VMAP::StaticMapTree::CanLoadMap().

◆ GetAreaAndLiquidData()

bool VMAP::VMapMgr2::GetAreaAndLiquidData ( uint32  mapId,
float  x,
float  y,
float  z,
Optional< uint8 reqLiquidType,
AreaAndLiquidData data 
) const
overridevirtual

Query world model area info.

Parameters
zgets adjusted to the ground height for which this are info is valid

Implements VMAP::IVMapMgr.

257 {
258 InstanceTreeMap::const_iterator instanceTree = GetMapTree(mapId);
259 if (instanceTree != iInstanceMapTrees.end())
260 {
261 LocationInfo info;
262 Vector3 pos = convertPositionToInternalRep(x, y, z);
263 if (instanceTree->second->GetLocationInfo(pos, info))
264 {
265 data.floorZ = info.ground_Z;
267 {
268 uint32 liquidType = info.hitModel->GetLiquidType(); // entry from LiquidType.dbc
269 float liquidLevel;
270 if (!reqLiquidType || (GetLiquidFlagsPtr(liquidType) & *reqLiquidType))
271 if (info.hitInstance->GetLiquidLevel(pos, info, liquidLevel))
272 data.liquidInfo.emplace(liquidType, liquidLevel);
273 }
274
276 data.areaInfo.emplace(info.hitModel->GetWmoID(), info.hitInstance->adtId, info.rootId, info.hitModel->GetMogpFlags(), info.hitInstance->ID);
277 return true;
278 }
279 }
280
281 return false;
282 }
std::uint32_t uint32
Definition Define.h:107
G3D::Vector3 convertPositionToInternalRep(float x, float y, float z) const
Definition VMapMgr2.cpp:65
InstanceTreeMap::const_iterator GetMapTree(uint32 mapId) const
Definition VMapMgr2.cpp:76
@ VMAP_DISABLE_LIQUIDSTATUS
Definition VMapMgr2.h:72
@ VMAP_DISABLE_AREAFLAG
Definition VMapMgr2.h:69

References VMAP::ModelSpawn::adtId, VMAP::AreaAndLiquidData::areaInfo, convertPositionToInternalRep(), VMAP::AreaAndLiquidData::floorZ, GetLiquidFlagsPtr, VMAP::ModelInstance::GetLiquidLevel(), VMAP::GroupModel::GetLiquidType(), GetMapTree(), VMAP::GroupModel::GetMogpFlags(), VMAP::GroupModel::GetWmoID(), VMAP::LocationInfo::ground_Z, VMAP::LocationInfo::hitInstance, VMAP::LocationInfo::hitModel, VMAP::ModelSpawn::ID, iInstanceMapTrees, IsVMAPDisabledForPtr, VMAP::AreaAndLiquidData::liquidInfo, VMAP::LocationInfo::rootId, VMAP::VMAP_DISABLE_AREAFLAG, and VMAP::VMAP_DISABLE_LIQUIDSTATUS.

◆ getDirFileName()

std::string VMAP::VMapMgr2::getDirFileName ( unsigned int  mapId,
int  ,
int   
) const
inlineoverridevirtual

Implements VMAP::IVMapMgr.

125 {
126 return getMapFileName(mapId);
127 }

References getMapFileName().

◆ getHeight()

float VMAP::VMapMgr2::getHeight ( unsigned int  mapId,
float  x,
float  y,
float  z,
float  maxSearchDist 
)
overridevirtual

get height or INVALID_HEIGHT if no height available

Implements VMAP::IVMapMgr.

234 {
235#if defined(ENABLE_VMAP_CHECKS)
237#endif
238 {
239 InstanceTreeMap::const_iterator instanceTree = GetMapTree(mapId);
240 if (instanceTree != iInstanceMapTrees.end())
241 {
242 Vector3 pos = convertPositionToInternalRep(x, y, z);
243 float height = instanceTree->second->getHeight(pos, maxSearchDist);
244 if (height >= G3D::finf())
245 {
246 return height = VMAP_INVALID_HEIGHT_VALUE; // No height
247 }
248
249 return height;
250 }
251 }
252
254 }
#define VMAP_INVALID_HEIGHT_VALUE
Definition IVMapMgr.h:49
bool isHeightCalcEnabled() const
Definition IVMapMgr.h:122
@ VMAP_DISABLE_HEIGHT
Definition VMapMgr2.h:70

References convertPositionToInternalRep(), GetMapTree(), iInstanceMapTrees, VMAP::IVMapMgr::isHeightCalcEnabled(), IsVMAPDisabledForPtr, VMAP::VMAP_DISABLE_HEIGHT, and VMAP_INVALID_HEIGHT_VALUE.

◆ GetInstanceMapTree()

void VMAP::VMapMgr2::GetInstanceMapTree ( InstanceTreeMap instanceMapTree)
335 {
336 instanceMapTree = iInstanceMapTrees;
337 }

References iInstanceMapTrees.

◆ GetLiquidFlagsDummy()

static uint32 VMAP::VMapMgr2::GetLiquidFlagsDummy ( uint32  )
inlinestaticprotected
89{ return 0; }

Referenced by VMapMgr2().

◆ getMapFileName()

std::string VMAP::VMapMgr2::getMapFileName ( unsigned int  mapId)
static
90 {
91 std::stringstream fname;
92 fname.width(3);
93 fname << std::setfill('0') << mapId << std::string(MAP_FILENAME_EXTENSION2);
94
95 return fname.str();
96 }
#define MAP_FILENAME_EXTENSION2
Definition VMapMgr2.h:28

References MAP_FILENAME_EXTENSION2.

Referenced by _loadMap(), VMAP::StaticMapTree::CanLoadMap(), and getDirFileName().

◆ GetMapTree()

InstanceTreeMap::const_iterator VMAP::VMapMgr2::GetMapTree ( uint32  mapId) const
protected
77 {
78 // return the iterator if found or end() if not found/NULL
79 InstanceTreeMap::const_iterator itr = iInstanceMapTrees.find(mapId);
80 if (itr != iInstanceMapTrees.cend() && !itr->second)
81 {
82 itr = iInstanceMapTrees.cend();
83 }
84
85 return itr;
86 }

References iInstanceMapTrees.

Referenced by GetAreaAndLiquidData(), getHeight(), GetObjectHitPos(), and isInLineOfSight().

◆ GetObjectHitPos()

bool VMAP::VMapMgr2::GetObjectHitPos ( unsigned int  mapId,
float  x1,
float  y1,
float  z1,
float  x2,
float  y2,
float  z2,
float &  rx,
float &  ry,
float &  rz,
float  modifyDist 
)
overridevirtual

fill the hit pos and return true, if an object was hit

get the hit position and return true if we hit something otherwise the result pos will be the dest pos

Implements VMAP::IVMapMgr.

202 {
203#if defined(ENABLE_VMAP_CHECKS)
205#endif
206 {
207 InstanceTreeMap::const_iterator instanceTree = GetMapTree(mapId);
208 if (instanceTree != iInstanceMapTrees.end())
209 {
210 Vector3 pos1 = convertPositionToInternalRep(x1, y1, z1);
211 Vector3 pos2 = convertPositionToInternalRep(x2, y2, z2);
212 Vector3 resultPos;
213 bool result = instanceTree->second->GetObjectHitPos(pos1, pos2, resultPos, modifyDist);
214 resultPos = convertPositionToInternalRep(resultPos.x, resultPos.y, resultPos.z);
215 rx = resultPos.x;
216 ry = resultPos.y;
217 rz = resultPos.z;
218 return result;
219 }
220 }
221
222 rx = x2;
223 ry = y2;
224 rz = z2;
225
226 return false;
227 }
bool isLineOfSightCalcEnabled() const
Definition IVMapMgr.h:121
@ VMAP_DISABLE_LOS
Definition VMapMgr2.h:71

References convertPositionToInternalRep(), GetMapTree(), iInstanceMapTrees, VMAP::IVMapMgr::isLineOfSightCalcEnabled(), IsVMAPDisabledForPtr, and VMAP::VMAP_DISABLE_LOS.

Referenced by Map::CheckCollisionAndGetValidCoords(), and Spell::SelectImplicitCasterDestTargets().

◆ InitializeThreadUnsafe()

void VMAP::VMapMgr2::InitializeThreadUnsafe ( const std::vector< uint32 > &  mapIds)
55 {
56 // the caller must pass the list of all mapIds that will be used in the VMapMgr2 lifetime
57 for (const uint32& mapId : mapIds)
58 {
59 iInstanceMapTrees.emplace(mapId, nullptr);
60 }
61
63 }

References iInstanceMapTrees, and thread_safe_environment.

Referenced by World::SetInitialWorldSettings().

◆ isInLineOfSight()

bool VMAP::VMapMgr2::isInLineOfSight ( unsigned int  mapId,
float  x1,
float  y1,
float  z1,
float  x2,
float  y2,
float  z2,
ModelIgnoreFlags  ignoreFlags 
)
overridevirtual

Implements VMAP::IVMapMgr.

175 {
176#if defined(ENABLE_VMAP_CHECKS)
178 {
179 return true;
180 }
181#endif
182
183 InstanceTreeMap::const_iterator instanceTree = GetMapTree(mapId);
184 if (instanceTree != iInstanceMapTrees.end())
185 {
186 Vector3 pos1 = convertPositionToInternalRep(x1, y1, z1);
187 Vector3 pos2 = convertPositionToInternalRep(x2, y2, z2);
188 if (pos1 != pos2)
189 {
190 return instanceTree->second->isInLineOfSight(pos1, pos2, ignoreFlags);
191 }
192 }
193
194 return true;
195 }

References convertPositionToInternalRep(), GetMapTree(), iInstanceMapTrees, VMAP::IVMapMgr::isLineOfSightCalcEnabled(), IsVMAPDisabledForPtr, and VMAP::VMAP_DISABLE_LOS.

◆ IsVMAPDisabledForDummy()

static bool VMAP::VMapMgr2::IsVMAPDisabledForDummy ( uint32  ,
uint8   
)
inlinestaticprotected
90{ return false; }

Referenced by VMapMgr2().

◆ loadMap()

int VMAP::VMapMgr2::loadMap ( const char *  pBasePath,
unsigned int  mapId,
int  x,
int  y 
)
overridevirtual

Implements VMAP::IVMapMgr.

99 {
100 int result = VMAP_LOAD_RESULT_IGNORED;
102 {
103 if (_loadMap(mapId, basePath, x, y))
104 {
105 result = VMAP_LOAD_RESULT_OK;
106 }
107 else
108 {
109 result = VMAP_LOAD_RESULT_ERROR;
110 }
111 }
112
113 return result;
114 }
bool isMapLoadingEnabled() const
Definition IVMapMgr.h:123
bool _loadMap(uint32 mapId, const std::string &basePath, uint32 tileX, uint32 tileY)
Definition VMapMgr2.cpp:117
@ VMAP_LOAD_RESULT_ERROR
Definition IVMapMgr.h:36
@ VMAP_LOAD_RESULT_OK
Definition IVMapMgr.h:37
@ VMAP_LOAD_RESULT_IGNORED
Definition IVMapMgr.h:38

References _loadMap(), VMAP::IVMapMgr::isMapLoadingEnabled(), VMAP::VMAP_LOAD_RESULT_ERROR, VMAP::VMAP_LOAD_RESULT_IGNORED, and VMAP::VMAP_LOAD_RESULT_OK.

Referenced by GridTerrainLoader::LoadVMap().

◆ processCommand()

bool VMAP::VMapMgr2::processCommand ( char *  pCommand)
inlineoverridevirtual

send debug commands

Implements VMAP::IVMapMgr.

116{ return false; } // for debug and extensions

◆ releaseModelInstance()

void VMAP::VMapMgr2::releaseModelInstance ( const std::string &  filename)

Critical section, thread safe access to iLoadedModelFiles

311 {
313 std::lock_guard<std::mutex> lock(LoadedModelFilesLock);
314
315 ModelFileMap::iterator model = iLoadedModelFiles.find(filename);
316 if (model == iLoadedModelFiles.end())
317 {
318 LOG_ERROR("maps", "VMapMgr2: trying to unload non-loaded file '{}'", filename);
319 return;
320 }
321 if (model->second.decRefCount() == 0)
322 {
323 LOG_DEBUG("maps", "VMapMgr2: unloading file '{}'", filename);
324 delete model->second.getModel();
325 iLoadedModelFiles.erase(model);
326 }
327 }

References iLoadedModelFiles, LoadedModelFilesLock, LOG_DEBUG, and LOG_ERROR.

Referenced by VMAP::StaticMapTree::UnloadMap(), VMAP::StaticMapTree::UnloadMapTile(), and GameObjectModel::~GameObjectModel().

◆ unloadMap() [1/2]

void VMAP::VMapMgr2::unloadMap ( unsigned int  mapId)
overridevirtual

Implements VMAP::IVMapMgr.

147 {
148 InstanceTreeMap::iterator instanceTree = iInstanceMapTrees.find(mapId);
149 if (instanceTree != iInstanceMapTrees.end() && instanceTree->second)
150 {
151 instanceTree->second->UnloadMap(this);
152 if (instanceTree->second->numLoadedTiles() == 0)
153 {
154 delete instanceTree->second;
155 instanceTree->second = nullptr;
156 }
157 }
158 }

References iInstanceMapTrees.

◆ unloadMap() [2/2]

void VMAP::VMapMgr2::unloadMap ( unsigned int  mapId,
int  x,
int  y 
)
overridevirtual

Implements VMAP::IVMapMgr.

161 {
162 InstanceTreeMap::iterator instanceTree = iInstanceMapTrees.find(mapId);
163 if (instanceTree != iInstanceMapTrees.end() && instanceTree->second)
164 {
165 instanceTree->second->UnloadMapTile(x, y, this);
166 if (instanceTree->second->numLoadedTiles() == 0)
167 {
168 delete instanceTree->second;
169 instanceTree->second = nullptr;
170 }
171 }
172 }

References iInstanceMapTrees.

Referenced by GridTerrainUnloader::UnloadTerrain().

Member Data Documentation

◆ GetLiquidFlagsPtr

GetLiquidFlagsFn VMAP::VMapMgr2::GetLiquidFlagsPtr

◆ iInstanceMapTrees

◆ iLoadedModelFiles

ModelFileMap VMAP::VMapMgr2::iLoadedModelFiles
protected

◆ IsVMAPDisabledForPtr

◆ LoadedModelFilesLock

std::mutex VMAP::VMapMgr2::LoadedModelFilesLock
protected

◆ thread_safe_environment

bool VMAP::VMapMgr2::thread_safe_environment
protected

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