Skip to content

Commit e3680a0

Browse files
XenphisShaurenclaude
committed
Core/Maps: Move terrain data handling out of Map class
Co-Authored-By: Shauren <shauren.trinity@gmail.com> Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent e213a92 commit e3680a0

29 files changed

Lines changed: 1788 additions & 1490 deletions

File tree

src/common/Collision/Management/IVMapManager.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,13 @@ This is the minimum interface to the VMapMamager.
3131

3232
namespace VMAP
3333
{
34-
35-
enum VMAP_LOAD_RESULT
36-
{
37-
VMAP_LOAD_RESULT_ERROR,
38-
VMAP_LOAD_RESULT_OK,
39-
VMAP_LOAD_RESULT_IGNORED
40-
};
41-
4234
enum class LoadResult : uint8
4335
{
4436
Success,
4537
FileNotFound,
46-
VersionMismatch
38+
VersionMismatch,
39+
ReadFromFileFailed,
40+
DisabledInConfig
4741
};
4842

4943
#define VMAP_INVALID_HEIGHT -100000.0f // for check
@@ -86,7 +80,7 @@ namespace VMAP
8680

8781
virtual ~IVMapManager(void) { }
8882

89-
virtual int loadMap(char const* pBasePath, unsigned int pMapId, int x, int y) = 0;
83+
virtual LoadResult loadMap(char const* pBasePath, unsigned int pMapId, int x, int y) = 0;
9084

9185
virtual LoadResult existsMap(char const* pBasePath, unsigned int pMapId, int x, int y) = 0;
9286

src/common/Collision/Management/VMapManager2.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,12 @@ namespace VMAP
8181
return fname.str();
8282
}
8383

84-
int VMapManager2::loadMap(char const* basePath, unsigned int mapId, int x, int y)
84+
LoadResult VMapManager2::loadMap(char const* basePath, unsigned int mapId, int x, int y)
8585
{
86-
int result = VMAP_LOAD_RESULT_IGNORED;
87-
if (isMapLoadingEnabled())
88-
{
89-
if (_loadMap(mapId, basePath, x, y))
90-
result = VMAP_LOAD_RESULT_OK;
91-
else
92-
result = VMAP_LOAD_RESULT_ERROR;
93-
}
86+
if (!isMapLoadingEnabled())
87+
return LoadResult::DisabledInConfig;
9488

95-
return result;
89+
return _loadMap(mapId, basePath, x, y) ? LoadResult::Success : LoadResult::ReadFromFileFailed;
9690
}
9791

9892
InstanceTreeMap::const_iterator VMapManager2::GetMapTree(uint32 mapId) const

src/common/Collision/Management/VMapManager2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ namespace VMAP
101101
~VMapManager2(void);
102102

103103
void InitializeThreadUnsafe(const std::vector<uint32>& mapIds);
104-
int loadMap(char const* pBasePath, unsigned int mapId, int x, int y) override;
104+
LoadResult loadMap(char const* pBasePath, unsigned int mapId, int x, int y) override;
105105

106106
void unloadMap(unsigned int mapId, int x, int y) override;
107107
void unloadMap(unsigned int mapId) override;

src/common/Collision/Maps/MMapDefines.h

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

2121
#include "Define.h"
22-
#include "MapDefines.h"
2322
#include "Optional.h"
2423
#include <DetourNavMesh.h>
2524

@@ -71,47 +70,4 @@ enum NavTerrainFlag
7170
NAV_MAGMA_SLIME = 1 << (NAV_AREA_MAX_VALUE - NAV_AREA_MAGMA_SLIME)
7271
};
7372

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

src/common/Collision/Maps/MapDefines.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,47 @@ struct map_liquidHeader
120120
float liquidLevel;
121121
};
122122

