OregonCore  revision fb2a440-git
Your Favourite TBC server
VMAP::VMapManager2 Class Reference

#include <VMapManager2.h>

+ Inheritance diagram for VMAP::VMapManager2:

Public Member Functions

G3D::Vector3 convertPositionToInternalRep (float x, float y, float z) const
 
 VMapManager2 ()
 
 ~VMapManager2 (void)
 
VMAPLoadResult loadMap (const char *pBasePath, unsigned int mapId, int x, int y)
 
void InitializeThreadUnsafe (const std::vector< uint32 > &mapIds)
 
void unloadMap (unsigned int mapId, int x, int y)
 
void unloadMap (unsigned int mapId)
 
bool isInLineOfSight (unsigned int mapId, float x1, float y1, float z1, float x2, float y2, float z2)
 
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)
 
float getHeight (unsigned int mapId, float x, float y, float z, float maxSearchDist)
 
bool processCommand (char *)
 
bool getAreaInfo (unsigned int pMapId, float x, float y, float &z, uint32 &flags, int32 &adtId, int32 &rootId, int32 &groupId) const
 
bool GetLiquidLevel (uint32 pMapId, float x, float y, float z, uint8 reqLiquidType, float &level, float &floor, uint32 &type) const
 
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
 
virtual bool existsMap (const char *basePath, unsigned int mapId, int x, int y)
 
- 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

uint32(* GetLiquidFlagsPtr )(uint32 liquidType)
 

Protected Member Functions

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

Protected Attributes

ModelFileMap iLoadedModelFiles
 
InstanceTreeMap iInstanceMapTrees
 
bool thread_safe_environment
 
ACE_Thread_Mutex LoadedModelFilesLock
 

Detailed Description

Definition at line 69 of file VMapManager2.h.

Constructor & Destructor Documentation

VMAP::VMapManager2::VMapManager2 ( )

Definition at line 42 of file VMapManager2.cpp.

References GetLiquidFlagsPtr, and thread_safe_environment.

43 {
44  GetLiquidFlagsPtr = &GetLiquidFlagsDummy;
46 }
bool thread_safe_environment
Definition: VMapManager2.h:75
uint32(* GetLiquidFlagsPtr)(uint32 liquidType)
Definition: VMapManager2.h:120
VMAP::VMapManager2::~VMapManager2 ( void  )

Definition at line 48 of file VMapManager2.cpp.

References iInstanceMapTrees, and iLoadedModelFiles.

49 {
50  for (InstanceTreeMap::iterator i = iInstanceMapTrees.begin(); i != iInstanceMapTrees.end(); ++i)
51  {
52  delete i->second;
53  }
54  for (ModelFileMap::iterator i = iLoadedModelFiles.begin(); i != iLoadedModelFiles.end(); ++i)
55  {
56  delete i->second.getModel();
57  }
58 }
ModelFileMap iLoadedModelFiles
Definition: VMapManager2.h:73
InstanceTreeMap iInstanceMapTrees
Definition: VMapManager2.h:74

Member Function Documentation

bool VMAP::VMapManager2::_loadMap ( uint32  mapId,
const std::string &  basePath,
uint32  tileX,
uint32  tileY 
)
protected

Definition at line 115 of file VMapManager2.cpp.

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

Referenced by loadMap().

116 {
117  InstanceTreeMap::iterator instanceTree = iInstanceMapTrees.find(mapId);
118  if (instanceTree == iInstanceMapTrees.end())
119  {
121  instanceTree = iInstanceMapTrees.insert(InstanceTreeMap::value_type(mapId, nullptr)).first;
122  else
123  ASSERT(false);
124  }
125 
126  if (!instanceTree->second)
127  {
128  std::string mapFileName = getMapFileName(mapId);
129  StaticMapTree* newTree = new StaticMapTree(mapId, basePath);
130  if (!newTree->InitMap(mapFileName, this))
131  return false;
132  instanceTree->second = newTree;
133  }
134 
135  return instanceTree->second->LoadMapTile(tileX, tileY, this);
136 }
static std::string getMapFileName(unsigned int mapId)
bool thread_safe_environment
Definition: VMapManager2.h:75
#define ASSERT
Definition: Errors.h:29
InstanceTreeMap iInstanceMapTrees
Definition: VMapManager2.h:74
WorldModel * VMAP::VMapManager2::acquireModelInstance ( const std::string &  basepath,
const std::string &  filename 
)

