Skip to content

Commit 6015530

Browse files
committed
Merge azerothcore PR azerothcore#23233 for testing
2 parents ee74e46 + 297d0cd commit 6015530

File tree

21 files changed

+165
-335
lines changed

21 files changed

+165
-335
lines changed

src/common/Collision/BoundingIntervalHierarchy.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class BIH
7070
{
7171
tree.clear();
7272
objects.clear();
73+
bounds = G3D::AABox::empty();
7374
// create space for the first node
7475
tree.push_back(3u << 30u); // dummy leaf
7576
tree.insert(tree.end(), 2, 0);
@@ -116,6 +117,7 @@ class BIH
116117
delete[] dat.indices;
117118
}
118119
[[nodiscard]] uint32 primCount() const { return objects.size(); }
120+
G3D::AABox const& bound() const { return bounds; }
119121

120122
template<typename RayCallback>
121123
void intersectRay(const G3D::Ray& r, RayCallback& intersectCallback, float& maxDist, bool stopAtFirstHit) const

src/common/Collision/DynamicTree.cpp

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -170,25 +170,6 @@ struct DynamicTreeIntersectionCallback
170170
VMAP::ModelIgnoreFlags _ignoreFlags;
171171
};
172172

173-
struct DynamicTreeAreaInfoCallback
174-
{
175-
DynamicTreeAreaInfoCallback(uint32 phaseMask) : _phaseMask(phaseMask) { }
176-
177-
void operator()(G3D::Vector3 const& p, GameObjectModel const& obj)
178-
{
179-
obj.IntersectPoint(p, _areaInfo, _phaseMask);
180-
}
181-
182-
VMAP::AreaInfo const& GetAreaInfo() const
183-
{
184-
return _areaInfo;
185-
}
186-
187-
private:
188-
uint32 _phaseMask;
189-
VMAP::AreaInfo _areaInfo;
190-
};
191-
192173
struct DynamicTreeLocationInfoCallback
193174
{
194175
DynamicTreeLocationInfoCallback(uint32 phaseMask)
@@ -308,24 +289,7 @@ float DynamicMapTree::getHeight(float x, float y, float z, float maxSearchDist,
308289
}
309290
}
310291

311-
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-
}
327-
328-
void DynamicMapTree::GetAreaAndLiquidData(float x, float y, float z, uint32 phasemask, uint8 reqLiquidType, VMAP::AreaAndLiquidData& data) const
292+
bool DynamicMapTree::GetAreaAndLiquidData(float x, float y, float z, uint32 phasemask, Optional<uint8> reqLiquidType, VMAP::AreaAndLiquidData& data) const
329293
{
330294
G3D::Vector3 v(x, y, z + 0.5f);
331295
DynamicTreeLocationInfoCallback intersectionCallBack(phasemask);
@@ -335,13 +299,16 @@ void DynamicMapTree::GetAreaAndLiquidData(float x, float y, float z, uint32 phas
335299
data.floorZ = intersectionCallBack.GetLocationInfo().ground_Z;
336300
uint32 liquidType = intersectionCallBack.GetLocationInfo().hitModel->GetLiquidType();
337301
float liquidLevel;
338-
if (!reqLiquidType || (dynamic_cast<VMAP::VMapMgr2*>(VMAP::VMapFactory::createOrGetVMapMgr())->GetLiquidFlagsPtr(liquidType) & reqLiquidType))
302+
if (!reqLiquidType || (dynamic_cast<VMAP::VMapMgr2*>(VMAP::VMapFactory::createOrGetVMapMgr())->GetLiquidFlagsPtr(liquidType) & *reqLiquidType))
339303
if (intersectionCallBack.GetHitModel()->GetLiquidLevel(v, intersectionCallBack.GetLocationInfo(), liquidLevel))
340304
data.liquidInfo.emplace(liquidType, liquidLevel);
341305

342-
data.areaInfo.emplace(0,
306+
data.areaInfo.emplace(intersectionCallBack.GetLocationInfo().hitModel->GetWmoID(),
307+
0,
343308
intersectionCallBack.GetLocationInfo().rootId,
344-
intersectionCallBack.GetLocationInfo().hitModel->GetWmoID(),
345-
intersectionCallBack.GetLocationInfo().hitModel->GetMogpFlags());
309+
intersectionCallBack.GetLocationInfo().hitModel->GetMogpFlags(),
310+
0);
311+
return true;
346312
}
313+
return false;
347314
}

