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

#include <VMapManager2.h>

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
 
 VMapManager2 ()
 
 ~VMapManager2 (void)
 
void InitializeThreadUnsafe (std::unordered_map< uint32, std::vector< uint32 >> const &mapData)
 
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) 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 getAreaInfo (unsigned int pMapId, float x, float y, float &z, uint32 &flags, int32 &adtId, int32 &rootId, int32 &groupId) const override
 
bool GetLiquidLevel (uint32 pMapId, float x, float y, float z, uint8 reqLiquidType, float &level, float &floor, uint32 &type) const override
 
WorldModelacquireModelInstance (const std::string &basepath, const std::string &filename)
 
void releaseModelInstance (const std::string &filename)
 
virtual std::string getDirFileName (unsigned int mapId, int, int) const override
 
virtual bool existsMap (const char *basePath, unsigned int mapId, int x, int y) override
 
void getInstanceMapTree (InstanceTreeMap &instanceMapTree)
 
- Public Member Functions inherited from VMAP::IVMapManager
 IVMapManager ()
 
virtual ~IVMapManager (void)
 
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
 

Member Typedef Documentation

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

Constructor & Destructor Documentation

VMAP::VMapManager2::VMapManager2 ( )
37  {
41  }
bool thread_safe_environment
Definition: VMapManager2.h:84
static uint32 GetLiquidFlagsDummy(uint32)
Definition: VMapManager2.h:91
GetLiquidFlagsFn GetLiquidFlagsPtr
Definition: VMapManager2.h:135
static bool IsVMAPDisabledForDummy(uint32, uint8)
Definition: VMapManager2.h:92
IsVMAPDisabledForFn IsVMAPDisabledForPtr
Definition: VMapManager2.h:138

+ Here is the call graph for this function:

VMAP::VMapManager2::~VMapManager2 ( void  )
44  {
45  for (InstanceTreeMap::iterator i = iInstanceMapTrees.begin(); i != iInstanceMapTrees.end(); ++i)
46  {
47  delete i->second;
48  }
49  for (ModelFileMap::iterator i = iLoadedModelFiles.begin(); i != iLoadedModelFiles.end(); ++i)
50  {
51  delete i->second.getModel();
52  }
53  }
ModelFileMap iLoadedModelFiles
Definition: VMapManager2.h:82
InstanceTreeMap iInstanceMapTrees
Definition: VMapManager2.h:83

Member Function Documentation

bool VMAP::VMapManager2::_loadMap ( uint32  mapId,
const std::string &  basePath,
uint32  tileX,
uint32  tileY 
)
protected
111  {
112  InstanceTreeMap::iterator instanceTree = iInstanceMapTrees.find(mapId);
113  if (instanceTree == iInstanceMapTrees.end())
114  {
116  instanceTree = iInstanceMapTrees.insert(InstanceTreeMap::value_type(mapId, nullptr)).first;
117  else
118  ASSERT(false, "Invalid mapId %u tile [%u, %u] passed to VMapManager2 after startup in thread unsafe environment",
119  mapId, tileX, tileY);
120  }
121 
122  if (!instanceTree->second)
123  {
124  std::string mapFileName = getMapFileName(mapId);
125  StaticMapTree* newTree = new StaticMapTree(mapId, basePath);
126  if (!newTree->InitMap(mapFileName, this))
127  {
128  delete newTree;
129  return false;
130  }
131  instanceTree->second = newTree;
132  }
133 
134  return instanceTree->second->LoadMapTile(tileX, tileY, this);
135  }
static std::string getMapFileName(unsigned int mapId)
Definition: VMapManager2.cpp:76
bool thread_safe_environment
Definition: VMapManager2.h:84
#define ASSERT
Definition: Errors.h:55
InstanceTreeMap iInstanceMapTrees
Definition: VMapManager2.h:83

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

WorldModel * VMAP::VMapManager2::acquireModelInstance ( const std::string &  basepath,
const std::string &  filename 
)

Critical section, thread safe access to iLoadedModelFiles

