AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
DynamicMapTree Class Reference

#include "DynamicTree.h"

Public Member Functions

 DynamicMapTree ()
 
 ~DynamicMapTree ()
 
bool isInLineOfSight (float x1, float y1, float z1, float x2, float y2, float z2, uint32 phasemask, VMAP::ModelIgnoreFlags ignoreFlags) const
 
bool GetIntersectionTime (uint32 phasemask, const G3D::Ray &ray, const G3D::Vector3 &endPos, float &maxDist) const
 
bool GetAreaAndLiquidData (float x, float y, float z, uint32 phasemask, Optional< uint8 > reqLiquidType, VMAP::AreaAndLiquidData &data) const
 
bool GetObjectHitPos (uint32 phasemask, const G3D::Vector3 &pPos1, const G3D::Vector3 &pPos2, G3D::Vector3 &pResultHitPos, float pModifyDist) const
 
float getHeight (float x, float y, float z, float maxSearchDist, uint32 phasemask) const
 
void insert (const GameObjectModel &)
 
void remove (const GameObjectModel &)
 
bool contains (const GameObjectModel &) const
 
int size () const
 
void balance ()
 
void update (uint32 diff)
 

Private Attributes

DynTreeImplimpl
 

Detailed Description

Constructor & Destructor Documentation

◆ DynamicMapTree()

DynamicMapTree::DynamicMapTree ( )
110: impl(new DynTreeImpl()) { }
DynTreeImpl * impl
Definition DynamicTree.h:41
Definition DynamicTree.cpp:60

◆ ~DynamicMapTree()

DynamicMapTree::~DynamicMapTree ( )
113{
114 delete impl;
115}

References impl.

Member Function Documentation

◆ balance()

void DynamicMapTree::balance ( )
133{
134 impl->balance();
135}
void balance()
Definition DynamicTree.cpp:82

References DynTreeImpl::balance(), and impl.

Referenced by Map::Balance().

◆ contains()

bool DynamicMapTree::contains ( const GameObjectModel mdl) const
128{
129 return impl->contains(mdl);
130}
bool contains(const T &value) const
Definition RegularGrid.h:142

References RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::contains(), and impl.

Referenced by Map::ContainsGameObjectModel().

◆ GetAreaAndLiquidData()

bool DynamicMapTree::GetAreaAndLiquidData ( float  x,
float  y,
float  z,
uint32  phasemask,
Optional< uint8 reqLiquidType,
VMAP::AreaAndLiquidData data 
) const
293{
294 G3D::Vector3 v(x, y, z + 0.5f);
295 DynamicTreeLocationInfoCallback intersectionCallBack(phasemask);
296 impl->intersectPoint(v, intersectionCallBack);
297 if (intersectionCallBack.GetLocationInfo().hitModel)
298 {
299 data.floorZ = intersectionCallBack.GetLocationInfo().ground_Z;
300 uint32 liquidType = intersectionCallBack.GetLocationInfo().hitModel->GetLiquidType();
301 float liquidLevel;
302 if (!reqLiquidType || (dynamic_cast<VMAP::VMapMgr2*>(VMAP::VMapFactory::createOrGetVMapMgr())->GetLiquidFlagsPtr(liquidType) & *reqLiquidType))
303 if (intersectionCallBack.GetHitModel()->GetLiquidLevel(v, intersectionCallBack.GetLocationInfo(), liquidLevel))
304 data.liquidInfo.emplace(liquidType, liquidLevel);
305
306 data.areaInfo.emplace(intersectionCallBack.GetLocationInfo().hitModel->GetWmoID(),
307 0,
308 intersectionCallBack.GetLocationInfo().rootId,
309 intersectionCallBack.GetLocationInfo().hitModel->GetMogpFlags(),
310 0);
311 return true;
312 }
313 return false;
314}
std::uint32_t uint32
Definition Define.h:107
void intersectPoint(const G3D::Vector3 &point, IsectCallback &intersectCallback)
Definition RegularGrid.h:264
static VMapMgr2 * createOrGetVMapMgr()
Definition VMapFactory.cpp:27
Definition VMapMgr2.h:76
Definition DynamicTree.cpp:174
Optional< AreaInfo > areaInfo
Definition IVMapMgr.h:75
Optional< LiquidInfo > liquidInfo
Definition IVMapMgr.h:76
float floorZ
Definition IVMapMgr.h:74

References VMAP::AreaAndLiquidData::areaInfo, VMAP::VMapFactory::createOrGetVMapMgr(), VMAP::AreaAndLiquidData::floorZ, DynamicTreeLocationInfoCallback::GetHitModel(), GameObjectModel::GetLiquidLevel(), VMAP::GroupModel::GetLiquidType(), DynamicTreeLocationInfoCallback::GetLocationInfo(), VMAP::GroupModel::GetMogpFlags(), VMAP::GroupModel::GetWmoID(), VMAP::LocationInfo::ground_Z, VMAP::LocationInfo::hitModel, impl, RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::intersectPoint(), VMAP::AreaAndLiquidData::liquidInfo, and VMAP::LocationInfo::rootId.

Referenced by Map::GetAreaInfo().

◆ getHeight()