src/common/Collision/DynamicTree.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#define _DYNTREE_H
2020

2121
#include "Define.h"
22+
#include "Optional.h"
2223

2324
namespace G3D
2425
{
@@ -47,8 +48,7 @@ class DynamicMapTree
4748

4849
bool GetIntersectionTime(uint32 phasemask, const G3D::Ray& ray, const G3D::Vector3& endPos, float& maxDist) const;
4950

50-
bool GetAreaInfo(float x, float y, float& z, uint32 phasemask, uint32& flags, int32& adtId, int32& rootId, int32& groupId) const;
51-
void GetAreaAndLiquidData(float x, float y, float z, uint32 phasemask, uint8 reqLiquidType, VMAP::AreaAndLiquidData& data) const;
51+
bool GetAreaAndLiquidData(float x, float y, float z, uint32 phasemask, Optional<uint8> reqLiquidType, VMAP::AreaAndLiquidData& data) const;
5252

5353
bool GetObjectHitPos(uint32 phasemask, const G3D::Vector3& pPos1,
5454
const G3D::Vector3& pPos2, G3D::Vector3& pResultHitPos,

src/common/Collision/Management/IVMapMgr.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,23 @@ namespace VMAP
5252
{
5353
struct AreaInfo
5454
{
55-
AreaInfo(int32 _adtId, int32 _rootId, int32 _groupId, uint32 _flags)
56-
: adtId(_adtId), rootId(_rootId), groupId(_groupId), mogpFlags(_flags) { }
57-
int32 const adtId;
58-
int32 const rootId;
59-
int32 const groupId;
60-
uint32 const mogpFlags;
55+
AreaInfo() = default;
56+
AreaInfo(int32 _groupId, int32 _adtId, int32 _rootId, uint32 _mogpFlags, uint32 _uniqueId)
57+
: groupId(_groupId), adtId(_adtId), rootId(_rootId), mogpFlags(_mogpFlags), uniqueId(_uniqueId) { }
58+
int32 groupId = 0;
59+
int32 adtId = 0;
60+
int32 rootId = 0;
61+
uint32 mogpFlags = 0;
62+
uint32 uniqueId = 0;
6163
};
6264

6365
struct LiquidInfo
6466
{
67+
LiquidInfo() = default;
6568
LiquidInfo(uint32 _type, float _level)
6669
: type(_type), level(_level) {}
67-
uint32 const type;
68-
float const level;
70+
uint32 type = 0;
71+
float level = 0.0f;
6972
};
7073

7174
float floorZ = VMAP_INVALID_HEIGHT;
@@ -120,14 +123,12 @@ namespace VMAP
120123
[[nodiscard]] bool isMapLoadingEnabled() const { return (iEnableLineOfSightCalc || iEnableHeightCalc ); }
121124

122125
[[nodiscard]] virtual std::string getDirFileName(unsigned int pMapId, int x, int y) const = 0;
126+
123127
/**
124128
Query world model area info.
125129
\param z gets adjusted to the ground height for which this are info is valid
126130
*/
127-
virtual bool GetAreaInfo(uint32 pMapId, float x, float y, float& z, uint32& flags, int32& adtId, int32& rootId, int32& groupId) const = 0;
128-
virtual bool GetLiquidLevel(uint32 pMapId, float x, float y, float z, uint8 ReqLiquidType, float& level, float& floor, uint32& type, uint32& mogpFlags) const = 0;
129-
// get both area + liquid data in a single vmap lookup
130-
virtual void GetAreaAndLiquidData(uint32 mapId, float x, float y, float z, uint8 reqLiquidType, AreaAndLiquidData& data) const = 0;
131+
virtual bool GetAreaAndLiquidData(uint32 mapId, float x, float y, float z, Optional<uint8> reqLiquidType, AreaAndLiquidData& data) const = 0;
131132
};
132133
}
133134

src/common/Collision/Management/VMapMgr2.cpp

Lines changed: 13 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -253,70 +253,8 @@ namespace VMAP
253253
return VMAP_INVALID_HEIGHT_VALUE;
254254
}
255255

