diff options
Diffstat (limited to 'src/common/Collision/Management/VMapManager2.cpp')
-rw-r--r-- | src/common/Collision/Management/VMapManager2.cpp | 123 |
1 files changed, 84 insertions, 39 deletions
diff --git a/src/common/Collision/Management/VMapManager2.cpp b/src/common/Collision/Management/VMapManager2.cpp index 354e3c03b87..9e5955b8794 100644 --- a/src/common/Collision/Management/VMapManager2.cpp +++ b/src/common/Collision/Management/VMapManager2.cpp @@ -40,23 +40,35 @@ namespace VMAP thread_safe_environment = true; } - VMapManager2::~VMapManager2(void) + VMapManager2::~VMapManager2() { - for (InstanceTreeMap::iterator i = iInstanceMapTrees.begin(); i != iInstanceMapTrees.end(); ++i) - { + for (auto i = iInstanceMapTrees.begin(); i != iInstanceMapTrees.end(); ++i) delete i->second; - } - for (ModelFileMap::iterator i = iLoadedModelFiles.begin(); i != iLoadedModelFiles.end(); ++i) - { + + for (auto i = iLoadedModelFiles.begin(); i != iLoadedModelFiles.end(); ++i) delete i->second.getModel(); - } } - void VMapManager2::InitializeThreadUnsafe(const std::vector<uint32>& mapIds) + 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<uint32, std::vector<uint32>> const& mapData) { // the caller must pass the list of all mapIds that will be used in the VMapManager2 lifetime - for (uint32 const& mapId : mapIds) - iInstanceMapTrees.insert(InstanceTreeMap::value_type(mapId, nullptr)); + iChildMapData = mapData; + for (std::pair<uint32 const, std::vector<uint32>> const& mapId : mapData) + { + iInstanceMapTrees.insert(InstanceTreeMap::value_type(mapId.first, nullptr)); + for (uint32 childMapId : mapId.second) + iParentMapData[childMapId] = mapId.first; + } thread_safe_environment = false; } @@ -87,8 +99,15 @@ namespace VMAP int result = VMAP_LOAD_RESULT_IGNORED; if (isMapLoadingEnabled()) { - if (_loadMap(mapId, basePath, x, y)) + if (loadSingleMap(mapId, basePath, x, y)) + { result = VMAP_LOAD_RESULT_OK; + auto childMaps = iChildMapData.find(mapId); + if (childMaps != iChildMapData.end()) + for (uint32 childMapId : childMaps->second) + if (!loadSingleMap(childMapId, basePath, x, y)) + result = VMAP_LOAD_RESULT_ERROR; + } else result = VMAP_LOAD_RESULT_ERROR; } @@ -96,20 +115,10 @@ namespace VMAP return result; } - InstanceTreeMap::const_iterator VMapManager2::GetMapTree(uint32 mapId) const - { - // return the iterator if found or end() if not found/NULL - InstanceTreeMap::const_iterator itr = iInstanceMapTrees.find(mapId); - if (itr != iInstanceMapTrees.cend() && !itr->second) - itr = iInstanceMapTrees.cend(); - - return itr; - } - // load one tile (internal use only) - bool VMapManager2::_loadMap(uint32 mapId, const std::string& basePath, uint32 tileX, uint32 tileY) + bool VMapManager2::loadSingleMap(uint32 mapId, const std::string& basePath, uint32 tileX, uint32 tileY) { - InstanceTreeMap::iterator instanceTree = iInstanceMapTrees.find(mapId); + auto instanceTree = iInstanceMapTrees.find(mapId); if (instanceTree == iInstanceMapTrees.end()) { if (thread_safe_environment) @@ -134,12 +143,22 @@ namespace VMAP return instanceTree->second->LoadMapTile(tileX, tileY, this); } - void VMapManager2::unloadMap(unsigned int mapId) + void VMapManager2::unloadMap(unsigned int mapId, int x, int y) { - InstanceTreeMap::iterator instanceTree = iInstanceMapTrees.find(mapId); + 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) { - instanceTree->second->UnloadMap(this); + instanceTree->second->UnloadMapTile(x, y, this); if (instanceTree->second->numLoadedTiles() == 0) { delete instanceTree->second; @@ -148,12 +167,22 @@ namespace VMAP } } - void VMapManager2::unloadMap(unsigned int mapId, int x, int y) + 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) { - InstanceTreeMap::iterator instanceTree = iInstanceMapTrees.find(mapId); + auto instanceTree = iInstanceMapTrees.find(mapId); if (instanceTree != iInstanceMapTrees.end() && instanceTree->second) { - instanceTree->second->UnloadMapTile(x, y, this); + instanceTree->second->UnloadMap(this); if (instanceTree->second->numLoadedTiles() == 0) { delete instanceTree->second; @@ -167,15 +196,13 @@ namespace VMAP if (!isLineOfSightCalcEnabled() || IsVMAPDisabledForPtr(mapId, VMAP_DISABLE_LOS)) return true; - InstanceTreeMap::const_iterator instanceTree = GetMapTree(mapId); + auto instanceTree = GetMapTree(mapId); if (instanceTree != iInstanceMapTrees.end()) { Vector3 pos1 = convertPositionToInternalRep(x1, y1, z1); Vector3 pos2 = convertPositionToInternalRep(x2, y2, z2); if (pos1 != pos2) - { return instanceTree->second->isInLineOfSight(pos1, pos2); - } } return true; @@ -189,7 +216,7 @@ namespace VMAP { if (isLineOfSightCalcEnabled() && !IsVMAPDisabledForPtr(mapId, VMAP_DISABLE_LOS)) { - InstanceTreeMap::const_iterator instanceTree = GetMapTree(mapId); + auto instanceTree = GetMapTree(mapId); if (instanceTree != iInstanceMapTrees.end()) { Vector3 pos1 = convertPositionToInternalRep(x1, y1, z1); @@ -219,7 +246,7 @@ namespace VMAP { if (isHeightCalcEnabled() && !IsVMAPDisabledForPtr(mapId, VMAP_DISABLE_HEIGHT)) { - InstanceTreeMap::const_iterator instanceTree = GetMapTree(mapId); + auto instanceTree = GetMapTree(mapId); if (instanceTree != iInstanceMapTrees.end()) { Vector3 pos = convertPositionToInternalRep(x, y, z); @@ -238,7 +265,7 @@ namespace VMAP { if (!IsVMAPDisabledForPtr(mapId, VMAP_DISABLE_AREAFLAG)) { - InstanceTreeMap::const_iterator instanceTree = GetMapTree(mapId); + auto instanceTree = GetMapTree(mapId); if (instanceTree != iInstanceMapTrees.end()) { Vector3 pos = convertPositionToInternalRep(x, y, z); @@ -256,7 +283,7 @@ namespace VMAP { if (!IsVMAPDisabledForPtr(mapId, VMAP_DISABLE_LIQUIDSTATUS)) { - InstanceTreeMap::const_iterator instanceTree = GetMapTree(mapId); + auto instanceTree = GetMapTree(mapId); if (instanceTree != iInstanceMapTrees.end()) { LocationInfo info; @@ -279,12 +306,21 @@ namespace VMAP return false; } + int32 VMapManager2::GetDistanceToClosestPrimaryTile(uint32 mapId, int32 x, int32 y) const + { + auto instanceTree = GetMapTree(mapId); + if (instanceTree != iInstanceMapTrees.end()) + return instanceTree->second->GetDistanceToClosestPrimaryTile(x, y); + + return std::numeric_limits<int32>::max(); + } + WorldModel* VMapManager2::acquireModelInstance(const std::string& basepath, const std::string& filename) { //! Critical section, thread safe access to iLoadedModelFiles std::lock_guard<std::mutex> lock(LoadedModelFilesLock); - ModelFileMap::iterator model = iLoadedModelFiles.find(filename); + auto model = iLoadedModelFiles.find(filename); if (model == iLoadedModelFiles.end()) { WorldModel* worldmodel = new WorldModel(); @@ -307,7 +343,7 @@ namespace VMAP //! Critical section, thread safe access to iLoadedModelFiles std::lock_guard<std::mutex> lock(LoadedModelFilesLock); - ModelFileMap::iterator model = iLoadedModelFiles.find(filename); + auto model = iLoadedModelFiles.find(filename); if (model == iLoadedModelFiles.end()) { VMAP_ERROR_LOG("misc", "VMapManager2: trying to unload non-loaded file '%s'", filename.c_str()); @@ -323,7 +359,7 @@ namespace VMAP bool VMapManager2::existsMap(const char* basePath, unsigned int mapId, int x, int y) { - return StaticMapTree::CanLoadMap(std::string(basePath), mapId, x, y); + return StaticMapTree::CanLoadMap(std::string(basePath), mapId, x, y, this); } void VMapManager2::getInstanceMapTree(InstanceTreeMap &instanceMapTree) @@ -331,4 +367,13 @@ namespace VMAP instanceMapTree = iInstanceMapTrees; } + int32 VMapManager2::getParentMapId(uint32 mapId) const + { + auto itr = iParentMapData.find(mapId); + if (itr != iParentMapData.end()) + return int32(itr->second); + + return -1; + } + } // namespace VMAP |