123+
enum ZLiquidStatus : uint32
124+
{
125+
LIQUID_MAP_NO_WATER = 0x00000000,
126+
LIQUID_MAP_ABOVE_WATER = 0x00000001,
127+
LIQUID_MAP_WATER_WALK = 0x00000002,
128+
LIQUID_MAP_IN_WATER = 0x00000004,
129+
LIQUID_MAP_UNDER_WATER = 0x00000008,
130+
};
131+
132+
#define MAP_LIQUID_STATUS_SWIMMING (LIQUID_MAP_IN_WATER | LIQUID_MAP_UNDER_WATER)
133+
#define MAP_LIQUID_STATUS_IN_CONTACT (MAP_LIQUID_STATUS_SWIMMING | LIQUID_MAP_WATER_WALK)
134+
135+
struct LiquidData
136+
{
137+
EnumFlag<map_liquidHeaderTypeFlags> type_flags = map_liquidHeaderTypeFlags::NoWater;
138+
uint32 entry;
139+
float level;
140+
float depth_level;
141+
};
142+
143+
struct WmoLocation
144+
{
145+
WmoLocation() = default;
146+
WmoLocation(int32 groupId, int32 nameSetId, int32 rootId, uint32 uniqueId)
147+
: GroupId(groupId), NameSetId(nameSetId), RootId(rootId), UniqueId(uniqueId) { }
148+
149+
int32 GroupId = 0;
150+
int32 NameSetId = 0;
151+
int32 RootId = 0;
152+
uint32 UniqueId = 0;
153+
};
154+
155+
struct PositionFullTerrainStatus
156+
{
157+
PositionFullTerrainStatus() : areaId(0), floorZ(0.0f), outdoors(true), liquidStatus(LIQUID_MAP_NO_WATER) { }
158+
uint32 areaId;
159+
float floorZ;
160+
bool outdoors;
161+
ZLiquidStatus liquidStatus;
162+
Optional<WmoLocation> wmoLocation;
163+
Optional<LiquidData> liquidInfo;
164+
};
165+
123166
#endif // MapDefines_h__

src/server/game/Entities/Player/Player.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
#include "SpellPackets.h"
100100
#include "StringConvert.h"
101101
#include "TalentPackets.h"
102+
#include "TerrainMgr.h"
102103
#include "TicketMgr.h"
103104
#include "TradeData.h"
104105
#include "Trainer.h"
@@ -6754,7 +6755,7 @@ uint32 Player::GetZoneIdFromDB(ObjectGuid guid)
67546755
if (!sMapStore.LookupEntry(map))
67556756
return 0;
67566757

6757-
zone = sMapMgr->GetZoneId(PHASEMASK_NORMAL, map, posx, posy, posz);
6758+
zone = sTerrainMgr.GetZoneId(PHASEMASK_NORMAL, map, posx, posy, posz);
67586759