256-
bool VMapMgr2::GetAreaInfo(uint32 mapId, float x, float y, float& z, uint32& flags, int32& adtId, int32& rootId, int32& groupId) const
256+
bool VMapMgr2::GetAreaAndLiquidData(uint32 mapId, float x, float y, float z, Optional<uint8> reqLiquidType, AreaAndLiquidData& data) const
257257
{
258-
#if defined(ENABLE_VMAP_CHECKS)
259-
if (!IsVMAPDisabledForPtr(mapId, VMAP_DISABLE_AREAFLAG))
260-
#endif
261-
{
262-
InstanceTreeMap::const_iterator instanceTree = GetMapTree(mapId);
263-
if (instanceTree != iInstanceMapTrees.end())
264-
{
265-
Vector3 pos = convertPositionToInternalRep(x, y, z);
266-
bool result = instanceTree->second->GetAreaInfo(pos, flags, adtId, rootId, groupId);
267-
// z is not touched by convertPositionToInternalRep(), so just copy
268-
z = pos.z;
269-
return result;
270-
}
271-
}
272-
273-
return false;
274-
}
275-
276-
bool VMapMgr2::GetLiquidLevel(uint32 mapId, float x, float y, float z, uint8 reqLiquidType, float& level, float& floor, uint32& type, uint32& mogpFlags) const
277-
{
278-
#if defined(ENABLE_VMAP_CHECKS)
279-
if (!IsVMAPDisabledForPtr(mapId, VMAP_DISABLE_LIQUIDSTATUS))
280-
#endif
281-
{
282-
InstanceTreeMap::const_iterator instanceTree = GetMapTree(mapId);
283-
if (instanceTree != iInstanceMapTrees.end())
284-
{
285-
LocationInfo info;
286-
Vector3 pos = convertPositionToInternalRep(x, y, z);
287-
if (instanceTree->second->GetLocationInfo(pos, info))
288-
{
289-
floor = info.ground_Z;
290-
ASSERT(floor < std::numeric_limits<float>::max());
291-
type = info.hitModel->GetLiquidType(); // entry from LiquidType.dbc
292-
mogpFlags = info.hitModel->GetMogpFlags();
293-
if (reqLiquidType && !(GetLiquidFlagsPtr(type) & reqLiquidType))
294-
{
295-
return false;
296-
}
297-
if (info.hitInstance->GetLiquidLevel(pos, info, level))
298-
{
299-
return true;
300-
}
301-
}
302-
}
303-
}
304-
305-
return false;
306-
}
307-
308-
void VMapMgr2::GetAreaAndLiquidData(uint32 mapId, float x, float y, float z, uint8 reqLiquidType, AreaAndLiquidData& data) const
309-
{
310-
if (IsVMAPDisabledForPtr(mapId, VMAP_DISABLE_LIQUIDSTATUS))
311-
{
312-
data.floorZ = z;
313-
int32 adtId, rootId, groupId;
314-
uint32 flags;
315-
if (GetAreaInfo(mapId, x, y, data.floorZ, flags, adtId, rootId, groupId))
316-
data.areaInfo.emplace(adtId, rootId, groupId, flags);
317-
return;
318-
}
319-
320258
InstanceTreeMap::const_iterator instanceTree = GetMapTree(mapId);
321259
if (instanceTree != iInstanceMapTrees.end())
322260
{
@@ -325,16 +263,22 @@ namespace VMAP
325263
if (instanceTree->second->GetLocationInfo(pos, info))
326264
{
327265
data.floorZ = info.ground_Z;
328-
uint32 liquidType = info.hitModel->GetLiquidType();
329-
float liquidLevel;
330-
if (!reqLiquidType || (GetLiquidFlagsPtr(liquidType) & reqLiquidType))
331-
if (info.hitInstance->GetLiquidLevel(pos, info, liquidLevel))
332-
data.liquidInfo.emplace(liquidType, liquidLevel);
266+
if (!IsVMAPDisabledForPtr(mapId, VMAP_DISABLE_LIQUIDSTATUS))
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+
}
333274

334275
if (!IsVMAPDisabledForPtr(mapId, VMAP_DISABLE_AREAFLAG))
335-
data.areaInfo.emplace(info.hitInstance->adtId, info.rootId, info.hitModel->GetWmoID(), info.hitModel->GetMogpFlags());
276+
data.areaInfo.emplace(info.hitModel->GetWmoID(), info.hitInstance->adtId, info.rootId, info.hitModel->GetMogpFlags(), info.hitInstance->ID);
277+
return true;
336278
}
337279
}
280+
281+
return false;
338282
}
339283

