From 16a06346aea16ffd6ee84081cedfdb0c75ac0b38 Mon Sep 17 00:00:00 2001 From: Shauren Date: Sat, 23 Jul 2022 19:13:33 +0200 Subject: Core/Maps: Move terrain data handling out of Map class Partial port of cmangos/mangos-wotlk@ff5232c64809207b5fa59d62e9870f58a36b6f3f --- src/common/Collision/Management/IVMapManager.h | 13 ++---- src/common/Collision/Management/MMapManager.cpp | 51 --------------------- src/common/Collision/Management/MMapManager.h | 5 --- src/common/Collision/Management/VMapManager2.cpp | 57 +++--------------------- src/common/Collision/Management/VMapManager2.h | 6 +-- 5 files changed, 9 insertions(+), 123 deletions(-) (limited to 'src/common/Collision/Management') diff --git a/src/common/Collision/Management/IVMapManager.h b/src/common/Collision/Management/IVMapManager.h index ec198ffcc70..59cb8409f46 100644 --- a/src/common/Collision/Management/IVMapManager.h +++ b/src/common/Collision/Management/IVMapManager.h @@ -31,20 +31,13 @@ This is the minimum interface to the VMapMamager. namespace VMAP { - - enum VMAP_LOAD_RESULT - { - VMAP_LOAD_RESULT_ERROR, - VMAP_LOAD_RESULT_OK, - VMAP_LOAD_RESULT_IGNORED - }; - enum class LoadResult : uint8 { Success, FileNotFound, VersionMismatch, - ReadFromFileFailed + ReadFromFileFailed, + DisabledInConfig }; #define VMAP_INVALID_HEIGHT -100000.0f // for check @@ -83,7 +76,7 @@ namespace VMAP virtual ~IVMapManager(void) { } - virtual int loadMap(char const* pBasePath, unsigned int pMapId, int x, int y) = 0; + 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; diff --git a/src/common/Collision/Management/MMapManager.cpp b/src/common/Collision/Management/MMapManager.cpp index 01e1489825a..ab51cd3e7ba 100644 --- a/src/common/Collision/Management/MMapManager.cpp +++ b/src/common/Collision/Management/MMapManager.cpp @@ -37,7 +37,6 @@ namespace MMAP void MMapManager::InitializeThreadUnsafe(std::unordered_map> const& mapData) { - childMapData = mapData; // the caller must pass the list of all mapIds that will be used in the VMapManager2 lifetime for (std::pair> const& mapId : mapData) { @@ -118,21 +117,6 @@ namespace MMAP } bool MMapManager::loadMap(std::string const& basePath, uint32 mapId, int32 x, int32 y) - { - if (!loadMapImpl(basePath, mapId, x, y)) - return false; - - bool success = true; - auto childMaps = childMapData.find(mapId); - if (childMaps != childMapData.end()) - for (uint32 childMapId : childMaps->second) - if (!loadMapImpl(basePath, childMapId, x, y)) - success = false; - - return success; - } - - bool MMapManager::loadMapImpl(std::string const& basePath, uint32 mapId, int32 x, int32 y) { // make sure the mmap is loaded and ready to load tiles if (!loadMapData(basePath, mapId)) @@ -227,21 +211,6 @@ namespace MMAP } bool MMapManager::loadMapInstance(std::string const& basePath, uint32 mapId, uint32 instanceId) - { - if (!loadMapInstanceImpl(basePath, mapId, instanceId)) - return false; - - bool success = true; - auto childMaps = childMapData.find(mapId); - if (childMaps != childMapData.end()) - for (uint32 childMapId : childMaps->second) - if (!loadMapInstanceImpl(basePath, childMapId, instanceId)) - success = false; - - return success; - } - - bool MMapManager::loadMapInstanceImpl(std::string const& basePath, uint32 mapId, uint32 instanceId) { if (!loadMapData(basePath, mapId)) return false; @@ -266,16 +235,6 @@ namespace MMAP } bool MMapManager::unloadMap(uint32 mapId, int32 x, int32 y) - { - auto childMaps = childMapData.find(mapId); - if (childMaps != childMapData.end()) - for (uint32 childMapId : childMaps->second) - unloadMapImpl(childMapId, x, y); - - return unloadMapImpl(mapId, x, y); - } - - bool MMapManager::unloadMapImpl(uint32 mapId, int32 x, int32 y) { // check if we have this map loaded MMapDataSet::const_iterator itr = GetMMapData(mapId); @@ -319,16 +278,6 @@ namespace MMAP } bool MMapManager::unloadMap(uint32 mapId) - { - auto childMaps = childMapData.find(mapId); - if (childMaps != childMapData.end()) - for (uint32 childMapId : childMaps->second) - unloadMapImpl(childMapId); - - return unloadMapImpl(mapId); - } - - bool MMapManager::unloadMapImpl(uint32 mapId) { MMapDataSet::iterator itr = loadedMMaps.find(mapId); if (itr == loadedMMaps.end() || !itr->second) diff --git a/src/common/Collision/Management/MMapManager.h b/src/common/Collision/Management/MMapManager.h index d2862631fa6..1627036cd00 100644 --- a/src/common/Collision/Management/MMapManager.h +++ b/src/common/Collision/Management/MMapManager.h @@ -76,10 +76,6 @@ namespace MMAP uint32 getLoadedMapsCount() const { return uint32(loadedMMaps.size()); } private: bool loadMapData(std::string const& basePath, uint32 mapId); - bool loadMapImpl(std::string const& basePath, uint32 mapId, int32 x, int32 y); - bool loadMapInstanceImpl(std::string const& basePath, uint32 mapId, uint32 instanceId); - bool unloadMapImpl(uint32 mapId, int32 x, int32 y); - bool unloadMapImpl(uint32 mapId); uint32 packTileID(int32 x, int32 y); MMapDataSet::const_iterator GetMMapData(uint32 mapId) const; @@ -87,7 +83,6 @@ namespace MMAP uint32 loadedTiles; bool thread_safe_environment; - std::unordered_map> childMapData; std::unordered_map parentMapData; }; } diff --git a/src/common/Collision/Management/VMapManager2.cpp b/src/common/Collision/Management/VMapManager2.cpp index 3ab64e99251..8afd4449dce 100644 --- a/src/common/Collision/Management/VMapManager2.cpp +++ b/src/common/Collision/Management/VMapManager2.cpp @@ -78,7 +78,6 @@ namespace VMAP 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 - iChildMapData = mapData; for (std::pair> const& mapId : mapData) { iInstanceMapTrees.insert(InstanceTreeMap::value_type(mapId.first, nullptr)); @@ -110,37 +109,11 @@ namespace VMAP return fname.str(); } - int VMapManager2::loadMap(char const* basePath, unsigned int mapId, int x, int y) + LoadResult VMapManager2::loadMap(char const* basePath, unsigned int mapId, int x, int y) { - int result = VMAP_LOAD_RESULT_IGNORED; - if (isMapLoadingEnabled()) - { - LoadResult parentLoadResult = loadSingleMap(mapId, basePath, x, y); - if (parentLoadResult == LoadResult::Success || parentLoadResult == LoadResult::FileNotFound) - { - if (parentLoadResult == LoadResult::Success) - result = VMAP_LOAD_RESULT_OK; - // else VMAP_LOAD_RESULT_IGNORED - - auto childMaps = iChildMapData.find(mapId); - if (childMaps != iChildMapData.end()) - for (uint32 childMapId : childMaps->second) - { - LoadResult childLoadResult = loadSingleMap(childMapId, basePath, x, y); - if (childLoadResult != LoadResult::Success && childLoadResult != LoadResult::FileNotFound) - result = VMAP_LOAD_RESULT_ERROR; - } - } - else - result = VMAP_LOAD_RESULT_ERROR; - } - - return result; - } + if (!isMapLoadingEnabled()) + return LoadResult::DisabledInConfig; - // load one tile (internal use only) - LoadResult VMapManager2::loadSingleMap(uint32 mapId, const std::string& basePath, uint32 tileX, uint32 tileY) - { auto instanceTree = iInstanceMapTrees.find(mapId); if (instanceTree == iInstanceMapTrees.end()) { @@ -148,7 +121,7 @@ namespace VMAP 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, tileX, tileY); + mapId, x, y); } if (!instanceTree->second) @@ -164,20 +137,10 @@ namespace VMAP instanceTree->second = newTree; } - return instanceTree->second->LoadMapTile(tileX, tileY, this); + return instanceTree->second->LoadMapTile(x, y, this); } void VMapManager2::unloadMap(unsigned int mapId, int x, int y) - { - auto childMaps = iChildMapData.find(mapId); - if (childMaps != iChildMapData.end()) - for (uint32 childMapId : childMaps->second) - unloadSingleMap(childMapId, x, y); - - unloadSingleMap(mapId, x, y); - } - - void VMapManager2::unloadSingleMap(uint32 mapId, int x, int y) { auto instanceTree = iInstanceMapTrees.find(mapId); if (instanceTree != iInstanceMapTrees.end() && instanceTree->second) @@ -192,16 +155,6 @@ namespace VMAP } void VMapManager2::unloadMap(unsigned int mapId) - { - auto childMaps = iChildMapData.find(mapId); - if (childMaps != iChildMapData.end()) - for (uint32 childMapId : childMaps->second) - unloadSingleMap(childMapId); - - unloadSingleMap(mapId); - } - - void VMapManager2::unloadSingleMap(uint32 mapId) { auto instanceTree = iInstanceMapTrees.find(mapId); if (instanceTree != iInstanceMapTrees.end() && instanceTree->second) diff --git a/src/common/Collision/Management/VMapManager2.h b/src/common/Collision/Management/VMapManager2.h index 64c550c48cf..b18d52ac042 100644 --- a/src/common/Collision/Management/VMapManager2.h +++ b/src/common/Collision/Management/VMapManager2.h @@ -68,7 +68,6 @@ namespace VMAP // Tree to check collision ModelFileMap iLoadedModelFiles; InstanceTreeMap iInstanceMapTrees; - std::unordered_map> iChildMapData; std::unordered_map iParentMapData; bool thread_safe_environment; // Mutex for iLoadedModelFiles @@ -89,14 +88,11 @@ namespace VMAP void InitializeThreadUnsafe(std::unordered_map> const& mapData); - int loadMap(char const* pBasePath, unsigned int mapId, int x, int y) override; - LoadResult loadSingleMap(uint32 mapId, const std::string& basePath, uint32 tileX, uint32 tileY); + LoadResult loadMap(char const* pBasePath, unsigned int mapId, int x, int y) override; void unloadMap(unsigned int mapId, int x, int y) override; - void unloadSingleMap(uint32 mapId, int x, int y); void unloadMap(unsigned int mapId) override; - void unloadSingleMap(uint32 mapId); bool isInLineOfSight(unsigned int mapId, float x1, float y1, float z1, float x2, float y2, float z2, ModelIgnoreFlags ignoreFlags) override ; /** -- cgit v1.2.3