Critical section, thread safe access to iLoadedModelFiles

Definition at line 277 of file VMapManager2.cpp.

References DEBUG_LOG, ERROR_LOG, iLoadedModelFiles, and VMAP::WorldModel::readFile().

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

278 {
280  //ACE_GUARD(ACE_Thread_Mutex, LoadedModelFilesLock);
281 
282  ModelFileMap::iterator model = iLoadedModelFiles.find(filename);
283  if (model == iLoadedModelFiles.end())
284  {
285  WorldModel* worldmodel = new WorldModel();
286  if (!worldmodel->readFile(basepath + filename + ".vmo"))
287  {
288  ERROR_LOG("VMapManager2: could not load '%s%s.vmo'", basepath.c_str(), filename.c_str());
289  delete worldmodel;
290  return NULL;
291  }
292  DEBUG_LOG("VMapManager2: loading file '%s%s'", basepath.c_str(), filename.c_str());
293  model = iLoadedModelFiles.insert(std::pair<std::string, ManagedModel>(filename, ManagedModel())).first;
294  model->second.setModel(worldmodel);
295  }
296  model->second.incRefCount();
297  return model->second.getModel();
298 }
ModelFileMap iLoadedModelFiles
Definition: VMapManager2.h:73
#define ERROR_LOG(...)
#define DEBUG_LOG(...)
Definition: Log.h:194
Vector3 VMAP::VMapManager2::convertPositionToInternalRep ( float  x,
float  y,
float  z 
) const

Definition at line 69 of file VMapManager2.cpp.

Referenced by getAreaInfo(), getHeight(), GetLiquidLevel(), getObjectHitPos(), and isInLineOfSight().

70 {
71  Vector3 pos;
72  const float mid = 0.5f * 64.0f * 533.33333333f;
73  pos.x = mid - x;
74  pos.y = mid - y;
75  pos.z = z;
76 
77  return pos;
78 }
bool VMAP::VMapManager2::existsMap ( const char *  basePath,
unsigned int  mapId,
int  x,
int  y 
)
virtual

Implements VMAP::IVMapManager.

Definition at line 319 of file VMapManager2.cpp.

References VMAP::StaticMapTree::CanLoadMap().

320 {
321  return StaticMapTree::CanLoadMap(std::string(basePath), mapId, x, y);
322 }
static bool CanLoadMap(const std::string &basePath, uint32 mapID, uint32 tileX, uint32 tileY)
Definition: MapTree.cpp:235
bool VMAP::VMapManager2::getAreaInfo ( unsigned int  pMapId,
float  x,
float  y,
float &  z,
uint32 flags,
int32 adtId,
int32 rootId,
int32 groupId 
) const
virtual

Query world model area info.

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

DisableMgr::IsDisabledFor(DISABLE_TYPE_VMAP, mapId, NULL, VMAP_DISABLE_AREAFLAG)

Implements VMAP::IVMapManager.

Definition at line 234 of file VMapManager2.cpp.

References convertPositionToInternalRep(), GetMapTree(), and iInstanceMapTrees.

235 {
236  if (true)
237  {
238  InstanceTreeMap::const_iterator instanceTree = GetMapTree(mapId);
239  if (instanceTree != iInstanceMapTrees.end())
240  {
241  Vector3 pos = convertPositionToInternalRep(x, y, z);
242  bool result = instanceTree->second->getAreaInfo(pos, flags, adtId, rootId, groupId);
243  // z is not touched by convertPositionToInternalRep(), so just copy
244  z = pos.z;
245  return result;
246  }
247  }
248 
249  return false;
250 }
InstanceTreeMap::const_iterator GetMapTree(uint32 mapId) const
G3D::Vector3 convertPositionToInternalRep(float x, float y, float z) const
InstanceTreeMap iInstanceMapTrees
Definition: VMapManager2.h:74
virtual std::string VMAP::VMapManager2::getDirFileName ( unsigned int  mapId,
int  ,
int   
) const
inlinevirtual

