Skip to content

Commit b4d6ca2

Browse files
committed
Core/vmaps: Removed vmap lookup functions duplicating functionality of each other
(cherry picked from commit 45ee989c70682c001d4467d97bf1ecedcf7dbcc3)
1 parent 225a1bb commit b4d6ca2

File tree

23 files changed

+127
-323
lines changed

23 files changed

+127
-323
lines changed

src/common/Collision/DynamicTree.cpp

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -150,22 +150,6 @@ struct DynamicTreeIntersectionCallback
150150
bool didHit() const { return did_hit;}
151151
};
152152

153-
struct DynamicTreeAreaInfoCallback
154-
{
155-
DynamicTreeAreaInfoCallback(uint32 phaseMask) : _phaseMask(phaseMask) {}
156-
157-
void operator()(G3D::Vector3 const& p, GameObjectModel const& obj)
158-
{
159-
obj.intersectPoint(p, _areaInfo, _phaseMask);
160-
}
161-
162-
VMAP::AreaInfo const& GetAreaInfo() const { return _areaInfo; }
163-
164-
private:
165-
uint32 _phaseMask;
166-
VMAP::AreaInfo _areaInfo;
167-
};
168-
169153
struct DynamicTreeLocationInfoCallback
170154
{
171155
DynamicTreeLocationInfoCallback(uint32 phaseMask) : _phaseMask(phaseMask), _hitModel(nullptr) {}
@@ -265,24 +249,7 @@ float DynamicMapTree::getHeight(float x, float y, float z, float maxSearchDist,
265249
return -G3D::finf();
266250
}
267251

268-
bool DynamicMapTree::getAreaInfo(float x, float y, float& z, uint32 phasemask, uint32& flags, int32& adtId, int32& rootId, int32& groupId) const
269-
{
270-
G3D::Vector3 v(x, y, z + 0.5f);
271-
DynamicTreeAreaInfoCallback intersectionCallBack(phasemask);
272-
impl->intersectPoint(v, intersectionCallBack);
273-
if (intersectionCallBack.GetAreaInfo().result)
274-
{
275-
flags = intersectionCallBack.GetAreaInfo().flags;
276-
adtId = intersectionCallBack.GetAreaInfo().adtId;
277-
rootId = intersectionCallBack.GetAreaInfo().rootId;
278-
groupId = intersectionCallBack.GetAreaInfo().groupId;
279-
z = intersectionCallBack.GetAreaInfo().ground_Z;
280-
return true;
281-
}
282-
return false;
283-
}
284-
285-
void DynamicMapTree::getAreaAndLiquidData(float x, float y, float z, uint32 phasemask, uint8 reqLiquidType, VMAP::AreaAndLiquidData& data) const
252+
bool DynamicMapTree::getAreaAndLiquidData(float x, float y, float z, uint32 phasemask, Optional<uint8> reqLiquidType, VMAP::AreaAndLiquidData& data) const
286253
{
287254
G3D::Vector3 v(x, y, z + 0.5f);
288255
DynamicTreeLocationInfoCallback intersectionCallBack(phasemask);
@@ -292,13 +259,16 @@ void DynamicMapTree::getAreaAndLiquidData(float x, float y, float z, uint32 phas
292259
data.floorZ = intersectionCallBack.GetLocationInfo().ground_Z;
293260
uint32 liquidType = intersectionCallBack.GetLocationInfo().hitModel->GetLiquidType();
294261
float liquidLevel;
295-
if (!reqLiquidType || VMAP::VMapFactory::createOrGetVMapManager()->GetLiquidFlagsPtr(liquidType) & reqLiquidType)
262+
if (!reqLiquidType || VMAP::VMapFactory::createOrGetVMapManager()->GetLiquidFlagsPtr(liquidType) & *reqLiquidType)
296263
if (intersectionCallBack.GetHitModel()->GetLiquidLevel(v, intersectionCallBack.GetLocationInfo(), liquidLevel))
297264
data.liquidInfo.emplace(liquidType, liquidLevel);
298265

299-
data.areaInfo.emplace(0,
266+
data.areaInfo.emplace(intersectionCallBack.GetLocationInfo().hitModel->GetWmoID(),
267+
0,
300268
intersectionCallBack.GetLocationInfo().rootId,
301-
intersectionCallBack.GetLocationInfo().hitModel->GetWmoID(),
302-
intersectionCallBack.GetLocationInfo().hitModel->GetMogpFlags());
269+
intersectionCallBack.GetLocationInfo().hitModel->GetMogpFlags(),
270+
0);
271+
return true;
303272
}
273+
return false;
304274
}

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
{
@@ -48,8 +49,7 @@ class TC_COMMON_API DynamicMapTree
4849

4950
bool getIntersectionTime(uint32 phasemask, const G3D::Ray& ray,
5051
const G3D::Vector3& endPos, float& maxDist) const;
51-
bool getAreaInfo(float x, float y, float& z, uint32 phasemask, uint32& flags, int32& adtId, int32& rootId, int32& groupId) const;
52-
void getAreaAndLiquidData(float x, float y, float z, uint32 phasemask, uint8 reqLiquidType, VMAP::AreaAndLiquidData& data) const;
52+
bool getAreaAndLiquidData(float x, float y, float z, uint32 phasemask, Optional<uint8> reqLiquidType, VMAP::AreaAndLiquidData& data) const;
5353

5454
bool getObjectHitPos(uint32 phasemask, const G3D::Vector3& pPos1,
5555
const G3D::Vector3& pPos2, G3D::Vector3& pResultHitPos,

src/common/Collision/Management/IVMapManager.h

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,21 @@ namespace VMAP
5353
{
5454
struct AreaInfo
5555
{
56-
AreaInfo(int32 _adtId, int32 _rootId, int32 _groupId, uint32 _flags) : adtId(_adtId), rootId(_rootId), groupId(_groupId), mogpFlags(_flags) { }
57-
int32 const adtId;
58-
int32 const rootId;
59-
int32 const groupId;
60-
uint32 const mogpFlags;
56+
AreaInfo() = default;
57+
AreaInfo(int32 _groupId, int32 _adtId, int32 _rootId, uint32 _mogpFlags, uint32 _uniqueId)
58+
: groupId(_groupId), adtId(_adtId), rootId(_rootId), mogpFlags(_mogpFlags), uniqueId(_uniqueId) { }
59+
int32 groupId = 0;
60+
int32 adtId = 0;
61+
int32 rootId = 0;
62+
uint32 mogpFlags = 0;
63+
uint32 uniqueId = 0;
6164
};
6265
struct LiquidInfo
6366
{
67+
LiquidInfo() = default;
6468
LiquidInfo(uint32 _type, float _level) : type(_type), level(_level) { }
65-
uint32 const type;
66-
float const level;
69+
uint32 type = 0;
70+
float level = 0.0f;
6771
};
6872

6973
float floorZ = VMAP_INVALID_HEIGHT;
@@ -117,14 +121,12 @@ namespace VMAP
117121
bool isMapLoadingEnabled() const { return(iEnableLineOfSightCalc || iEnableHeightCalc ); }
118122

119123
virtual std::string getDirFileName(unsigned int pMapId, int x, int y) const =0;
124+
120125
/**
121126
Query world model area info.
122127
\param z gets adjusted to the ground height for which this are info is valid
123128
*/
124-
virtual bool getAreaInfo(uint32 mapId, float x, float y, float &z, uint32 &flags, int32 &adtId, int32 &rootId, int32 &groupId) const=0;
125-
virtual bool GetLiquidLevel(uint32 mapId, float x, float y, float z, uint8 reqLiquidType, float& level, float& floor, uint32& type, uint32& mogpFlags) const=0;
126-
// get both area + liquid data in a single vmap lookup
127-
virtual void getAreaAndLiquidData(unsigned int mapId, float x, float y, float z, uint8 reqLiquidType, AreaAndLiquidData& data) const=0;
129+
virtual bool getAreaAndLiquidData(unsigned int mapId, float x, float y, float z, Optional<uint8> reqLiquidType, AreaAndLiquidData& data) const = 0;
128130
};
129131

130132
}

src/common/Collision/Management/VMapManager2.cpp

Lines changed: 14 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -233,63 +233,8 @@ namespace VMAP
233233
return VMAP_INVALID_HEIGHT_VALUE;
234234
}
235235

236-
bool VMapManager2::getAreaInfo(uint32 mapId, float x, float y, float& z, uint32& flags, int32& adtId, int32& rootId, int32& groupId) const
236+
bool VMapManager2::getAreaAndLiquidData(unsigned int mapId, float x, float y, float z, Optional<uint8> reqLiquidType, AreaAndLiquidData& data) const
237237
{
238-
if (!IsVMAPDisabledForPtr(mapId, VMAP_DISABLE_AREAFLAG))
239-
{
240-
InstanceTreeMap::const_iterator instanceTree = GetMapTree(mapId);
241-
if (instanceTree != iInstanceMapTrees.end())
242-
{
243-
Vector3 pos = convertPositionToInternalRep(x, y, z);
244-
bool result = instanceTree->second->getAreaInfo(pos, flags, adtId, rootId, groupId);
245-
// z is not touched by convertPositionToInternalRep(), so just copy
246-
z = pos.z;
247-
return result;
248-
}
249-
}
250-
251-
return false;
252-
}
253-
254-
bool VMapManager2::GetLiquidLevel(uint32 mapId, float x, float y, float z, uint8 reqLiquidType, float& level, float& floor, uint32& type, uint32& mogpFlags) const
255-
{
256-
if (!IsVMAPDisabledForPtr(mapId, VMAP_DISABLE_LIQUIDSTATUS))
257-
{
258-
InstanceTreeMap::const_iterator instanceTree = GetMapTree(mapId);
259-
if (instanceTree != iInstanceMapTrees.end())
260-
{
261-
LocationInfo info;
262-
Vector3 pos = convertPositionToInternalRep(x, y, z);
263-
if (instanceTree->second->GetLocationInfo(pos, info))
264-
{
265-
floor = info.ground_Z;
266-
ASSERT(floor < std::numeric_limits<float>::max());
267-
ASSERT(info.hitModel);
268-
type = info.hitModel->GetLiquidType(); // entry from LiquidType.dbc
269-
mogpFlags = info.hitModel->GetMogpFlags();
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-
}
281-
282-
void VMapManager2::getAreaAndLiquidData(unsigned int mapId, float x, float y, float z, uint8 reqLiquidType, AreaAndLiquidData& data) const
283-
{
284-
if (IsVMAPDisabledForPtr(mapId, VMAP_DISABLE_LIQUIDSTATUS))
285-
{
286-
data.floorZ = z;
287-
int32 adtId, rootId, groupId;
288-
uint32 flags;
289-
if (getAreaInfo(mapId, x, y, data.floorZ, flags, adtId, rootId, groupId))
290-
data.areaInfo.emplace(adtId, rootId, groupId, flags);
291-
return;
292-
}
293238
InstanceTreeMap::const_iterator instanceTree = GetMapTree(mapId);
294239
if (instanceTree != iInstanceMapTrees.end())
295240
{
@@ -300,16 +245,23 @@ namespace VMAP
300245
ASSERT(info.hitModel);
301246
ASSERT(info.hitInstance);
302247
data.floorZ = info.ground_Z;
303-
uint32 liquidType = info.hitModel->GetLiquidType();
304-
float liquidLevel;
305-
if (!reqLiquidType || (GetLiquidFlagsPtr(liquidType) & reqLiquidType))
306-
if (info.hitInstance->GetLiquidLevel(pos, info, liquidLevel))
307-
data.liquidInfo.emplace(liquidType, liquidLevel);
248+
if (!IsVMAPDisabledForPtr(mapId, VMAP_DISABLE_LIQUIDSTATUS))
249+
{
250+
uint32 liquidType = info.hitModel->GetLiquidType(); // entry from LiquidType.dbc
251+
float liquidLevel;
252+
if (!reqLiquidType || (GetLiquidFlagsPtr(liquidType) & *reqLiquidType))
253+
if (info.hitInstance->GetLiquidLevel(pos, info, liquidLevel))
254+
data.liquidInfo.emplace(liquidType, liquidLevel);
255+
}
308256

309257
if (!IsVMAPDisabledForPtr(mapId, VMAP_DISABLE_AREAFLAG))
310-
data.areaInfo.emplace(info.hitInstance->adtId, info.rootId, info.hitModel->GetWmoID(), info.hitModel->GetMogpFlags());
258+
data.areaInfo.emplace(info.hitModel->GetWmoID(), info.hitInstance->adtId, info.rootId, info.hitModel->GetMogpFlags(), info.hitInstance->ID);
259+
260+
return true;
311261
}
312262
}
263+
264+
return false;
313265
}
314266

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

src/common/Collision/Management/VMapManager2.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 mapId, float x, float y, float& z, uint32& flags, int32& adtId, int32& rootId, int32& groupId) const override;
119-
bool GetLiquidLevel(uint32 mapId, 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 = 0);
123121
void releaseModelInstance(const std::string& filename);

src/common/Collision/Maps/MapDefines.h

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

2121
#include "Define.h"
22-
#include "DetourNavMesh.h"
22+
#include "Optional.h"
23+
#include <DetourNavMesh.h>
2324

2425
const uint32 MMAP_MAGIC = 0x4d4d4150; // 'MMAP'
2526
#define MMAP_VERSION 15
@@ -69,4 +70,47 @@ enum NavTerrainFlag
6970
NAV_MAGMA_SLIME = 1 << (NAV_AREA_MAX_VALUE - NAV_AREA_MAGMA_SLIME)
7071
};
7172

72-
#endif /* _MAPDEFINES_H */
73+
enum ZLiquidStatus : uint32
74+
{
75+
LIQUID_MAP_NO_WATER = 0x00000000,
76+
LIQUID_MAP_ABOVE_WATER = 0x00000001,
77+
LIQUID_MAP_WATER_WALK = 0x00000002,
78+
LIQUID_MAP_IN_WATER = 0x00000004,
79+
LIQUID_MAP_UNDER_WATER = 0x00000008,
80+
};
81+
82+
#define MAP_LIQUID_STATUS_SWIMMING (LIQUID_MAP_IN_WATER | LIQUID_MAP_UNDER_WATER)
83+
#define MAP_LIQUID_STATUS_IN_CONTACT (MAP_LIQUID_STATUS_SWIMMING | LIQUID_MAP_WATER_WALK)
84+
85+
struct LiquidData
86+
{
87+
uint32 type_flags;
88+
uint32 entry;
89+
float level;
90+
float depth_level;
91+
};
92+
93+
struct WmoLocation
94+
{
95+
WmoLocation() = default;
96+
WmoLocation(int32 groupId, int32 nameSetId, int32 rootId, uint32 uniqueId)
97+
: GroupId(groupId), NameSetId(nameSetId), RootId(rootId), UniqueId(uniqueId) { }
98+
99+
int32 GroupId = 0;
100+
int32 NameSetId = 0;
101+
int32 RootId = 0;
102+
uint32 UniqueId = 0;
103+
};
104+
105+
struct PositionFullTerrainStatus
106+
{
107+
PositionFullTerrainStatus() : areaId(0), floorZ(0.0f), outdoors(true), liquidStatus(LIQUID_MAP_NO_WATER) { }
108+
uint32 areaId;
109+
float floorZ;
110+
bool outdoors;
111+
ZLiquidStatus liquidStatus;
112+
Optional<WmoLocation> wmoLocation;
113+
Optional<LiquidData> liquidInfo;
114+
};
115+
116+
#endif // _MAPDEFINES_H

src/common/Collision/Maps/MapTree.cpp

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,6 @@ namespace VMAP
5050
ModelIgnoreFlags flags;
5151
};
5252

