From 03e2aa6737f7c4212f24bc739141c1f2b72639dd Mon Sep 17 00:00:00 2001 From: Shauren Date: Sat, 25 Oct 2025 00:55:34 +0200 Subject: Core/Vmaps: Rename VMapManager2 to VMapManager --- src/common/Collision/DynamicTree.cpp | 2 +- src/common/Collision/Management/VMapFactory.cpp | 8 +- src/common/Collision/Management/VMapFactory.h | 4 +- src/common/Collision/Management/VMapManager.cpp | 330 +++++++++++++++++++++++ src/common/Collision/Management/VMapManager.h | 188 +++++++++++++ src/common/Collision/Management/VMapManager2.cpp | 330 ----------------------- src/common/Collision/Management/VMapManager2.h | 188 ------------- src/common/Collision/Maps/MapTree.cpp | 18 +- src/common/Collision/Maps/MapTree.h | 8 +- src/common/Collision/Models/GameObjectModel.cpp | 2 +- src/common/Collision/VMapDefinitions.h | 2 +- src/server/game/Conditions/DisableMgr.cpp | 2 +- src/server/game/Entities/Object/Object.cpp | 2 +- src/server/game/Globals/ObjectMgr.cpp | 6 +- src/server/game/Maps/Map.cpp | 2 +- src/server/game/Maps/TerrainMgr.cpp | 14 +- src/server/game/Spells/Spell.cpp | 2 +- src/server/game/World/World.cpp | 4 +- src/server/scripts/Commands/cs_server.cpp | 2 +- src/tools/mmaps_generator/PathCommon.h | 4 +- src/tools/mmaps_generator/PathGenerator.cpp | 6 +- src/tools/mmaps_generator/TerrainBuilder.cpp | 8 +- src/tools/mmaps_generator/TerrainBuilder.h | 8 +- src/tools/mmaps_generator/TileBuilder.cpp | 4 +- 24 files changed, 572 insertions(+), 572 deletions(-) create mode 100644 src/common/Collision/Management/VMapManager.cpp create mode 100644 src/common/Collision/Management/VMapManager.h delete mode 100644 src/common/Collision/Management/VMapManager2.cpp delete mode 100644 src/common/Collision/Management/VMapManager2.h (limited to 'src') diff --git a/src/common/Collision/DynamicTree.cpp b/src/common/Collision/DynamicTree.cpp index 7566edb473d..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 #include 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 29583348ee8..bb401888beb 100644 --- a/src/common/Collision/Management/VMapFactory.h +++ b/src/common/Collision/Management/VMapFactory.h @@ -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/VMapManager.cpp b/src/common/Collision/Management/VMapManager.cpp new file mode 100644 index 00000000000..ddf8c70be71 --- /dev/null +++ b/src/common/Collision/Management/VMapManager.cpp @@ -0,0 +1,330 @@ +/* + * 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 . + */ + +#include "VMapManager.h" +#include "Errors.h" +#include "Log.h" +#include "MapTree.h" +#include "ModelInstance.h" +#include "VMapDefinitions.h" +#include "WorldModel.h" +#include + +namespace VMAP +{ + class ManagedModel + { + public: + 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() + { + _mgr.releaseModelInstance(_name); + } + + WorldModel Model; + + private: + 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) + { + if (fread(dest, sizeof(char), len, rf) != len) return false; + return memcmp(dest, compare, len) == 0; + } + + VMapManager::VMapManager() : + iEnableLineOfSightCalc(true), + iEnableHeightCalc(true), + thread_safe_environment(true), + GetLiquidFlagsPtr([](uint32 /*liquidTypeId*/) { return 0u; }), + IsVMAPDisabledForPtr([](uint32 /*mapId*/, uint8 /*disableFlags*/) { return false; }) + { + } + + VMapManager::~VMapManager() = default; + + InstanceTreeMap::const_iterator VMapManager::GetMapTree(uint32 mapId) const + { + // return the iterator if found or end() if not found/NULL + auto itr = iInstanceMapTrees.find(mapId); + if (itr != iInstanceMapTrees.cend() && !itr->second) + itr = iInstanceMapTrees.cend(); + + return itr; + } + + void VMapManager::InitializeThreadUnsafe(std::unordered_map> const& 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[mapId] = nullptr; + for (uint32 childMapId : childMapIds) + iParentMapData[childMapId] = mapId; + } + + thread_safe_environment = false; + } + + void VMapManager::InitializeThreadUnsafe(uint32 mapId, int32 parentMapId) + { + 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; + + return pos; + } + + std::string VMapManager::getMapFileName(uint32 mapId) + { + return Trinity::StringFormat("{:04}/{:04}.vmtree", mapId, mapId); + } + + 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; + + auto instanceTree = iInstanceMapTrees.find(mapId); + if (instanceTree == iInstanceMapTrees.end()) + { + if (thread_safe_environment) + instanceTree = iInstanceMapTrees.insert(InstanceTreeMap::value_type(mapId, nullptr)).first; + else + 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); + std::unique_ptr newTree = std::make_unique(mapId, basePath); + LoadResult treeInitResult = newTree->InitMap(mapFileName); + if (treeInitResult != LoadResult::Success) + return treeInitResult; + + instanceTree->second = std::move(newTree); + } + + return instanceTree->second->LoadMapTile(x, y, this); + } + + 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) + instanceTree->second = nullptr; + } + } + + void VMapManager::unloadMap(uint32 mapId) + { + auto instanceTree = iInstanceMapTrees.find(mapId); + if (instanceTree != iInstanceMapTrees.end() && instanceTree->second) + { + instanceTree->second->UnloadMap(); + if (instanceTree->second->numLoadedTiles() == 0) + instanceTree->second = nullptr; + } + } + + 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; + + auto instanceTree = GetMapTree(mapId); + if (instanceTree != iInstanceMapTrees.end()) + { + G3D::Vector3 pos1 = convertPositionToInternalRep(x1, y1, z1); + G3D::Vector3 pos2 = convertPositionToInternalRep(x2, y2, z2); + if (pos1 != pos2) + return instanceTree->second->isInLineOfSight(pos1, pos2, ignoreFlags); + } + + return true; + } + + /** + get the hit position and return true if we hit something + otherwise the result pos will be the dest pos + */ + 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()) + { + 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; + ry = resultPos.y; + rz = resultPos.z; + return result; + } + } + + rx = x2; + ry = y2; + rz = z2; + + return false; + } + + /** + get height or INVALID_HEIGHT if no height available + */ + + 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()) + { + 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 + + return height; + } + } + + return VMAP_INVALID_HEIGHT_VALUE; + } + + bool VMapManager::getAreaAndLiquidData(uint32 mapId, float x, float y, float z, Optional reqLiquidType, AreaAndLiquidData& data) const + { + InstanceTreeMap::const_iterator instanceTree = GetMapTree(mapId); + if (instanceTree != iInstanceMapTrees.end()) + { + LocationInfo info; + G3D::Vector3 pos = convertPositionToInternalRep(x, y, z); + if (instanceTree->second->GetLocationInfo(pos, info)) + { + data.floorZ = info.ground_Z; + if (!IsVMAPDisabledForPtr(mapId, VMAP_DISABLE_LIQUIDSTATUS)) + { + uint32 liquidType = info.hitModel->GetLiquidType(); // entry from LiquidType.dbc + float liquidLevel; + if (!reqLiquidType || (GetLiquidFlagsPtr(liquidType) & *reqLiquidType)) + if (info.hitInstance->GetLiquidLevel(pos, info, liquidLevel)) + data.liquidInfo.emplace(liquidType, liquidLevel); + } + + if (!IsVMAPDisabledForPtr(mapId, VMAP_DISABLE_AREAFLAG)) + data.areaInfo.emplace(info.hitModel->GetWmoID(), info.hitInstance->adtId, info.rootId, info.hitModel->GetMogpFlags(), info.hitInstance->ID); + + return true; + } + } + + return false; + } + + std::shared_ptr VMapManager::acquireModelInstance(std::string const& basepath, std::string const& filename) + { + std::shared_ptr 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 lock(LoadedModelFilesLock); + + auto& [key, model] = *iLoadedModelFiles.try_emplace(filename).first; + worldmodel = model.lock(); + if (worldmodel) + return std::shared_ptr(worldmodel, &worldmodel->Model); + + worldmodel = std::make_shared(*this, key); + if (!worldmodel->Model.readFile(basepath + filename + ".vmo")) + { + TC_LOG_ERROR("misc", "VMapManager: could not load '{}{}.vmo'", basepath, filename); + return nullptr; + } + TC_LOG_DEBUG("maps", "VMapManager: loading file '{}{}'", basepath, filename); + + model = worldmodel; + + return std::shared_ptr(worldmodel, &worldmodel->Model); + } + + void VMapManager::releaseModelInstance(std::string const& filename) + { + //! Critical section, thread safe access to iLoadedModelFiles + std::lock_guard lock(LoadedModelFilesLock); + + TC_LOG_DEBUG("maps", "VMapManager: unloading file '{}'", filename); + + std::size_t erased = iLoadedModelFiles.erase(filename); + if (!erased) + TC_LOG_ERROR("misc", "VMapManager: trying to unload non-loaded file '{}'", filename); + } + + LoadResult VMapManager::existsMap(std::string const& basePath, uint32 mapId, uint32 x, uint32 y) + { + return StaticMapTree::CanLoadMap(basePath, mapId, x, y, this); + } + + std::span VMapManager::getModelsOnMap(uint32 mapId) const + { + InstanceTreeMap::const_iterator mapTree = GetMapTree(mapId); + if (mapTree != iInstanceMapTrees.end()) + return mapTree->second->getModelInstances(); + + return {}; + } + + int32 VMapManager::getParentMapId(uint32 mapId) const + { + auto itr = iParentMapData.find(mapId); + if (itr != iParentMapData.end()) + return int32(itr->second); + + return -1; + } + +} // namespace VMAP 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 . + */ + +#ifndef TRINITYCORE_VMAP_MANAGER2_H +#define TRINITYCORE_VMAP_MANAGER2_H + +#include "Define.h" +#include "ModelIgnoreFlags.h" +#include "Optional.h" +#include +#include +#include +#include +#include +#include + +//=========================================================== + +/** +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> InstanceTreeMap; + typedef std::unordered_map> 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; + Optional 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 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> 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 reqLiquidType, AreaAndLiquidData& data) const; + + std::shared_ptr 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 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.cpp b/src/common/Collision/Management/VMapManager2.cpp deleted file mode 100644 index b4f01411543..00000000000 --- a/src/common/Collision/Management/VMapManager2.cpp +++ /dev/null @@ -1,330 +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 . - */ - -#include "VMapManager2.h" -#include "Errors.h" -#include "Log.h" -#include "MapTree.h" -#include "ModelInstance.h" -#include "VMapDefinitions.h" -#include "WorldModel.h" -#include - -namespace VMAP -{ - class ManagedModel - { - 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); - } - - WorldModel Model; - - private: - VMapManager2& _mgr; - std::string const& _name; // valid only while model is held in VMapManager2::iLoadedModelFiles - }; - - bool readChunk(FILE* rf, char* dest, const char* compare, uint32 len) - { - if (fread(dest, sizeof(char), len, rf) != len) return false; - return memcmp(dest, compare, len) == 0; - } - - VMapManager2::VMapManager2() : - iEnableLineOfSightCalc(true), - iEnableHeightCalc(true), - thread_safe_environment(true), - GetLiquidFlagsPtr([](uint32 /*liquidTypeId*/) { return 0u; }), - IsVMAPDisabledForPtr([](uint32 /*mapId*/, uint8 /*disableFlags*/) { return false; }) - { - } - - VMapManager2::~VMapManager2() = default; - - InstanceTreeMap::const_iterator VMapManager2::GetMapTree(uint32 mapId) const - { - // return the iterator if found or end() if not found/NULL - auto itr = iInstanceMapTrees.find(mapId); - if (itr != iInstanceMapTrees.cend() && !itr->second) - itr = iInstanceMapTrees.cend(); - - return itr; - } - - void VMapManager2::InitializeThreadUnsafe(std::unordered_map> const& mapData) - { - // the caller must pass the list of all mapIds that will be used in the VMapManager2 lifetime - for (auto const& [mapId, childMapIds] : mapData) - { - iInstanceMapTrees[mapId] = nullptr; - for (uint32 childMapId : childMapIds) - iParentMapData[childMapId] = mapId; - } - - thread_safe_environment = false; - } - - void VMapManager2::InitializeThreadUnsafe(uint32 mapId, int32 parentMapId) - { - 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; - - return pos; - } - - std::string VMapManager2::getMapFileName(uint32 mapId) - { - return Trinity::StringFormat("{:04}/{:04}.vmtree", mapId, mapId); - } - - 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; - - auto instanceTree = iInstanceMapTrees.find(mapId); - if (instanceTree == iInstanceMapTrees.end()) - { - 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", - mapId, x, y); - } - - if (!instanceTree->second) - { - std::string mapFileName = getMapFileName(mapId); - std::unique_ptr newTree = std::make_unique(mapId, basePath); - LoadResult treeInitResult = newTree->InitMap(mapFileName); - if (treeInitResult != LoadResult::Success) - return treeInitResult; - - instanceTree->second = std::move(newTree); - } - - return instanceTree->second->LoadMapTile(x, y, this); - } - - 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) - instanceTree->second = nullptr; - } - } - - void VMapManager2::unloadMap(uint32 mapId) - { - auto instanceTree = iInstanceMapTrees.find(mapId); - if (instanceTree != iInstanceMapTrees.end() && instanceTree->second) - { - instanceTree->second->UnloadMap(); - if (instanceTree->second->numLoadedTiles() == 0) - instanceTree->second = nullptr; - } - } - - 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; - - auto instanceTree = GetMapTree(mapId); - if (instanceTree != iInstanceMapTrees.end()) - { - G3D::Vector3 pos1 = convertPositionToInternalRep(x1, y1, z1); - G3D::Vector3 pos2 = convertPositionToInternalRep(x2, y2, z2); - if (pos1 != pos2) - return instanceTree->second->isInLineOfSight(pos1, pos2, ignoreFlags); - } - - return true; - } - - /** - get the hit position and return true if we hit something - otherwise the result pos will be the dest pos - */ - 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()) - { - 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; - ry = resultPos.y; - rz = resultPos.z; - return result; - } - } - - rx = x2; - ry = y2; - rz = z2; - - return false; - } - - /** - get height or INVALID_HEIGHT if no height available - */ - - 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()) - { - 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 - - return height; - } - } - - return VMAP_INVALID_HEIGHT_VALUE; - } - - bool VMapManager2::getAreaAndLiquidData(uint32 mapId, float x, float y, float z, Optional reqLiquidType, AreaAndLiquidData& data) const - { - InstanceTreeMap::const_iterator instanceTree = GetMapTree(mapId); - if (instanceTree != iInstanceMapTrees.end()) - { - LocationInfo info; - G3D::Vector3 pos = convertPositionToInternalRep(x, y, z); - if (instanceTree->second->GetLocationInfo(pos, info)) - { - data.floorZ = info.ground_Z; - if (!IsVMAPDisabledForPtr(mapId, VMAP_DISABLE_LIQUIDSTATUS)) - { - uint32 liquidType = info.hitModel->GetLiquidType(); // entry from LiquidType.dbc - float liquidLevel; - if (!reqLiquidType || (GetLiquidFlagsPtr(liquidType) & *reqLiquidType)) - if (info.hitInstance->GetLiquidLevel(pos, info, liquidLevel)) - data.liquidInfo.emplace(liquidType, liquidLevel); - } - - if (!IsVMAPDisabledForPtr(mapId, VMAP_DISABLE_AREAFLAG)) - data.areaInfo.emplace(info.hitModel->GetWmoID(), info.hitInstance->adtId, info.rootId, info.hitModel->GetMogpFlags(), info.hitInstance->ID); - - return true; - } - } - - return false; - } - - std::shared_ptr VMapManager2::acquireModelInstance(std::string const& basepath, std::string const& filename) - { - std::shared_ptr 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 lock(LoadedModelFilesLock); - - auto& [key, model] = *iLoadedModelFiles.try_emplace(filename).first; - worldmodel = model.lock(); - if (worldmodel) - return std::shared_ptr(worldmodel, &worldmodel->Model); - - worldmodel = std::make_shared(*this, key); - if (!worldmodel->Model.readFile(basepath + filename + ".vmo")) - { - TC_LOG_ERROR("misc", "VMapManager2: could not load '{}{}.vmo'", basepath, filename); - return nullptr; - } - TC_LOG_DEBUG("maps", "VMapManager2: loading file '{}{}'", basepath, filename); - - model = worldmodel; - - return std::shared_ptr(worldmodel, &worldmodel->Model); - } - - void VMapManager2::releaseModelInstance(std::string const& filename) - { - //! Critical section, thread safe access to iLoadedModelFiles - std::lock_guard lock(LoadedModelFilesLock); - - TC_LOG_DEBUG("maps", "VMapManager2: unloading file '{}'", filename); - - std::size_t erased = iLoadedModelFiles.erase(filename); - if (!erased) - TC_LOG_ERROR("misc", "VMapManager2: trying to unload non-loaded file '{}'", filename); - } - - LoadResult VMapManager2::existsMap(std::string const& basePath, uint32 mapId, uint32 x, uint32 y) - { - return StaticMapTree::CanLoadMap(basePath, mapId, x, y, this); - } - - std::span VMapManager2::getModelsOnMap(uint32 mapId) const - { - InstanceTreeMap::const_iterator mapTree = GetMapTree(mapId); - if (mapTree != iInstanceMapTrees.end()) - return mapTree->second->getModelInstances(); - - return {}; - } - - int32 VMapManager2::getParentMapId(uint32 mapId) const - { - auto itr = iParentMapData.find(mapId); - if (itr != iParentMapData.end()) - return int32(itr->second); - - return -1; - } - -} // namespace VMAP diff --git a/src/common/Collision/Management/VMapManager2.h b/src/common/Collision/Management/VMapManager2.h deleted file mode 100644 index 84aac14f76d..00000000000 --- a/src/common/Collision/Management/VMapManager2.h +++ /dev/null @@ -1,188 +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 . - */ - -#ifndef TRINITYCORE_VMAP_MANAGER2_H -#define TRINITYCORE_VMAP_MANAGER2_H - -#include "Define.h" -#include "ModelIgnoreFlags.h" -#include "Optional.h" -#include -#include -#include -#include -#include -#include - -//=========================================================== - -/** -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> InstanceTreeMap; - typedef std::unordered_map> 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; - Optional 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 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); - - VMapManager2(); - - VMapManager2(VMapManager2 const&) = delete; - VMapManager2(VMapManager2&&) = delete; - - VMapManager2& operator=(VMapManager2 const&) = delete; - VMapManager2& operator=(VMapManager2&&) = delete; - - ~VMapManager2(); - - void InitializeThreadUnsafe(std::unordered_map> 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 reqLiquidType, AreaAndLiquidData& data) const; - - std::shared_ptr 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 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/Maps/MapTree.cpp b/src/common/Collision/Maps/MapTree.cpp index 9438ba6b219..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 #include @@ -199,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 + VMapManager2::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 + VMapManager2::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 + VMapManager2::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) @@ -225,13 +225,13 @@ namespace VMAP } //========================================================= - LoadResult StaticMapTree::CanLoadMap(std::string const& 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.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) @@ -285,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()) { @@ -369,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); diff --git a/src/common/Collision/Maps/MapTree.h b/src/common/Collision/Maps/MapTree.h index 641708fa2ad..049b1c416b5 100644 --- a/src/common/Collision/Maps/MapTree.h +++ b/src/common/Collision/Maps/MapTree.h @@ -27,7 +27,7 @@ namespace VMAP { class ModelInstance; class GroupModel; - class VMapManager2; + class VMapManager; enum class LoadResult : uint8; enum class ModelIgnoreFlags : uint32; @@ -66,7 +66,7 @@ namespace VMAP 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(std::string const& basePath, uint32 mapID, uint32 tileX, uint32 tileY, VMapManager2* vm); + static LoadResult CanLoadMap(std::string const& basePath, uint32 mapID, uint32 tileX, uint32 tileY, VMapManager* vm); StaticMapTree(uint32 mapID, std::string const& basePath); ~StaticMapTree(); @@ -78,8 +78,8 @@ namespace VMAP 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()); } std::span getModelInstances() const; 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/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); } diff --git a/src/server/game/Conditions/DisableMgr.cpp b/src/server/game/Conditions/DisableMgr.cpp index 0ef3df3ae3b..a09abd8bc50 100644 --- a/src/server/game/Conditions/DisableMgr.cpp +++ b/src/server/game/Conditions/DisableMgr.cpp @@ -26,7 +26,7 @@ #include "Player.h" #include "SpellMgr.h" #include "StringConvert.h" -#include "VMapManager2.h" +#include "VMapManager.h" #include "World.h" namespace DisableMgr diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp index 0f729d06dff..aa090bc5c1b 100644 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -52,7 +52,7 @@ #include "Util.h" #include "VMapFactory.h" #include "Vehicle.h" -#include "VMapManager2.h" +#include "VMapManager.h" #include "World.h" #include #include diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp index f6e53f377a1..1b9857defad 100644 --- a/src/server/game/Globals/ObjectMgr.cpp +++ b/src/server/game/Globals/ObjectMgr.cpp @@ -71,7 +71,7 @@ #include "Timer.h" #include "TransportMgr.h" #include "VMapFactory.h" -#include "VMapManager2.h" +#include "VMapManager.h" #include "Vehicle.h" #include "World.h" #include "advstd.h" @@ -2197,7 +2197,7 @@ void ObjectMgr::LoadCreatures() if (sWorld->getBoolConfig(CONFIG_CREATURE_CHECK_INVALID_POSITION)) { - if (VMAP::VMapManager2* vmgr = VMAP::VMapFactory::createOrGetVMapManager()) + if (VMAP::VMapManager* vmgr = VMAP::VMapFactory::createOrGetVMapManager()) { if (vmgr->isMapLoadingEnabled() && !IsTransportMap(data.mapId)) { @@ -2553,7 +2553,7 @@ void ObjectMgr::LoadGameObjects() if (sWorld->getBoolConfig(CONFIG_GAME_OBJECT_CHECK_INVALID_POSITION)) { - if (VMAP::VMapManager2* vmgr = VMAP::VMapFactory::createOrGetVMapManager()) + if (VMAP::VMapManager* vmgr = VMAP::VMapFactory::createOrGetVMapManager()) { if (vmgr->isMapLoadingEnabled() && !IsTransportMap(data.mapId)) { diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index e9e4748b440..3a8e3c4cc56 100644 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -52,7 +52,7 @@ #include "TerrainMgr.h" #include "Transport.h" #include "VMapFactory.h" -#include "VMapManager2.h" +#include "VMapManager.h" #include "Vehicle.h" #include "Vignette.h" #include "VignettePackets.h" diff --git a/src/server/game/Maps/TerrainMgr.cpp b/src/server/game/Maps/TerrainMgr.cpp index 6bfe066994d..19dd852baca 100644 --- a/src/server/game/Maps/TerrainMgr.cpp +++ b/src/server/game/Maps/TerrainMgr.cpp @@ -28,7 +28,7 @@ #include "ScriptMgr.h" #include "Util.h" #include "VMapFactory.h" -#include "VMapManager2.h" +#include "VMapManager.h" #include "World.h" #include @@ -109,12 +109,12 @@ bool TerrainInfo::ExistMap(uint32 mapid, int32 gx, int32 gy, bool log /*= true*/ bool TerrainInfo::ExistVMap(uint32 mapid, int32 gx, int32 gy) { - if (VMAP::VMapManager2* vmgr = VMAP::VMapFactory::createOrGetVMapManager()) + if (VMAP::VMapManager* vmgr = VMAP::VMapFactory::createOrGetVMapManager()) { if (vmgr->isMapLoadingEnabled()) { VMAP::LoadResult result = vmgr->existsMap(sWorld->GetDataPath() + "vmaps", mapid, gx, gy); - std::string name = VMAP::VMapManager2::getDirFileName(mapid, gx, gy); + std::string name = VMAP::VMapManager::getDirFileName(mapid, gx, gy); switch (result) { case VMAP::LoadResult::Success: @@ -334,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 reqLiquidType, float collisionHeight, DynamicMapTree const* dynamicMapTree) { - VMAP::VMapManager2* vmgr = VMAP::VMapFactory::createOrGetVMapManager(); + VMAP::VMapManager* vmgr = VMAP::VMapFactory::createOrGetVMapManager(); VMAP::AreaAndLiquidData vmapData; VMAP::AreaAndLiquidData dynData; VMAP::AreaAndLiquidData* wmoData = nullptr; @@ -484,7 +484,7 @@ void TerrainInfo::GetFullTerrainStatusForPosition(PhaseShift const& phaseShift, ZLiquidStatus TerrainInfo::GetLiquidStatus(PhaseShift const& phaseShift, uint32 mapId, float x, float y, float z, Optional ReqLiquidType, LiquidData* data, float collisionHeight) { ZLiquidStatus result = LIQUID_MAP_NO_WATER; - VMAP::VMapManager2* vmgr = VMAP::VMapFactory::createOrGetVMapManager(); + VMAP::VMapManager* vmgr = VMAP::VMapFactory::createOrGetVMapManager(); VMAP::AreaAndLiquidData vmapData; bool useGridLiquid = true; uint32 terrainMapId = PhasingHandler::GetTerrainMapId(phaseShift, mapId, this, x, y); @@ -585,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::VMapManager2* vmgr = VMAP::VMapFactory::createOrGetVMapManager(); + VMAP::VMapManager* vmgr = VMAP::VMapFactory::createOrGetVMapManager(); VMAP::AreaAndLiquidData vdata; VMAP::AreaAndLiquidData ddata; @@ -703,7 +703,7 @@ float TerrainInfo::GetStaticHeight(PhaseShift const& phaseShift, uint32 mapId, f float vmapHeight = VMAP_INVALID_HEIGHT_VALUE; if (checkVMap) { - VMAP::VMapManager2* vmgr = VMAP::VMapFactory::createOrGetVMapManager(); + VMAP::VMapManager* vmgr = VMAP::VMapFactory::createOrGetVMapManager(); if (vmgr->isHeightCalcEnabled()) vmapHeight = vmgr->getHeight(terrainMapId, x, y, z, maxSearchDist); } diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp index c4260860fb3..3904b81a472 100644 --- a/src/server/game/Spells/Spell.cpp +++ b/src/server/game/Spells/Spell.cpp @@ -65,7 +65,7 @@ #include "Util.h" #include "VMapFactory.h" #include "Vehicle.h" -#include "VMapManager2.h" +#include "VMapManager.h" #include "World.h" #include "WorldSession.h" #include diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp index d4436a76e96..7bb15be57ca 100644 --- a/src/server/game/World/World.cpp +++ b/src/server/game/World/World.cpp @@ -99,7 +99,7 @@ #include "Unit.h" #include "UpdateTime.h" #include "VMapFactory.h" -#include "VMapManager2.h" +#include "VMapManager.h" #include "WardenCheckMgr.h" #include "WaypointManager.h" #include "WeatherMgr.h" @@ -1247,7 +1247,7 @@ bool World::SetInitialWorldSettings() dtAllocSetCustom(dtCustomAlloc, dtCustomFree); ///- Initialize VMapManager function pointers (to untangle game/collision circular deps) - VMAP::VMapManager2* vmmgr2 = VMAP::VMapFactory::createOrGetVMapManager(); + VMAP::VMapManager* vmmgr2 = VMAP::VMapFactory::createOrGetVMapManager(); vmmgr2->GetLiquidFlagsPtr = &DB2Manager::GetLiquidFlags; vmmgr2->IsVMAPDisabledForPtr = &DisableMgr::IsVMAPDisabledFor; diff --git a/src/server/scripts/Commands/cs_server.cpp b/src/server/scripts/Commands/cs_server.cpp index a6321d49d6f..843c46d98b3 100644 --- a/src/server/scripts/Commands/cs_server.cpp +++ b/src/server/scripts/Commands/cs_server.cpp @@ -38,7 +38,7 @@ EndScriptData */ #include "UpdateTime.h" #include "Util.h" #include "VMapFactory.h" -#include "VMapManager2.h" +#include "VMapManager.h" #include "World.h" #include "WorldSession.h" #include diff --git a/src/tools/mmaps_generator/PathCommon.h b/src/tools/mmaps_generator/PathCommon.h index b7c05fe1541..b0761cc2d9a 100644 --- a/src/tools/mmaps_generator/PathCommon.h +++ b/src/tools/mmaps_generator/PathCommon.h @@ -38,7 +38,7 @@ namespace VMAP { - class VMapManager2; + class VMapManager; } namespace MMAP @@ -141,7 +141,7 @@ namespace MMAP namespace VMapFactory { - std::unique_ptr CreateVMapManager(uint32 mapId); + std::unique_ptr CreateVMapManager(uint32 mapId); } } diff --git a/src/tools/mmaps_generator/PathGenerator.cpp b/src/tools/mmaps_generator/PathGenerator.cpp index 1e98b19a852..0830c977886 100644 --- a/src/tools/mmaps_generator/PathGenerator.cpp +++ b/src/tools/mmaps_generator/PathGenerator.cpp @@ -25,7 +25,7 @@ #include "PathCommon.h" #include "Timer.h" #include "Util.h" -#include "VMapManager2.h" +#include "VMapManager.h" #include #include #include @@ -46,9 +46,9 @@ namespace MMAP namespace VMapFactory { - std::unique_ptr CreateVMapManager(uint32 mapId) + std::unique_ptr CreateVMapManager(uint32 mapId) { - std::unique_ptr vmgr = std::make_unique(); + std::unique_ptr vmgr = std::make_unique(); do { diff --git a/src/tools/mmaps_generator/TerrainBuilder.cpp b/src/tools/mmaps_generator/TerrainBuilder.cpp index 6894021ea90..ed417ad51e4 100644 --- a/src/tools/mmaps_generator/TerrainBuilder.cpp +++ b/src/tools/mmaps_generator/TerrainBuilder.cpp @@ -23,7 +23,7 @@ #include "ModelInstance.h" #include "StringFormat.h" #include "Util.h" -#include "VMapManager2.h" +#include "VMapManager.h" #include namespace MMAP @@ -64,7 +64,7 @@ namespace MMAP } /**************************************************************************/ - void TerrainBuilder::loadMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData& meshData, VMAP::VMapManager2* vmapManager) + void TerrainBuilder::loadMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData& meshData, VMAP::VMapManager* vmapManager) { if (loadMap(mapID, tileX, tileY, meshData, vmapManager, ENTIRE)) { @@ -76,7 +76,7 @@ namespace MMAP } /**************************************************************************/ - bool TerrainBuilder::loadMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData& meshData, VMAP::VMapManager2* vmapManager, Spot portion) + bool TerrainBuilder::loadMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData& meshData, VMAP::VMapManager* vmapManager, Spot portion) { std::string mapFileName = Trinity::StringFormat("maps/{:04}_{:02}_{:02}.map", mapID, tileY, tileX); @@ -579,7 +579,7 @@ namespace MMAP } /**************************************************************************/ - bool TerrainBuilder::loadVMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData& meshData, VMAP::VMapManager2* vmapManager) + bool TerrainBuilder::loadVMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData& meshData, VMAP::VMapManager* vmapManager) { VMAP::LoadResult result = vmapManager->loadMap("vmaps", mapID, tileX, tileY); bool retval = false; diff --git a/src/tools/mmaps_generator/TerrainBuilder.h b/src/tools/mmaps_generator/TerrainBuilder.h index fff061d4618..7a7cc6ba918 100644 --- a/src/tools/mmaps_generator/TerrainBuilder.h +++ b/src/tools/mmaps_generator/TerrainBuilder.h @@ -25,7 +25,7 @@ namespace VMAP { -class VMapManager2; +class VMapManager; } enum class map_liquidHeaderTypeFlags : uint8; @@ -97,8 +97,8 @@ namespace MMAP public: explicit TerrainBuilder(bool skipLiquid); - void loadMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData& meshData, VMAP::VMapManager2* vmapManager); - bool loadVMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData& meshData, VMAP::VMapManager2* vmapManager); + void loadMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData& meshData, VMAP::VMapManager* vmapManager); + bool loadVMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData& meshData, VMAP::VMapManager* vmapManager); void loadOffMeshConnections(uint32 mapID, uint32 tileX, uint32 tileY, MeshData& meshData, std::vector const& offMeshConnections); bool usesLiquids() const { return !m_skipLiquid; } @@ -112,7 +112,7 @@ namespace MMAP static void cleanVertices(G3D::Array& verts, G3D::Array& tris); private: /// Loads a portion of a map's terrain - bool loadMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData& meshData, VMAP::VMapManager2* vmapManager, Spot portion); + bool loadMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData& meshData, VMAP::VMapManager* vmapManager, Spot portion); /// Sets loop variables for selecting only certain parts of a map's terrain void getLoopVars(Spot portion, int& loopStart, int& loopEnd, int& loopInc); diff --git a/src/tools/mmaps_generator/TileBuilder.cpp b/src/tools/mmaps_generator/TileBuilder.cpp index 7b0a7bef00f..bdd25b7ef04 100644 --- a/src/tools/mmaps_generator/TileBuilder.cpp +++ b/src/tools/mmaps_generator/TileBuilder.cpp @@ -21,7 +21,7 @@ #include "MMapDefines.h" #include "PathCommon.h" #include "StringFormat.h" -#include "VMapManager2.h" +#include "VMapManager.h" #include namespace @@ -95,7 +95,7 @@ namespace MMAP MeshData meshData; - std::unique_ptr vmapManager = VMapFactory::CreateVMapManager(mapID); + std::unique_ptr vmapManager = VMapFactory::CreateVMapManager(mapID); // get heightmap data m_terrainBuilder.loadMap(mapID, tileX, tileY, meshData, vmapManager.get()); -- cgit v1.2.3