mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-21 17:54:48 +01:00
Core/MMaps: Use unique_ptr for memory management and remove MMapFactory
This commit is contained in:
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "MMapFactory.h"
|
||||
|
||||
namespace MMAP
|
||||
{
|
||||
// ######################## MMapFactory ########################
|
||||
// our global singleton copy
|
||||
MMapManager* g_MMapManager = nullptr;
|
||||
|
||||
MMapManager* MMapFactory::createOrGetMMapManager()
|
||||
{
|
||||
if (g_MMapManager == nullptr)
|
||||
g_MMapManager = new MMapManager();
|
||||
|
||||
return g_MMapManager;
|
||||
}
|
||||
|
||||
void MMapFactory::clear()
|
||||
{
|
||||
if (g_MMapManager)
|
||||
{
|
||||
delete g_MMapManager;
|
||||
g_MMapManager = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _MMAP_FACTORY_H
|
||||
#define _MMAP_FACTORY_H
|
||||
|
||||
#include "Define.h"
|
||||
#include "MMapManager.h"
|
||||
|
||||
namespace MMAP
|
||||
{
|
||||
enum MMAP_LOAD_RESULT
|
||||
{
|
||||
MMAP_LOAD_RESULT_ERROR,
|
||||
MMAP_LOAD_RESULT_OK,
|
||||
MMAP_LOAD_RESULT_IGNORED
|
||||
};
|
||||
|
||||
// static class
|
||||
// holds all mmap global data
|
||||
// access point to MMapManager singleton
|
||||
class TC_COMMON_API MMapFactory
|
||||
{
|
||||
public:
|
||||
static MMapManager* createOrGetMMapManager();
|
||||
static void clear();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
#include "MMapManager.h"
|
||||
#include "Errors.h"
|
||||
#include "Hash.h"
|
||||
#include "Log.h"
|
||||
#include "MMapDefines.h"
|
||||
#include "Memory.h"
|
||||
@@ -26,24 +27,42 @@ namespace MMAP
|
||||
constexpr char MAP_FILE_NAME_FORMAT[] = "{}mmaps/{:04}.mmap";
|
||||
constexpr char TILE_FILE_NAME_FORMAT[] = "{}mmaps/{:04}{:02}{:02}.mmtile";
|
||||
|
||||
// ######################## MMapManager ########################
|
||||
MMapManager::~MMapManager()
|
||||
{
|
||||
for (std::pair<uint32 const, MMapData*>& loadedMMap : loadedMMaps)
|
||||
delete loadedMMap.second;
|
||||
using NavMeshPtr = std::unique_ptr<dtNavMesh, decltype(Trinity::unique_ptr_deleter<dtNavMesh*, &::dtFreeNavMesh>())>;
|
||||
using NavMeshQueryPtr = std::unique_ptr<dtNavMeshQuery, decltype(Trinity::unique_ptr_deleter<dtNavMeshQuery*, &::dtFreeNavMeshQuery>())>;
|
||||
|
||||
// by now we should not have maps loaded
|
||||
// if we had, tiles in MMapData->mmapLoadedTiles, their actual data is lost!
|
||||
typedef std::unordered_map<std::pair<uint32, uint32>, NavMeshQueryPtr> NavMeshQuerySet;
|
||||
typedef std::unordered_map<uint32, dtTileRef> MMapTileSet;
|
||||
|
||||
// dummy struct to hold map's mmap data
|
||||
struct MMapData
|
||||
{
|
||||
explicit MMapData(NavMeshPtr&& mesh) : navMesh(std::move(mesh)) { }
|
||||
|
||||
// we have to use single dtNavMeshQuery for every instance, since those are not thread safe
|
||||
NavMeshQuerySet navMeshQueries; // instanceId to query
|
||||
|
||||
NavMeshPtr navMesh;
|
||||
MMapTileSet loadedTileRefs; // maps [map grid coords] to [dtTile]
|
||||
};
|
||||
|
||||
// ######################## MMapManager ########################
|
||||
MMapManager::MMapManager() = default;
|
||||
MMapManager::~MMapManager() = default;
|
||||
|
||||
MMapManager* MMapManager::instance()
|
||||
{
|
||||
static MMapManager instance;
|
||||
return &instance;
|
||||
}
|
||||
|
||||
void MMapManager::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)
|
||||
// the caller must pass the list of all mapIds that will be used in the MMapManager lifetime
|
||||
for (auto const& [mapId, childMapIds] : mapData)
|
||||
{
|
||||
loadedMMaps.insert(MMapDataSet::value_type(mapId.first, nullptr));
|
||||
for (uint32 childMapId : mapId.second)
|
||||
parentMapData[childMapId] = mapId.first;
|
||||
loadedMMaps.insert(MMapDataSet::value_type(mapId, nullptr));
|
||||
for (uint32 childMapId : childMapIds)
|
||||
parentMapData[childMapId] = mapId;
|
||||
}
|
||||
|
||||
thread_safe_environment = false;
|
||||
@@ -59,7 +78,7 @@ namespace MMAP
|
||||
return itr;
|
||||
}
|
||||
|
||||
LoadResult MMapManager::loadMapData(std::string const& basePath, uint32 mapId)
|
||||
LoadResult MMapManager::loadMapData(std::string_view basePath, uint32 mapId)
|
||||
{
|
||||
// we already have this map loaded?
|
||||
MMapDataSet::iterator itr = loadedMMaps.find(mapId);
|
||||
@@ -93,11 +112,10 @@ namespace MMAP
|
||||
return LoadResult::ReadFromFileFailed;
|
||||
}
|
||||
|
||||
dtNavMesh* mesh = dtAllocNavMesh();
|
||||
NavMeshPtr mesh(dtAllocNavMesh());
|
||||
ASSERT(mesh);
|
||||
if (dtStatusFailed(mesh->init(¶ms)))
|
||||
{
|
||||
dtFreeNavMesh(mesh);
|
||||
TC_LOG_ERROR("maps", "MMAP:loadMapData: Failed to initialize dtNavMesh for mmap {:04} from file {}", mapId, fileName);
|
||||
return LoadResult::LibraryError;
|
||||
}
|
||||
@@ -105,9 +123,7 @@ namespace MMAP
|
||||
TC_LOG_DEBUG("maps", "MMAP:loadMapData: Loaded {:04}.mmap", mapId);
|
||||
|
||||
// store inside our map list
|
||||
MMapData* mmap_data = new MMapData(mesh);
|
||||
|
||||
itr->second = mmap_data;
|
||||
itr->second.reset(new MMapData(std::move(mesh)));
|
||||
return LoadResult::Success;
|
||||
}
|
||||
|
||||
@@ -116,7 +132,7 @@ namespace MMAP
|
||||
return uint32(x << 16 | y);
|
||||
}
|
||||
|
||||
LoadResult MMapManager::loadMap(std::string const& basePath, uint32 mapId, int32 x, int32 y)
|
||||
LoadResult MMapManager::loadMap(std::string_view basePath, uint32 mapId, int32 x, int32 y)
|
||||
{
|
||||
// make sure the mmap is loaded and ready to load tiles
|
||||
switch (LoadResult mapResult = loadMapData(basePath, mapId))
|
||||
@@ -129,12 +145,12 @@ namespace MMAP
|
||||
}
|
||||
|
||||
// get this mmap data
|
||||
MMapData* mmap = loadedMMaps[mapId];
|
||||
MMapData* mmap = loadedMMaps[mapId].get();
|
||||
ASSERT(mmap->navMesh);
|
||||
|
||||
// check if we already have this tile loaded
|
||||
uint32 packedGridPos = packTileID(x, y);
|
||||
if (mmap->loadedTileRefs.find(packedGridPos) != mmap->loadedTileRefs.end())
|
||||
if (mmap->loadedTileRefs.contains(packedGridPos))
|
||||
return LoadResult::AlreadyLoaded;
|
||||
|
||||
// load this tile :: mmaps/MMMMXXYY.mmtile
|
||||
@@ -187,21 +203,21 @@ namespace MMAP
|
||||
|
||||
fseek(file.get(), pos, SEEK_SET);
|
||||
|
||||
unsigned char* data = (unsigned char*)dtAlloc(fileHeader.size, DT_ALLOC_PERM);
|
||||
auto data = Trinity::make_unique_ptr_with_deleter<&::dtFree>(dtAlloc(fileHeader.size, DT_ALLOC_PERM));
|
||||
ASSERT(data);
|
||||
|
||||
size_t result = fread(data, fileHeader.size, 1, file.get());
|
||||
size_t result = fread(data.get(), fileHeader.size, 1, file.get());
|
||||
if (!result)
|
||||
{
|
||||
TC_LOG_ERROR("maps", "MMAP:loadMap: Bad header or data in mmap {:04}{:02}{:02}.mmtile", mapId, x, y);
|
||||
return LoadResult::ReadFromFileFailed;
|
||||
}
|
||||
|
||||
dtMeshHeader* header = (dtMeshHeader*)data;
|
||||
dtMeshHeader* header = static_cast<dtMeshHeader*>(data.get());
|
||||
dtTileRef tileRef = 0;
|
||||
|
||||
// memory allocated for data is now managed by detour, and will be deallocated when the tile is removed
|
||||
if (dtStatusSucceed(mmap->navMesh->addTile(data, fileHeader.size, DT_TILE_FREE_DATA, 0, &tileRef)))
|
||||
if (dtStatusSucceed(mmap->navMesh->addTile(static_cast<unsigned char*>(data.release()), fileHeader.size, DT_TILE_FREE_DATA, 0, &tileRef)))
|
||||
{
|
||||
mmap->loadedTileRefs.insert(std::pair<uint32, dtTileRef>(packedGridPos, tileRef));
|
||||
++loadedTiles;
|
||||
@@ -211,12 +227,11 @@ namespace MMAP
|
||||
else
|
||||
{
|
||||
TC_LOG_ERROR("maps", "MMAP:loadMap: Could not load {:04}{:02}{:02}.mmtile into navmesh", mapId, x, y);
|
||||
dtFree(data);
|
||||
return LoadResult::LibraryError;
|
||||
}
|
||||
}
|
||||
|
||||
bool MMapManager::loadMapInstance(std::string const& basePath, uint32 meshMapId, uint32 instanceMapId, uint32 instanceId)
|
||||
bool MMapManager::loadMapInstance(std::string_view basePath, uint32 meshMapId, uint32 instanceMapId, uint32 instanceId)
|
||||
{
|
||||
switch (loadMapData(basePath, meshMapId))
|
||||
{
|
||||
@@ -227,24 +242,23 @@ namespace MMAP
|
||||
return false;
|
||||
}
|
||||
|
||||
MMapData* mmap = loadedMMaps[meshMapId];
|
||||
MMapData* mmap = loadedMMaps[meshMapId].get();
|
||||
auto [queryItr, inserted] = mmap->navMeshQueries.try_emplace({ instanceMapId, instanceId }, nullptr);
|
||||
if (!inserted)
|
||||
return true;
|
||||
|
||||
// allocate mesh query
|
||||
dtNavMeshQuery* query = dtAllocNavMeshQuery();
|
||||
NavMeshQueryPtr query(dtAllocNavMeshQuery());
|
||||
ASSERT(query);
|
||||
if (dtStatusFailed(query->init(mmap->navMesh, 1024)))
|
||||
if (dtStatusFailed(query->init(mmap->navMesh.get(), 1024)))
|
||||
{
|
||||
dtFreeNavMeshQuery(query);
|
||||
mmap->navMeshQueries.erase(queryItr);
|
||||
TC_LOG_ERROR("maps", "MMAP:GetNavMeshQuery: Failed to initialize dtNavMeshQuery for mapId {:04} instanceId {}", instanceMapId, instanceId);
|
||||
return false;
|
||||
}
|
||||
|
||||
TC_LOG_DEBUG("maps", "MMAP:GetNavMeshQuery: created dtNavMeshQuery for mapId {:04} instanceId {}", instanceMapId, instanceId);
|
||||
queryItr->second = query;
|
||||
queryItr->second = std::move(query);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -259,12 +273,12 @@ namespace MMAP
|
||||
return false;
|
||||
}
|
||||
|
||||
MMapData* mmap = itr->second;
|
||||
MMapData* mmap = itr->second.get();
|
||||
|
||||
// check if we have this tile loaded
|
||||
uint32 packedGridPos = packTileID(x, y);
|
||||
auto tileRefItr = mmap->loadedTileRefs.find(packedGridPos);
|
||||
if (tileRefItr == mmap->loadedTileRefs.end())
|
||||
auto tileRef = mmap->loadedTileRefs.extract(packedGridPos);
|
||||
if (!tileRef)
|
||||
{
|
||||
// file may not exist, therefore not loaded
|
||||
TC_LOG_DEBUG("maps", "MMAP:unloadMap: Asked to unload not loaded navmesh tile. {:04}{:02}{:02}.mmtile", mapId, x, y);
|
||||
@@ -272,7 +286,7 @@ namespace MMAP
|
||||
}
|
||||
|
||||
// unload, and mark as non loaded
|
||||
if (dtStatusFailed(mmap->navMesh->removeTile(tileRefItr->second, nullptr, nullptr)))
|
||||
if (dtStatusFailed(mmap->navMesh->removeTile(tileRef.mapped(), nullptr, nullptr)))
|
||||
{
|
||||
// this is technically a memory leak
|
||||
// if the grid is later reloaded, dtNavMesh::addTile will return error but no extra memory is used
|
||||
@@ -282,7 +296,6 @@ namespace MMAP
|
||||
}
|
||||
else
|
||||
{
|
||||
mmap->loadedTileRefs.erase(tileRefItr);
|
||||
--loadedTiles;
|
||||
TC_LOG_DEBUG("maps", "MMAP:unloadMap: Unloaded mmtile {:04}[{:02}, {:02}] from {:03}", mapId, x, y, mapId);
|
||||
return true;
|
||||
@@ -302,12 +315,12 @@ namespace MMAP
|
||||
}
|
||||
|
||||
// unload all tiles from given map
|
||||
MMapData* mmap = itr->second;
|
||||
for (MMapTileSet::iterator i = mmap->loadedTileRefs.begin(); i != mmap->loadedTileRefs.end(); ++i)
|
||||
MMapData* mmap = itr->second.get();
|
||||
for (auto const& [tileId, tileRef] : mmap->loadedTileRefs)
|
||||
{
|
||||
uint32 x = (i->first >> 16);
|
||||
uint32 y = (i->first & 0x0000FFFF);
|
||||
if (dtStatusFailed(mmap->navMesh->removeTile(i->second, nullptr, nullptr)))
|
||||
uint32 x = (tileId >> 16);
|
||||
uint32 y = (tileId & 0x0000FFFF);
|
||||
if (dtStatusFailed(mmap->navMesh->removeTile(tileRef, nullptr, nullptr)))
|
||||
TC_LOG_ERROR("maps", "MMAP:unloadMap: Could not unload {:04}{:02}{:02}.mmtile from navmesh", mapId, x, y);
|
||||
else
|
||||
{
|
||||
@@ -316,7 +329,6 @@ namespace MMAP
|
||||
}
|
||||
}
|
||||
|
||||
delete mmap;
|
||||
itr->second = nullptr;
|
||||
TC_LOG_DEBUG("maps", "MMAP:unloadMap: Unloaded {:04}.mmap", mapId);
|
||||
|
||||
@@ -334,16 +346,14 @@ namespace MMAP
|
||||
return false;
|
||||
}
|
||||
|
||||
MMapData* mmap = itr->second;
|
||||
auto queryItr = mmap->navMeshQueries.find({ instanceMapId, instanceId });
|
||||
if (queryItr == mmap->navMeshQueries.end())
|
||||
MMapData* mmap = itr->second.get();
|
||||
std::size_t erased = mmap->navMeshQueries.erase({ instanceMapId, instanceId });
|
||||
if (!erased)
|
||||
{
|
||||
TC_LOG_DEBUG("maps", "MMAP:unloadMapInstance: Asked to unload not loaded dtNavMeshQuery mapId {:04} instanceId {}", instanceMapId, instanceId);
|
||||
return false;
|
||||
}
|
||||
|
||||
dtFreeNavMeshQuery(queryItr->second);
|
||||
mmap->navMeshQueries.erase(queryItr);
|
||||
TC_LOG_DEBUG("maps", "MMAP:unloadMapInstance: Unloaded mapId {:04} instanceId {}", instanceMapId, instanceId);
|
||||
|
||||
return true;
|
||||
@@ -355,7 +365,7 @@ namespace MMAP
|
||||
if (itr == loadedMMaps.end())
|
||||
return nullptr;
|
||||
|
||||
return itr->second->navMesh;
|
||||
return itr->second->navMesh.get();
|
||||
}
|
||||
|
||||
dtNavMeshQuery const* MMapManager::GetNavMeshQuery(uint32 meshMapId, uint32 instanceMapId, uint32 instanceId)
|
||||
@@ -368,6 +378,6 @@ namespace MMAP
|
||||
if (queryItr == itr->second->navMeshQueries.end())
|
||||
return nullptr;
|
||||
|
||||
return queryItr->second;
|
||||
return queryItr->second.get();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,40 +19,19 @@
|
||||
#define _MMAP_MANAGER_H
|
||||
|
||||
#include "Define.h"
|
||||
#include "DetourNavMesh.h"
|
||||
#include "DetourNavMeshQuery.h"
|
||||
#include "Hash.h"
|
||||
#include <string>
|
||||
#include <DetourNavMesh.h>
|
||||
#include <DetourNavMeshQuery.h>
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
// move map related classes
|
||||
namespace MMAP
|
||||
{
|
||||
typedef std::unordered_map<uint32, dtTileRef> MMapTileSet;
|
||||
typedef std::unordered_map<std::pair<uint32, uint32>, dtNavMeshQuery*> NavMeshQuerySet;
|
||||
struct MMapData;
|
||||
|
||||
// dummy struct to hold map's mmap data
|
||||
struct TC_COMMON_API MMapData
|
||||
{
|
||||
MMapData(dtNavMesh* mesh) : navMesh(mesh) { }
|
||||
~MMapData()
|
||||
{
|
||||
for (NavMeshQuerySet::iterator i = navMeshQueries.begin(); i != navMeshQueries.end(); ++i)
|
||||
dtFreeNavMeshQuery(i->second);
|
||||
|
||||
if (navMesh)
|
||||
dtFreeNavMesh(navMesh);
|
||||
}
|
||||
|
||||
// we have to use single dtNavMeshQuery for every instance, since those are not thread safe
|
||||
NavMeshQuerySet navMeshQueries; // instanceId to query
|
||||
|
||||
dtNavMesh* navMesh;
|
||||
MMapTileSet loadedTileRefs; // maps [map grid coords] to [dtTile]
|
||||
};
|
||||
|
||||
typedef std::unordered_map<uint32, MMapData*> MMapDataSet;
|
||||
typedef std::unordered_map<uint32, std::unique_ptr<MMapData>> MMapDataSet;
|
||||
|
||||
enum class LoadResult : uint8
|
||||
{
|
||||
@@ -69,12 +48,18 @@ namespace MMAP
|
||||
class TC_COMMON_API MMapManager
|
||||
{
|
||||
public:
|
||||
MMapManager() : loadedTiles(0), thread_safe_environment(true) {}
|
||||
MMapManager();
|
||||
MMapManager(MMapManager const& other) = delete;
|
||||
MMapManager(MMapManager&& other) noexcept = delete;
|
||||
MMapManager& operator=(MMapManager const& other) = delete;
|
||||
MMapManager& operator=(MMapManager&& other) noexcept = delete;
|
||||
~MMapManager();
|
||||
|
||||
static MMapManager* instance();
|
||||
|
||||
void InitializeThreadUnsafe(std::unordered_map<uint32, std::vector<uint32>> const& mapData);
|
||||
LoadResult loadMap(std::string const& basePath, uint32 mapId, int32 x, int32 y);
|
||||
bool loadMapInstance(std::string const& basePath, uint32 meshMapId, uint32 instanceMapId, uint32 instanceId);
|
||||
LoadResult loadMap(std::string_view basePath, uint32 mapId, int32 x, int32 y);
|
||||
bool loadMapInstance(std::string_view basePath, uint32 meshMapId, uint32 instanceMapId, uint32 instanceId);
|
||||
bool unloadMap(uint32 mapId, int32 x, int32 y);
|
||||
bool unloadMap(uint32 mapId);
|
||||
bool unloadMapInstance(uint32 meshMapId, uint32 instanceMapId, uint32 instanceId);
|
||||
@@ -86,13 +71,13 @@ namespace MMAP
|
||||
uint32 getLoadedTilesCount() const { return loadedTiles; }
|
||||
uint32 getLoadedMapsCount() const { return uint32(loadedMMaps.size()); }
|
||||
private:
|
||||
LoadResult loadMapData(std::string const& basePath, uint32 mapId);
|
||||
LoadResult loadMapData(std::string_view basePath, uint32 mapId);
|
||||
uint32 packTileID(int32 x, int32 y);
|
||||
|
||||
MMapDataSet::const_iterator GetMMapData(uint32 mapId) const;
|
||||
MMapDataSet loadedMMaps;
|
||||
uint32 loadedTiles;
|
||||
bool thread_safe_environment;
|
||||
uint32 loadedTiles = 0;
|
||||
bool thread_safe_environment = true;
|
||||
|
||||
std::unordered_map<uint32, uint32> parentMapData;
|
||||
};
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#include "GridMap.h"
|
||||
#include "Log.h"
|
||||
#include "Memory.h"
|
||||
#include "MMapFactory.h"
|
||||
#include "MMapManager.h"
|
||||
#include "PhasingHandler.h"
|
||||
#include "Random.h"
|
||||
#include "ScriptMgr.h"
|
||||
@@ -39,7 +39,7 @@ TerrainInfo::TerrainInfo(uint32 mapId) : _mapId(mapId), _parentTerrain(nullptr),
|
||||
TerrainInfo::~TerrainInfo()
|
||||
{
|
||||
VMAP::VMapFactory::createOrGetVMapManager()->unloadMap(GetId());
|
||||
MMAP::MMapFactory::createOrGetMMapManager()->unloadMap(GetId());
|
||||
MMAP::MMapManager::instance()->unloadMap(GetId());
|
||||
}
|
||||
|
||||
char const* TerrainInfo::GetMapName() const
|
||||
@@ -185,7 +185,7 @@ void TerrainInfo::LoadMapAndVMapImpl(int32 gx, int32 gy)
|
||||
|
||||
void TerrainInfo::LoadMMapInstanceImpl(uint32 mapId, uint32 instanceId)
|
||||
{
|
||||
MMAP::MMapFactory::createOrGetMMapManager()->loadMapInstance(sWorld->GetDataPath(), _mapId, mapId, instanceId);
|
||||
MMAP::MMapManager::instance()->loadMapInstance(sWorld->GetDataPath(), _mapId, mapId, instanceId);
|
||||
}
|
||||
|
||||
void TerrainInfo::LoadMap(int32 gx, int32 gy)
|
||||
@@ -239,7 +239,7 @@ void TerrainInfo::LoadMMap(int32 gx, int32 gy)
|
||||
if (!DisableMgr::IsPathfindingEnabled(GetId()))
|
||||
return;
|
||||
|
||||
switch (MMAP::LoadResult mmapLoadResult = MMAP::MMapFactory::createOrGetMMapManager()->loadMap(sWorld->GetDataPath(), GetId(), gx, gy))
|
||||
switch (MMAP::LoadResult mmapLoadResult = MMAP::MMapManager::instance()->loadMap(sWorld->GetDataPath(), GetId(), gx, gy))
|
||||
{
|
||||
case MMAP::LoadResult::Success:
|
||||
TC_LOG_DEBUG("mmaps.tiles", "MMAP loaded name:{}, id:{}, x:{}, y:{} (mmap rep.: x:{}, y:{})", GetMapName(), GetId(), gx, gy, gx, gy);
|
||||
@@ -274,7 +274,7 @@ void TerrainInfo::UnloadMapImpl(int32 gx, int32 gy)
|
||||
{
|
||||
_gridMap[gx][gy] = nullptr;
|
||||
VMAP::VMapFactory::createOrGetVMapManager()->unloadMap(GetId(), gx, gy);
|
||||
MMAP::MMapFactory::createOrGetMMapManager()->unloadMap(GetId(), gx, gy);
|
||||
MMAP::MMapManager::instance()->unloadMap(GetId(), gx, gy);
|
||||
|
||||
for (std::shared_ptr<TerrainInfo> const& childTerrain : _childTerrain)
|
||||
childTerrain->UnloadMapImpl(gx, gy);
|
||||
@@ -284,7 +284,7 @@ void TerrainInfo::UnloadMapImpl(int32 gx, int32 gy)
|
||||
|
||||
void TerrainInfo::UnloadMMapInstanceImpl(uint32 mapId, uint32 instanceId)
|
||||
{
|
||||
MMAP::MMapFactory::createOrGetMMapManager()->unloadMapInstance(_mapId, mapId, instanceId);
|
||||
MMAP::MMapManager::instance()->unloadMapInstance(_mapId, mapId, instanceId);
|
||||
}
|
||||
|
||||
GridMap* TerrainInfo::GetGrid(uint32 mapId, float x, float y, bool loadIfMissing /*= true*/)
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#include "DisableMgr.h"
|
||||
#include "G3DPosition.hpp"
|
||||
#include "Log.h"
|
||||
#include "MMapFactory.h"
|
||||
#include "MMapManager.h"
|
||||
#include "Map.h"
|
||||
#include "Metric.h"
|
||||
@@ -42,7 +41,7 @@ PathGenerator::PathGenerator(WorldObject const* owner) :
|
||||
uint32 mapId = PhasingHandler::GetTerrainMapId(_source->GetPhaseShift(), _source->GetMapId(), _source->GetMap()->GetTerrain(), _startPosition.x, _startPosition.y);
|
||||
if (DisableMgr::IsPathfindingEnabled(_source->GetMapId()))
|
||||
{
|
||||
MMAP::MMapManager* mmap = MMAP::MMapFactory::createOrGetMMapManager();
|
||||
MMAP::MMapManager* mmap = MMAP::MMapManager::instance();
|
||||
_navMeshQuery = mmap->GetNavMeshQuery(mapId, _source->GetMapId(), _source->GetInstanceId());
|
||||
_navMesh = _navMeshQuery ? _navMeshQuery->getAttachedNavMesh() : mmap->GetNavMesh(mapId);
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@
|
||||
#include "LootItemStorage.h"
|
||||
#include "LootMgr.h"
|
||||
#include "M2Stores.h"
|
||||
#include "MMapFactory.h"
|
||||
#include "MMapManager.h"
|
||||
#include "Map.h"
|
||||
#include "MapManager.h"
|
||||
#include "MapUtils.h"
|
||||
@@ -188,7 +188,6 @@ World::~World()
|
||||
delete command;
|
||||
|
||||
VMAP::VMapFactory::clear();
|
||||
MMAP::MMapFactory::clear();
|
||||
|
||||
/// @todo free addSessQueue
|
||||
}
|
||||
@@ -1356,7 +1355,7 @@ bool World::SetInitialWorldSettings()
|
||||
|
||||
vmmgr2->InitializeThreadUnsafe(mapData);
|
||||
|
||||
MMAP::MMapManager* mmmgr = MMAP::MMapFactory::createOrGetMMapManager();
|
||||
MMAP::MMapManager* mmmgr = MMAP::MMapManager::instance();
|
||||
mmmgr->InitializeThreadUnsafe(mapData);
|
||||
|
||||
///- Initialize static helper structures
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#include "ItemBonusMgr.h"
|
||||
#include "Language.h"
|
||||
#include "MiscPackets.h"
|
||||
#include "MMapFactory.h"
|
||||
#include "MMapManager.h"
|
||||
#include "MotionMaster.h"
|
||||
#include "MovementDefines.h"
|
||||
#include "ObjectAccessor.h"
|
||||
@@ -258,7 +258,7 @@ public:
|
||||
|
||||
uint32 haveMap = TerrainInfo::ExistMap(mapId, gridX, gridY) ? 1 : 0;
|
||||
uint32 haveVMap = TerrainInfo::ExistVMap(mapId, gridX, gridY) ? 1 : 0;
|
||||
uint32 haveMMap = (DisableMgr::IsPathfindingEnabled(mapId) && MMAP::MMapFactory::createOrGetMMapManager()->GetNavMesh(handler->GetSession()->GetPlayer()->GetMapId())) ? 1 : 0;
|
||||
uint32 haveMMap = (DisableMgr::IsPathfindingEnabled(mapId) && MMAP::MMapManager::instance()->GetNavMesh(handler->GetSession()->GetPlayer()->GetMapId())) ? 1 : 0;
|
||||
|
||||
if (haveVMap)
|
||||
{
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include "ChatCommand.h"
|
||||
#include "DisableMgr.h"
|
||||
#include "GridNotifiersImpl.h"
|
||||
#include "MMapFactory.h"
|
||||
#include "MMapManager.h"
|
||||
#include "PathGenerator.h"
|
||||
#include "PhasingHandler.h"
|
||||
#include "Player.h"
|
||||
@@ -66,7 +66,7 @@ public:
|
||||
|
||||
static bool HandleMmapPathCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!MMAP::MMapFactory::createOrGetMMapManager()->GetNavMesh(handler->GetSession()->GetPlayer()->GetMapId()))
|
||||
if (!MMAP::MMapManager::instance()->GetNavMesh(handler->GetSession()->GetPlayer()->GetMapId()))
|
||||
{
|
||||
handler->PSendSysMessage("NavMesh not loaded for current map.");
|
||||
return true;
|
||||
@@ -144,8 +144,8 @@ public:
|
||||
handler->PSendSysMessage("%04u%02i%02i.mmtile", terrainMapId, gx, gy);
|
||||
handler->PSendSysMessage("tileloc [%i, %i]", gy, gx);
|
||||
|
||||
dtNavMesh const* navmesh = MMAP::MMapFactory::createOrGetMMapManager()->GetNavMesh(terrainMapId);
|
||||
dtNavMeshQuery const* navmeshquery = MMAP::MMapFactory::createOrGetMMapManager()->GetNavMeshQuery(terrainMapId, player->GetMapId(), player->GetInstanceId());
|
||||
dtNavMesh const* navmesh = MMAP::MMapManager::instance()->GetNavMesh(terrainMapId);
|
||||
dtNavMeshQuery const* navmeshquery = MMAP::MMapManager::instance()->GetNavMeshQuery(terrainMapId, player->GetMapId(), player->GetInstanceId());
|
||||
if (!navmesh || !navmeshquery)
|
||||
{
|
||||
handler->PSendSysMessage("NavMesh not loaded for current map.");
|
||||
@@ -195,8 +195,8 @@ public:
|
||||
{
|
||||
Player* player = handler->GetSession()->GetPlayer();
|
||||
uint32 terrainMapId = PhasingHandler::GetTerrainMapId(player->GetPhaseShift(), player->GetMapId(), player->GetMap()->GetTerrain(), player->GetPositionX(), player->GetPositionY());
|
||||
dtNavMesh const* navmesh = MMAP::MMapFactory::createOrGetMMapManager()->GetNavMesh(terrainMapId);
|
||||
dtNavMeshQuery const* navmeshquery = MMAP::MMapFactory::createOrGetMMapManager()->GetNavMeshQuery(terrainMapId, player->GetMapId(), player->GetInstanceId());
|
||||
dtNavMesh const* navmesh = MMAP::MMapManager::instance()->GetNavMesh(terrainMapId);
|
||||
dtNavMeshQuery const* navmeshquery = MMAP::MMapManager::instance()->GetNavMeshQuery(terrainMapId, player->GetMapId(), player->GetInstanceId());
|
||||
if (!navmesh || !navmeshquery)
|
||||
{
|
||||
handler->PSendSysMessage("NavMesh not loaded for current map.");
|
||||
@@ -224,7 +224,7 @@ public:
|
||||
handler->PSendSysMessage("mmap stats:");
|
||||
handler->PSendSysMessage(" global mmap pathfinding is %sabled", DisableMgr::IsPathfindingEnabled(player->GetMapId()) ? "en" : "dis");
|
||||
|
||||
MMAP::MMapManager* manager = MMAP::MMapFactory::createOrGetMMapManager();
|
||||
MMAP::MMapManager* manager = MMAP::MMapManager::instance();
|
||||
handler->PSendSysMessage(" %u maps loaded with %u tiles overall", manager->getLoadedMapsCount(), manager->getLoadedTilesCount());
|
||||
|
||||
dtNavMesh const* navmesh = manager->GetNavMesh(terrainMapId);
|
||||
|
||||
Reference in New Issue
Block a user