53-
class AreaInfoCallback
54-
{
55-
public:
56-
AreaInfoCallback(ModelInstance* val): prims(val) { }
57-
void operator()(Vector3 const& point, uint32 entry)
58-
{
59-
#ifdef VMAP_DEBUG
60-
TC_LOG_DEBUG("maps", "AreaInfoCallback: trying to intersect '{}'", prims[entry].name);
61-
#endif
62-
prims[entry].intersectPoint(point, aInfo);
63-
}
64-
65-
ModelInstance* prims;
66-
AreaInfo aInfo;
67-
};
68-
6953
class LocationInfoCallback
7054
{
7155
public:
@@ -96,22 +80,6 @@ namespace VMAP
9680
return tilefilename.str();
9781
}
9882

99-
bool StaticMapTree::getAreaInfo(Vector3 &pos, uint32 &flags, int32 &adtId, int32 &rootId, int32 &groupId) const
100-
{
101-
AreaInfoCallback intersectionCallBack(iTreeValues);
102-
iTree.intersectPoint(pos, intersectionCallBack);
103-
if (intersectionCallBack.aInfo.result)
104-
{
105-
flags = intersectionCallBack.aInfo.flags;
106-
adtId = intersectionCallBack.aInfo.adtId;
107-
rootId = intersectionCallBack.aInfo.rootId;
108-
groupId = intersectionCallBack.aInfo.groupId;
109-
pos.z = intersectionCallBack.aInfo.ground_Z;
110-
return true;
111-
}
112-
return false;
113-
}
114-
11583
bool StaticMapTree::GetLocationInfo(Vector3 const& pos, LocationInfo &info) const
11684
{
11785
LocationInfoCallback intersectionCallBack(iTreeValues, info);

src/common/Collision/Maps/MapTree.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ namespace VMAP
7979
bool isInLineOfSight(const G3D::Vector3& pos1, const G3D::Vector3& pos2, ModelIgnoreFlags ignoreFlags) const;
8080
bool getObjectHitPos(const G3D::Vector3& pos1, const G3D::Vector3& pos2, G3D::Vector3& pResultHitPos, float pModifyDist) const;
8181
float getHeight(const G3D::Vector3& pPos, float maxSearchDist) const;
82-
bool getAreaInfo(G3D::Vector3 &pos, uint32 &flags, int32 &adtId, int32 &rootId, int32 &groupId) const;
8382
bool GetLocationInfo(const G3D::Vector3 &pos, LocationInfo &info) const;
8483

8584
bool InitMap(const std::string &fname, VMapManager2* vm);

src/common/Collision/Models/GameObjectModel.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -183,27 +183,6 @@ bool GameObjectModel::intersectRay(const G3D::Ray& ray, float& MaxDist, bool Sto
183183
return hit;
184184
}
185185

186-
void GameObjectModel::intersectPoint(G3D::Vector3 const& point, VMAP::AreaInfo& info, uint32 ph_mask) const
187-
{
188-
if (!(phasemask & ph_mask) || !owner->IsSpawned() || !isMapObject())
189-
return;
190-
191-
if (!iBound.contains(point))
192-
return;
193-
194-
// child bounds are defined in object space:
195-
Vector3 pModel = iInvRot * (point - iPos) * iInvScale;
196-
Vector3 zDirModel = iInvRot * Vector3(0.f, 0.f, -1.f);
197-
float zDist;
198-
if (iModel->IntersectPoint(pModel, zDirModel, zDist, info))
199-
{
200-
Vector3 modelGround = pModel + zDist * zDirModel;
201-
float world_Z = ((modelGround * iInvRot) * iScale + iPos).z;
202-
if (info.ground_Z < world_Z)
203-
info.ground_Z = world_Z;
204-
}
205-
}
206-
207186
bool GameObjectModel::GetLocationInfo(G3D::Vector3 const& point, VMAP::LocationInfo& info, uint32 ph_mask) const
208187
{
209188
if (!(phasemask & ph_mask) || !owner->IsSpawned() || !isMapObject())

src/common/Collision/Models/GameObjectModel.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ class TC_COMMON_API GameObjectModel /*, public Intersectable*/
7171
bool isMapObject() const { return isWmo; }
7272

7373
bool intersectRay(const G3D::Ray& Ray, float& MaxDist, bool StopAtFirstHit, uint32 ph_mask, VMAP::ModelIgnoreFlags ignoreFlags) const;
74-
void intersectPoint(G3D::Vector3 const& point, VMAP::AreaInfo& info, uint32 ph_mask) const;
7574
bool GetLocationInfo(G3D::Vector3 const& point, VMAP::LocationInfo& info, uint32 ph_mask) const;
7675
bool GetLiquidLevel(G3D::Vector3 const& point, VMAP::LocationInfo& info, float& liqHeight) const;
7776

0 commit comments

Comments
 (0)