aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2025-10-25 00:52:55 +0200
committerShauren <shauren.trinity@gmail.com>2025-10-25 00:52:55 +0200
commit96b567995a36bee5de0ffa1f18fac6ba93f39bed (patch)
treede525c3e96be31f25269e4a8bf6f08d1a65d7238
parent81a1a5585132257972fe527bb2f7d9b672cc0422 (diff)
Core/Vmaps: Remove VMapManager2 virtual interface
-rw-r--r--src/common/Collision/Management/IVMapManager.h127
-rw-r--r--src/common/Collision/Management/VMapFactory.h2
-rw-r--r--src/common/Collision/Management/VMapManager2.cpp105
-rw-r--r--src/common/Collision/Management/VMapManager2.h124
-rw-r--r--src/common/Collision/Maps/MapTree.cpp29
-rw-r--r--src/common/Collision/Maps/MapTree.h21
-rw-r--r--src/server/game/Globals/ObjectMgr.cpp8
-rw-r--r--src/server/game/Maps/TerrainMgr.cpp27
-rw-r--r--src/tools/mmaps_generator/TerrainBuilder.cpp17
9 files changed, 188 insertions, 272 deletions
diff --git a/src/common/Collision/Management/IVMapManager.h b/src/common/Collision/Management/IVMapManager.h
deleted file mode 100644
index baece194fb9..00000000000
--- a/src/common/Collision/Management/IVMapManager.h
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef _IVMAPMANAGER_H
-#define _IVMAPMANAGER_H
-
-#include "Define.h"
-#include "ModelIgnoreFlags.h"
-#include "Optional.h"
-#include <string>
-
-//===========================================================
-
-/**
-This is the minimum interface to the VMapMamager.
-*/
-
-namespace VMAP
-{
- enum class LoadResult : uint8
- {
- Success,
- FileNotFound,
- VersionMismatch,
- ReadFromFileFailed,
- DisabledInConfig
- };
-
- #define VMAP_INVALID_HEIGHT -100000.0f // for check
- #define VMAP_INVALID_HEIGHT_VALUE -200000.0f // real assigned value in unknown height case
-
- struct AreaAndLiquidData
- {
- struct AreaInfo
- {
- AreaInfo() = default;
- AreaInfo(int32 _groupId, int32 _adtId, int32 _rootId, uint32 _mogpFlags, uint32 _uniqueId)
- : groupId(_groupId), adtId(_adtId), rootId(_rootId), mogpFlags(_mogpFlags), uniqueId(_uniqueId) { }
- int32 groupId = 0;
- int32 adtId = 0;
- int32 rootId = 0;
- uint32 mogpFlags = 0;
- uint32 uniqueId = 0;
- };
- struct LiquidInfo
- {
- LiquidInfo() = default;
- LiquidInfo(uint32 _type, float _level) : type(_type), level(_level) { }
- uint32 type = 0;
- float level = 0.0f;
- };
-
- float floorZ = VMAP_INVALID_HEIGHT;
- Optional<AreaInfo> areaInfo;
- Optional<LiquidInfo> liquidInfo;
- };
- //===========================================================
- class TC_COMMON_API IVMapManager
- {
- private:
- bool iEnableLineOfSightCalc;
- bool iEnableHeightCalc;
-
- public:
- IVMapManager() : iEnableLineOfSightCalc(true), iEnableHeightCalc(true) { }
-
- virtual ~IVMapManager(void) { }
-
- virtual LoadResult loadMap(char const* pBasePath, unsigned int pMapId, int x, int y) = 0;
-
- virtual LoadResult existsMap(char const* pBasePath, unsigned int pMapId, int x, int y) = 0;
-
- virtual void unloadMap(unsigned int pMapId, int x, int y) = 0;
- virtual void unloadMap(unsigned int pMapId) = 0;
-
- virtual bool isInLineOfSight(unsigned int pMapId, float x1, float y1, float z1, float x2, float y2, float z2, ModelIgnoreFlags ignoreFlags) = 0;
- virtual float getHeight(unsigned int pMapId, float x, float y, float z, float maxSearchDist) = 0;
- /**
- test if we hit an object. return true if we hit one. rx, ry, rz will hold the hit position or the dest position, if no intersection was found
- return a position, that is pReduceDist closer to the origin
- */
- virtual bool getObjectHitPos(unsigned int pMapId, float x1, float y1, float z1, float x2, float y2, float z2, float& rx, float &ry, float& rz, float pModifyDist) = 0;
- /**
- send debug commands
- */
- virtual bool processCommand(char *pCommand)= 0;
-
- /**
- Enable/disable LOS calculation
- It is enabled by default. If it is enabled in mid game the maps have to loaded manualy
- */
- void setEnableLineOfSightCalc(bool pVal) { iEnableLineOfSightCalc = pVal; }
- /**
- Enable/disable model height calculation
- It is enabled by default. If it is enabled in mid game the maps have to loaded manualy
- */
- void setEnableHeightCalc(bool pVal) { iEnableHeightCalc = pVal; }
-
- bool isLineOfSightCalcEnabled() const { return(iEnableLineOfSightCalc); }
- bool isHeightCalcEnabled() const { return(iEnableHeightCalc); }
- bool isMapLoadingEnabled() const { return(iEnableLineOfSightCalc || iEnableHeightCalc ); }
-
- virtual std::string getDirFileName(unsigned int pMapId, int x, int y) const =0;
-
- /**
- Query world model area info.
- \param z gets adjusted to the ground height for which this are info is valid
- */
- virtual bool getAreaAndLiquidData(unsigned int mapId, float x, float y, float z, Optional<uint8> reqLiquidType, AreaAndLiquidData& data) const = 0;
- };
-
-}
-#endif
diff --git a/src/common/Collision/Management/VMapFactory.h b/src/common/Collision/Management/VMapFactory.h
index ceb07fce975..29583348ee8 100644
--- a/src/common/Collision/Management/VMapFactory.h
+++ b/src/common/Collision/Management/VMapFactory.h
@@ -18,7 +18,7 @@
#ifndef _VMAPFACTORY_H
#define _VMAPFACTORY_H
-#include "IVMapManager.h"
+#include "Define.h"
/**
This is the access point to the VMapManager.
diff --git a/src/common/Collision/Management/VMapManager2.cpp b/src/common/Collision/Management/VMapManager2.cpp
index 481b1cdb0ea..b4f01411543 100644
--- a/src/common/Collision/Management/VMapManager2.cpp
+++ b/src/common/Collision/Management/VMapManager2.cpp
@@ -23,9 +23,6 @@
#include "VMapDefinitions.h"
#include "WorldModel.h"
#include <G3D/Vector3.h>
-#include <string>
-
-using G3D::Vector3;
namespace VMAP
{
@@ -34,6 +31,12 @@ namespace VMAP
public:
explicit ManagedModel(VMapManager2& mgr, std::string const& name) : _mgr(mgr), _name(name) { }
+ ManagedModel(ManagedModel const&) = delete;
+ ManagedModel(ManagedModel&&) = delete;
+
+ ManagedModel& operator=(ManagedModel const&) = delete;
+ ManagedModel& operator=(ManagedModel&&) = delete;
+
~ManagedModel()
{
_mgr.releaseModelInstance(_name);
@@ -52,18 +55,16 @@ namespace VMAP
return memcmp(dest, compare, len) == 0;
}
- VMapManager2::VMapManager2()
+ VMapManager2::VMapManager2() :
+ iEnableLineOfSightCalc(true),
+ iEnableHeightCalc(true),
+ thread_safe_environment(true),
+ GetLiquidFlagsPtr([](uint32 /*liquidTypeId*/) { return 0u; }),
+ IsVMAPDisabledForPtr([](uint32 /*mapId*/, uint8 /*disableFlags*/) { return false; })
{
- GetLiquidFlagsPtr = &GetLiquidFlagsDummy;
- IsVMAPDisabledForPtr = &IsVMAPDisabledForDummy;
- thread_safe_environment = true;
}
- VMapManager2::~VMapManager2()
- {
- for (std::pair<uint32 const, StaticMapTree*>& iInstanceMapTree : iInstanceMapTrees)
- delete iInstanceMapTree.second;
- }
+ VMapManager2::~VMapManager2() = default;
InstanceTreeMap::const_iterator VMapManager2::GetMapTree(uint32 mapId) const
{
@@ -78,11 +79,11 @@ namespace VMAP
void VMapManager2::InitializeThreadUnsafe(std::unordered_map<uint32, std::vector<uint32>> const& mapData)
{
// the caller must pass the list of all mapIds that will be used in the VMapManager2 lifetime
- for (std::pair<uint32 const, std::vector<uint32>> const& mapId : mapData)
+ for (auto const& [mapId, childMapIds] : mapData)
{
- iInstanceMapTrees.insert(InstanceTreeMap::value_type(mapId.first, nullptr));
- for (uint32 childMapId : mapId.second)
- iParentMapData[childMapId] = mapId.first;
+ iInstanceMapTrees[mapId] = nullptr;
+ for (uint32 childMapId : childMapIds)
+ iParentMapData[childMapId] = mapId;
}
thread_safe_environment = false;
@@ -95,10 +96,10 @@ namespace VMAP
iParentMapData[mapId] = parentMapId;
}
- Vector3 VMapManager2::convertPositionToInternalRep(float x, float y, float z) const
+ inline static G3D::Vector3 convertPositionToInternalRep(float x, float y, float z)
{
- Vector3 pos;
- const float mid = 0.5f * 64.0f * 533.33333333f;
+ G3D::Vector3 pos;
+ constexpr float mid = 0.5f * 64.0f * 533.33333333f;
pos.x = mid - x;
pos.y = mid - y;
pos.z = z;
@@ -106,13 +107,17 @@ namespace VMAP
return pos;
}
- // move to MapTree too?
- std::string VMapManager2::getMapFileName(unsigned int mapId)
+ std::string VMapManager2::getMapFileName(uint32 mapId)
{
return Trinity::StringFormat("{:04}/{:04}.vmtree", mapId, mapId);
}
- LoadResult VMapManager2::loadMap(char const* basePath, unsigned int mapId, int x, int y)
+ std::string VMapManager2::getTileFileName(uint32 mapID, uint32 tileX, uint32 tileY, std::string_view extension)
+ {
+ return Trinity::StringFormat("{:04}/{:04}_{:02}_{:02}.{}", mapID, mapID, tileY, tileX, extension);
+ }
+
+ LoadResult VMapManager2::loadMap(std::string const& basePath, uint32 mapId, uint32 x, uint32 y)
{
if (!isMapLoadingEnabled())
return LoadResult::DisabledInConfig;
@@ -130,48 +135,40 @@ namespace VMAP
if (!instanceTree->second)
{
std::string mapFileName = getMapFileName(mapId);
- StaticMapTree* newTree = new StaticMapTree(mapId, basePath);
+ std::unique_ptr<StaticMapTree> newTree = std::make_unique<StaticMapTree>(mapId, basePath);
LoadResult treeInitResult = newTree->InitMap(mapFileName);
if (treeInitResult != LoadResult::Success)
- {
- delete newTree;
return treeInitResult;
- }
- instanceTree->second = newTree;
+
+ instanceTree->second = std::move(newTree);
}
return instanceTree->second->LoadMapTile(x, y, this);
}
- void VMapManager2::unloadMap(unsigned int mapId, int x, int y)
+ void VMapManager2::unloadMap(uint32 mapId, uint32 x, uint32 y)
{
auto instanceTree = iInstanceMapTrees.find(mapId);
if (instanceTree != iInstanceMapTrees.end() && instanceTree->second)
{
instanceTree->second->UnloadMapTile(x, y, this);
if (instanceTree->second->numLoadedTiles() == 0)
- {
- delete instanceTree->second;
instanceTree->second = nullptr;
- }
}
}
- void VMapManager2::unloadMap(unsigned int mapId)
+ void VMapManager2::unloadMap(uint32 mapId)
{
auto instanceTree = iInstanceMapTrees.find(mapId);
if (instanceTree != iInstanceMapTrees.end() && instanceTree->second)
{
instanceTree->second->UnloadMap();
if (instanceTree->second->numLoadedTiles() == 0)
- {
- delete instanceTree->second;
instanceTree->second = nullptr;
- }
}
}
- bool VMapManager2::isInLineOfSight(unsigned int mapId, float x1, float y1, float z1, float x2, float y2, float z2, ModelIgnoreFlags ignoreFlags)
+ bool VMapManager2::isInLineOfSight(uint32 mapId, float x1, float y1, float z1, float x2, float y2, float z2, ModelIgnoreFlags ignoreFlags)
{
if (!isLineOfSightCalcEnabled() || IsVMAPDisabledForPtr(mapId, VMAP_DISABLE_LOS))
return true;
@@ -179,8 +176,8 @@ namespace VMAP
auto instanceTree = GetMapTree(mapId);
if (instanceTree != iInstanceMapTrees.end())
{
- Vector3 pos1 = convertPositionToInternalRep(x1, y1, z1);
- Vector3 pos2 = convertPositionToInternalRep(x2, y2, z2);
+ G3D::Vector3 pos1 = convertPositionToInternalRep(x1, y1, z1);
+ G3D::Vector3 pos2 = convertPositionToInternalRep(x2, y2, z2);
if (pos1 != pos2)
return instanceTree->second->isInLineOfSight(pos1, pos2, ignoreFlags);
}
@@ -192,16 +189,16 @@ namespace VMAP
get the hit position and return true if we hit something
otherwise the result pos will be the dest pos
*/
- bool VMapManager2::getObjectHitPos(unsigned int mapId, float x1, float y1, float z1, float x2, float y2, float z2, float& rx, float &ry, float& rz, float modifyDist)
+ bool VMapManager2::getObjectHitPos(uint32 mapId, float x1, float y1, float z1, float x2, float y2, float z2, float& rx, float &ry, float& rz, float modifyDist)
{
if (isLineOfSightCalcEnabled() && !IsVMAPDisabledForPtr(mapId, VMAP_DISABLE_LOS))
{
auto instanceTree = GetMapTree(mapId);
if (instanceTree != iInstanceMapTrees.end())
{
- Vector3 pos1 = convertPositionToInternalRep(x1, y1, z1);
- Vector3 pos2 = convertPositionToInternalRep(x2, y2, z2);
- Vector3 resultPos;
+ G3D::Vector3 pos1 = convertPositionToInternalRep(x1, y1, z1);
+ G3D::Vector3 pos2 = convertPositionToInternalRep(x2, y2, z2);
+ G3D::Vector3 resultPos;
bool result = instanceTree->second->getObjectHitPos(pos1, pos2, resultPos, modifyDist);
resultPos = convertPositionToInternalRep(resultPos.x, resultPos.y, resultPos.z);
rx = resultPos.x;
@@ -222,14 +219,14 @@ namespace VMAP
get height or INVALID_HEIGHT if no height available
*/
- float VMapManager2::getHeight(unsigned int mapId, float x, float y, float z, float maxSearchDist)
+ float VMapManager2::getHeight(uint32 mapId, float x, float y, float z, float maxSearchDist)
{
if (isHeightCalcEnabled() && !IsVMAPDisabledForPtr(mapId, VMAP_DISABLE_HEIGHT))
{
auto instanceTree = GetMapTree(mapId);
if (instanceTree != iInstanceMapTrees.end())
{
- Vector3 pos = convertPositionToInternalRep(x, y, z);
+ G3D::Vector3 pos = convertPositionToInternalRep(x, y, z);
float height = instanceTree->second->getHeight(pos, maxSearchDist);
if (!(height < G3D::finf()))
return height = VMAP_INVALID_HEIGHT_VALUE; // No height
@@ -241,13 +238,13 @@ namespace VMAP
return VMAP_INVALID_HEIGHT_VALUE;
}
- bool VMapManager2::getAreaAndLiquidData(unsigned int mapId, float x, float y, float z, Optional<uint8> reqLiquidType, AreaAndLiquidData& data) const
+ bool VMapManager2::getAreaAndLiquidData(uint32 mapId, float x, float y, float z, Optional<uint8> reqLiquidType, AreaAndLiquidData& data) const
{
InstanceTreeMap::const_iterator instanceTree = GetMapTree(mapId);
if (instanceTree != iInstanceMapTrees.end())
{
LocationInfo info;
- Vector3 pos = convertPositionToInternalRep(x, y, z);
+ G3D::Vector3 pos = convertPositionToInternalRep(x, y, z);
if (instanceTree->second->GetLocationInfo(pos, info))
{
data.floorZ = info.ground_Z;
@@ -275,7 +272,7 @@ namespace VMAP
std::shared_ptr<ManagedModel> worldmodel; // this is intentionally declared before lock so that it is destroyed after it to prevent deadlocks in releaseModelInstance
//! Critical section, thread safe access to iLoadedModelFiles
- std::lock_guard<std::mutex> lock(LoadedModelFilesLock);
+ std::lock_guard lock(LoadedModelFilesLock);
auto& [key, model] = *iLoadedModelFiles.try_emplace(filename).first;
worldmodel = model.lock();
@@ -298,7 +295,7 @@ namespace VMAP
void VMapManager2::releaseModelInstance(std::string const& filename)
{
//! Critical section, thread safe access to iLoadedModelFiles
- std::lock_guard<std::mutex> lock(LoadedModelFilesLock);
+ std::lock_guard lock(LoadedModelFilesLock);
TC_LOG_DEBUG("maps", "VMapManager2: unloading file '{}'", filename);
@@ -307,14 +304,18 @@ namespace VMAP
TC_LOG_ERROR("misc", "VMapManager2: trying to unload non-loaded file '{}'", filename);
}
- LoadResult VMapManager2::existsMap(char const* basePath, unsigned int mapId, int x, int y)
+ LoadResult VMapManager2::existsMap(std::string const& basePath, uint32 mapId, uint32 x, uint32 y)
{
- return StaticMapTree::CanLoadMap(std::string(basePath), mapId, x, y, this);
+ return StaticMapTree::CanLoadMap(basePath, mapId, x, y, this);
}
- void VMapManager2::getInstanceMapTree(InstanceTreeMap &instanceMapTree)
+ std::span<ModelInstance const> VMapManager2::getModelsOnMap(uint32 mapId) const
{
- instanceMapTree = iInstanceMapTrees;
+ InstanceTreeMap::const_iterator mapTree = GetMapTree(mapId);
+ if (mapTree != iInstanceMapTrees.end())
+ return mapTree->second->getModelInstances();
+
+ return {};
}
int32 VMapManager2::getParentMapId(uint32 mapId) const
diff --git a/src/common/Collision/Management/VMapManager2.h b/src/common/Collision/Management/VMapManager2.h
index 8fbc9b05ed1..84aac14f76d 100644
--- a/src/common/Collision/Management/VMapManager2.h
+++ b/src/common/Collision/Management/VMapManager2.h
@@ -15,13 +15,16 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef _VMAPMANAGER2_H
-#define _VMAPMANAGER2_H
+#ifndef TRINITYCORE_VMAP_MANAGER2_H
+#define TRINITYCORE_VMAP_MANAGER2_H
#include "Define.h"
-#include "IVMapManager.h"
+#include "ModelIgnoreFlags.h"
+#include "Optional.h"
#include <memory>
#include <mutex>
+#include <span>
+#include <string>
#include <unordered_map>
#include <vector>
@@ -37,21 +40,17 @@ Additionally a table to match map ids and map names is used.
//===========================================================
-namespace G3D
-{
- class Vector3;
-}
-
namespace VMAP
{
class ManagedModel;
+ class ModelInstance;
class StaticMapTree;
class WorldModel;
- typedef std::unordered_map<uint32, StaticMapTree*> InstanceTreeMap;
+ typedef std::unordered_map<uint32, std::unique_ptr<StaticMapTree>> InstanceTreeMap;
typedef std::unordered_map<std::string, std::weak_ptr<ManagedModel>> ModelFileMap;
- enum DisableTypes
+ enum DisableTypes : uint8
{
VMAP_DISABLE_AREAFLAG = 0x1,
VMAP_DISABLE_HEIGHT = 0x2,
@@ -59,61 +58,122 @@ namespace VMAP
VMAP_DISABLE_LIQUIDSTATUS = 0x8
};
- class TC_COMMON_API VMapManager2 : public IVMapManager
+ enum class LoadResult : uint8
+ {
+ Success,
+ FileNotFound,
+ VersionMismatch,
+ ReadFromFileFailed,
+ DisabledInConfig
+ };
+
+ #define VMAP_INVALID_HEIGHT -100000.0f // for check
+ #define VMAP_INVALID_HEIGHT_VALUE -200000.0f // real assigned value in unknown height case
+
+ struct AreaAndLiquidData
+ {
+ struct AreaInfo
+ {
+ AreaInfo() = default;
+ AreaInfo(int32 _groupId, int32 _adtId, int32 _rootId, uint32 _mogpFlags, uint32 _uniqueId)
+ : groupId(_groupId), adtId(_adtId), rootId(_rootId), mogpFlags(_mogpFlags), uniqueId(_uniqueId) { }
+ int32 groupId = 0;
+ int32 adtId = 0;
+ int32 rootId = 0;
+ uint32 mogpFlags = 0;
+ uint32 uniqueId = 0;
+ };
+ struct LiquidInfo
+ {
+ LiquidInfo() = default;
+ LiquidInfo(uint32 _type, float _level) : type(_type), level(_level) { }
+ uint32 type = 0;
+ float level = 0.0f;
+ };
+
+ float floorZ = VMAP_INVALID_HEIGHT;
+ Optional<AreaInfo> areaInfo;
+ Optional<LiquidInfo> liquidInfo;
+ };
+
+ class TC_COMMON_API VMapManager2
{
protected:
+ bool iEnableLineOfSightCalc;
+ bool iEnableHeightCalc;
+ bool thread_safe_environment;
// Tree to check collision
ModelFileMap iLoadedModelFiles;
InstanceTreeMap iInstanceMapTrees;
std::unordered_map<uint32, uint32> iParentMapData;
- bool thread_safe_environment;
// Mutex for iLoadedModelFiles
std::mutex LoadedModelFilesLock;
- static uint32 GetLiquidFlagsDummy(uint32) { return 0; }
- static bool IsVMAPDisabledForDummy(uint32 /*entry*/, uint8 /*flags*/) { return false; }
-
InstanceTreeMap::const_iterator GetMapTree(uint32 mapId) const;
public:
// public for debug
- G3D::Vector3 convertPositionToInternalRep(float x, float y, float z) const;
- static std::string getMapFileName(unsigned int mapId);
+ static std::string getMapFileName(uint32 mapId);
+ static std::string getTileFileName(uint32 mapID, uint32 tileX, uint32 tileY, std::string_view extension);
VMapManager2();
+
+ VMapManager2(VMapManager2 const&) = delete;
+ VMapManager2(VMapManager2&&) = delete;
+
+ VMapManager2& operator=(VMapManager2 const&) = delete;
+ VMapManager2& operator=(VMapManager2&&) = delete;
+
~VMapManager2();
void InitializeThreadUnsafe(std::unordered_map<uint32, std::vector<uint32>> const& mapData);
void InitializeThreadUnsafe(uint32 mapId, int32 parentMapId);
+ /**
+ Enable/disable LOS calculation
+ It is enabled by default. If it is enabled in mid game the maps have to loaded manualy
+ */
+ void setEnableLineOfSightCalc(bool enableLineOfSightCalc) { iEnableLineOfSightCalc = enableLineOfSightCalc; }
+
+ /**
+ Enable/disable model height calculation
+ It is enabled by default. If it is enabled in mid game the maps have to loaded manualy
+ */
+ void setEnableHeightCalc(bool enableHeightCalc) { iEnableHeightCalc = enableHeightCalc; }
+
+ bool isLineOfSightCalcEnabled() const { return iEnableLineOfSightCalc; }
+ bool isHeightCalcEnabled() const { return iEnableHeightCalc; }
+ bool isMapLoadingEnabled() const { return iEnableLineOfSightCalc || iEnableHeightCalc; }
- LoadResult loadMap(char const* pBasePath, unsigned int mapId, int x, int y) override;
+ LoadResult loadMap(std::string const& basePath, uint32 mapId, uint32 x, uint32 y);
- void unloadMap(unsigned int mapId, int x, int y) override;
+ void unloadMap(uint32 mapId, uint32 x, uint32 y);
- void unloadMap(unsigned int mapId) override;
+ void unloadMap(uint32 mapId);
- bool isInLineOfSight(unsigned int mapId, float x1, float y1, float z1, float x2, float y2, float z2, ModelIgnoreFlags ignoreFlags) override ;
+ bool isInLineOfSight(uint32 mapId, float x1, float y1, float z1, float x2, float y2, float z2, ModelIgnoreFlags ignoreFlags);
/**
- fill the hit pos and return true, if an object was hit
+ test if we hit an object. return true if we hit one. rx, ry, rz will hold the hit position or the dest position, if no intersection was found
+ return a position, that is modifyDist closer to the origin
*/
- bool getObjectHitPos(unsigned int mapId, float x1, float y1, float z1, float x2, float y2, float z2, float& rx, float& ry, float& rz, float modifyDist) override;
- float getHeight(unsigned int mapId, float x, float y, float z, float maxSearchDist) override;
+ bool getObjectHitPos(uint32 mapId, float x1, float y1, float z1, float x2, float y2, float z2, float& rx, float& ry, float& rz, float modifyDist);
+ float getHeight(uint32 mapId, float x, float y, float z, float maxSearchDist);
- bool processCommand(char* /*command*/) override { return false; } // for debug and extensions
-
- bool getAreaAndLiquidData(uint32 mapId, float x, float y, float z, Optional<uint8> reqLiquidType, AreaAndLiquidData& data) const override;
+ /**
+ Query world model area info.
+ */
+ bool getAreaAndLiquidData(uint32 mapId, float x, float y, float z, Optional<uint8> reqLiquidType, AreaAndLiquidData& data) const;
std::shared_ptr<WorldModel> acquireModelInstance(std::string const& basepath, std::string const& filename);
void releaseModelInstance(std::string const& filename);
// what's the use of this? o.O
- virtual std::string getDirFileName(unsigned int mapId, int /*x*/, int /*y*/) const override
+ static std::string getDirFileName(uint32 mapId, uint32 x, uint32 y)
{
- return getMapFileName(mapId);
+ return getTileFileName(mapId, x, y, "vmtile");
}
- virtual LoadResult existsMap(char const* basePath, unsigned int mapId, int x, int y) override;
+ LoadResult existsMap(std::string const& basePath, uint32 mapId, uint32 x, uint32 y);
- void getInstanceMapTree(InstanceTreeMap &instanceMapTree);
+ std::span<ModelInstance const> getModelsOnMap(uint32 mapId) const;
int32 getParentMapId(uint32 mapId) const;
@@ -125,4 +185,4 @@ namespace VMAP
};
}
-#endif
+#endif // TRINITYCORE_VMAP_MANAGER2_H
diff --git a/src/common/Collision/Maps/MapTree.cpp b/src/common/Collision/Maps/MapTree.cpp
index d828326806c..9438ba6b219 100644
--- a/src/common/Collision/Maps/MapTree.cpp
+++ b/src/common/Collision/Maps/MapTree.cpp
@@ -35,7 +35,7 @@ namespace VMAP
{
public:
MapRayCallback(ModelInstance const* val, ModelIgnoreFlags ignoreFlags) : prims(val), hit(false), flags(ignoreFlags) { }
- bool operator()(const G3D::Ray& ray, uint32 entry, float& distance, bool pStopAtFirstHit = true)
+ bool operator()(G3D::Ray const& ray, uint32 entry, float& distance, bool pStopAtFirstHit = true)
{
bool result = prims[entry].intersectRay(ray, distance, pStopAtFirstHit, flags);
if (result)
@@ -69,11 +69,6 @@ namespace VMAP
//=========================================================
- std::string getTileFileName(uint32 mapID, uint32 tileX, uint32 tileY, std::string_view extension)
- {
- return Trinity::StringFormat("{:04}/{:04}_{:02}_{:02}.{}", mapID, mapID, tileY, tileX, extension);
- }
-
bool StaticMapTree::GetLocationInfo(Vector3 const& pos, LocationInfo& info) const
{
LocationInfoCallback intersectionCallBack(iTreeValues.data(), info);
@@ -84,10 +79,8 @@ namespace VMAP
StaticMapTree::StaticMapTree(uint32 mapID, std::string const& basePath)
: iMapID(mapID), iBasePath(basePath)
{
- if (iBasePath.length() > 0 && iBasePath[iBasePath.length() - 1] != '/' && iBasePath[iBasePath.length() - 1] != '\\')
- {
+ if (!iBasePath.empty() && iBasePath.back() != '/' && iBasePath.back() != '\\')
iBasePath.push_back('/');
- }
}
//=========================================================
@@ -100,7 +93,7 @@ namespace VMAP
Else, pMaxDist is not modified and returns false;
*/
- bool StaticMapTree::getIntersectionTime(const G3D::Ray& pRay, float& pMaxDist, bool pStopAtFirstHit, ModelIgnoreFlags ignoreFlags) const
+ bool StaticMapTree::getIntersectionTime(G3D::Ray const& pRay, float& pMaxDist, bool pStopAtFirstHit, ModelIgnoreFlags ignoreFlags) const
{
float distance = pMaxDist;
MapRayCallback intersectionCallBack(iTreeValues.data(), ignoreFlags);
@@ -209,16 +202,16 @@ namespace VMAP
TileFileOpenResult OpenMapTileFile(std::string const& basePath, uint32 mapID, uint32 tileX, uint32 tileY, VMapManager2* vm)
{
TileFileOpenResult result;
- result.Name = basePath + getTileFileName(mapID, tileX, tileY, "vmtile");
+ result.Name = basePath + VMapManager2::getTileFileName(mapID, tileX, tileY, "vmtile");
result.TileFile.reset(fopen(result.Name.c_str(), "rb"));
- result.SpawnIndicesFile.reset(fopen((basePath + getTileFileName(mapID, tileX, tileY, "vmtileidx")).c_str(), "rb"));
+ result.SpawnIndicesFile.reset(fopen((basePath + VMapManager2::getTileFileName(mapID, tileX, tileY, "vmtileidx")).c_str(), "rb"));
result.UsedMapId = mapID;
if (!result.TileFile)
{
int32 parentMapId = vm->getParentMapId(mapID);
while (parentMapId != -1)
{
- result.Name = basePath + getTileFileName(parentMapId, tileX, tileY, "vmtile");
+ result.Name = basePath + VMapManager2::getTileFileName(parentMapId, tileX, tileY, "vmtile");
result.TileFile.reset(fopen(result.Name.c_str(), "rb"));
result.UsedMapId = parentMapId;
if (result.TileFile)
@@ -232,11 +225,12 @@ namespace VMAP
}
//=========================================================
- LoadResult StaticMapTree::CanLoadMap(const std::string& vmapPath, uint32 mapID, uint32 tileX, uint32 tileY, VMapManager2* vm)
+ LoadResult StaticMapTree::CanLoadMap(std::string const& vmapPath, uint32 mapID, uint32 tileX, uint32 tileY, VMapManager2* vm)
{
std::string basePath = vmapPath;
- if (basePath.length() > 0 && basePath[basePath.length() - 1] != '/' && basePath[basePath.length() - 1] != '\\')
+ if (!basePath.empty() && basePath.back() != '/' && basePath.back() != '\\')
basePath.push_back('/');
+
std::string fullname = basePath + VMapManager2::getMapFileName(mapID);
auto rf = Trinity::make_unique_ptr_with_deleter<&::fclose>(fopen(fullname.c_str(), "rb"));
@@ -436,9 +430,8 @@ namespace VMAP
"Map: " + std::to_string(iMapID) + " TileX: " + std::to_string(tileX) + " TileY: " + std::to_string(tileY));
}
- void StaticMapTree::getModelInstances(ModelInstance*& models, uint32& count)
+ std::span<ModelInstance const> StaticMapTree::getModelInstances() const
{
- models = iTreeValues.data();
- count = iTreeValues.size();
+ return iTreeValues;
}
}
diff --git a/src/common/Collision/Maps/MapTree.h b/src/common/Collision/Maps/MapTree.h
index 4c088a7bad2..641708fa2ad 100644
--- a/src/common/Collision/Maps/MapTree.h
+++ b/src/common/Collision/Maps/MapTree.h
@@ -20,6 +20,7 @@
#include "Define.h"
#include "BoundingIntervalHierarchy.h"
+#include <span>
#include <unordered_map>
namespace VMAP
@@ -60,27 +61,27 @@ namespace VMAP
std::string iBasePath;
private:
- bool getIntersectionTime(const G3D::Ray& pRay, float &pMaxDist, bool pStopAtFirstHit, ModelIgnoreFlags ignoreFlags) const;
+ bool getIntersectionTime(G3D::Ray const& pRay, float& pMaxDist, bool pStopAtFirstHit, ModelIgnoreFlags ignoreFlags) const;
//bool containsLoadedMapTile(unsigned int pTileIdent) const { return(iLoadedMapTiles.containsKey(pTileIdent)); }
public:
- static uint32 packTileID(uint32 tileX, uint32 tileY) { return tileX<<16 | tileY; }
- static void unpackTileID(uint32 ID, uint32 &tileX, uint32 &tileY) { tileX = ID >> 16; tileY = ID & 0xFF; }
- static LoadResult CanLoadMap(const std::string &basePath, uint32 mapID, uint32 tileX, uint32 tileY, VMapManager2* vm);
+ static uint32 packTileID(uint32 tileX, uint32 tileY) { return tileX << 16 | tileY; }
+ static void unpackTileID(uint32 ID, uint32& tileX, uint32& tileY) { tileX = ID >> 16; tileY = ID & 0xFF; }
+ static LoadResult CanLoadMap(std::string const& basePath, uint32 mapID, uint32 tileX, uint32 tileY, VMapManager2* vm);
- StaticMapTree(uint32 mapID, const std::string &basePath);
+ StaticMapTree(uint32 mapID, std::string const& basePath);
~StaticMapTree();
- bool isInLineOfSight(const G3D::Vector3& pos1, const G3D::Vector3& pos2, ModelIgnoreFlags ignoreFlags) const;
- bool getObjectHitPos(const G3D::Vector3& pos1, const G3D::Vector3& pos2, G3D::Vector3& pResultHitPos, float pModifyDist) const;
- float getHeight(const G3D::Vector3& pPos, float maxSearchDist) const;
- bool GetLocationInfo(const G3D::Vector3 &pos, LocationInfo &info) const;
+ bool isInLineOfSight(G3D::Vector3 const& pos1, G3D::Vector3 const& pos2, ModelIgnoreFlags ignoreFlags) const;
+ bool getObjectHitPos(G3D::Vector3 const& pos1, G3D::Vector3 const& pos2, G3D::Vector3& pResultHitPos, float pModifyDist) const;
+ float getHeight(G3D::Vector3 const& pPos, float maxSearchDist) const;
+ bool GetLocationInfo(G3D::Vector3 const& pos, LocationInfo& info) const;
LoadResult InitMap(std::string const& fname);
void UnloadMap();
LoadResult LoadMapTile(uint32 tileX, uint32 tileY, VMapManager2* vm);
void UnloadMapTile(uint32 tileX, uint32 tileY, VMapManager2* vm);
uint32 numLoadedTiles() const { return uint32(iLoadedTiles.size()); }
- void getModelInstances(ModelInstance* &models, uint32 &count);
+ std::span<ModelInstance const> getModelInstances() const;
private:
StaticMapTree(StaticMapTree const& right) = delete;
diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp
index 72be6ff52fb..f6e53f377a1 100644
--- a/src/server/game/Globals/ObjectMgr.cpp
+++ b/src/server/game/Globals/ObjectMgr.cpp
@@ -2197,7 +2197,7 @@ void ObjectMgr::LoadCreatures()
if (sWorld->getBoolConfig(CONFIG_CREATURE_CHECK_INVALID_POSITION))
{
- if (VMAP::IVMapManager* vmgr = VMAP::VMapFactory::createOrGetVMapManager())
+ if (VMAP::VMapManager2* vmgr = VMAP::VMapFactory::createOrGetVMapManager())
{
if (vmgr->isMapLoadingEnabled() && !IsTransportMap(data.mapId))
{
@@ -2205,7 +2205,7 @@ void ObjectMgr::LoadCreatures()
int gx = (MAX_NUMBER_OF_GRIDS - 1) - gridCoord.x_coord;
int gy = (MAX_NUMBER_OF_GRIDS - 1) - gridCoord.y_coord;
- VMAP::LoadResult result = vmgr->existsMap((sWorld->GetDataPath() + "vmaps").c_str(), data.mapId, gx, gy);
+ VMAP::LoadResult result = vmgr->existsMap(sWorld->GetDataPath() + "vmaps", data.mapId, gx, gy);
if (result != VMAP::LoadResult::Success)
TC_LOG_ERROR("sql.sql", "Table `creature` has creature (GUID: {} Entry: {} MapID: {}) spawned on a possible invalid position ({})",
guid, data.id, data.mapId, data.spawnPoint.ToString());
@@ -2553,7 +2553,7 @@ void ObjectMgr::LoadGameObjects()
if (sWorld->getBoolConfig(CONFIG_GAME_OBJECT_CHECK_INVALID_POSITION))
{
- if (VMAP::IVMapManager* vmgr = VMAP::VMapFactory::createOrGetVMapManager())
+ if (VMAP::VMapManager2* vmgr = VMAP::VMapFactory::createOrGetVMapManager())
{
if (vmgr->isMapLoadingEnabled() && !IsTransportMap(data.mapId))
{
@@ -2561,7 +2561,7 @@ void ObjectMgr::LoadGameObjects()
int gx = (MAX_NUMBER_OF_GRIDS - 1) - gridCoord.x_coord;
int gy = (MAX_NUMBER_OF_GRIDS - 1) - gridCoord.y_coord;
- VMAP::LoadResult result = vmgr->existsMap((sWorld->GetDataPath() + "vmaps").c_str(), data.mapId, gx, gy);
+ VMAP::LoadResult result = vmgr->existsMap(sWorld->GetDataPath() + "vmaps", data.mapId, gx, gy);
if (result != VMAP::LoadResult::Success)
TC_LOG_ERROR("sql.sql", "Table `gameobject` has gameobject (GUID: {} Entry: {} MapID: {}) spawned on a possible invalid position ({})",
guid, data.id, data.mapId, data.spawnPoint.ToString());
diff --git a/src/server/game/Maps/TerrainMgr.cpp b/src/server/game/Maps/TerrainMgr.cpp
index 7dc70479a96..6bfe066994d 100644
--- a/src/server/game/Maps/TerrainMgr.cpp
+++ b/src/server/game/Maps/TerrainMgr.cpp
@@ -109,30 +109,30 @@ bool TerrainInfo::ExistMap(uint32 mapid, int32 gx, int32 gy, bool log /*= true*/
bool TerrainInfo::ExistVMap(uint32 mapid, int32 gx, int32 gy)
{
- if (VMAP::IVMapManager* vmgr = VMAP::VMapFactory::createOrGetVMapManager())
+ if (VMAP::VMapManager2* vmgr = VMAP::VMapFactory::createOrGetVMapManager())
{
if (vmgr->isMapLoadingEnabled())
{
- VMAP::LoadResult result = vmgr->existsMap((sWorld->GetDataPath() + "vmaps").c_str(), mapid, gx, gy);
- std::string name = vmgr->getDirFileName(mapid, gx, gy);
+ VMAP::LoadResult result = vmgr->existsMap(sWorld->GetDataPath() + "vmaps", mapid, gx, gy);
+ std::string name = VMAP::VMapManager2::getDirFileName(mapid, gx, gy);
switch (result)
{
case VMAP::LoadResult::Success:
break;
case VMAP::LoadResult::FileNotFound:
- TC_LOG_ERROR("maps", "VMap file '{}' does not exist", (sWorld->GetDataPath() + "vmaps/" + name));
+ TC_LOG_ERROR("maps", "VMap file '{}vmaps/{}' does not exist", sWorld->GetDataPath(), name);
TC_LOG_ERROR("maps", "Please place VMAP files (*.vmtree and *.vmtile) in the vmap directory ({}), or correct the DataDir setting in your worldserver.conf file.", (sWorld->GetDataPath() + "vmaps/"));
return false;
case VMAP::LoadResult::VersionMismatch:
- TC_LOG_ERROR("maps", "VMap file '{}' couldn't be loaded", (sWorld->GetDataPath() + "vmaps/" + name));
+ TC_LOG_ERROR("maps", "VMap file '{}vmaps/{}' couldn't be loaded", sWorld->GetDataPath(), name);
TC_LOG_ERROR("maps", "This is because the version of the VMap file and the version of this module are different, please re-extract the maps with the tools compiled with this module.");
return false;
case VMAP::LoadResult::ReadFromFileFailed:
- TC_LOG_ERROR("maps", "VMap file '{}' couldn't be loaded", (sWorld->GetDataPath() + "vmaps/" + name));
+ TC_LOG_ERROR("maps", "VMap file '{}vmaps/{}' couldn't be loaded", sWorld->GetDataPath(), name);
TC_LOG_ERROR("maps", "This is because VMAP files are corrupted, please re-extract the maps with the tools compiled with this module.");
return false;
case VMAP::LoadResult::DisabledInConfig:
- TC_LOG_ERROR("maps", "VMap file '{}' couldn't be loaded", (sWorld->GetDataPath() + "vmaps/" + name));
+ TC_LOG_ERROR("maps", "VMap file '{}vmaps/{}' couldn't be loaded", sWorld->GetDataPath(), name);
TC_LOG_ERROR("maps", "This is because VMAP is disabled in config file.");
return false;
}
@@ -215,9 +215,8 @@ void TerrainInfo::LoadVMap(int32 gx, int32 gy)
{
if (!VMAP::VMapFactory::createOrGetVMapManager()->isMapLoadingEnabled())
return;
- // x and y are swapped !!
- VMAP::LoadResult vmapLoadResult = VMAP::VMapFactory::createOrGetVMapManager()->loadMap((sWorld->GetDataPath() + "vmaps").c_str(), GetId(), gx, gy);
- switch (vmapLoadResult)
+
+ switch (VMAP::VMapFactory::createOrGetVMapManager()->loadMap(sWorld->GetDataPath() + "vmaps", GetId(), gx, gy))
{
case VMAP::LoadResult::Success:
TC_LOG_DEBUG("maps", "VMAP loaded name:{}, id:{}, x:{}, y:{} (vmap rep.: x:{}, y:{})", GetMapName(), GetId(), gx, gy, gx, gy);
@@ -335,7 +334,7 @@ static bool IsInWMOInterior(uint32 mogpFlags)
void TerrainInfo::GetFullTerrainStatusForPosition(PhaseShift const& phaseShift, uint32 mapId, float x, float y, float z, PositionFullTerrainStatus& data,
Optional<map_liquidHeaderTypeFlags> reqLiquidType, float collisionHeight, DynamicMapTree const* dynamicMapTree)
{
- VMAP::IVMapManager* vmgr = VMAP::VMapFactory::createOrGetVMapManager();
+ VMAP::VMapManager2* vmgr = VMAP::VMapFactory::createOrGetVMapManager();
VMAP::AreaAndLiquidData vmapData;
VMAP::AreaAndLiquidData dynData;
VMAP::AreaAndLiquidData* wmoData = nullptr;
@@ -485,7 +484,7 @@ void TerrainInfo::GetFullTerrainStatusForPosition(PhaseShift const& phaseShift,
ZLiquidStatus TerrainInfo::GetLiquidStatus(PhaseShift const& phaseShift, uint32 mapId, float x, float y, float z, Optional<map_liquidHeaderTypeFlags> ReqLiquidType, LiquidData* data, float collisionHeight)
{
ZLiquidStatus result = LIQUID_MAP_NO_WATER;
- VMAP::IVMapManager* vmgr = VMAP::VMapFactory::createOrGetVMapManager();
+ VMAP::VMapManager2* vmgr = VMAP::VMapFactory::createOrGetVMapManager();
VMAP::AreaAndLiquidData vmapData;
bool useGridLiquid = true;
uint32 terrainMapId = PhasingHandler::GetTerrainMapId(phaseShift, mapId, this, x, y);
@@ -586,7 +585,7 @@ bool TerrainInfo::GetAreaInfo(PhaseShift const& phaseShift, uint32 mapId, float
{
float check_z = z;
uint32 terrainMapId = PhasingHandler::GetTerrainMapId(phaseShift, mapId, this, x, y);
- VMAP::IVMapManager* vmgr = VMAP::VMapFactory::createOrGetVMapManager();
+ VMAP::VMapManager2* vmgr = VMAP::VMapFactory::createOrGetVMapManager();
VMAP::AreaAndLiquidData vdata;
VMAP::AreaAndLiquidData ddata;
@@ -704,7 +703,7 @@ float TerrainInfo::GetStaticHeight(PhaseShift const& phaseShift, uint32 mapId, f
float vmapHeight = VMAP_INVALID_HEIGHT_VALUE;
if (checkVMap)
{
- VMAP::IVMapManager* vmgr = VMAP::VMapFactory::createOrGetVMapManager();
+ VMAP::VMapManager2* vmgr = VMAP::VMapFactory::createOrGetVMapManager();
if (vmgr->isHeightCalcEnabled())
vmapHeight = vmgr->getHeight(terrainMapId, x, y, z, maxSearchDist);
}
diff --git a/src/tools/mmaps_generator/TerrainBuilder.cpp b/src/tools/mmaps_generator/TerrainBuilder.cpp
index a2a542ed095..6894021ea90 100644
--- a/src/tools/mmaps_generator/TerrainBuilder.cpp
+++ b/src/tools/mmaps_generator/TerrainBuilder.cpp
@@ -589,23 +589,12 @@ namespace MMAP
if (result != VMAP::LoadResult::Success)
break;
- VMAP::InstanceTreeMap instanceTrees;
- vmapManager->getInstanceMapTree(instanceTrees);
-
- if (!instanceTrees[mapID])
+ std::span<VMAP::ModelInstance const> models = vmapManager->getModelsOnMap(mapID);
+ if (models.empty())
break;
- VMAP::ModelInstance* models = nullptr;
- uint32 count = 0;
- instanceTrees[mapID]->getModelInstances(models, count);
-
- if (!models)
- break;
-
- for (uint32 i = 0; i < count; ++i)
+ for (VMAP::ModelInstance const& instance : models)
{
- VMAP::ModelInstance const& instance = models[i];
-
// model instances exist in tree even though there are instances of that model in this tile
VMAP::WorldModel const* worldModel = instance.getWorldModel();
if (!worldModel)