283  {
285  std::lock_guard<std::mutex> lock(LoadedModelFilesLock);
286 
287  ModelFileMap::iterator model = iLoadedModelFiles.find(filename);
288  if (model == iLoadedModelFiles.end())
289  {
290  WorldModel* worldmodel = new WorldModel();
291  if (!worldmodel->readFile(basepath + filename + ".vmo"))
292  {
293  VMAP_ERROR_LOG("misc", "VMapManager2: could not load '%s%s.vmo'", basepath.c_str(), filename.c_str());
294  delete worldmodel;
295  return NULL;
296  }
297  VMAP_DEBUG_LOG("maps", "VMapManager2: loading file '%s%s'", basepath.c_str(), filename.c_str());
298  model = iLoadedModelFiles.insert(std::pair<std::string, ManagedModel>(filename, ManagedModel())).first;
299  model->second.setModel(worldmodel);
300  }
301  model->second.incRefCount();
302  return model->second.getModel();
303  }
arena_t NULL
Definition: jemalloc_internal.h:624
std::mutex LoadedModelFilesLock
Definition: VMapManager2.h:86
ModelFileMap iLoadedModelFiles
Definition: VMapManager2.h:82
#define VMAP_DEBUG_LOG(FILTER,...)
Definition: VMapDefinitions.h:39
#define VMAP_ERROR_LOG(FILTER,...)
Definition: VMapDefinitions.h:38

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Vector3 VMAP::VMapManager2::convertPositionToInternalRep ( float  x,
float  y,
float  z 
) const
65  {
66  Vector3 pos;
67  const float mid = 0.5f * 64.0f * 533.33333333f;
68  pos.x = mid - x;
69  pos.y = mid - y;
70  pos.z = z;
71 
72  return pos;
73  }
float x
Definition: Vector3.h:62
float y
Definition: Vector3.h:62
Definition: Vector3.h:58
G3D::int16 z
Definition: Vector3int16.h:46
G3D::int16 y
Definition: Vector2int16.h:38
float z
Definition: Vector3.h:62
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the caller graph for this function:

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

Implements VMAP::IVMapManager.

325  {
326  return StaticMapTree::CanLoadMap(std::string(basePath), mapId, x, y);
327  }
G3D::int16 y
Definition: Vector2int16.h:38
static bool CanLoadMap(const std::string &basePath, uint32 mapID, uint32 tileX, uint32 tileY)
Definition: MapTree.cpp:241
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the call graph for this function:

bool VMAP::VMapManager2::getAreaInfo ( unsigned int  pMapId,
float  x,
float  y,
float &  z,
uint32 flags,
int32 adtId,
int32 rootId,
int32 groupId 
) const
overridevirtual

Query world model area info.

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

Implements VMAP::IVMapManager.

238  {
240  {
241  InstanceTreeMap::const_iterator instanceTree = GetMapTree(mapId);
242  if (instanceTree != iInstanceMapTrees.end())
243  {
245  bool result = instanceTree->second->getAreaInfo(pos, flags, adtId, rootId, groupId);
246  // z is not touched by convertPositionToInternalRep(), so just copy
247  z = pos.z;
248  return result;
249  }
250  }
251 
252  return false;
253  }
InstanceTreeMap::const_iterator GetMapTree(uint32 mapId) const
Definition: VMapManager2.cpp:99
Definition: Vector3.h:58
G3D::Vector3 convertPositionToInternalRep(float x, float y, float z) const
Definition: VMapManager2.cpp:64
G3D::int16 z
Definition: Vector3int16.h:46
G3D::int16 y
Definition: Vector2int16.h:38
float z
Definition: Vector3.h:62
uint8 flags
Definition: DisableMgr.cpp:44
G3D::int16 x
Definition: Vector2int16.h:37
IsVMAPDisabledForFn IsVMAPDisabledForPtr
Definition: VMapManager2.h:138
Definition: VMapManager2.h:72
InstanceTreeMap iInstanceMapTrees
Definition: VMapManager2.h:83

+ Here is the call graph for this function:

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

Implements VMAP::IVMapManager.

127  {
128  return getMapFileName(mapId);
129  }
static std::string getMapFileName(unsigned int mapId)
Definition: VMapManager2.cpp:76
float VMAP::VMapManager2::getHeight ( unsigned int  mapId,
float  x,
float  y,
float  z,
float  maxSearchDist 
)
overridevirtual

