aboutsummaryrefslogtreecommitdiff
path: root/src/common/Collision/Management
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2018-02-24 21:07:08 +0100
committerShauren <shauren.trinity@gmail.com>2018-03-25 19:28:36 +0300
commit4798d9ce7abd86be381af086763d8dbc9ed67ef3 (patch)
tree01ff6ae3c36ca7c443d8cdfd105825262e29e92a /src/common/Collision/Management
parent91be2332e249147ce3169c46a7da77f0f8c2211d (diff)
Core/VMaps: Implement loading phased tiles
Closes #15163
Diffstat (limited to 'src/common/Collision/Management')
-rw-r--r--src/common/Collision/Management/IVMapManager.h2
-rw-r--r--src/common/Collision/Management/VMapManager2.cpp123
-rw-r--r--src/common/Collision/Management/VMapManager2.h18
3 files changed, 99 insertions, 44 deletions
diff --git a/src/common/Collision/Management/IVMapManager.h b/src/common/Collision/Management/IVMapManager.h
index cec5657f5ed..922549f53da 100644
--- a/src/common/Collision/Management/IVMapManager.h
+++ b/src/common/Collision/Management/IVMapManager.h
@@ -94,6 +94,8 @@ namespace VMAP
*/
virtual bool getAreaInfo(unsigned int pMapId, float x, float y, float &z, uint32 &flags, int32 &adtId, int32 &rootId, int32 &groupId) const=0;
virtual bool GetLiquidLevel(uint32 pMapId, float x, float y, float z, uint8 ReqLiquidType, float &level, float &floor, uint32 &type) const=0;
+
+ virtual int32 GetDistanceToClosestPrimaryTile(uint32 mapId, int32 x, int32 y) const = 0;
};
}
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
diff --git a/src/common/Collision/Management/VMapManager2.h b/src/common/Collision/Management/VMapManager2.h
index ba48c8cae34..fb23f6e239f 100644
--- a/src/common/Collision/Management/VMapManager2.h
+++ b/src/common/Collision/Management/VMapManager2.h
@@ -81,13 +81,12 @@ namespace VMAP
// Tree to check collision
ModelFileMap iLoadedModelFiles;
InstanceTreeMap iInstanceMapTrees;
+ std::unordered_map<uint32, std::vector<uint32>> iChildMapData;
+ std::unordered_map<uint32, uint32> iParentMapData;
bool thread_safe_environment;
// Mutex for iLoadedModelFiles
std::mutex LoadedModelFilesLock;
- bool _loadMap(uint32 mapId, const std::string& basePath, uint32 tileX, uint32 tileY);
- /* void _unloadMap(uint32 pMapId, uint32 x, uint32 y); */
-
static uint32 GetLiquidFlagsDummy(uint32) { return 0; }
static bool IsVMAPDisabledForDummy(uint32 /*entry*/, uint8 /*flags*/) { return false; }
@@ -99,13 +98,18 @@ namespace VMAP
static std::string getMapFileName(unsigned int mapId);
VMapManager2();
- ~VMapManager2(void);
+ ~VMapManager2();
+
+ void InitializeThreadUnsafe(std::unordered_map<uint32, std::vector<uint32>> const& mapData);
- void InitializeThreadUnsafe(const std::vector<uint32>& mapIds);
int loadMap(const char* pBasePath, unsigned int mapId, int x, int y) override;
+ bool loadSingleMap(uint32 mapId, const std::string& basePath, uint32 tileX, uint32 tileY);
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) override ;
/**
@@ -119,6 +123,8 @@ namespace VMAP
bool getAreaInfo(unsigned int pMapId, float x, float y, float& z, uint32& flags, int32& adtId, int32& rootId, int32& groupId) const override;
bool GetLiquidLevel(uint32 pMapId, float x, float y, float z, uint8 reqLiquidType, float& level, float& floor, uint32& type) const override;
+ int32 GetDistanceToClosestPrimaryTile(uint32 mapId, int32 x, int32 y) const override;
+
WorldModel* acquireModelInstance(const std::string& basepath, const std::string& filename);
void releaseModelInstance(const std::string& filename);
@@ -131,6 +137,8 @@ namespace VMAP
void getInstanceMapTree(InstanceTreeMap &instanceMapTree);
+ int32 getParentMapId(uint32 mapId) const;
+
typedef uint32(*GetLiquidFlagsFn)(uint32 liquidType);
GetLiquidFlagsFn GetLiquidFlagsPtr;