Implements VMAP::IVMapManager.

Definition at line 113 of file VMapManager2.h.

114  {
115  return getMapFileName(mapId);
116  }
static std::string getMapFileName(unsigned int mapId)
float VMAP::VMapManager2::getHeight ( unsigned int  mapId,
float  x,
float  y,
float  z,
float  maxSearchDist 
)
virtual

get height or INVALID_HEIGHT if no height available

Implements VMAP::IVMapManager.

Definition at line 216 of file VMapManager2.cpp.

References convertPositionToInternalRep(), GetMapTree(), iInstanceMapTrees, VMAP::IVMapManager::isHeightCalcEnabled(), and VMAP_INVALID_HEIGHT_VALUE.

217 {
218  if (isHeightCalcEnabled()/* && !DisableMgr::IsDisabledFor(DISABLE_TYPE_VMAP, mapId, NULL, VMAP_DISABLE_HEIGHT)*/)
219  {
220  InstanceTreeMap::const_iterator instanceTree = GetMapTree(mapId); if (instanceTree != iInstanceMapTrees.end())
221  {
222  Vector3 pos = convertPositionToInternalRep(x, y, z);
223  float height = instanceTree->second->getHeight(pos, maxSearchDist);
224  if (!(height < G3D::inf()))
225  return height = VMAP_INVALID_HEIGHT_VALUE; // No height
226 
227  return height;
228  }
229  }
230 
232 }
InstanceTreeMap::const_iterator GetMapTree(uint32 mapId) const
G3D::Vector3 convertPositionToInternalRep(float x, float y, float z) const
#define VMAP_INVALID_HEIGHT_VALUE
Definition: IVMapManager.h:41
bool isHeightCalcEnabled() const
Definition: IVMapManager.h:86
InstanceTreeMap iInstanceMapTrees
Definition: VMapManager2.h:74
bool VMAP::VMapManager2::GetLiquidLevel ( uint32  pMapId,
float  x,
float  y,
float  z,
uint8  reqLiquidType,
float &  level,
float &  floor,
uint32 type 
) const
virtual

DisableMgr::IsDisabledFor(DISABLE_TYPE_VMAP, mapId, NULL, VMAP_DISABLE_LIQUIDSTATUS)

Implements VMAP::IVMapManager.

Definition at line 252 of file VMapManager2.cpp.

References ASSERT, convertPositionToInternalRep(), GetLiquidFlagsPtr, VMAP::ModelInstance::GetLiquidLevel(), VMAP::GroupModel::GetLiquidType(), GetMapTree(), VMAP::LocationInfo::ground_Z, VMAP::LocationInfo::hitInstance, VMAP::LocationInfo::hitModel, and iInstanceMapTrees.

253 {
254  if (true)
255  {
256  InstanceTreeMap::const_iterator instanceTree = GetMapTree(mapId);
257  if (instanceTree != iInstanceMapTrees.end())
258  {
259  LocationInfo info;
260  Vector3 pos = convertPositionToInternalRep(x, y, z);
261  if (instanceTree->second->GetLocationInfo(pos, info))
262  {
263  floor = info.ground_Z;
264  ASSERT(floor < std::numeric_limits<float>::max());
265  type = info.hitModel->GetLiquidType(); // entry from LiquidType.dbc
266  if (reqLiquidType && !(GetLiquidFlagsPtr(type) & reqLiquidType))
267  return false;
268  if (info.hitInstance->GetLiquidLevel(pos, info, level))
269  return true;
270  }
271  }
272  }
273 
274  return false;
275 }
InstanceTreeMap::const_iterator GetMapTree(uint32 mapId) const
G3D::Vector3 convertPositionToInternalRep(float x, float y, float z) const
uint32(* GetLiquidFlagsPtr)(uint32 liquidType)
Definition: VMapManager2.h:120
#define ASSERT
Definition: Errors.h:29
InstanceTreeMap iInstanceMapTrees
Definition: VMapManager2.h:74
std::string VMAP::VMapManager2::getMapFileName ( unsigned int  mapId)
static