340284
WorldModel* VMapMgr2::acquireModelInstance(const std::string& basepath, const std::string& filename, uint32 flags/* Only used when creating the model */)

src/common/Collision/Management/VMapMgr2.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ namespace VMAP
115115

116116
bool processCommand(char* /*command*/) override { return false; } // for debug and extensions
117117

118-
bool GetAreaInfo(uint32 pMapId, float x, float y, float& z, uint32& flags, int32& adtId, int32& rootId, int32& groupId) const override;
119-
bool GetLiquidLevel(uint32 pMapId, float x, float y, float z, uint8 reqLiquidType, float& level, float& floor, uint32& type, uint32& mogpFlags) const override;
120-
void GetAreaAndLiquidData(uint32 mapId, float x, float y, float z, uint8 reqLiquidType, AreaAndLiquidData& data) const override;
118+
bool GetAreaAndLiquidData(uint32 mapId, float x, float y, float z, Optional<uint8> reqLiquidType, AreaAndLiquidData& data) const override;
121119

122120
WorldModel* acquireModelInstance(const std::string& basepath, const std::string& filename, uint32 flags);
123121
void releaseModelInstance(const std::string& filename);

src/common/Collision/Maps/MapTree.cpp

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,6 @@ namespace VMAP
5151
bool hit;
5252
};
5353

54-
class AreaInfoCallback
55-
{
56-
public:
57-
AreaInfoCallback(ModelInstance* val): prims(val) {}
58-
void operator()(const Vector3& point, uint32 entry)
59-
{
60-
#if defined(VMAP_DEBUG)
61-
LOG_DEBUG("maps", "AreaInfoCallback: trying to intersect '{}'", prims[entry].name);
62-
#endif
63-
prims[entry].intersectPoint(point, aInfo);
64-
}
65-
66-
ModelInstance* prims;
67-
AreaInfo aInfo;
68-
};
69-
7054
class LocationInfoCallback
7155
{
7256
public:
@@ -99,22 +83,6 @@ namespace VMAP
9983
return tilefilename.str();
10084
}
10185