float DynamicMapTree::getHeight ( float  x,
float  y,
float  z,
float  maxSearchDist,
uint32  phasemask 
) const
276{
277 G3D::Vector3 v(x, y, z);
278 G3D::Ray r(v, G3D::Vector3(0, 0, -1));
280 impl->intersectZAllignedRay(r, callback, maxSearchDist);
281
282 if (callback.didHit())
283 {
284 return v.z - maxSearchDist;
285 }
286 else
287 {
288 return -G3D::finf();
289 }
290}
void intersectZAllignedRay(const G3D::Ray &ray, RayCallback &intersectCallback, float &max_dist)
Definition RegularGrid.h:279
Definition DynamicTree.cpp:148

References DynamicTreeIntersectionCallback::didHit(), impl, RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::intersectZAllignedRay(), and VMAP::Nothing.

Referenced by BattlegroundRV::CheckPositionForUnit(), Map::GetGameObjectFloor(), and Map::GetHeight().

◆ GetIntersectionTime()

bool DynamicMapTree::GetIntersectionTime ( uint32  phasemask,
const G3D::Ray &  ray,
const G3D::Vector3 &  endPos,
float &  maxDist 
) const
200{
201 float distance = maxDist;
203 impl->intersectRay(ray, callback, distance, endPos, false);
204 if (callback.didHit())
205 {
206 maxDist = distance;
207 }
208 return callback.didHit();
209}
void intersectRay(const G3D::Ray &ray, RayCallback &intersectCallback, float max_dist, bool stopAtFirstHit)
Definition RegularGrid.h:176

References DynamicTreeIntersectionCallback::didHit(), impl, RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::intersectRay(), and VMAP::Nothing.

Referenced by GetObjectHitPos().

◆ GetObjectHitPos()

bool DynamicMapTree::GetObjectHitPos ( uint32  phasemask,
const G3D::Vector3 &  pPos1,
const G3D::Vector3 &  pPos2,
G3D::Vector3 &  pResultHitPos,
float  pModifyDist 
) const
214{
215 bool result = false;
216 float maxDist = (endPos - startPos).magnitude();
217 // valid map coords should *never ever* produce float overflow, but this would produce NaNs too
218 ASSERT(maxDist < std::numeric_limits<float>::max());
219 // prevent NaN values which can cause BIH intersection to enter infinite loop
220 if (maxDist < 1e-10f)
221 {
222 resultHit = endPos;
223 return false;
224 }
225 G3D::Vector3 dir = (endPos - startPos) / maxDist; // direction with length of 1
226 G3D::Ray ray(startPos, dir);
227 float dist = maxDist;
228 if (GetIntersectionTime(phasemask, ray, endPos, dist))
229 {
230 resultHit = startPos + dir * dist;
231 if (modifyDist < 0)
232 {
233 if ((resultHit - startPos).magnitude() > -modifyDist)
234 {
235 resultHit = resultHit + dir * modifyDist;
236 }
237 else
238 {
239 resultHit = startPos;
240 }
241 }
242 else
243 {
244 resultHit = resultHit + dir * modifyDist;
245 }
246
247 result = true;
248 }
249 else
250 {
251 resultHit = endPos;
252 result = false;
253 }
254 return result;
255}
#define ASSERT
Definition Errors.h:68
bool GetIntersectionTime(uint32 phasemask, const G3D::Ray &ray, const G3D::Vector3 &endPos, float &maxDist) const
Definition DynamicTree.cpp:199

References ASSERT, and GetIntersectionTime().

Referenced by Map::GetObjectHitPos().

◆ insert()

void DynamicMapTree::insert ( const GameObjectModel mdl)
118{
119 impl->insert(mdl);
120}
void insert(const Model &mdl)
Definition DynamicTree.cpp:70

References impl, and DynTreeImpl::insert().

Referenced by Map::InsertGameObjectModel().

◆ isInLineOfSight()

bool DynamicMapTree::isInLineOfSight ( float  x1,
float  y1,
float  z1,
float  x2,
float  y2,
float  z2,
uint32  phasemask,
VMAP::ModelIgnoreFlags  ignoreFlags 
) const
258{
259 G3D::Vector3 v1(x1, y1, z1), v2(x2, y2, z2);
260
261 float maxDist = (v2 - v1).magnitude();
262
263 if (!G3D::fuzzyGt(maxDist, 0))
264 {
265 return true;
266 }
267
268 G3D::Ray r(v1, (v2 - v1) / maxDist);
269 DynamicTreeIntersectionCallback callback(phasemask, ignoreFlags);
270 impl->intersectRay(r, callback, maxDist, v2, true);
271
272 return !callback.didHit();
273}

References DynamicTreeIntersectionCallback::didHit(), impl, and RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::intersectRay().

Referenced by Map::isInLineOfSight().

◆ remove()

void DynamicMapTree::remove ( const GameObjectModel mdl)
123{
124 impl->remove(mdl);
125}
void remove(const Model &mdl)
Definition DynamicTree.cpp:76

References impl, and DynTreeImpl::remove().

Referenced by Map::RemoveGameObjectModel().

◆ size()

int DynamicMapTree::size ( ) const
138{
139 return impl->size();
140}
int size() const
Definition RegularGrid.h:143

References impl, and RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::size().

◆ update()

void DynamicMapTree::update ( uint32  diff)
143{
144 impl->update(t_diff);
145}
void update(uint32 difftime)
Definition DynamicTree.cpp:88

References impl, and DynTreeImpl::update().

Referenced by Map::Update().

Member Data Documentation

◆ impl


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