Definition at line 81 of file VMapManager2.cpp.

References MAP_FILENAME_EXTENSION2.

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

82 {
83  std::stringstream fname;
84  fname.width(3);
85  fname << std::setfill('0') << mapId << std::string(MAP_FILENAME_EXTENSION2);
86 
87  return fname.str();
88 }
#define MAP_FILENAME_EXTENSION2
Definition: VMapManager2.h:29
InstanceTreeMap::const_iterator VMAP::VMapManager2::GetMapTree ( uint32  mapId) const
protected

Definition at line 104 of file VMapManager2.cpp.

References iInstanceMapTrees.

Referenced by getAreaInfo(), getHeight(), GetLiquidLevel(), getObjectHitPos(), and isInLineOfSight().

105 {
106  // return the iterator if found or end() if not found/NULL
107  InstanceTreeMap::const_iterator itr = iInstanceMapTrees.find(mapId);
108  if (itr != iInstanceMapTrees.cend() && !itr->second)
109  itr = iInstanceMapTrees.cend();
110 
111  return itr;
112 }
InstanceTreeMap iInstanceMapTrees
Definition: VMapManager2.h:74
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 
)
virtual

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.

Definition at line 187 of file VMapManager2.cpp.

References convertPositionToInternalRep(), GetMapTree(), iInstanceMapTrees, and VMAP::IVMapManager::isLineOfSightCalcEnabled().

188 {
189  if (isLineOfSightCalcEnabled() /*&& !DisableMgr::IsDisabledFor(DISABLE_TYPE_VMAP, mapId, NULL, VMAP_DISABLE_LOS)*/)
190  {
191  InstanceTreeMap::const_iterator instanceTree = GetMapTree(mapId);
192  if (instanceTree != iInstanceMapTrees.end())
193  {
194  Vector3 pos1 = convertPositionToInternalRep(x1, y1, z1);
195  Vector3 pos2 = convertPositionToInternalRep(x2, y2, z2);
196  Vector3 resultPos;
197  bool result = instanceTree->second->getObjectHitPos(pos1, pos2, resultPos, modifyDist);
198  resultPos = convertPositionToInternalRep(resultPos.x, resultPos.y, resultPos.z);
199  rx = resultPos.x;
200  ry = resultPos.y;
201  rz = resultPos.z;
202  return result;
203  }
204  }
205 
206  rx = x2;
207  ry = y2;
208  rz = z2;
209 
210  return false;
211 }
InstanceTreeMap::const_iterator GetMapTree(uint32 mapId) const
G3D::Vector3 convertPositionToInternalRep(float x, float y, float z) const
bool isLineOfSightCalcEnabled() const
Definition: IVMapManager.h:85
InstanceTreeMap iInstanceMapTrees
Definition: VMapManager2.h:74
void VMAP::VMapManager2::InitializeThreadUnsafe ( const std::vector< uint32 > &  mapIds)

Definition at line 60 of file VMapManager2.cpp.

References iInstanceMapTrees, and thread_safe_environment.

61 {
62  // the caller must pass the list of all mapIds that will be used in the VMapManager2 lifetime
63  for (const uint32& mapId : mapIds)
64  iInstanceMapTrees.insert(InstanceTreeMap::value_type(mapId, nullptr));
65 
67 }
bool thread_safe_environment
Definition: VMapManager2.h:75
ACE_UINT32 uint32
Definition: Define.h:71
InstanceTreeMap iInstanceMapTrees
Definition: VMapManager2.h:74
bool VMAP::VMapManager2::isInLineOfSight ( unsigned int  mapId,
float  x1,
float  y1,
float  z1,
float  x2,
float  y2,
float  z2 
)
virtual

Implements VMAP::IVMapManager.

Definition at line 166 of file VMapManager2.cpp.

References convertPositionToInternalRep(), GetMapTree(), iInstanceMapTrees, and VMAP::IVMapManager::isLineOfSightCalcEnabled().