102-
bool StaticMapTree::GetAreaInfo(Vector3& pos, uint32& flags, int32& adtId, int32& rootId, int32& groupId) const
103-
{
104-
AreaInfoCallback intersectionCallBack(iTreeValues);
105-
iTree.intersectPoint(pos, intersectionCallBack);
106-
if (intersectionCallBack.aInfo.result)
107-
{
108-
flags = intersectionCallBack.aInfo.flags;
109-
adtId = intersectionCallBack.aInfo.adtId;
110-
rootId = intersectionCallBack.aInfo.rootId;
111-
groupId = intersectionCallBack.aInfo.groupId;
112-
pos.z = intersectionCallBack.aInfo.ground_Z;
113-
return true;
114-
}
115-
return false;
116-
}
117-
11886
bool StaticMapTree::GetLocationInfo(const Vector3& pos, LocationInfo& info) const
11987
{
12088
LocationInfoCallback intersectionCallBack(iTreeValues, info);

src/common/Collision/Maps/MapTree.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ namespace VMAP
3030
enum class ModelIgnoreFlags : uint32;
3131
enum class LoadResult : uint8;
3232

33+
struct GroupLocationInfo
34+
{
35+
const GroupModel* hitModel = nullptr;
36+
int32 rootId = -1;
37+
};
38+
3339
struct LocationInfo
3440
{
3541
LocationInfo(): ground_Z(-G3D::inf()) { }
@@ -73,7 +79,6 @@ namespace VMAP
7379
[[nodiscard]] bool isInLineOfSight(const G3D::Vector3& pos1, const G3D::Vector3& pos2, ModelIgnoreFlags ignoreFlags) const;
7480
bool GetObjectHitPos(const G3D::Vector3& pos1, const G3D::Vector3& pos2, G3D::Vector3& pResultHitPos, float pModifyDist) const;
7581
[[nodiscard]] float getHeight(const G3D::Vector3& pPos, float maxSearchDist) const;
76-
bool GetAreaInfo(G3D::Vector3& pos, uint32& flags, int32& adtId, int32& rootId, int32& groupId) const;
7782
bool GetLocationInfo(const G3D::Vector3& pos, LocationInfo& info) const;
7883

7984
bool InitMap(const std::string& fname, VMapMgr2* vm);

src/common/Collision/Models/GameObjectModel.cpp

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -203,27 +203,6 @@ bool GameObjectModel::intersectRay(const G3D::Ray& ray, float& MaxDist, bool Sto
203203
return hit;
204204
}
205205

206-
void GameObjectModel::IntersectPoint(G3D::Vector3 const& point, VMAP::AreaInfo& info, uint32 ph_mask) const
207-
{
208-
if (!(phasemask & ph_mask) || !owner->IsSpawned() || !IsMapObject())
209-
return;
210-
211-
if (!iBound.contains(point))
212-
return;
213-
214-
// child bounds are defined in object space:
215-
Vector3 pModel = iInvRot * (point - iPos) * iInvScale;
216-
Vector3 zDirModel = iInvRot * Vector3(0.f, 0.f, -1.f);
217-
float zDist;
218-
if (iModel->IntersectPoint(pModel, zDirModel, zDist, info))
219-
{
220-
Vector3 modelGround = pModel + zDist * zDirModel;
221-
float world_Z = ((modelGround * iInvRot) * iScale + iPos).z;
222-
if (info.ground_Z < world_Z)
223-
info.ground_Z = world_Z;
224-
}
225-
}
226-
227206
bool GameObjectModel::GetLocationInfo(G3D::Vector3 const& point, VMAP::LocationInfo& info, uint32 ph_mask) const
228207
{
229208
if (!(phasemask & ph_mask) || !owner->IsSpawned() || !IsMapObject())
@@ -236,7 +215,9 @@ bool GameObjectModel::GetLocationInfo(G3D::Vector3 const& point, VMAP::LocationI
236215
Vector3 pModel = iInvRot * (point - iPos) * iInvScale;
237216
Vector3 zDirModel = iInvRot * Vector3(0.f, 0.f, -1.f);
238217
float zDist;
239-
if (iModel->GetLocationInfo(pModel, zDirModel, zDist, info))
218+
219+
VMAP::GroupLocationInfo groupInfo;
220+
if (iModel->GetLocationInfo(pModel, zDirModel, zDist, groupInfo))
240221
{
241222
Vector3 modelGround = pModel + zDist * zDirModel;
242223
float world_Z = ((modelGround * iInvRot) * iScale + iPos).z;

src/common/Collision/Models/GameObjectModel.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ class GameObjectModel
7070
[[nodiscard]] bool IsMapObject() const { return isWmo; }
7171

7272
bool intersectRay(const G3D::Ray& Ray, float& MaxDist, bool StopAtFirstHit, uint32 ph_mask, VMAP::ModelIgnoreFlags ignoreFlags) const;
73-
void IntersectPoint(G3D::Vector3 const& point, VMAP::AreaInfo& info, uint32 ph_mask) const;
7473
bool GetLocationInfo(G3D::Vector3 const& point, VMAP::LocationInfo& info, uint32 ph_mask) const;
7574
bool GetLiquidLevel(G3D::Vector3 const& point, VMAP::LocationInfo& info, float& liqHeight) const;
7675

0 commit comments

Comments
 (0)