get height or INVALID_HEIGHT if no height available

Implements VMAP::IVMapManager.

219  {
221  {
222  InstanceTreeMap::const_iterator instanceTree = GetMapTree(mapId);
223  if (instanceTree != iInstanceMapTrees.end())
224  {
226  float height = instanceTree->second->getHeight(pos, maxSearchDist);
227  if (!(height < G3D::finf()))
228  return height = VMAP_INVALID_HEIGHT_VALUE; // No height
229 
230  return height;
231  }
232  }
233 
235  }
float finf()
Definition: g3dmath.cpp:71
Definition: VMapManager2.h:73
InstanceTreeMap::const_iterator GetMapTree(uint32 mapId) const
Definition: VMapManager2.cpp:99
Definition: Vector3.h:58
G3D::Vector3 convertPositionToInternalRep(float x, float y, float z) const
Definition: VMapManager2.cpp:64
G3D::int16 z
Definition: Vector3int16.h:46
#define VMAP_INVALID_HEIGHT_VALUE
Definition: IVMapManager.h:42
G3D::int16 y
Definition: Vector2int16.h:38
bool isHeightCalcEnabled() const
Definition: IVMapManager.h:87
G3D::int16 x
Definition: Vector2int16.h:37
IsVMAPDisabledForFn IsVMAPDisabledForPtr
Definition: VMapManager2.h:138
InstanceTreeMap iInstanceMapTrees
Definition: VMapManager2.h:83

+ Here is the call graph for this function:

void VMAP::VMapManager2::getInstanceMapTree ( InstanceTreeMap instanceMapTree)
330  {
331  instanceMapTree = iInstanceMapTrees;
332  }
InstanceTreeMap iInstanceMapTrees
Definition: VMapManager2.h:83
static uint32 VMAP::VMapManager2::GetLiquidFlagsDummy ( uint32  )
inlinestaticprotected
91 { return 0; }

+ Here is the caller graph for this function:

bool VMAP::VMapManager2::GetLiquidLevel ( uint32  pMapId,
float  x,
float  y,
float  z,
uint8  reqLiquidType,
float &  level,
float &  floor,
uint32 type 
) const
overridevirtual

Implements VMAP::IVMapManager.

256  {
258  {
259  InstanceTreeMap::const_iterator instanceTree = GetMapTree(mapId);
260  if (instanceTree != iInstanceMapTrees.end())
261  {
262  LocationInfo info;
264  if (instanceTree->second->GetLocationInfo(pos, info))
265  {
266  floor = info.ground_Z;
268  ASSERT(info.hitModel);
269  type = info.hitModel->GetLiquidType(); // entry from LiquidType.dbc
270  if (reqLiquidType && !(GetLiquidFlagsPtr(type) & reqLiquidType))
271  return false;
272  ASSERT(info.hitInstance);
273  if (info.hitInstance->GetLiquidLevel(pos, info, level))
274  return true;
275  }
276  }
277  }
278 
279  return false;
280  }
static Vector3int16 floor(const Vector3 &v)
Definition: VMapManager2.h:75
InstanceTreeMap::const_iterator GetMapTree(uint32 mapId) const
Definition: VMapManager2.cpp:99
T max(const T &x, const T &y)
Definition: g3dmath.h:320
Definition: Vector3.h:58
G3D::Vector3 convertPositionToInternalRep(float x, float y, float z) const
Definition: VMapManager2.cpp:64
GetLiquidFlagsFn GetLiquidFlagsPtr
Definition: VMapManager2.h:135
G3D::int16 z
Definition: Vector3int16.h:46
G3D::int16 y
Definition: Vector2int16.h:38
#define ASSERT
Definition: Errors.h:55
G3D::int16 x
Definition: Vector2int16.h:37
IsVMAPDisabledForFn IsVMAPDisabledForPtr
Definition: VMapManager2.h:138
InstanceTreeMap iInstanceMapTrees
Definition: VMapManager2.h:83

+ Here is the call graph for this function:

std::string VMAP::VMapManager2::getMapFileName ( unsigned int  mapId)
static
77  {
78  std::stringstream fname;
79  fname.width(4);
80  fname << std::setfill('0') << mapId << std::string(MAP_FILENAME_EXTENSION2);
81 
82  return fname.str();
83  }
#define MAP_FILENAME_EXTENSION2
Definition: VMapManager2.h:30

