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 GetAreaInfo (float x, float y, float &z, uint32 phasemask, uint32 &flags, int32 &adtId, int32 &rootId, int32 &groupId) const
 
void GetAreaAndLiquidData (float x, float y, float z, uint32 phasemask, 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()) { }
Definition: DynamicTree.cpp:60
DynTreeImpl * impl
Definition: DynamicTree.h:40

◆ ~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:143

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

Referenced by Map::ContainsGameObjectModel().

◆ GetAreaAndLiquidData()

void DynamicMapTree::GetAreaAndLiquidData ( float  x,
float  y,
float  z,
uint32  phasemask,
uint8  reqLiquidType,
VMAP::AreaAndLiquidData data 
) const
329{
330 G3D::Vector3 v(x, y, z + 0.5f);
331 DynamicTreeLocationInfoCallback intersectionCallBack(phasemask);
332 impl->intersectPoint(v, intersectionCallBack);
333 if (intersectionCallBack.GetLocationInfo().hitModel)
334 {
335 data.floorZ = intersectionCallBack.GetLocationInfo().ground_Z;
336 uint32 liquidType = intersectionCallBack.GetLocationInfo().hitModel->GetLiquidType();
337 float liquidLevel;
338 if (!reqLiquidType || (dynamic_cast<VMAP::VMapMgr2*>(VMAP::VMapFactory::createOrGetVMapMgr())->GetLiquidFlagsPtr(liquidType) & reqLiquidType))
339 if (intersectionCallBack.GetHitModel()->GetLiquidLevel(v, intersectionCallBack.GetLocationInfo(), liquidLevel))
340 data.liquidInfo.emplace(liquidType, liquidLevel);
341
342 data.areaInfo.emplace(0,
343 intersectionCallBack.GetLocationInfo().rootId,
344 intersectionCallBack.GetLocationInfo().hitModel->GetWmoID(),
345 intersectionCallBack.GetLocationInfo().hitModel->GetMogpFlags());
346 }
347}
std::uint32_t uint32
Definition: Define.h:108
Definition: DynamicTree.cpp:193
Optional< AreaInfo > areaInfo
Definition: IVMapMgr.h:72
Optional< LiquidInfo > liquidInfo
Definition: IVMapMgr.h:73
float floorZ
Definition: IVMapMgr.h:71
static VMapMgr2 * createOrGetVMapMgr()
Definition: VMapFactory.cpp:27
Definition: VMapMgr2.h:77
void intersectPoint(const G3D::Vector3 &point, IsectCallback &intersectCallback)
Definition: RegularGrid.h:265

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.

◆ GetAreaInfo()

bool DynamicMapTree::GetAreaInfo ( float  x,
float  y,
float &  z,
uint32  phasemask,
uint32 flags,
int32 adtId,
int32 rootId,
int32 groupId 
) const
312{
313 G3D::Vector3 v(x, y, z + 0.5f);
314 DynamicTreeAreaInfoCallback intersectionCallBack(phasemask);
315 impl->intersectPoint(v, intersectionCallBack);
316 if (intersectionCallBack.GetAreaInfo().result)
317 {
318 flags = intersectionCallBack.GetAreaInfo().flags;
319 adtId = intersectionCallBack.GetAreaInfo().adtId;
320 rootId = intersectionCallBack.GetAreaInfo().rootId;
321 groupId = intersectionCallBack.GetAreaInfo().groupId;
322 z = intersectionCallBack.GetAreaInfo().ground_Z;
323 return true;
324 }
325 return false;
326}
Definition: DynamicTree.cpp:174

References VMAP::AreaInfo::adtId, VMAP::AreaInfo::flags, DynamicTreeAreaInfoCallback::GetAreaInfo(), VMAP::AreaInfo::ground_Z, VMAP::AreaInfo::groupId, impl, RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::intersectPoint(), VMAP::AreaInfo::result, and VMAP::AreaInfo::rootId.

Referenced by Map::GetAreaInfo().

◆ getHeight()

float DynamicMapTree::getHeight ( float  x,
float  y,
float  z,
float  maxSearchDist,
uint32  phasemask 
) const
295{
296 G3D::Vector3 v(x, y, z);
297 G3D::Ray r(v, G3D::Vector3(0, 0, -1));
299 impl->intersectZAllignedRay(r, callback, maxSearchDist);
300
301 if (callback.didHit())
302 {
303 return v.z - maxSearchDist;
304 }
305 else
306 {
307 return -G3D::finf();
308 }
309}
Definition: DynamicTree.cpp:148
void intersectZAllignedRay(const G3D::Ray &ray, RayCallback &intersectCallback, float &max_dist)
Definition: RegularGrid.h:280

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
219{
220 float distance = maxDist;
222 impl->intersectRay(ray, callback, distance, endPos, false);
223 if (callback.didHit())
224 {
225 maxDist = distance;
226 }
227 return callback.didHit();
228}
void intersectRay(const G3D::Ray &ray, RayCallback &intersectCallback, float max_dist, bool stopAtFirstHit)
Definition: RegularGrid.h:177

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
233{
234 bool result = false;
235 float maxDist = (endPos - startPos).magnitude();
236 // valid map coords should *never ever* produce float overflow, but this would produce NaNs too
237 ASSERT(maxDist < std::numeric_limits<float>::max());
238 // prevent NaN values which can cause BIH intersection to enter infinite loop
239 if (maxDist < 1e-10f)
240 {
241 resultHit = endPos;
242 return false;
243 }
244 G3D::Vector3 dir = (endPos - startPos) / maxDist; // direction with length of 1
245 G3D::Ray ray(startPos, dir);
246 float dist = maxDist;
247 if (GetIntersectionTime(phasemask, ray, endPos, dist))
248 {
249 resultHit = startPos + dir * dist;
250 if (modifyDist < 0)
251 {
252 if ((resultHit - startPos).magnitude() > -modifyDist)
253 {
254 resultHit = resultHit + dir * modifyDist;
255 }
256 else
257 {
258 resultHit = startPos;
259 }
260 }
261 else
262 {
263 resultHit = resultHit + dir * modifyDist;
264 }
265
266 result = true;
267 }
268 else
269 {
270 resultHit = endPos;
271 result = false;
272 }
273 return result;
274}
#define ASSERT
Definition: Errors.h:68
bool GetIntersectionTime(uint32 phasemask, const G3D::Ray &ray, const G3D::Vector3 &endPos, float &maxDist) const
Definition: DynamicTree.cpp:218

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
277{
278 G3D::Vector3 v1(x1, y1, z1), v2(x2, y2, z2);
279
280 float maxDist = (v2 - v1).magnitude();
281
282 if (!G3D::fuzzyGt(maxDist, 0) )
283 {
284 return true;
285 }
286
287 G3D::Ray r(v1, (v2 - v1) / maxDist);
288 DynamicTreeIntersectionCallback callback(phasemask, ignoreFlags);
289 impl->intersectRay(r, callback, maxDist, v2, true);
290
291 return !callback.didHit();
292}

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

Referenced by Map::isInLineOfSight(), and MysticBuffetTargetFilter::operator()().

◆ 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:144

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