refactor(Core/Collision): Store collision data on map context (#25049)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#include "DisableMgr.h"
|
||||
#include "GridTerrainLoader.h"
|
||||
#include "MMapFactory.h"
|
||||
#include "IVMapMgr.h"
|
||||
#include "Map.h"
|
||||
#include "MMapMgr.h"
|
||||
#include "ScriptMgr.h"
|
||||
#include "VMapFactory.h"
|
||||
@@ -9,6 +9,7 @@
|
||||
void GridTerrainLoader::LoadTerrain()
|
||||
{
|
||||
LoadMap();
|
||||
|
||||
if (_map->GetInstanceId() == 0)
|
||||
{
|
||||
LoadVMap();
|
||||
@@ -18,13 +19,10 @@ void GridTerrainLoader::LoadTerrain()
|
||||
|
||||
void GridTerrainLoader::LoadMap()
|
||||
{
|
||||
// Instances will point to the parent maps terrain data
|
||||
// Instances will point to the parent maps terrain data, no need to load anything.
|
||||
if (_map->GetInstanceId() != 0)
|
||||
{
|
||||
// load grid map for base map
|
||||
Map* parentMap = const_cast<Map*>(_map->GetParent());
|
||||
|
||||
// GetGridTerrainData will create the parent map grid
|
||||
_grid.SetTerrainData(parentMap->GetGridTerrainDataSharedPtr(GridCoord(_grid.GetX(), _grid.GetY())));
|
||||
return;
|
||||
}
|
||||
@@ -51,7 +49,7 @@ void GridTerrainLoader::LoadMap()
|
||||
|
||||
void GridTerrainLoader::LoadVMap()
|
||||
{
|
||||
int vmapLoadResult = VMAP::VMapFactory::createOrGetVMapMgr()->loadMap((sWorld->GetDataPath() + "vmaps").c_str(), _map->GetId(), _grid.GetX(), _grid.GetY());
|
||||
int const vmapLoadResult = _map->GetMapCollisionData().LoadVMapTile(_grid.GetX(), _grid.GetY());
|
||||
switch (vmapLoadResult)
|
||||
{
|
||||
case VMAP::VMAP_LOAD_RESULT_OK:
|
||||
@@ -66,15 +64,14 @@ void GridTerrainLoader::LoadVMap()
|
||||
LOG_DEBUG("maps", "Ignored VMAP name:{}, id:{}, x:{}, y:{} (vmap rep.: x:{}, y:{})",
|
||||
_map->GetMapName(), _map->GetId(), _grid.GetX(), _grid.GetY(), _grid.GetX(), _grid.GetY());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void GridTerrainLoader::LoadMMap()
|
||||
{
|
||||
if (!DisableMgr::IsPathfindingEnabled(_map))
|
||||
return;
|
||||
|
||||
int mmapLoadResult = MMAP::MMapFactory::createOrGetMMapMgr()->loadMap(_map->GetId(), _grid.GetX(), _grid.GetY());
|
||||
int const mmapLoadResult = _map->GetMapCollisionData().LoadMMapTile(_grid.GetX(), _grid.GetY());
|
||||
switch (mmapLoadResult)
|
||||
{
|
||||
case MMAP::MMAP_LOAD_RESULT_OK:
|
||||
@@ -89,6 +86,8 @@ void GridTerrainLoader::LoadMMap()
|
||||
LOG_DEBUG("maps", "Ignored MMAP name:{}, id:{}, x:{}, y:{} (vmap rep.: x:{}, y:{})",
|
||||
_map->GetMapName(), _map->GetId(), _grid.GetX(), _grid.GetY(), _grid.GetX(), _grid.GetY());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,13 +144,3 @@ bool GridTerrainLoader::ExistVMap(uint32 mapid, int gx, int gy)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void GridTerrainUnloader::UnloadTerrain()
|
||||
{
|
||||
// Only parent maps manage terrain data
|
||||
if (_map->GetInstanceId() != 0)
|
||||
return;
|
||||
|
||||
VMAP::VMapFactory::createOrGetVMapMgr()->unloadMap(_map->GetId(), _grid.GetX(), _grid.GetY());
|
||||
MMAP::MMapFactory::createOrGetMMapMgr()->unloadMap(_map->GetId(), _grid.GetX(), _grid.GetY());
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
|
||||
#include "GridDefines.h"
|
||||
|
||||
class Map;
|
||||
|
||||
class GridTerrainLoader
|
||||
{
|
||||
public:
|
||||
@@ -40,17 +42,4 @@ private:
|
||||
Map* _map;
|
||||
};
|
||||
|
||||
class GridTerrainUnloader
|
||||
{
|
||||
public:
|
||||
GridTerrainUnloader(MapGridType& grid, Map* map)
|
||||
: _grid(grid), _map(map) { }
|
||||
|
||||
void UnloadTerrain();
|
||||
|
||||
private:
|
||||
MapGridType& _grid;
|
||||
Map* _map;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -8,9 +8,19 @@ void MapGridManager::CreateGrid(uint16 const x, uint16 const y)
|
||||
if (IsGridCreated(x, y))
|
||||
return;
|
||||
|
||||
// If we are an instance, ensure parent map has already created the grid before proceeding.
|
||||
// Note: grid loading is locked and is safe across multiple map threads in the
|
||||
// event of multiple child maps attempting to create the same parent map grid
|
||||
if (_map->GetInstanceId() != 0)
|
||||
{
|
||||
Map* parentMap = const_cast<Map*>(_map->GetParent());
|
||||
parentMap->EnsureGridCreated(GridCoord(x, y));
|
||||
}
|
||||
|
||||
std::unique_ptr<MapGridType> grid = std::make_unique<MapGridType>(x, y);
|
||||
grid->link(_map);
|
||||
|
||||
// Terrain is loading during create (should/can we move this to LoadGrid?)
|
||||
GridTerrainLoader loader(*grid, _map);
|
||||
loader.LoadTerrain();
|
||||
|
||||
@@ -19,6 +29,7 @@ void MapGridManager::CreateGrid(uint16 const x, uint16 const y)
|
||||
++_createdGridsCount;
|
||||
}
|
||||
|
||||
// Loads objects, terrain already loaded in CreateGrid
|
||||
bool MapGridManager::LoadGrid(uint16 const x, uint16 const y)
|
||||
{
|
||||
MapGridType* grid = GetGrid(x, y);
|
||||
@@ -55,9 +66,6 @@ void MapGridManager::UnloadGrid(uint16 const x, uint16 const y)
|
||||
grid->VisitAllCells(visitor);
|
||||
}
|
||||
|
||||
GridTerrainUnloader terrainUnloader(*grid, _map);
|
||||
terrainUnloader.UnloadTerrain();
|
||||
|
||||
_mapGrid[x][y] = nullptr;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user