+ Here is the caller graph for this function:

InstanceTreeMap::const_iterator VMAP::VMapManager2::GetMapTree ( uint32  mapId) const
protected
100  {
101  // return the iterator if found or end() if not found/NULL
102  InstanceTreeMap::const_iterator itr = iInstanceMapTrees.find(mapId);
103  if (itr != iInstanceMapTrees.cend() && !itr->second)
104  itr = iInstanceMapTrees.cend();
105 
106  return itr;
107  }
InstanceTreeMap iInstanceMapTrees
Definition: VMapManager2.h:83

+ Here is the caller graph for this function:

bool VMAP::VMapManager2::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::IVMapManager.

189  {
191  {
192  InstanceTreeMap::const_iterator instanceTree = GetMapTree(mapId);
193  if (instanceTree != iInstanceMapTrees.end())
194  {
195  Vector3 pos1 = convertPositionToInternalRep(x1, y1, z1);
196  Vector3 pos2 = convertPositionToInternalRep(x2, y2, z2);
197  Vector3 resultPos;
198  bool result = instanceTree->second->getObjectHitPos(pos1, pos2, resultPos, modifyDist);
199  resultPos = convertPositionToInternalRep(resultPos.x, resultPos.y, resultPos.z);
200  rx = resultPos.x;
201  ry = resultPos.y;
202  rz = resultPos.z;
203  return result;
204  }
205  }
206 
207  rx = x2;
208  ry = y2;
209  rz = z2;
210 
211  return false;
212  }
float x
Definition: Vector3.h:62
InstanceTreeMap::const_iterator GetMapTree(uint32 mapId) const
Definition: VMapManager2.cpp:99
float y
Definition: Vector3.h:62
Definition: Vector3.h:58
G3D::Vector3 convertPositionToInternalRep(float x, float y, float z) const
Definition: VMapManager2.cpp:64
bool isLineOfSightCalcEnabled() const
Definition: IVMapManager.h:86
float z
Definition: Vector3.h:62
Definition: VMapManager2.h:74
IsVMAPDisabledForFn IsVMAPDisabledForPtr
Definition: VMapManager2.h:138
InstanceTreeMap iInstanceMapTrees
Definition: VMapManager2.h:83

+ Here is the call graph for this function:

void VMAP::VMapManager2::InitializeThreadUnsafe ( std::unordered_map< uint32, std::vector< uint32 >> const mapData)
56  {
57  // the caller must pass the list of all mapIds that will be used in the VMapManager2 lifetime
58  for (auto const& p : mapData)
59  iInstanceMapTrees.insert(InstanceTreeMap::value_type(p.first, nullptr));
60 
62  }
bool thread_safe_environment
Definition: VMapManager2.h:84
InstanceTreeMap iInstanceMapTrees
Definition: VMapManager2.h:83
bool VMAP::VMapManager2::isInLineOfSight ( unsigned int  mapId,
float  x1,
float  y1,
float  z1,
float  x2,
float  y2,
float  z2 
)
overridevirtual

Implements VMAP::IVMapManager.

166  {
168  return true;
169 
170  InstanceTreeMap::const_iterator instanceTree = GetMapTree(mapId);
171  if (instanceTree != iInstanceMapTrees.end())
172  {
173  Vector3 pos1 = convertPositionToInternalRep(x1, y1, z1);
174  Vector3 pos2 = convertPositionToInternalRep(x2, y2, z2);
175  if (pos1 != pos2)
176  {
177  return instanceTree->second->isInLineOfSight(pos1, pos2);
178  }
179  }
180 
181  return true;
182  }
InstanceTreeMap::const_iterator GetMapTree(uint32 mapId) const
Definition: VMapManager2.cpp:99
Definition: Vector3.h:58
G3D::Vector3 convertPositionToInternalRep(float x, float y, float z) const
Definition: VMapManager2.cpp:64
bool isLineOfSightCalcEnabled() const
Definition: IVMapManager.h:86
Definition: VMapManager2.h:74
IsVMAPDisabledForFn IsVMAPDisabledForPtr
Definition: VMapManager2.h:138
InstanceTreeMap iInstanceMapTrees
Definition: VMapManager2.h:83