167 {
168  if (!isLineOfSightCalcEnabled() /*|| DisableMgr::IsDisabledFor(DISABLE_TYPE_VMAP, mapId, NULL, VMAP_DISABLE_LOS)*/)
169  return true;
170 
171  InstanceTreeMap::const_iterator instanceTree = GetMapTree(mapId);
172  if (instanceTree != iInstanceMapTrees.end())
173  {
174  Vector3 pos1 = convertPositionToInternalRep(x1, y1, z1);
175  Vector3 pos2 = convertPositionToInternalRep(x2, y2, z2);
176  if (pos1 != pos2)
177  return instanceTree->second->isInLineOfSight(pos1, pos2);
178  }
179 
180  return true;
181 }
InstanceTreeMap::const_iterator GetMapTree(uint32 mapId) const
G3D::Vector3 convertPositionToInternalRep(float x, float y, float z) const
bool isLineOfSightCalcEnabled() const
Definition: IVMapManager.h:85
InstanceTreeMap iInstanceMapTrees
Definition: VMapManager2.h:74
VMAPLoadResult VMAP::VMapManager2::loadMap ( const char *  pBasePath,
unsigned int  mapId,
int  x,
int  y 
)
virtual

Implements VMAP::IVMapManager.

Definition at line 90 of file VMapManager2.cpp.

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

91 {
93  if (isMapLoadingEnabled())
94  {
95  if (_loadMap(mapId, basePath, x, y))
96  result = VMAP_LOAD_RESULT_OK;
97  else
98  result = VMAP_LOAD_RESULT_ERROR;
99  }
100 
101  return result;
102 }
VMAPLoadResult
Definition: IVMapManager.h:33
bool _loadMap(uint32 mapId, const std::string &basePath, uint32 tileX, uint32 tileY)
bool isMapLoadingEnabled() const
Definition: IVMapManager.h:87
bool VMAP::VMapManager2::processCommand ( char *  pCommand)
inlinevirtual

send debug commands

Implements VMAP::IVMapManager.

Definition at line 105 of file VMapManager2.h.

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

Critical section, thread safe access to iLoadedModelFiles

Definition at line 300 of file VMapManager2.cpp.

References DEBUG_LOG, ERROR_LOG, and iLoadedModelFiles.

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

301 {
303  //ACE_GUARD(ACE_Thread_Mutex, LoadedModelFilesLock);
304 
305  ModelFileMap::iterator model = iLoadedModelFiles.find(filename);
306  if (model == iLoadedModelFiles.end())
307  {
308  ERROR_LOG("VMapManager2: trying to unload non-loaded file '%s'", filename.c_str());
309  return;
310  }
311  if (model->second.decRefCount() == 0)
312  {
313  DEBUG_LOG("VMapManager2: unloading file '%s'", filename.c_str());
314  delete model->second.getModel();
315  iLoadedModelFiles.erase(model);
316  }
317 }
ModelFileMap iLoadedModelFiles
Definition: VMapManager2.h:73
#define ERROR_LOG(...)
#define DEBUG_LOG(...)
Definition: Log.h:194
void VMAP::VMapManager2::unloadMap ( unsigned int  mapId,
int  x,
int  y 
)
virtual

Implements VMAP::IVMapManager.

Definition at line 152 of file VMapManager2.cpp.

References iInstanceMapTrees.

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

Implements VMAP::IVMapManager.

Definition at line 138 of file VMapManager2.cpp.

References iInstanceMapTrees.

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

Member Data Documentation

uint32(* VMAP::VMapManager2::GetLiquidFlagsPtr) (uint32 liquidType)

Definition at line 120 of file VMapManager2.h.

Referenced by GetLiquidLevel(), and VMapManager2().

InstanceTreeMap VMAP::VMapManager2::iInstanceMapTrees
protected
ModelFileMap VMAP::VMapManager2::iLoadedModelFiles
protected

Definition at line 73 of file VMapManager2.h.

Referenced by acquireModelInstance(), releaseModelInstance(), and ~VMapManager2().

ACE_Thread_Mutex VMAP::VMapManager2::LoadedModelFilesLock
protected

Definition at line 77 of file VMapManager2.h.

bool VMAP::VMapManager2::thread_safe_environment
protected

Definition at line 75 of file VMapManager2.h.

Referenced by _loadMap(), InitializeThreadUnsafe(), and VMapManager2().


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