aboutsummaryrefslogtreecommitdiff
path: root/src/common/Collision
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/Collision')
-rw-r--r--src/common/Collision/BoundingIntervalHierarchy.cpp1
-rw-r--r--src/common/Collision/BoundingIntervalHierarchy.h2
-rw-r--r--src/common/Collision/DynamicTree.cpp7
-rw-r--r--src/common/Collision/DynamicTree.h3
-rw-r--r--src/common/Collision/Management/IVMapManager.h127
-rw-r--r--src/common/Collision/Management/MMapManager.cpp1
-rw-r--r--src/common/Collision/Management/VMapFactory.cpp8
-rw-r--r--src/common/Collision/Management/VMapFactory.h6
-rw-r--r--src/common/Collision/Management/VMapManager.cpp (renamed from src/common/Collision/Management/VMapManager2.cpp)142
-rw-r--r--src/common/Collision/Management/VMapManager.h188
-rw-r--r--src/common/Collision/Management/VMapManager2.h127
-rw-r--r--src/common/Collision/Maps/MapTree.cpp39
-rw-r--r--src/common/Collision/Maps/MapTree.h27
-rw-r--r--src/common/Collision/Models/GameObjectModel.cpp2
-rw-r--r--src/common/Collision/RegularGrid.h60
-rw-r--r--src/common/Collision/VMapDefinitions.h2
16 files changed, 329 insertions, 413 deletions
diff --git a/src/common/Collision/BoundingIntervalHierarchy.cpp b/src/common/Collision/BoundingIntervalHierarchy.cpp
index e37d00b802a..7e58d6c9003 100644
--- a/src/common/Collision/BoundingIntervalHierarchy.cpp
+++ b/src/common/Collision/BoundingIntervalHierarchy.cpp
@@ -16,6 +16,7 @@
*/
#include "BoundingIntervalHierarchy.h"
+#include <stdexcept>
void BIH::buildHierarchy(std::vector<uint32>& tempTree, buildData& dat, BuildStats& stats) const
{
diff --git a/src/common/Collision/BoundingIntervalHierarchy.h b/src/common/Collision/BoundingIntervalHierarchy.h
index 5c9c69ed1b6..5674ee2057d 100644
--- a/src/common/Collision/BoundingIntervalHierarchy.h
+++ b/src/common/Collision/BoundingIntervalHierarchy.h
@@ -24,8 +24,6 @@
#include <G3D/Ray.h>
#include <G3D/Vector3.h>
#include <algorithm>
-#include <limits>
-#include <stdexcept>
#include <vector>
#define MAX_STACK_SIZE 64
diff --git a/src/common/Collision/DynamicTree.cpp b/src/common/Collision/DynamicTree.cpp
index 073e317e4ae..85dc9d52618 100644
--- a/src/common/Collision/DynamicTree.cpp
+++ b/src/common/Collision/DynamicTree.cpp
@@ -23,7 +23,7 @@
#include "RegularGrid.h"
#include "Timer.h"
#include "VMapFactory.h"
-#include "VMapManager2.h"
+#include "VMapManager.h"
#include "WorldModel.h"
#include <G3D/AABox.h>
#include <G3D/Ray.h>
@@ -101,10 +101,7 @@ struct DynTreeImpl : public ParentTree/*, public Intersectable*/
DynamicMapTree::DynamicMapTree() : impl(new DynTreeImpl()) { }
-DynamicMapTree::~DynamicMapTree()
-{
- delete impl;
-}
+DynamicMapTree::~DynamicMapTree() = default;
void DynamicMapTree::insert(GameObjectModel const& mdl)
{
diff --git a/src/common/Collision/DynamicTree.h b/src/common/Collision/DynamicTree.h
index 50dc3d92993..11d701ebd7c 100644
--- a/src/common/Collision/DynamicTree.h
+++ b/src/common/Collision/DynamicTree.h
@@ -20,6 +20,7 @@
#include "Define.h"
#include "Optional.h"
+#include <memory>
namespace G3D
{
@@ -38,7 +39,7 @@ namespace VMAP
class TC_COMMON_API DynamicMapTree
{
- DynTreeImpl *impl;
+ std::unique_ptr<DynTreeImpl> impl;
public:
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/MMapManager.cpp b/src/common/Collision/Management/MMapManager.cpp
index 8c926d79a6e..c10d64bfd36 100644
--- a/src/common/Collision/Management/MMapManager.cpp
+++ b/src/common/Collision/Management/MMapManager.cpp
@@ -21,6 +21,7 @@
#include "Log.h"
#include "MMapDefines.h"
#include "Memory.h"
+#include <algorithm>
namespace MMAP
{
diff --git a/src/common/Collision/Management/VMapFactory.cpp b/src/common/Collision/Management/VMapFactory.cpp
index 191f33a7663..90c611a78c2 100644
--- a/src/common/Collision/Management/VMapFactory.cpp
+++ b/src/common/Collision/Management/VMapFactory.cpp
@@ -16,18 +16,18 @@
*/
#include "VMapFactory.h"
-#include "VMapManager2.h"
+#include "VMapManager.h"
namespace VMAP
{
- VMapManager2* gVMapManager = nullptr;
+ VMapManager* gVMapManager = nullptr;
//===============================================
// just return the instance
- VMapManager2* VMapFactory::createOrGetVMapManager()
+ VMapManager* VMapFactory::createOrGetVMapManager()
{
if (gVMapManager == nullptr)
- gVMapManager= new VMapManager2();
+ gVMapManager= new VMapManager();
return gVMapManager;
}
diff --git a/src/common/Collision/Management/VMapFactory.h b/src/common/Collision/Management/VMapFactory.h
index ceb07fce975..bb401888beb 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.
@@ -26,12 +26,12 @@ This is the access point to the VMapManager.
namespace VMAP
{
- class VMapManager2;
+ class VMapManager;
class TC_COMMON_API VMapFactory
{
public:
- static VMapManager2* createOrGetVMapManager();
+ static VMapManager* createOrGetVMapManager();
static void clear();
};
diff --git a/src/common/Collision/Management/VMapManager2.cpp b/src/common/Collision/Management/VMapManager.cpp
index 93a1f7e4995..ddf8c70be71 100644
--- a/src/common/Collision/Management/VMapManager2.cpp
+++ b/src/common/Collision/Management/VMapManager.cpp
@@ -15,7 +15,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "VMapManager2.h"
+#include "VMapManager.h"
#include "Errors.h"
#include "Log.h"
#include "MapTree.h"
@@ -23,16 +23,19 @@
#include "VMapDefinitions.h"
#include "WorldModel.h"
#include <G3D/Vector3.h>
-#include <string>
-
-using G3D::Vector3;
namespace VMAP
{
class ManagedModel
{
public:
- explicit ManagedModel(VMapManager2& mgr, std::string const& name) : _mgr(mgr), _name(name) { }
+ explicit ManagedModel(VMapManager& 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()
{
@@ -42,8 +45,8 @@ namespace VMAP
WorldModel Model;
private:
- VMapManager2& _mgr;
- std::string const& _name; // valid only while model is held in VMapManager2::iLoadedModelFiles
+ VMapManager& _mgr;
+ std::string const& _name; // valid only while model is held in VMapManager::iLoadedModelFiles
};
bool readChunk(FILE* rf, char* dest, const char* compare, uint32 len)
@@ -52,20 +55,18 @@ namespace VMAP
return memcmp(dest, compare, len) == 0;
}
- VMapManager2::VMapManager2()
+ VMapManager::VMapManager() :
+ 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;
- }
+ VMapManager::~VMapManager() = default;
- InstanceTreeMap::const_iterator VMapManager2::GetMapTree(uint32 mapId) const
+ InstanceTreeMap::const_iterator VMapManager::GetMapTree(uint32 mapId) const
{
// return the iterator if found or end() if not found/NULL
auto itr = iInstanceMapTrees.find(mapId);
@@ -75,23 +76,30 @@ namespace VMAP
return itr;
}
- void VMapManager2::InitializeThreadUnsafe(std::unordered_map<uint32, std::vector<uint32>> const& mapData)
+ void VMapManager::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)
+ // the caller must pass the list of all mapIds that will be used in the VMapManager lifetime
+ 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;
}
- Vector3 VMapManager2::convertPositionToInternalRep(float x, float y, float z) const
+ void VMapManager::InitializeThreadUnsafe(uint32 mapId, int32 parentMapId)
{
- Vector3 pos;
- const float mid = 0.5f * 64.0f * 533.33333333f;
+ iInstanceMapTrees[mapId] = nullptr;
+ if (parentMapId >= 0)
+ iParentMapData[mapId] = parentMapId;
+ }
+
+ inline static G3D::Vector3 convertPositionToInternalRep(float x, float y, float z)
+ {
+ G3D::Vector3 pos;
+ constexpr float mid = 0.5f * 64.0f * 533.33333333f;
pos.x = mid - x;
pos.y = mid - y;
pos.z = z;
@@ -99,13 +107,17 @@ namespace VMAP
return pos;
}
- // move to MapTree too?
- std::string VMapManager2::getMapFileName(unsigned int mapId)
+ std::string VMapManager::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 VMapManager::getTileFileName(uint32 mapID, uint32 tileX, uint32 tileY, std::string_view extension)
+ {
+ return Trinity::StringFormat("{:04}/{:04}_{:02}_{:02}.{}", mapID, mapID, tileY, tileX, extension);
+ }
+
+ LoadResult VMapManager::loadMap(std::string const& basePath, uint32 mapId, uint32 x, uint32 y)
{
if (!isMapLoadingEnabled())
return LoadResult::DisabledInConfig;
@@ -116,55 +128,47 @@ namespace VMAP
if (thread_safe_environment)
instanceTree = iInstanceMapTrees.insert(InstanceTreeMap::value_type(mapId, nullptr)).first;
else
- ABORT_MSG("Invalid mapId %u tile [%u, %u] passed to VMapManager2 after startup in thread unsafe environment",
+ ABORT_MSG("Invalid mapId %u tile [%u, %u] passed to VMapManager after startup in thread unsafe environment",
mapId, x, y);
}
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 VMapManager::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 VMapManager::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 VMapManager::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;
@@ -172,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);
}
@@ -185,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 VMapManager::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;
@@ -215,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 VMapManager::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
@@ -234,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 VMapManager::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;
@@ -263,12 +267,12 @@ namespace VMAP
return false;
}
- std::shared_ptr<WorldModel> VMapManager2::acquireModelInstance(std::string const& basepath, std::string const& filename)
+ std::shared_ptr<WorldModel> VMapManager::acquireModelInstance(std::string const& basepath, std::string const& filename)
{
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();
@@ -278,39 +282,43 @@ namespace VMAP
worldmodel = std::make_shared<ManagedModel>(*this, key);
if (!worldmodel->Model.readFile(basepath + filename + ".vmo"))
{
- TC_LOG_ERROR("misc", "VMapManager2: could not load '{}{}.vmo'", basepath, filename);
+ TC_LOG_ERROR("misc", "VMapManager: could not load '{}{}.vmo'", basepath, filename);
return nullptr;
}
- TC_LOG_DEBUG("maps", "VMapManager2: loading file '{}{}'", basepath, filename);
+ TC_LOG_DEBUG("maps", "VMapManager: loading file '{}{}'", basepath, filename);
model = worldmodel;
return std::shared_ptr<WorldModel>(worldmodel, &worldmodel->Model);
}
- void VMapManager2::releaseModelInstance(std::string const& filename)
+ void VMapManager::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);
+ TC_LOG_DEBUG("maps", "VMapManager: unloading file '{}'", filename);
std::size_t erased = iLoadedModelFiles.erase(filename);
if (!erased)
- TC_LOG_ERROR("misc", "VMapManager2: trying to unload non-loaded file '{}'", filename);
+ TC_LOG_ERROR("misc", "VMapManager: trying to unload non-loaded file '{}'", filename);
}
- LoadResult VMapManager2::existsMap(char const* basePath, unsigned int mapId, int x, int y)
+ LoadResult VMapManager::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> VMapManager::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
+ int32 VMapManager::getParentMapId(uint32 mapId) const
{
auto itr = iParentMapData.find(mapId);
if (itr != iParentMapData.end())
diff --git a/src/common/Collision/Management/VMapManager.h b/src/common/Collision/Management/VMapManager.h
new file mode 100644
index 00000000000..ae91d3db50e
--- /dev/null
+++ b/src/common/Collision/Management/VMapManager.h
@@ -0,0 +1,188 @@
+/*
+ * 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 TRINITYCORE_VMAP_MANAGER2_H
+#define TRINITYCORE_VMAP_MANAGER2_H
+
+#include "Define.h"
+#include "ModelIgnoreFlags.h"
+#include "Optional.h"
+#include <memory>
+#include <mutex>
+#include <span>
+#include <string>
+#include <unordered_map>
+#include <vector>
+
+//===========================================================
+
+/**
+This is the main Class to manage loading and unloading of maps, line of sight, height calculation and so on.
+For each map or map tile to load it reads a directory file that contains the ModelContainer files used by this map or map tile.
+Each global map or instance has its own dynamic BSP-Tree.
+The loaded ModelContainers are included in one of these BSP-Trees.
+Additionally a table to match map ids and map names is used.
+*/
+
+//===========================================================
+
+namespace VMAP
+{
+ class ManagedModel;
+ class ModelInstance;
+ class StaticMapTree;
+ class WorldModel;
+
+ typedef std::unordered_map<uint32, std::unique_ptr<StaticMapTree>> InstanceTreeMap;
+ typedef std::unordered_map<std::string, std::weak_ptr<ManagedModel>> ModelFileMap;
+
+ enum DisableTypes : uint8
+ {
+ VMAP_DISABLE_AREAFLAG = 0x1,
+ VMAP_DISABLE_HEIGHT = 0x2,
+ VMAP_DISABLE_LOS = 0x4,
+ VMAP_DISABLE_LIQUIDSTATUS = 0x8
+ };
+
+ 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 VMapManager
+ {
+ protected:
+ bool iEnableLineOfSightCalc;
+ bool iEnableHeightCalc;
+ bool thread_safe_environment;
+ // Tree to check collision
+ ModelFileMap iLoadedModelFiles;
+ InstanceTreeMap iInstanceMapTrees;
+ std::unordered_map<uint32, uint32> iParentMapData;
+ // Mutex for iLoadedModelFiles
+ std::mutex LoadedModelFilesLock;
+
+ InstanceTreeMap::const_iterator GetMapTree(uint32 mapId) const;
+
+ public:
+ // public for debug
+ static std::string getMapFileName(uint32 mapId);
+ static std::string getTileFileName(uint32 mapID, uint32 tileX, uint32 tileY, std::string_view extension);
+
+ VMapManager();
+
+ VMapManager(VMapManager const&) = delete;
+ VMapManager(VMapManager&&) = delete;
+
+ VMapManager& operator=(VMapManager const&) = delete;
+ VMapManager& operator=(VMapManager&&) = delete;
+
+ ~VMapManager();
+
+ 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(std::string const& basePath, uint32 mapId, uint32 x, uint32 y);
+
+ void unloadMap(uint32 mapId, uint32 x, uint32 y);
+
+ void unloadMap(uint32 mapId);
+
+ bool isInLineOfSight(uint32 mapId, float x1, float y1, float z1, float x2, float y2, float z2, ModelIgnoreFlags ignoreFlags);
+ /**
+ 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(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);
+
+ /**
+ 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
+ static std::string getDirFileName(uint32 mapId, uint32 x, uint32 y)
+ {
+ return getTileFileName(mapId, x, y, "vmtile");
+ }
+ LoadResult existsMap(std::string const& basePath, uint32 mapId, uint32 x, uint32 y);
+
+ std::span<ModelInstance const> getModelsOnMap(uint32 mapId) const;
+
+ int32 getParentMapId(uint32 mapId) const;
+
+ typedef uint32(*GetLiquidFlagsFn)(uint32 liquidType);
+ GetLiquidFlagsFn GetLiquidFlagsPtr;
+
+ typedef bool(*IsVMAPDisabledForFn)(uint32 entry, uint8 flags);
+ IsVMAPDisabledForFn IsVMAPDisabledForPtr;
+ };
+}
+
+#endif // TRINITYCORE_VMAP_MANAGER2_H
diff --git a/src/common/Collision/Management/VMapManager2.h b/src/common/Collision/Management/VMapManager2.h
deleted file mode 100644
index 5abe003056c..00000000000
--- a/src/common/Collision/Management/VMapManager2.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 _VMAPMANAGER2_H
-#define _VMAPMANAGER2_H
-
-#include "Define.h"
-#include "IVMapManager.h"
-#include <memory>
-#include <mutex>
-#include <unordered_map>
-#include <vector>
-
-//===========================================================
-
-/**
-This is the main Class to manage loading and unloading of maps, line of sight, height calculation and so on.
-For each map or map tile to load it reads a directory file that contains the ModelContainer files used by this map or map tile.
-Each global map or instance has its own dynamic BSP-Tree.
-The loaded ModelContainers are included in one of these BSP-Trees.
-Additionally a table to match map ids and map names is used.
-*/
-
-//===========================================================
-
-namespace G3D
-{
- class Vector3;
-}
-
-namespace VMAP
-{
- class ManagedModel;
- class StaticMapTree;
- class WorldModel;
-
- typedef std::unordered_map<uint32, StaticMapTree*> InstanceTreeMap;
- typedef std::unordered_map<std::string, std::weak_ptr<ManagedModel>> ModelFileMap;
-
- enum DisableTypes
- {
- VMAP_DISABLE_AREAFLAG = 0x1,
- VMAP_DISABLE_HEIGHT = 0x2,
- VMAP_DISABLE_LOS = 0x4,
- VMAP_DISABLE_LIQUIDSTATUS = 0x8
- };
-
- class TC_COMMON_API VMapManager2 : public IVMapManager
- {
- protected:
- // 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);
-
- VMapManager2();
- ~VMapManager2();
-
- void InitializeThreadUnsafe(std::unordered_map<uint32, std::vector<uint32>> const& mapData);
-
- LoadResult loadMap(char const* pBasePath, unsigned int mapId, int x, int y) override;
-
- void unloadMap(unsigned int mapId, int x, int y) override;
-
- void unloadMap(unsigned int mapId) override;
-
- bool isInLineOfSight(unsigned int mapId, float x1, float y1, float z1, float x2, float y2, float z2, ModelIgnoreFlags ignoreFlags) override ;
- /**
- fill the hit pos and return true, if an object was hit
- */
- 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 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;
-
- 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
- {
- return getMapFileName(mapId);
- }
- virtual LoadResult existsMap(char const* basePath, unsigned int mapId, int x, int y) override;
-
- void getInstanceMapTree(InstanceTreeMap &instanceMapTree);
-
- int32 getParentMapId(uint32 mapId) const;
-
- typedef uint32(*GetLiquidFlagsFn)(uint32 liquidType);
- GetLiquidFlagsFn GetLiquidFlagsPtr;
-
- typedef bool(*IsVMAPDisabledForFn)(uint32 entry, uint8 flags);
- IsVMAPDisabledForFn IsVMAPDisabledForPtr;
- };
-}
-
-#endif
diff --git a/src/common/Collision/Maps/MapTree.cpp b/src/common/Collision/Maps/MapTree.cpp
index d828326806c..086ef975f1f 100644
--- a/src/common/Collision/Maps/MapTree.cpp
+++ b/src/common/Collision/Maps/MapTree.cpp
@@ -22,7 +22,7 @@
#include "Metric.h"
#include "ModelInstance.h"
#include "VMapDefinitions.h"
-#include "VMapManager2.h"
+#include "VMapManager.h"
#include "WorldModel.h"
#include <limits>
#include <string>
@@ -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);
@@ -206,19 +199,19 @@ namespace VMAP
explicit operator bool() const { return TileFile && SpawnIndicesFile; }
};
- TileFileOpenResult OpenMapTileFile(std::string const& basePath, uint32 mapID, uint32 tileX, uint32 tileY, VMapManager2* vm)
+ TileFileOpenResult OpenMapTileFile(std::string const& basePath, uint32 mapID, uint32 tileX, uint32 tileY, VMapManager* vm)
{
TileFileOpenResult result;
- result.Name = basePath + getTileFileName(mapID, tileX, tileY, "vmtile");
+ result.Name = basePath + VMapManager::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 + VMapManager::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 + VMapManager::getTileFileName(parentMapId, tileX, tileY, "vmtile");
result.TileFile.reset(fopen(result.Name.c_str(), "rb"));
result.UsedMapId = parentMapId;
if (result.TileFile)
@@ -232,12 +225,13 @@ 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, VMapManager* 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);
+
+ std::string fullname = basePath + VMapManager::getMapFileName(mapID);
auto rf = Trinity::make_unique_ptr_with_deleter<&::fclose>(fopen(fullname.c_str(), "rb"));
if (!rf)
@@ -291,7 +285,7 @@ namespace VMAP
//=========================================================
- LoadResult StaticMapTree::LoadMapTile(uint32 tileX, uint32 tileY, VMapManager2* vm)
+ LoadResult StaticMapTree::LoadMapTile(uint32 tileX, uint32 tileY, VMapManager* vm)
{
if (iTreeValues.empty())
{
@@ -375,7 +369,7 @@ namespace VMAP
//=========================================================
- void StaticMapTree::UnloadMapTile(uint32 tileX, uint32 tileY, VMapManager2* vm)
+ void StaticMapTree::UnloadMapTile(uint32 tileX, uint32 tileY, VMapManager* vm)
{
uint32 tileID = packTileID(tileX, tileY);
loadedTileMap::iterator tile = iLoadedTiles.find(tileID);
@@ -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..049b1c416b5 100644
--- a/src/common/Collision/Maps/MapTree.h
+++ b/src/common/Collision/Maps/MapTree.h
@@ -20,13 +20,14 @@
#include "Define.h"
#include "BoundingIntervalHierarchy.h"
+#include <span>
#include <unordered_map>
namespace VMAP
{
class ModelInstance;
class GroupModel;
- class VMapManager2;
+ class VMapManager;
enum class LoadResult : uint8;
enum class ModelIgnoreFlags : uint32;
@@ -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, VMapManager* 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);
+ LoadResult LoadMapTile(uint32 tileX, uint32 tileY, VMapManager* vm);
+ void UnloadMapTile(uint32 tileX, uint32 tileY, VMapManager* 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/common/Collision/Models/GameObjectModel.cpp b/src/common/Collision/Models/GameObjectModel.cpp
index 5d8712561f6..a1b583d14cc 100644
--- a/src/common/Collision/Models/GameObjectModel.cpp
+++ b/src/common/Collision/Models/GameObjectModel.cpp
@@ -16,7 +16,7 @@
*/
#include "VMapFactory.h"
-#include "VMapManager2.h"
+#include "VMapManager.h"
#include "VMapDefinitions.h"
#include "WorldModel.h"
#include "GameObjectModel.h"
diff --git a/src/common/Collision/RegularGrid.h b/src/common/Collision/RegularGrid.h
index 0110a17f412..459388d2662 100644
--- a/src/common/Collision/RegularGrid.h
+++ b/src/common/Collision/RegularGrid.h
@@ -22,7 +22,7 @@
#include "IteratorPair.h"
#include <G3D/Ray.h>
#include <G3D/BoundsTrait.h>
-#include <G3D/PositionTrait.h>
+#include <memory>
#include <unordered_map>
template<class Node>
@@ -33,8 +33,7 @@ struct NodeCreator{
template<class T,
class Node,
class NodeCreatorFunc = NodeCreator<Node>,
-class BoundsFunc = BoundsTrait<T>,
-class PositionFunc = PositionTrait<T>
+class BoundsFunc = BoundsTrait<T>
>
class TC_COMMON_API RegularGrid2D
{
@@ -44,27 +43,14 @@ public:
CELL_NUMBER = 64,
};
- #define HGRID_MAP_SIZE (533.33333f * 64.f) // shouldn't be changed
- #define CELL_SIZE float(HGRID_MAP_SIZE/(float)CELL_NUMBER)
+ #define CELL_SIZE 533.33333f
- typedef std::unordered_multimap<const T*, Node*> MemberTable;
+ typedef std::unordered_multimap<T const*, Node*> MemberTable;
MemberTable memberTable;
- Node* nodes[CELL_NUMBER][CELL_NUMBER];
+ std::unique_ptr<Node> nodes[CELL_NUMBER][CELL_NUMBER] = { };
- RegularGrid2D()
- {
- memset(nodes, 0, sizeof(nodes));
- }
-
- ~RegularGrid2D()
- {
- for (int x = 0; x < CELL_NUMBER; ++x)
- for (int y = 0; y < CELL_NUMBER; ++y)
- delete nodes[x][y];
- }
-
- void insert(const T& value)
+ void insert(T const& value)
{
G3D::AABox bounds = G3D::AABox::empty();
BoundsFunc::getBounds(value, bounds);
@@ -81,7 +67,7 @@ public:
}
}
- void remove(const T& value)
+ void remove(T const& value)
{
for (auto& p : Trinity::Containers::MapEqualRange(memberTable, &value))
p.second->remove(value);
@@ -93,25 +79,22 @@ public:
{
for (int x = 0; x < CELL_NUMBER; ++x)
for (int y = 0; y < CELL_NUMBER; ++y)
- if (Node* n = nodes[x][y])
+ if (Node* n = nodes[x][y].get())
n->balance();
}
- bool contains(const T& value) const { return memberTable.count(&value) > 0; }
+ bool contains(T const& value) const { return memberTable.contains(&value); }
bool empty() const { return memberTable.empty(); }
struct Cell
{
int x, y;
- bool operator==(Cell const& c2) const
- {
- return x == c2.x && y == c2.y;
- }
+
+ friend bool operator==(Cell const&, Cell const&) = default;
static Cell ComputeCell(float fx, float fy)
{
- Cell c = { int(fx * (1.f / CELL_SIZE) + (CELL_NUMBER / 2)), int(fy * (1.f / CELL_SIZE) + (CELL_NUMBER / 2)) };
- return c;
+ return { .x = int(fx * (1.f / CELL_SIZE) + (CELL_NUMBER / 2)), .y = int(fy * (1.f / CELL_SIZE) + (CELL_NUMBER / 2)) };
}
bool isValid() const { return x >= 0 && x < CELL_NUMBER && y >= 0 && y < CELL_NUMBER; }
@@ -121,18 +104,18 @@ public:
{
ASSERT(x < CELL_NUMBER && y < CELL_NUMBER);
if (!nodes[x][y])
- nodes[x][y] = NodeCreatorFunc::makeNode(x, y);
+ nodes[x][y].reset(NodeCreatorFunc::makeNode(x, y));
return *nodes[x][y];
}
template<typename RayCallback>
- void intersectRay(const G3D::Ray& ray, RayCallback& intersectCallback, float max_dist)
+ void intersectRay(G3D::Ray const& ray, RayCallback& intersectCallback, float max_dist)
{
intersectRay(ray, intersectCallback, max_dist, ray.origin() + ray.direction() * max_dist);
}
template<typename RayCallback>
- void intersectRay(const G3D::Ray& ray, RayCallback& intersectCallback, float& max_dist, const G3D::Vector3& end)
+ void intersectRay(G3D::Ray const& ray, RayCallback& intersectCallback, float& max_dist, G3D::Vector3 const& end)
{
Cell cell = Cell::ComputeCell(ray.origin().x, ray.origin().y);
if (!cell.isValid())
@@ -142,7 +125,7 @@ public:
if (cell == last_cell)
{
- if (Node* node = nodes[cell.x][cell.y])
+ if (Node* node = nodes[cell.x][cell.y].get())
node->intersectRay(ray, intersectCallback, max_dist);
return;
}
@@ -186,7 +169,7 @@ public:
float tDeltaY = voxel * std::fabs(ky_inv);
do
{
- if (Node* node = nodes[cell.x][cell.y])
+ if (Node* node = nodes[cell.x][cell.y].get())
{
//float enterdist = max_dist;
node->intersectRay(ray, intersectCallback, max_dist);
@@ -208,28 +191,27 @@ public:
}
template<typename IsectCallback>
- void intersectPoint(const G3D::Vector3& point, IsectCallback& intersectCallback)
+ void intersectPoint(G3D::Vector3 const& point, IsectCallback& intersectCallback)
{
Cell cell = Cell::ComputeCell(point.x, point.y);
if (!cell.isValid())
return;
- if (Node* node = nodes[cell.x][cell.y])
+ if (Node* node = nodes[cell.x][cell.y].get())
node->intersectPoint(point, intersectCallback);
}
// Optimized verson of intersectRay function for rays with vertical directions
template<typename RayCallback>
- void intersectZAllignedRay(const G3D::Ray& ray, RayCallback& intersectCallback, float& max_dist)
+ void intersectZAllignedRay(G3D::Ray const& ray, RayCallback& intersectCallback, float& max_dist)
{
Cell cell = Cell::ComputeCell(ray.origin().x, ray.origin().y);
if (!cell.isValid())
return;
- if (Node* node = nodes[cell.x][cell.y])
+ if (Node* node = nodes[cell.x][cell.y].get())
node->intersectRay(ray, intersectCallback, max_dist);
}
};
#undef CELL_SIZE
-#undef HGRID_MAP_SIZE
#endif
diff --git a/src/common/Collision/VMapDefinitions.h b/src/common/Collision/VMapDefinitions.h
index cb08107bc98..b5369eeb0a8 100644
--- a/src/common/Collision/VMapDefinitions.h
+++ b/src/common/Collision/VMapDefinitions.h
@@ -28,7 +28,7 @@ namespace VMAP
const char RAW_VMAP_MAGIC[] = "VMAP04D"; // used in extracted vmap files with raw data
const char GAMEOBJECT_MODELS[] = "GameObjectModels.dtree";
- // defined in VMapManager2.cpp currently...
+ // defined in VMapManager.cpp currently...
bool readChunk(FILE* rf, char *dest, const char *compare, uint32 len);
}