+ Here is the call graph for this function:

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

+ Here is the caller graph for this function:

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

Implements VMAP::IVMapManager.

86  {
87  int result = VMAP_LOAD_RESULT_IGNORED;
88  if (isMapLoadingEnabled())
89  {
90  if (_loadMap(mapId, basePath, x, y))
91  result = VMAP_LOAD_RESULT_OK;
92  else
93  result = VMAP_LOAD_RESULT_ERROR;
94  }
95 
96  return result;
97  }
Definition: IVMapManager.h:38
Definition: IVMapManager.h:36
G3D::int16 y
Definition: Vector2int16.h:38
bool _loadMap(uint32 mapId, const std::string &basePath, uint32 tileX, uint32 tileY)
Definition: VMapManager2.cpp:110
bool isMapLoadingEnabled() const
Definition: IVMapManager.h:88
Definition: IVMapManager.h:37
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the call graph for this function:

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

send debug commands

Implements VMAP::IVMapManager.

117 { return false; } // for debug and extensions
void VMAP::VMapManager2::releaseModelInstance ( const std::string &  filename)

Critical section, thread safe access to iLoadedModelFiles

306  {
308  std::lock_guard<std::mutex> lock(LoadedModelFilesLock);
309 
310  ModelFileMap::iterator model = iLoadedModelFiles.find(filename);
311  if (model == iLoadedModelFiles.end())
312  {
313  VMAP_ERROR_LOG("misc", "VMapManager2: trying to unload non-loaded file '%s'", filename.c_str());
314  return;
315  }
316  if (model->second.decRefCount() == 0)
317  {
318  VMAP_DEBUG_LOG("maps", "VMapManager2: unloading file '%s'", filename.c_str());
319  delete model->second.getModel();
320  iLoadedModelFiles.erase(model);
321  }
322  }
std::mutex LoadedModelFilesLock
Definition: VMapManager2.h:86
ModelFileMap iLoadedModelFiles
Definition: VMapManager2.h:82
#define VMAP_DEBUG_LOG(FILTER,...)
Definition: VMapDefinitions.h:39
#define VMAP_ERROR_LOG(FILTER,...)
Definition: VMapDefinitions.h:38

+ Here is the caller graph for this function:

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

Implements VMAP::IVMapManager.

152  {
153  InstanceTreeMap::iterator instanceTree = iInstanceMapTrees.find(mapId);
154  if (instanceTree != iInstanceMapTrees.end() && instanceTree->second)
155  {
156  instanceTree->second->UnloadMapTile(x, y, this);
157  if (instanceTree->second->numLoadedTiles() == 0)
158  {
159  delete instanceTree->second;
160  instanceTree->second = nullptr;
161  }
162  }
163  }
G3D::int16 y
Definition: Vector2int16.h:38
G3D::int16 x
Definition: Vector2int16.h:37
InstanceTreeMap iInstanceMapTrees
Definition: VMapManager2.h:83
void VMAP::VMapManager2::unloadMap ( unsigned int  mapId)
overridevirtual

Implements VMAP::IVMapManager.

138  {
139  InstanceTreeMap::iterator instanceTree = iInstanceMapTrees.find(mapId);
140  if (instanceTree != iInstanceMapTrees.end() && instanceTree->second)
141  {
142  instanceTree->second->UnloadMap(this);
143  if (instanceTree->second->numLoadedTiles() == 0)
144  {
145  delete instanceTree->second;
146  instanceTree->second = nullptr;
147  }
148  }
149  }
InstanceTreeMap iInstanceMapTrees
Definition: VMapManager2.h:83

Member Data Documentation

GetLiquidFlagsFn VMAP::VMapManager2::GetLiquidFlagsPtr
InstanceTreeMap VMAP::VMapManager2::iInstanceMapTrees
protected
ModelFileMap VMAP::VMapManager2::iLoadedModelFiles
protected
IsVMAPDisabledForFn VMAP::VMapManager2::IsVMAPDisabledForPtr
std::mutex VMAP::VMapManager2::LoadedModelFilesLock
protected
bool VMAP::VMapManager2::thread_safe_environment
protected

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