diff options
Diffstat (limited to 'src/common/Collision/Management')
| -rw-r--r-- | src/common/Collision/Management/IVMapManager.h | 127 | ||||
| -rw-r--r-- | src/common/Collision/Management/MMapManager.cpp | 1 | ||||
| -rw-r--r-- | src/common/Collision/Management/VMapFactory.cpp | 8 | ||||
| -rw-r--r-- | src/common/Collision/Management/VMapFactory.h | 6 | ||||
| -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.h | 188 | ||||
| -rw-r--r-- | src/common/Collision/Management/VMapManager2.h | 127 |
7 files changed, 271 insertions, 328 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/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 |
