diff options
| author | Shauren <shauren.trinity@gmail.com> | 2025-10-25 00:52:55 +0200 |
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2025-10-25 00:52:55 +0200 |
| commit | 96b567995a36bee5de0ffa1f18fac6ba93f39bed (patch) | |
| tree | de525c3e96be31f25269e4a8bf6f08d1a65d7238 /src/common/Collision/Management/VMapManager2.cpp | |
| parent | 81a1a5585132257972fe527bb2f7d9b672cc0422 (diff) | |
Core/Vmaps: Remove VMapManager2 virtual interface
Diffstat (limited to 'src/common/Collision/Management/VMapManager2.cpp')
| -rw-r--r-- | src/common/Collision/Management/VMapManager2.cpp | 105 |
1 files changed, 53 insertions, 52 deletions
diff --git a/src/common/Collision/Management/VMapManager2.cpp b/src/common/Collision/Management/VMapManager2.cpp index 481b1cdb0ea..b4f01411543 100644 --- a/src/common/Collision/Management/VMapManager2.cpp +++ b/src/common/Collision/Management/VMapManager2.cpp @@ -23,9 +23,6 @@ #include "VMapDefinitions.h" #include "WorldModel.h" #include <G3D/Vector3.h> -#include <string> - -using G3D::Vector3; namespace VMAP { @@ -34,6 +31,12 @@ namespace VMAP public: explicit ManagedModel(VMapManager2& mgr, std::string const& name) : _mgr(mgr), _name(name) { } + ManagedModel(ManagedModel const&) = delete; + ManagedModel(ManagedModel&&) = delete; + + ManagedModel& operator=(ManagedModel const&) = delete; + ManagedModel& operator=(ManagedModel&&) = delete; + ~ManagedModel() { _mgr.releaseModelInstance(_name); @@ -52,18 +55,16 @@ namespace VMAP return memcmp(dest, compare, len) == 0; } - VMapManager2::VMapManager2() + VMapManager2::VMapManager2() : + iEnableLineOfSightCalc(true), + iEnableHeightCalc(true), + thread_safe_environment(true), + GetLiquidFlagsPtr([](uint32 /*liquidTypeId*/) { return 0u; }), + IsVMAPDisabledForPtr([](uint32 /*mapId*/, uint8 /*disableFlags*/) { return false; }) { - GetLiquidFlagsPtr = &GetLiquidFlagsDummy; - IsVMAPDisabledForPtr = &IsVMAPDisabledForDummy; - thread_safe_environment = true; } - VMapManager2::~VMapManager2() - { - for (std::pair<uint32 const, StaticMapTree*>& iInstanceMapTree : iInstanceMapTrees) - delete iInstanceMapTree.second; - } + VMapManager2::~VMapManager2() = default; InstanceTreeMap::const_iterator VMapManager2::GetMapTree(uint32 mapId) const { @@ -78,11 +79,11 @@ namespace VMAP void VMapManager2::InitializeThreadUnsafe(std::unordered_map<uint32, std::vector<uint32>> const& mapData) { // the caller must pass the list of all mapIds that will be used in the VMapManager2 lifetime - for (std::pair<uint32 const, std::vector<uint32>> const& mapId : mapData) + for (auto const& [mapId, childMapIds] : mapData) { - iInstanceMapTrees.insert(InstanceTreeMap::value_type(mapId.first, nullptr)); - for (uint32 childMapId : mapId.second) - iParentMapData[childMapId] = mapId.first; + iInstanceMapTrees[mapId] = nullptr; + for (uint32 childMapId : childMapIds) + iParentMapData[childMapId] = mapId; } thread_safe_environment = false; @@ -95,10 +96,10 @@ namespace VMAP iParentMapData[mapId] = parentMapId; } - Vector3 VMapManager2::convertPositionToInternalRep(float x, float y, float z) const + inline static G3D::Vector3 convertPositionToInternalRep(float x, float y, float z) { - Vector3 pos; - const float mid = 0.5f * 64.0f * 533.33333333f; + G3D::Vector3 pos; + constexpr float mid = 0.5f * 64.0f * 533.33333333f; pos.x = mid - x; pos.y = mid - y; pos.z = z; @@ -106,13 +107,17 @@ namespace VMAP return pos; } - // move to MapTree too? - std::string VMapManager2::getMapFileName(unsigned int mapId) + std::string VMapManager2::getMapFileName(uint32 mapId) { return Trinity::StringFormat("{:04}/{:04}.vmtree", mapId, mapId); } - LoadResult VMapManager2::loadMap(char const* basePath, unsigned int mapId, int x, int y) + std::string VMapManager2::getTileFileName(uint32 mapID, uint32 tileX, uint32 tileY, std::string_view extension) + { + return Trinity::StringFormat("{:04}/{:04}_{:02}_{:02}.{}", mapID, mapID, tileY, tileX, extension); + } + + LoadResult VMapManager2::loadMap(std::string const& basePath, uint32 mapId, uint32 x, uint32 y) { if (!isMapLoadingEnabled()) return LoadResult::DisabledInConfig; @@ -130,48 +135,40 @@ namespace VMAP if (!instanceTree->second) { std::string mapFileName = getMapFileName(mapId); - StaticMapTree* newTree = new StaticMapTree(mapId, basePath); + std::unique_ptr<StaticMapTree> newTree = std::make_unique<StaticMapTree>(mapId, basePath); LoadResult treeInitResult = newTree->InitMap(mapFileName); if (treeInitResult != LoadResult::Success) - { - delete newTree; return treeInitResult; - } - instanceTree->second = newTree; + + instanceTree->second = std::move(newTree); } return instanceTree->second->LoadMapTile(x, y, this); } - void VMapManager2::unloadMap(unsigned int mapId, int x, int y) + void VMapManager2::unloadMap(uint32 mapId, uint32 x, uint32 y) { auto instanceTree = iInstanceMapTrees.find(mapId); if (instanceTree != iInstanceMapTrees.end() && instanceTree->second) { instanceTree->second->UnloadMapTile(x, y, this); if (instanceTree->second->numLoadedTiles() == 0) - { - delete instanceTree->second; instanceTree->second = nullptr; - } } } - void VMapManager2::unloadMap(unsigned int mapId) + void VMapManager2::unloadMap(uint32 mapId) { auto instanceTree = iInstanceMapTrees.find(mapId); if (instanceTree != iInstanceMapTrees.end() && instanceTree->second) { instanceTree->second->UnloadMap(); if (instanceTree->second->numLoadedTiles() == 0) - { - delete instanceTree->second; instanceTree->second = nullptr; - } } } - bool VMapManager2::isInLineOfSight(unsigned int mapId, float x1, float y1, float z1, float x2, float y2, float z2, ModelIgnoreFlags ignoreFlags) + bool VMapManager2::isInLineOfSight(uint32 mapId, float x1, float y1, float z1, float x2, float y2, float z2, ModelIgnoreFlags ignoreFlags) { if (!isLineOfSightCalcEnabled() || IsVMAPDisabledForPtr(mapId, VMAP_DISABLE_LOS)) return true; @@ -179,8 +176,8 @@ namespace VMAP auto instanceTree = GetMapTree(mapId); if (instanceTree != iInstanceMapTrees.end()) { - Vector3 pos1 = convertPositionToInternalRep(x1, y1, z1); - Vector3 pos2 = convertPositionToInternalRep(x2, y2, z2); + G3D::Vector3 pos1 = convertPositionToInternalRep(x1, y1, z1); + G3D::Vector3 pos2 = convertPositionToInternalRep(x2, y2, z2); if (pos1 != pos2) return instanceTree->second->isInLineOfSight(pos1, pos2, ignoreFlags); } @@ -192,16 +189,16 @@ namespace VMAP get the hit position and return true if we hit something otherwise the result pos will be the dest pos */ - bool VMapManager2::getObjectHitPos(unsigned int mapId, float x1, float y1, float z1, float x2, float y2, float z2, float& rx, float &ry, float& rz, float modifyDist) + bool VMapManager2::getObjectHitPos(uint32 mapId, float x1, float y1, float z1, float x2, float y2, float z2, float& rx, float &ry, float& rz, float modifyDist) { if (isLineOfSightCalcEnabled() && !IsVMAPDisabledForPtr(mapId, VMAP_DISABLE_LOS)) { auto instanceTree = GetMapTree(mapId); if (instanceTree != iInstanceMapTrees.end()) { - Vector3 pos1 = convertPositionToInternalRep(x1, y1, z1); - Vector3 pos2 = convertPositionToInternalRep(x2, y2, z2); - Vector3 resultPos; + G3D::Vector3 pos1 = convertPositionToInternalRep(x1, y1, z1); + G3D::Vector3 pos2 = convertPositionToInternalRep(x2, y2, z2); + G3D::Vector3 resultPos; bool result = instanceTree->second->getObjectHitPos(pos1, pos2, resultPos, modifyDist); resultPos = convertPositionToInternalRep(resultPos.x, resultPos.y, resultPos.z); rx = resultPos.x; @@ -222,14 +219,14 @@ namespace VMAP get height or INVALID_HEIGHT if no height available */ - float VMapManager2::getHeight(unsigned int mapId, float x, float y, float z, float maxSearchDist) + float VMapManager2::getHeight(uint32 mapId, float x, float y, float z, float maxSearchDist) { if (isHeightCalcEnabled() && !IsVMAPDisabledForPtr(mapId, VMAP_DISABLE_HEIGHT)) { auto instanceTree = GetMapTree(mapId); if (instanceTree != iInstanceMapTrees.end()) { - Vector3 pos = convertPositionToInternalRep(x, y, z); + G3D::Vector3 pos = convertPositionToInternalRep(x, y, z); float height = instanceTree->second->getHeight(pos, maxSearchDist); if (!(height < G3D::finf())) return height = VMAP_INVALID_HEIGHT_VALUE; // No height @@ -241,13 +238,13 @@ namespace VMAP return VMAP_INVALID_HEIGHT_VALUE; } - bool VMapManager2::getAreaAndLiquidData(unsigned int mapId, float x, float y, float z, Optional<uint8> reqLiquidType, AreaAndLiquidData& data) const + bool VMapManager2::getAreaAndLiquidData(uint32 mapId, float x, float y, float z, Optional<uint8> reqLiquidType, AreaAndLiquidData& data) const { InstanceTreeMap::const_iterator instanceTree = GetMapTree(mapId); if (instanceTree != iInstanceMapTrees.end()) { LocationInfo info; - Vector3 pos = convertPositionToInternalRep(x, y, z); + G3D::Vector3 pos = convertPositionToInternalRep(x, y, z); if (instanceTree->second->GetLocationInfo(pos, info)) { data.floorZ = info.ground_Z; @@ -275,7 +272,7 @@ namespace VMAP std::shared_ptr<ManagedModel> worldmodel; // this is intentionally declared before lock so that it is destroyed after it to prevent deadlocks in releaseModelInstance //! Critical section, thread safe access to iLoadedModelFiles - std::lock_guard<std::mutex> lock(LoadedModelFilesLock); + std::lock_guard lock(LoadedModelFilesLock); auto& [key, model] = *iLoadedModelFiles.try_emplace(filename).first; worldmodel = model.lock(); @@ -298,7 +295,7 @@ namespace VMAP void VMapManager2::releaseModelInstance(std::string const& filename) { //! Critical section, thread safe access to iLoadedModelFiles - std::lock_guard<std::mutex> lock(LoadedModelFilesLock); + std::lock_guard lock(LoadedModelFilesLock); TC_LOG_DEBUG("maps", "VMapManager2: unloading file '{}'", filename); @@ -307,14 +304,18 @@ namespace VMAP TC_LOG_ERROR("misc", "VMapManager2: trying to unload non-loaded file '{}'", filename); } - LoadResult VMapManager2::existsMap(char const* basePath, unsigned int mapId, int x, int y) + LoadResult VMapManager2::existsMap(std::string const& basePath, uint32 mapId, uint32 x, uint32 y) { - return StaticMapTree::CanLoadMap(std::string(basePath), mapId, x, y, this); + return StaticMapTree::CanLoadMap(basePath, mapId, x, y, this); } - void VMapManager2::getInstanceMapTree(InstanceTreeMap &instanceMapTree) + std::span<ModelInstance const> VMapManager2::getModelsOnMap(uint32 mapId) const { - instanceMapTree = iInstanceMapTrees; + InstanceTreeMap::const_iterator mapTree = GetMapTree(mapId); + if (mapTree != iInstanceMapTrees.end()) + return mapTree->second->getModelInstances(); + + return {}; } int32 VMapManager2::getParentMapId(uint32 mapId) const |