67596760
if (zone > 0)
67606761
{

src/server/game/Globals/ObjectMgr.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include "SpellScript.h"
5151
#include "StringConvert.h"
5252
#include "TemporarySummon.h"
53+
#include "TerrainMgr.h"
5354
#include "ThreadPool.h"
5455
#include "UpdateMask.h"
5556
#include "Util.h"
@@ -2315,7 +2316,7 @@ void ObjectMgr::LoadCreatures()
23152316
{
23162317
uint32 zoneId = 0;
23172318
uint32 areaId = 0;
2318-
sMapMgr->GetZoneAndAreaId(data.phaseMask, zoneId, areaId, data.mapId, data.spawnPoint);
2319+
sTerrainMgr.GetZoneAndAreaId(data.phaseMask, zoneId, areaId, data.mapId, data.spawnPoint);
23192320

23202321
WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_UPD_CREATURE_ZONE_AREA_DATA);
23212322

@@ -2633,7 +2634,7 @@ void ObjectMgr::LoadGameObjects()
26332634
{
26342635
uint32 zoneId = 0;
26352636
uint32 areaId = 0;
2636-
sMapMgr->GetZoneAndAreaId(data.phaseMask, zoneId, areaId, data.mapId, data.spawnPoint);
2637+
sTerrainMgr.GetZoneAndAreaId(data.phaseMask, zoneId, areaId, data.mapId, data.spawnPoint);
26372638

26382639
WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_UPD_GAMEOBJECT_ZONE_AREA_DATA);
26392640

@@ -6911,7 +6912,7 @@ WorldSafeLocsEntry const* ObjectMgr::GetDefaultGraveyard(uint32 team) const
69116912
WorldSafeLocsEntry const* ObjectMgr::GetClosestGraveyard(float x, float y, float z, uint32 MapId, uint32 team, WorldObject* conditionObject) const
69126913
{
69136914
// search for zone associated closest graveyard
6914-
uint32 zoneId = sMapMgr->GetZoneId(PHASEMASK_NORMAL, MapId, x, y, z);
6915+
uint32 zoneId = sTerrainMgr.GetZoneId(PHASEMASK_NORMAL, MapId, x, y, z);
69156916

69166917
if (!zoneId)
69176918
{

src/server/game/Grids/GridDefines.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ class Player;
5656
#define MAP_SIZE (SIZE_OF_GRIDS*MAX_NUMBER_OF_GRIDS)
5757
#define MAP_HALFSIZE (MAP_SIZE/2)
5858

59+
#define MAX_HEIGHT 100000.0f // can be use for find ground height at surface
60+
#define INVALID_HEIGHT -100000.0f // for check, must be equal to VMAP_INVALID_HEIGHT, real value for unknown height is VMAP_INVALID_HEIGHT_VALUE
61+
#define MAX_FALL_DISTANCE 250000.0f // "unlimited fall" to find VMap ground if it is available, just larger than MAX_HEIGHT - INVALID_HEIGHT
62+
#define DEFAULT_HEIGHT_SEARCH 50.0f // default search distance to find height at nearby locations
63+
5964
// Creature used instead pet to simplify *::Visit templates (not required duplicate code for Creature->Pet case)
6065
typedef TYPELIST_4(Player, Creature/*pets*/, Corpse/*resurrectable*/, DynamicObject/*farsight target*/) AllWorldObjectTypes;
6166
typedef TYPELIST_5(GameObject, Creature/*except pets*/, DynamicObject, Corpse/*Bones*/, AreaTrigger) AllGridObjectTypes;

src/server/game/Grids/NGrid.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
#include "Random.h"
2121

2222
GridInfo::GridInfo() : i_timer(0), vis_Update(0, irand(0, DEFAULT_VISIBILITY_NOTIFY_PERIOD)),
23-
i_unloadActiveLockCount(0), i_unloadExplicitLock(false), i_unloadReferenceLock(false)
23+
i_unloadActiveLockCount(0), i_unloadExplicitLock(false)
2424
{
2525
}
2626

2727
GridInfo::GridInfo(time_t expiry, bool unload /*= true */) : i_timer(expiry), vis_Update(0, irand(0, DEFAULT_VISIBILITY_NOTIFY_PERIOD)),
28-
i_unloadActiveLockCount(0), i_unloadExplicitLock(!unload), i_unloadReferenceLock(false)
28+
i_unloadActiveLockCount(0), i_unloadExplicitLock(!unload)
2929
{
3030
}
3131

src/server/game/Grids/NGrid.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ class TC_GAME_API GridInfo
3333
GridInfo();
3434
GridInfo(time_t expiry, bool unload = true);
3535
TimeTracker const& getTimeTracker() const { return i_timer; }
36-
bool getUnloadLock() const { return i_unloadActiveLockCount || i_unloadExplicitLock || i_unloadReferenceLock; }
36+
bool getUnloadLock() const { return i_unloadActiveLockCount || i_unloadExplicitLock; }
3737
void setUnloadExplicitLock(bool on) { i_unloadExplicitLock = on; }
38-
void setUnloadReferenceLock(bool on) { i_unloadReferenceLock = on; }
3938
void incUnloadActiveLock() { ++i_unloadActiveLockCount; }
4039
void decUnloadActiveLock() { if (i_unloadActiveLockCount) --i_unloadActiveLockCount; }
4140

@@ -49,7 +48,6 @@ class TC_GAME_API GridInfo
4948

5049
uint16 i_unloadActiveLockCount; // lock from active object spawn points (prevent clone loading)
5150
bool i_unloadExplicitLock : 1; // explicit manual lock or config setting
52-
bool i_unloadReferenceLock : 1; // lock from instance map copy
5351
};
5452

5553
typedef enum
@@ -106,7 +104,6 @@ class NGrid
106104
TimeTracker const& getTimeTracker() const { return i_GridInfo.getTimeTracker(); }
107105
bool getUnloadLock() const { return i_GridInfo.getUnloadLock(); }
108106
void setUnloadExplicitLock(bool on) { i_GridInfo.setUnloadExplicitLock(on); }
109-
void setUnloadReferenceLock(bool on) { i_GridInfo.setUnloadReferenceLock(on); }
110107
void incUnloadActiveLock() { i_GridInfo.incUnloadActiveLock(); }
111108
void decUnloadActiveLock() { i_GridInfo.decUnloadActiveLock(); }
112109
void ResetTimeTracker(time_t interval) { i_GridInfo.ResetTimeTracker(interval); }

0 commit comments

Comments
 (0)