feat(Core/Common): delete lib game-interface inherited (#5333)

Co-authored-by: Kitzunu <24550914+Kitzunu@users.noreply.github.com>
This commit is contained in:
Kargatum
2021-05-07 02:16:44 +07:00
committed by GitHub
parent 6947789622
commit db7d754f3f
45 changed files with 428 additions and 475 deletions
-2
View File
@@ -49,8 +49,6 @@ target_include_directories(common
${CMAKE_CURRENT_BINARY_DIR}) ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(common target_link_libraries(common
PRIVATE
game-interface
PUBLIC PUBLIC
acore-core-interface acore-core-interface
ace ace
+2 -14
View File
@@ -5,16 +5,12 @@
*/ */
#include "DynamicTree.h" #include "DynamicTree.h"
//#include "QuadTree.h"
//#include "RegularGrid.h"
#include "BoundingIntervalHierarchyWrapper.h" #include "BoundingIntervalHierarchyWrapper.h"
#include "Log.h" #include "Log.h"
#include "RegularGrid.h" #include "RegularGrid.h"
#include "Timer.h" #include "Timer.h"
#include "GameObjectModel.h" #include "GameObjectModel.h"
#include "ModelInstance.h" #include "ModelInstance.h"
#include <G3D/AABox.h> #include <G3D/AABox.h>
#include <G3D/Ray.h> #include <G3D/Ray.h>
#include <G3D/Vector3.h> #include <G3D/Vector3.h>
@@ -23,10 +19,8 @@ using VMAP::ModelInstance;
namespace namespace
{ {
int CHECK_TREE_PERIOD = 200; int CHECK_TREE_PERIOD = 200;
}
} // namespace
template<> struct HashTrait< GameObjectModel> template<> struct HashTrait< GameObjectModel>
{ {
@@ -44,15 +38,9 @@ template<> struct BoundsTrait< GameObjectModel>
static void getBounds2(const GameObjectModel* g, G3D::AABox& out) { out = g->getBounds();} static void getBounds2(const GameObjectModel* g, G3D::AABox& out) { out = g->getBounds();}
}; };
/*
static bool operator == (const GameObjectModel& mdl, const GameObjectModel& mdl2){
return &mdl == &mdl2;
}
*/
typedef RegularGrid2D<GameObjectModel, BIHWrap<GameObjectModel>> ParentTree; typedef RegularGrid2D<GameObjectModel, BIHWrap<GameObjectModel>> ParentTree;
struct DynTreeImpl : public ParentTree/*, public Intersectable*/ struct DynTreeImpl : public ParentTree
{ {
typedef GameObjectModel Model; typedef GameObjectModel Model;
typedef ParentTree base; typedef ParentTree base;
@@ -35,4 +35,4 @@ namespace MMAP
}; };
} }
#endif #endif
@@ -18,7 +18,6 @@ This is the minimum interface to the VMapMamager.
namespace VMAP namespace VMAP
{ {
enum VMAP_LOAD_RESULT enum VMAP_LOAD_RESULT
{ {
VMAP_LOAD_RESULT_ERROR, VMAP_LOAD_RESULT_ERROR,
@@ -83,6 +82,6 @@ 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 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 bool GetLiquidLevel(uint32 pMapId, float x, float y, float z, uint8 ReqLiquidType, float& level, float& floor, uint32& type) const = 0;
}; };
} }
#endif #endif
@@ -5,7 +5,6 @@
*/ */
#include "MMapFactory.h" #include "MMapFactory.h"
#include "World.h"
#include <set> #include <set>
namespace MMAP namespace MMAP
@@ -23,12 +22,6 @@ namespace MMAP
return g_MMapManager; return g_MMapManager;
} }
bool MMapFactory::IsPathfindingEnabled(const Map* map)
{
if (!map) return false;
return !forbiddenMaps[map->GetId()] && (sWorld->getBoolConfig(CONFIG_ENABLE_MMAPS) ? true : map->IsBattlegroundOrArena());
}
void MMapFactory::InitializeDisabledMaps() void MMapFactory::InitializeDisabledMaps()
{ {
memset(&forbiddenMaps, 0, sizeof(forbiddenMaps)); memset(&forbiddenMaps, 0, sizeof(forbiddenMaps));
@@ -46,4 +39,4 @@ namespace MMAP
g_MMapManager = nullptr; g_MMapManager = nullptr;
} }
} }
} }
@@ -10,8 +10,7 @@
#include "MMapManager.h" #include "MMapManager.h"
#include "DetourAlloc.h" #include "DetourAlloc.h"
#include "DetourNavMesh.h" #include "DetourNavMesh.h"
#include "Navigation/DetourExtended.h" #include "DetourExtended.h"
#include "Map.h"
#include <unordered_map> #include <unordered_map>
namespace MMAP namespace MMAP
@@ -31,7 +30,6 @@ namespace MMAP
public: public:
static MMapManager* createOrGetMMapManager(); static MMapManager* createOrGetMMapManager();
static void clear(); static void clear();
static bool IsPathfindingEnabled(const Map* map);
static void InitializeDisabledMaps(); static void InitializeDisabledMaps();
static bool forbiddenMaps[1000]; static bool forbiddenMaps[1000];
}; };
+74 -101
View File
@@ -4,9 +4,10 @@
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*/ */
#include "Config.h"
#include "MapManager.h"
#include "MMapManager.h" #include "MMapManager.h"
#include "Config.h"
#include "Errors.h"
#include "MapDefines.h"
#include "Log.h" #include "Log.h"
#include "StringFormat.h" #include "StringFormat.h"
@@ -25,11 +26,41 @@ namespace MMAP
// if we had, tiles in MMapData->mmapLoadedTiles, their actual data is lost! // if we had, tiles in MMapData->mmapLoadedTiles, their actual data is lost!
} }
void MMapManager::InitializeThreadUnsafe(const std::vector<uint32>& mapIds)
{
// the caller must pass the list of all mapIds that will be used in the VMapManager2 lifetime
for (const uint32& mapId : mapIds)
loadedMMaps.emplace(mapId, nullptr);
thread_safe_environment = false;
}
MMapDataSet::const_iterator MMapManager::GetMMapData(uint32 mapId) const
{
// return the iterator if found or end() if not found/NULL
MMapDataSet::const_iterator itr = loadedMMaps.find(mapId);
if (itr != loadedMMaps.cend() && !itr->second)
itr = loadedMMaps.cend();
return itr;
}
bool MMapManager::loadMapData(uint32 mapId) bool MMapManager::loadMapData(uint32 mapId)
{ {
// we already have this map loaded? // we already have this map loaded?
if (loadedMMaps.find(mapId) != loadedMMaps.end()) MMapDataSet::iterator itr = loadedMMaps.find(mapId);
return true; if (itr != loadedMMaps.end())
{
if (itr->second)
return true;
}
else
{
if (thread_safe_environment)
itr = loadedMMaps.insert(MMapDataSet::value_type(mapId, nullptr)).first;
else
ASSERT(false, "Invalid mapId %u passed to MMapManager after startup in thread unsafe environment", mapId);
}
// load and init dtNavMesh - read parameters from file // load and init dtNavMesh - read parameters from file
std::string fileName = acore::StringFormat(MAP_FILE_NAME_FORMAT, sConfigMgr->GetOption<std::string>("DataDir", ".").c_str(), mapId); std::string fileName = acore::StringFormat(MAP_FILE_NAME_FORMAT, sConfigMgr->GetOption<std::string>("DataDir", ".").c_str(), mapId);
@@ -37,18 +68,16 @@ namespace MMAP
FILE* file = fopen(fileName.c_str(), "rb"); FILE* file = fopen(fileName.c_str(), "rb");
if (!file) if (!file)
{ {
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
LOG_DEBUG("maps", "MMAP:loadMapData: Error: Could not open mmap file '%s'", fileName.c_str()); LOG_DEBUG("maps", "MMAP:loadMapData: Error: Could not open mmap file '%s'", fileName.c_str());
#endif
return false; return false;
} }
dtNavMeshParams params; dtNavMeshParams params;
int count = fread(&params, sizeof(dtNavMeshParams), 1, file); uint32 count = uint32(fread(&params, sizeof(dtNavMeshParams), 1, file));
fclose(file); fclose(file);
if (count != 1) if (count != 1)
{ {
;//TC_LOG_DEBUG(LOG_FILTER_MAPS, "MMAP:loadMapData: Error: Could not read params from file '%s'", fileName); LOG_DEBUG("maps", "MMAP:loadMapData: Error: Could not read params from file '%s'", fileName.c_str());
return false; return false;
} }
@@ -61,15 +90,11 @@ namespace MMAP
return false; return false;
} }
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS) LOG_DEBUG("maps", "MMAP:loadMapData: Loaded %03i.mmap", mapId);
LOG_DEBUG("server", "MMAP:loadMapData: Loaded %03i.mmap", mapId);
#endif
// store inside our map list // store inside our map list
MMapData* mmap_data = new MMapData(mesh); MMapData* mmap_data = new MMapData(mesh);
mmap_data->mmapLoadedTiles.clear(); itr->second = mmap_data;
loadedMMaps.insert(std::pair<uint32, MMapData*>(mapId, mmap_data));
return true; return true;
} }
@@ -78,22 +103,8 @@ namespace MMAP
return uint32(x << 16 | y); return uint32(x << 16 | y);
} }
std::shared_mutex& MMapManager::GetMMapLock(uint32 mapId)
{
Map* map = sMapMgr->FindBaseMap(mapId);
if (!map)
{
LOG_INFO("misc", "ZOMG! MoveMaps: BaseMap not found!");
return this->MMapLock;
}
return map->GetMMapLock();
}
bool MMapManager::loadMap(uint32 mapId, int32 x, int32 y) bool MMapManager::loadMap(uint32 mapId, int32 x, int32 y)
{ {
std::unique_lock<std::shared_mutex> guard(MMapManagerLock);
// make sure the mmap is loaded and ready to load tiles // make sure the mmap is loaded and ready to load tiles
if (!loadMapData(mapId)) if (!loadMapData(mapId))
return false; return false;
@@ -104,7 +115,7 @@ namespace MMAP
// check if we already have this tile loaded // check if we already have this tile loaded
uint32 packedGridPos = packTileID(x, y); uint32 packedGridPos = packTileID(x, y);
if (mmap->mmapLoadedTiles.find(packedGridPos) != mmap->mmapLoadedTiles.end()) if (mmap->loadedTileRefs.find(packedGridPos) != mmap->loadedTileRefs.end())
{ {
LOG_ERROR("server", "MMAP:loadMap: Asked to load already loaded navmesh tile. %03u%02i%02i.mmtile", mapId, x, y); LOG_ERROR("server", "MMAP:loadMap: Asked to load already loaded navmesh tile. %03u%02i%02i.mmtile", mapId, x, y);
return false; return false;
@@ -151,26 +162,18 @@ namespace MMAP
dtTileRef tileRef = 0; dtTileRef tileRef = 0;
dtStatus stat;
{
std::unique_lock<std::shared_mutex> guard(GetMMapLock(mapId));
stat = mmap->navMesh->addTile(data, fileHeader.size, DT_TILE_FREE_DATA, 0, &tileRef);
}
// memory allocated for data is now managed by detour, and will be deallocated when the tile is removed // memory allocated for data is now managed by detour, and will be deallocated when the tile is removed
if (stat == DT_SUCCESS) if (dtStatusSucceed(mmap->navMesh->addTile(data, fileHeader.size, DT_TILE_FREE_DATA, 0, &tileRef)))
{ {
mmap->mmapLoadedTiles.insert(std::pair<uint32, dtTileRef>(packedGridPos, tileRef)); mmap->loadedTileRefs.insert(std::pair<uint32, dtTileRef>(packedGridPos, tileRef));
++loadedTiles; ++loadedTiles;
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
dtMeshHeader* header = (dtMeshHeader*)data; dtMeshHeader* header = (dtMeshHeader*)data;
LOG_DEBUG("server", "MMAP:loadMap: Loaded mmtile %03i[%02i,%02i] into %03i[%02i,%02i]", mapId, x, y, mapId, header->x, header->y); LOG_DEBUG("maps", "MMAP:loadMap: Loaded mmtile %03i[%02i,%02i] into %03i[%02i,%02i]", mapId, x, y, mapId, header->x, header->y);
#endif
return true; return true;
} }
else else
{ {
LOG_ERROR("server", "MMAP:loadMap: Could not load %03u%02i%02i.mmtile into navmesh", mapId, x, y); LOG_ERROR("maps", "MMAP:loadMap: Could not load %03u%02i%02i.mmtile into navmesh", mapId, x, y);
dtFree(data); dtFree(data);
return false; return false;
} }
@@ -180,10 +183,9 @@ namespace MMAP
bool MMapManager::unloadMap(uint32 mapId, int32 x, int32 y) bool MMapManager::unloadMap(uint32 mapId, int32 x, int32 y)
{ {
std::unique_lock<std::shared_mutex> guard(MMapManagerLock);
// check if we have this map loaded // check if we have this map loaded
if (loadedMMaps.find(mapId) == loadedMMaps.end()) MMapDataSet::const_iterator itr = GetMMapData(mapId);
if (itr == loadedMMaps.end())
{ {
// file may not exist, therefore not loaded // file may not exist, therefore not loaded
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS) #if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
@@ -192,11 +194,11 @@ namespace MMAP
return false; return false;
} }
MMapData* mmap = loadedMMaps[mapId]; MMapData* mmap = itr->second;
// check if we have this tile loaded // check if we have this tile loaded
uint32 packedGridPos = packTileID(x, y); uint32 packedGridPos = packTileID(x, y);
if (mmap->mmapLoadedTiles.find(packedGridPos) == mmap->mmapLoadedTiles.end()) if (mmap->loadedTileRefs.find(packedGridPos) == mmap->loadedTileRefs.end())
{ {
// file may not exist, therefore not loaded // file may not exist, therefore not loaded
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS) #if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
@@ -205,16 +207,10 @@ namespace MMAP
return false; return false;
} }
dtTileRef tileRef = mmap->mmapLoadedTiles[packedGridPos]; dtTileRef tileRef = mmap->loadedTileRefs[packedGridPos];
dtStatus status;
{
std::unique_lock<std::shared_mutex> guard(GetMMapLock(mapId));
status = mmap->navMesh->removeTile(tileRef, nullptr, nullptr);
}
// unload, and mark as non loaded // unload, and mark as non loaded
if (status != DT_SUCCESS) if (dtStatusFailed(mmap->navMesh->removeTile(tileRef, nullptr, nullptr)))
{ {
// this is technically a memory leak // this is technically a memory leak
// if the grid is later reloaded, dtNavMesh::addTile will return error but no extra memory is used // if the grid is later reloaded, dtNavMesh::addTile will return error but no extra memory is used
@@ -224,11 +220,9 @@ namespace MMAP
} }
else else
{ {
mmap->mmapLoadedTiles.erase(packedGridPos); mmap->loadedTileRefs.erase(packedGridPos);
--loadedTiles; --loadedTiles;
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS) LOG_DEBUG("maps", "MMAP:unloadMap: Unloaded mmtile %03i[%02i,%02i] from %03i", mapId, x, y, mapId);
LOG_DEBUG("server", "MMAP:unloadMap: Unloaded mmtile %03i[%02i,%02i] from %03i", mapId, x, y, mapId);
#endif
return true; return true;
} }
@@ -237,70 +231,52 @@ namespace MMAP
bool MMapManager::unloadMap(uint32 mapId) bool MMapManager::unloadMap(uint32 mapId)
{ {
std::unique_lock<std::shared_mutex> guard(MMapManagerLock); MMapDataSet::iterator itr = loadedMMaps.find(mapId);
if (itr == loadedMMaps.end() || !itr->second)
if (loadedMMaps.find(mapId) == loadedMMaps.end())
{ {
// file may not exist, therefore not loaded // file may not exist, therefore not loaded
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
LOG_DEBUG("maps", "MMAP:unloadMap: Asked to unload not loaded navmesh map %03u", mapId); LOG_DEBUG("maps", "MMAP:unloadMap: Asked to unload not loaded navmesh map %03u", mapId);
#endif
return false; return false;
} }
// unload all tiles from given map // unload all tiles from given map
MMapData* mmap = loadedMMaps[mapId]; MMapData* mmap = itr->second;
for (MMapTileSet::iterator i = mmap->mmapLoadedTiles.begin(); i != mmap->mmapLoadedTiles.end(); ++i) for (auto i : mmap->loadedTileRefs)
{ {
uint32 x = (i->first >> 16); uint32 x = (i.first >> 16);
uint32 y = (i->first & 0x0000FFFF); uint32 y = (i.first & 0x0000FFFF);
dtStatus status; if (dtStatusFailed(mmap->navMesh->removeTile(i.second, nullptr, nullptr)))
{
std::unique_lock<std::shared_mutex> guard(GetMMapLock(mapId));
status = mmap->navMesh->removeTile(i->second, nullptr, nullptr);
}
if (status != DT_SUCCESS)
LOG_ERROR("server", "MMAP:unloadMap: Could not unload %03u%02i%02i.mmtile from navmesh", mapId, x, y); LOG_ERROR("server", "MMAP:unloadMap: Could not unload %03u%02i%02i.mmtile from navmesh", mapId, x, y);
else else
{ {
--loadedTiles; --loadedTiles;
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
LOG_DEBUG("server", "MMAP:unloadMap: Unloaded mmtile %03i[%02i,%02i] from %03i", mapId, x, y, mapId); LOG_DEBUG("server", "MMAP:unloadMap: Unloaded mmtile %03i[%02i,%02i] from %03i", mapId, x, y, mapId);
#endif
} }
} }
delete mmap; delete mmap;
loadedMMaps.erase(mapId); itr->second = nullptr;
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS) LOG_DEBUG("maps", "MMAP:unloadMap: Unloaded %03i.mmap", mapId);
LOG_DEBUG("server", "MMAP:unloadMap: Unloaded %03i.mmap", mapId);
#endif
return true; return true;
} }
bool MMapManager::unloadMapInstance(uint32 mapId, uint32 instanceId) bool MMapManager::unloadMapInstance(uint32 mapId, uint32 instanceId)
{ {
std::unique_lock<std::shared_mutex> guard(MMapManagerLock);
// check if we have this map loaded // check if we have this map loaded
if (loadedMMaps.find(mapId) == loadedMMaps.end()) MMapDataSet::const_iterator itr = GetMMapData(mapId);
if (itr == loadedMMaps.end())
{ {
// file may not exist, therefore not loaded // file may not exist, therefore not loaded
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
LOG_DEBUG("maps", "MMAP:unloadMapInstance: Asked to unload not loaded navmesh map %03u", mapId); LOG_DEBUG("maps", "MMAP:unloadMapInstance: Asked to unload not loaded navmesh map %03u", mapId);
#endif
return false; return false;
} }
MMapData* mmap = loadedMMaps[mapId]; MMapData* mmap = itr->second;
if (mmap->navMeshQueries.find(instanceId) == mmap->navMeshQueries.end()) if (mmap->navMeshQueries.find(instanceId) == mmap->navMeshQueries.end())
{ {
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
LOG_DEBUG("maps", "MMAP:unloadMapInstance: Asked to unload not loaded dtNavMeshQuery mapId %03u instanceId %u", mapId, instanceId); LOG_DEBUG("maps", "MMAP:unloadMapInstance: Asked to unload not loaded dtNavMeshQuery mapId %03u instanceId %u", mapId, instanceId);
#endif
return false; return false;
} }
@@ -308,47 +284,44 @@ namespace MMAP
dtFreeNavMeshQuery(query); dtFreeNavMeshQuery(query);
mmap->navMeshQueries.erase(instanceId); mmap->navMeshQueries.erase(instanceId);
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS) LOG_DEBUG("maps", "MMAP:unloadMapInstance: Unloaded mapId %03u instanceId %u", mapId, instanceId);
LOG_DEBUG("server", "MMAP:unloadMapInstance: Unloaded mapId %03u instanceId %u", mapId, instanceId);
#endif
return true; return true;
} }
dtNavMesh const* MMapManager::GetNavMesh(uint32 mapId) dtNavMesh const* MMapManager::GetNavMesh(uint32 mapId)
{ {
if (loadedMMaps.find(mapId) == loadedMMaps.end()) MMapDataSet::const_iterator itr = GetMMapData(mapId);
if (itr == loadedMMaps.end())
return nullptr; return nullptr;
return loadedMMaps[mapId]->navMesh; return itr->second->navMesh;
} }
dtNavMeshQuery const* MMapManager::GetNavMeshQuery(uint32 mapId, uint32 instanceId) dtNavMeshQuery const* MMapManager::GetNavMeshQuery(uint32 mapId, uint32 instanceId)
{ {
if (loadedMMaps.find(mapId) == loadedMMaps.end()) MMapDataSet::const_iterator itr = GetMMapData(mapId);
if (itr == loadedMMaps.end())
return nullptr; return nullptr;
MMapData* mmap = loadedMMaps[mapId]; MMapData* mmap = itr->second;
if (mmap->navMeshQueries.find(instanceId) == mmap->navMeshQueries.end()) if (mmap->navMeshQueries.find(instanceId) == mmap->navMeshQueries.end())
{ {
// pussywizard: different instances of the same map shouldn't access this simultaneously
std::unique_lock<std::shared_mutex> guard(GetMMapLock(mapId));
// check again after acquiring mutex // check again after acquiring mutex
if (mmap->navMeshQueries.find(instanceId) == mmap->navMeshQueries.end()) if (mmap->navMeshQueries.find(instanceId) == mmap->navMeshQueries.end())
{ {
// allocate mesh query // allocate mesh query
dtNavMeshQuery* query = dtAllocNavMeshQuery(); dtNavMeshQuery* query = dtAllocNavMeshQuery();
ASSERT(query); ASSERT(query);
if (DT_SUCCESS != query->init(mmap->navMesh, 1024))
if (dtStatusFailed(query->init(mmap->navMesh, 1024)))
{ {
dtFreeNavMeshQuery(query); dtFreeNavMeshQuery(query);
LOG_ERROR("server", "MMAP:GetNavMeshQuery: Failed to initialize dtNavMeshQuery for mapId %03u instanceId %u", mapId, instanceId); LOG_ERROR("server", "MMAP:GetNavMeshQuery: Failed to initialize dtNavMeshQuery for mapId %03u instanceId %u", mapId, instanceId);
return nullptr; return nullptr;
} }
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS) LOG_DEBUG("maps", "MMAP:GetNavMeshQuery: created dtNavMeshQuery for mapId %03u instanceId %u", mapId, instanceId);
LOG_DEBUG("server", "MMAP:GetNavMeshQuery: created dtNavMeshQuery for mapId %03u instanceId %u", mapId, instanceId);
#endif
mmap->navMeshQueries.insert(std::pair<uint32, dtNavMeshQuery*>(instanceId, query)); mmap->navMeshQueries.insert(std::pair<uint32, dtNavMeshQuery*>(instanceId, query));
} }
} }
+9 -12
View File
@@ -34,7 +34,8 @@ namespace MMAP
// dummy struct to hold map's mmap data // dummy struct to hold map's mmap data
struct MMapData struct MMapData
{ {
MMapData(dtNavMesh* mesh) : navMesh(mesh) {} MMapData(dtNavMesh* mesh) : navMesh(mesh) { }
~MMapData() ~MMapData()
{ {
for (NavMeshQuerySet::iterator i = navMeshQueries.begin(); i != navMeshQueries.end(); ++i) for (NavMeshQuerySet::iterator i = navMeshQueries.begin(); i != navMeshQueries.end(); ++i)
@@ -44,11 +45,10 @@ namespace MMAP
dtFreeNavMesh(navMesh); dtFreeNavMesh(navMesh);
} }
dtNavMesh* navMesh;
// we have to use single dtNavMeshQuery for every instance, since those are not thread safe // we have to use single dtNavMeshQuery for every instance, since those are not thread safe
NavMeshQuerySet navMeshQueries; // instanceId to query NavMeshQuerySet navMeshQueries; // instanceId to query
MMapTileSet mmapLoadedTiles; // maps [map grid coords] to [dtTile] dtNavMesh* navMesh;
MMapTileSet loadedTileRefs; // maps [map grid coords] to [dtTile]
}; };
typedef std::unordered_map<uint32, MMapData*> MMapDataSet; typedef std::unordered_map<uint32, MMapData*> MMapDataSet;
@@ -58,9 +58,10 @@ namespace MMAP
class MMapManager class MMapManager
{ {
public: public:
MMapManager() : loadedTiles(0) {} MMapManager() : loadedTiles(0), thread_safe_environment(true) { }
~MMapManager(); ~MMapManager();
void InitializeThreadUnsafe(const std::vector<uint32>& mapIds);
bool loadMap(uint32 mapId, int32 x, int32 y); bool loadMap(uint32 mapId, int32 x, int32 y);
bool unloadMap(uint32 mapId, int32 x, int32 y); bool unloadMap(uint32 mapId, int32 x, int32 y);
bool unloadMap(uint32 mapId); bool unloadMap(uint32 mapId);
@@ -73,18 +74,14 @@ namespace MMAP
uint32 getLoadedTilesCount() const { return loadedTiles; } uint32 getLoadedTilesCount() const { return loadedTiles; }
uint32 getLoadedMapsCount() const { return loadedMMaps.size(); } uint32 getLoadedMapsCount() const { return loadedMMaps.size(); }
std::shared_mutex& GetMMapLock(uint32 mapId);
std::shared_mutex& GetMMapGeneralLock() { return MMapLock; } // pussywizard: in case a per-map mutex can't be found, should never happen
std::shared_mutex& GetManagerLock() { return MMapManagerLock; }
private: private:
bool loadMapData(uint32 mapId); bool loadMapData(uint32 mapId);
uint32 packTileID(int32 x, int32 y); uint32 packTileID(int32 x, int32 y);
MMapDataSet::const_iterator GetMMapData(uint32 mapId) const;
MMapDataSet loadedMMaps; MMapDataSet loadedMMaps;
uint32 loadedTiles; uint32 loadedTiles;
bool thread_safe_environment;
std::shared_mutex MMapManagerLock;
std::shared_mutex MMapLock; // pussywizard: in case a per-map mutex can't be found, should never happen
}; };
} }
@@ -9,14 +9,15 @@
namespace VMAP namespace VMAP
{ {
IVMapManager* gVMapManager = nullptr; VMapManager2* gVMapManager = nullptr;
//=============================================== //===============================================
// just return the instance // just return the instance
IVMapManager* VMapFactory::createOrGetVMapManager() VMapManager2* VMapFactory::createOrGetVMapManager()
{ {
if (gVMapManager == 0) if (!gVMapManager)
gVMapManager = new VMapManager2(); // should be taken from config ... Please change if you like :-) gVMapManager = new VMapManager2();
return gVMapManager; return gVMapManager;
} }
@@ -9,20 +9,16 @@
#include "IVMapManager.h" #include "IVMapManager.h"
/** // This is the access point to the VMapManager.
This is the access point to the VMapManager.
*/
namespace VMAP namespace VMAP
{ {
//=========================================================== class VMapManager2;
class VMapFactory class VMapFactory
{ {
public: public:
static IVMapManager* createOrGetVMapManager(); static VMapManager2* createOrGetVMapManager();
static void clear(); static void clear();
}; };
} }
#endif #endif
@@ -15,21 +15,19 @@
* with this program. If not, see <http://www.gnu.org/licenses/>. * with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include "VMapManager2.h" #include "VMapManager2.h"
#include "MapTree.h" #include "MapTree.h"
#include "ModelInstance.h" #include "ModelInstance.h"
#include "WorldModel.h" #include "WorldModel.h"
#include <G3D/Vector3.h> #include "MapDefines.h"
#include <ace/Null_Mutex.h>
#include "DisableMgr.h"
#include "DBCStores.h"
#include "Log.h" #include "Log.h"
#include "VMapDefinitions.h" #include "VMapDefinitions.h"
#include "GridDefines.h" #include "Errors.h"
#include <G3D/Vector3.h>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
using G3D::Vector3; using G3D::Vector3;
@@ -38,20 +36,32 @@ namespace VMAP
VMapManager2::VMapManager2() VMapManager2::VMapManager2()
{ {
GetLiquidFlagsPtr = &GetLiquidFlagsDummy; GetLiquidFlagsPtr = &GetLiquidFlagsDummy;
IsVMAPDisabledForPtr = &IsVMAPDisabledForDummy;
thread_safe_environment = true;
} }
VMapManager2::~VMapManager2(void) VMapManager2::~VMapManager2()
{ {
for (InstanceTreeMap::iterator i = iInstanceMapTrees.begin(); i != iInstanceMapTrees.end(); ++i) for (InstanceTreeMap::iterator i = iInstanceMapTrees.begin(); i != iInstanceMapTrees.end(); ++i)
{ {
delete i->second; delete i->second;
} }
for (ModelFileMap::iterator i = iLoadedModelFiles.begin(); i != iLoadedModelFiles.end(); ++i) for (ModelFileMap::iterator i = iLoadedModelFiles.begin(); i != iLoadedModelFiles.end(); ++i)
{ {
delete i->second.getModel(); delete i->second.getModel();
} }
} }
void VMapManager2::InitializeThreadUnsafe(const std::vector<uint32>& mapIds)
{
// the caller must pass the list of all mapIds that will be used in the VMapManager2 lifetime
for (const uint32& mapId : mapIds)
iInstanceMapTrees.emplace(mapId, nullptr);
thread_safe_environment = false;
}
Vector3 VMapManager2::convertPositionToInternalRep(float x, float y, float z) const Vector3 VMapManager2::convertPositionToInternalRep(float x, float y, float z) const
{ {
Vector3 pos; Vector3 pos;
@@ -63,6 +73,16 @@ namespace VMAP
return pos; return pos;
} }
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;
}
// move to MapTree too? // move to MapTree too?
std::string VMapManager2::getMapFileName(unsigned int mapId) std::string VMapManager2::getMapFileName(unsigned int mapId)
{ {
@@ -92,6 +112,15 @@ namespace VMAP
{ {
InstanceTreeMap::iterator instanceTree = iInstanceMapTrees.find(mapId); InstanceTreeMap::iterator instanceTree = iInstanceMapTrees.find(mapId);
if (instanceTree == iInstanceMapTrees.end()) if (instanceTree == iInstanceMapTrees.end())
{
if (thread_safe_environment)
instanceTree = iInstanceMapTrees.insert(InstanceTreeMap::value_type(mapId, nullptr)).first;
else
ASSERT(false, "Invalid mapId %u tile [%u, %u] passed to VMapManager2 after startup in thread unsafe environment",
mapId, tileX, tileY);
}
if (!instanceTree->second)
{ {
std::string mapFileName = getMapFileName(mapId); std::string mapFileName = getMapFileName(mapId);
StaticMapTree* newTree = new StaticMapTree(mapId, basePath); StaticMapTree* newTree = new StaticMapTree(mapId, basePath);
@@ -100,7 +129,7 @@ namespace VMAP
delete newTree; delete newTree;
return false; return false;
} }
instanceTree = iInstanceMapTrees.insert(InstanceTreeMap::value_type(mapId, newTree)).first; instanceTree->second = newTree;
} }
return instanceTree->second->LoadMapTile(tileX, tileY, this); return instanceTree->second->LoadMapTile(tileX, tileY, this);
@@ -109,13 +138,13 @@ namespace VMAP
void VMapManager2::unloadMap(unsigned int mapId) void VMapManager2::unloadMap(unsigned int mapId)
{ {
InstanceTreeMap::iterator instanceTree = iInstanceMapTrees.find(mapId); InstanceTreeMap::iterator instanceTree = iInstanceMapTrees.find(mapId);
if (instanceTree != iInstanceMapTrees.end()) if (instanceTree != iInstanceMapTrees.end() && instanceTree->second)
{ {
instanceTree->second->UnloadMap(this); instanceTree->second->UnloadMap(this);
if (instanceTree->second->numLoadedTiles() == 0) if (instanceTree->second->numLoadedTiles() == 0)
{ {
delete instanceTree->second; delete instanceTree->second;
iInstanceMapTrees.erase(mapId); instanceTree->second = nullptr;
} }
} }
} }
@@ -123,25 +152,25 @@ namespace VMAP
void VMapManager2::unloadMap(unsigned int mapId, int x, int y) void VMapManager2::unloadMap(unsigned int mapId, int x, int y)
{ {
InstanceTreeMap::iterator instanceTree = iInstanceMapTrees.find(mapId); InstanceTreeMap::iterator instanceTree = iInstanceMapTrees.find(mapId);
if (instanceTree != iInstanceMapTrees.end()) if (instanceTree != iInstanceMapTrees.end() && instanceTree->second)
{ {
instanceTree->second->UnloadMapTile(x, y, this); instanceTree->second->UnloadMapTile(x, y, this);
if (instanceTree->second->numLoadedTiles() == 0) if (instanceTree->second->numLoadedTiles() == 0)
{ {
delete instanceTree->second; delete instanceTree->second;
iInstanceMapTrees.erase(mapId); instanceTree->second = nullptr;
} }
} }
} }
bool VMapManager2::isInLineOfSight(unsigned int mapId, float x1, float y1, float z1, float x2, float y2, float z2) bool VMapManager2::isInLineOfSight(unsigned int mapId, float x1, float y1, float z1, float x2, float y2, float z2)
{ {
#if defined(ENABLE_EXTRAS) && defined(ENABLE_VMAP_CHECKS) #if defined(ENABLE_VMAP_CHECKS)
if (!isLineOfSightCalcEnabled() || DisableMgr::IsDisabledFor(DISABLE_TYPE_VMAP, mapId, nullptr, VMAP_DISABLE_LOS)) if (!isLineOfSightCalcEnabled() || IsVMAPDisabledForPtr(mapId, VMAP_DISABLE_LOS))
return true; return true;
#endif #endif
InstanceTreeMap::iterator instanceTree = iInstanceMapTrees.find(mapId); InstanceTreeMap::const_iterator instanceTree = GetMapTree(mapId);
if (instanceTree != iInstanceMapTrees.end()) if (instanceTree != iInstanceMapTrees.end())
{ {
Vector3 pos1 = convertPositionToInternalRep(x1, y1, z1); Vector3 pos1 = convertPositionToInternalRep(x1, y1, z1);
@@ -161,11 +190,11 @@ namespace VMAP
*/ */
bool VMapManager2::getObjectHitPos(unsigned int mapId, float x1, float y1, float z1, float x2, float y2, float z2, float& rx, float& ry, float& rz, float modifyDist) bool VMapManager2::getObjectHitPos(unsigned int mapId, float x1, float y1, float z1, float x2, float y2, float z2, float& rx, float& ry, float& rz, float modifyDist)
{ {
#if defined(ENABLE_EXTRAS) && defined(ENABLE_VMAP_CHECKS) #if defined(ENABLE_VMAP_CHECKS)
if (isLineOfSightCalcEnabled() && !DisableMgr::IsDisabledFor(DISABLE_TYPE_VMAP, mapId, nullptr, VMAP_DISABLE_LOS)) if (isLineOfSightCalcEnabled() && !IsVMAPDisabledForPtr(mapId, VMAP_DISABLE_LOS))
#endif #endif
{ {
InstanceTreeMap::iterator instanceTree = iInstanceMapTrees.find(mapId); InstanceTreeMap::const_iterator instanceTree = GetMapTree(mapId);
if (instanceTree != iInstanceMapTrees.end()) if (instanceTree != iInstanceMapTrees.end())
{ {
Vector3 pos1 = convertPositionToInternalRep(x1, y1, z1); Vector3 pos1 = convertPositionToInternalRep(x1, y1, z1);
@@ -193,11 +222,11 @@ namespace VMAP
float VMapManager2::getHeight(unsigned int mapId, float x, float y, float z, float maxSearchDist) float VMapManager2::getHeight(unsigned int mapId, float x, float y, float z, float maxSearchDist)
{ {
#if defined(ENABLE_EXTRAS) && defined(ENABLE_VMAP_CHECKS) #if defined(ENABLE_VMAP_CHECKS)
if (isHeightCalcEnabled() && !DisableMgr::IsDisabledFor(DISABLE_TYPE_VMAP, mapId, nullptr, VMAP_DISABLE_HEIGHT)) if (isHeightCalcEnabled() && !IsVMAPDisabledForPtr(mapId, VMAP_DISABLE_HEIGHT))
#endif #endif
{ {
InstanceTreeMap::iterator instanceTree = iInstanceMapTrees.find(mapId); InstanceTreeMap::const_iterator instanceTree = GetMapTree(mapId);
if (instanceTree != iInstanceMapTrees.end()) if (instanceTree != iInstanceMapTrees.end())
{ {
Vector3 pos = convertPositionToInternalRep(x, y, z); Vector3 pos = convertPositionToInternalRep(x, y, z);
@@ -214,11 +243,11 @@ namespace VMAP
bool VMapManager2::getAreaInfo(unsigned int mapId, float x, float y, float& z, uint32& flags, int32& adtId, int32& rootId, int32& groupId) const bool VMapManager2::getAreaInfo(unsigned int mapId, float x, float y, float& z, uint32& flags, int32& adtId, int32& rootId, int32& groupId) const
{ {
#if defined(ENABLE_EXTRAS) && defined(ENABLE_VMAP_CHECKS) #if defined(ENABLE_VMAP_CHECKS)
if (!DisableMgr::IsDisabledFor(DISABLE_TYPE_VMAP, mapId, nullptr, VMAP_DISABLE_AREAFLAG)) if (!IsVMAPDisabledForPtr(mapId, VMAP_DISABLE_AREAFLAG))
#endif #endif
{ {
InstanceTreeMap::const_iterator instanceTree = iInstanceMapTrees.find(mapId); InstanceTreeMap::const_iterator instanceTree = GetMapTree(mapId);
if (instanceTree != iInstanceMapTrees.end()) if (instanceTree != iInstanceMapTrees.end())
{ {
Vector3 pos = convertPositionToInternalRep(x, y, z); Vector3 pos = convertPositionToInternalRep(x, y, z);
@@ -234,11 +263,11 @@ namespace VMAP
bool VMapManager2::GetLiquidLevel(uint32 mapId, float x, float y, float z, uint8 reqLiquidType, float& level, float& floor, uint32& type) const bool VMapManager2::GetLiquidLevel(uint32 mapId, float x, float y, float z, uint8 reqLiquidType, float& level, float& floor, uint32& type) const
{ {
#if defined(ENABLE_EXTRAS) && defined(ENABLE_VMAP_CHECKS) #if defined(ENABLE_VMAP_CHECKS)
if (!DisableMgr::IsDisabledFor(DISABLE_TYPE_VMAP, mapId, nullptr, VMAP_DISABLE_LIQUIDSTATUS)) if (!IsVMAPDisabledForPtr(mapId, VMAP_DISABLE_LIQUIDSTATUS))
#endif #endif
{ {
InstanceTreeMap::const_iterator instanceTree = iInstanceMapTrees.find(mapId); InstanceTreeMap::const_iterator instanceTree = GetMapTree(mapId);
if (instanceTree != iInstanceMapTrees.end()) if (instanceTree != iInstanceMapTrees.end())
{ {
LocationInfo info; LocationInfo info;
@@ -262,7 +291,7 @@ namespace VMAP
WorldModel* VMapManager2::acquireModelInstance(const std::string& basepath, const std::string& filename) WorldModel* VMapManager2::acquireModelInstance(const std::string& basepath, const std::string& filename)
{ {
//! Critical section, thread safe access to iLoadedModelFiles //! Critical section, thread safe access to iLoadedModelFiles
std::lock_guard<std::mutex> guard(LoadedModelFilesLock); std::lock_guard<std::mutex> lock(LoadedModelFilesLock);
ModelFileMap::iterator model = iLoadedModelFiles.find(filename); ModelFileMap::iterator model = iLoadedModelFiles.find(filename);
if (model == iLoadedModelFiles.end()) if (model == iLoadedModelFiles.end())
@@ -274,20 +303,19 @@ namespace VMAP
delete worldmodel; delete worldmodel;
return nullptr; return nullptr;
} }
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
LOG_DEBUG("maps", "VMapManager2: loading file '%s%s'", basepath.c_str(), filename.c_str()); LOG_DEBUG("maps", "VMapManager2: loading file '%s%s'", basepath.c_str(), filename.c_str());
#endif
model = iLoadedModelFiles.insert(std::pair<std::string, ManagedModel>(filename, ManagedModel())).first; model = iLoadedModelFiles.insert(std::pair<std::string, ManagedModel>(filename, ManagedModel())).first;
model->second.setModel(worldmodel); model->second.setModel(worldmodel);
} }
//model->second.incRefCount();
return model->second.getModel(); return model->second.getModel();
} }
void VMapManager2::releaseModelInstance(const std::string& filename) void VMapManager2::releaseModelInstance(const std::string& filename)
{ {
//! Critical section, thread safe access to iLoadedModelFiles //! Critical section, thread safe access to iLoadedModelFiles
std::lock_guard<std::mutex> guard(LoadedModelFilesLock); std::lock_guard<std::mutex> lock(LoadedModelFilesLock);
ModelFileMap::iterator model = iLoadedModelFiles.find(filename); ModelFileMap::iterator model = iLoadedModelFiles.find(filename);
if (model == iLoadedModelFiles.end()) if (model == iLoadedModelFiles.end())
{ {
@@ -296,9 +324,7 @@ namespace VMAP
} }
if (model->second.decRefCount() == 0) if (model->second.decRefCount() == 0)
{ {
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
LOG_DEBUG("maps", "VMapManager2: unloading file '%s'", filename.c_str()); LOG_DEBUG("maps", "VMapManager2: unloading file '%s'", filename.c_str());
#endif
delete model->second.getModel(); delete model->second.getModel();
iLoadedModelFiles.erase(model); iLoadedModelFiles.erase(model);
} }
@@ -309,4 +335,9 @@ namespace VMAP
return StaticMapTree::CanLoadMap(std::string(basePath), mapId, x, y); return StaticMapTree::CanLoadMap(std::string(basePath), mapId, x, y);
} }
void VMapManager2::getInstanceMapTree(InstanceTreeMap& instanceMapTree)
{
instanceMapTree = iInstanceMapTrees;
}
} // namespace VMAP } // namespace VMAP
+21 -3
View File
@@ -19,9 +19,10 @@
#define _VMAPMANAGER2_H #define _VMAPMANAGER2_H
#include "IVMapManager.h" #include "IVMapManager.h"
#include "Define.h" #include "Common.h"
#include <mutex> #include <mutex>
#include <unordered_map> #include <unordered_map>
#include <vector>
//=========================================================== //===========================================================
@@ -65,12 +66,22 @@ namespace VMAP
typedef std::unordered_map<uint32, StaticMapTree*> InstanceTreeMap; typedef std::unordered_map<uint32, StaticMapTree*> InstanceTreeMap;
typedef std::unordered_map<std::string, ManagedModel> ModelFileMap; typedef std::unordered_map<std::string, ManagedModel> ModelFileMap;
enum DisableTypes
{
VMAP_DISABLE_AREAFLAG = 0x1,
VMAP_DISABLE_HEIGHT = 0x2,
VMAP_DISABLE_LOS = 0x4,
VMAP_DISABLE_LIQUIDSTATUS = 0x8
};
class VMapManager2 : public IVMapManager class VMapManager2 : public IVMapManager
{ {
protected: protected:
// Tree to check collision // Tree to check collision
ModelFileMap iLoadedModelFiles; ModelFileMap iLoadedModelFiles;
InstanceTreeMap iInstanceMapTrees; InstanceTreeMap iInstanceMapTrees;
bool thread_safe_environment;
// Mutex for iLoadedModelFiles // Mutex for iLoadedModelFiles
std::mutex LoadedModelFilesLock; std::mutex LoadedModelFilesLock;
@@ -78,6 +89,9 @@ namespace VMAP
/* void _unloadMap(uint32 pMapId, uint32 x, uint32 y); */ /* void _unloadMap(uint32 pMapId, uint32 x, uint32 y); */
static uint32 GetLiquidFlagsDummy(uint32) { return 0; } static uint32 GetLiquidFlagsDummy(uint32) { return 0; }
static bool IsVMAPDisabledForDummy(uint32 /*entry*/, uint8 /*flags*/) { return false; }
InstanceTreeMap::const_iterator GetMapTree(uint32 mapId) const;
public: public:
// public for debug // public for debug
@@ -87,6 +101,8 @@ namespace VMAP
VMapManager2(); VMapManager2();
~VMapManager2() override; ~VMapManager2() override;
void InitializeThreadUnsafe(const std::vector<uint32>& mapIds);
int loadMap(const char* pBasePath, unsigned int mapId, int x, int y) override; int loadMap(const char* pBasePath, unsigned int mapId, int x, int y) override;
void unloadMap(unsigned int mapId, int x, int y) override; void unloadMap(unsigned int mapId, int x, int y) override;
@@ -113,12 +129,14 @@ namespace VMAP
return getMapFileName(mapId); return getMapFileName(mapId);
} }
bool existsMap(const char* basePath, unsigned int mapId, int x, int y) override; bool existsMap(const char* basePath, unsigned int mapId, int x, int y) override;
public:
void getInstanceMapTree(InstanceTreeMap& instanceMapTree); void getInstanceMapTree(InstanceTreeMap& instanceMapTree);
typedef uint32(*GetLiquidFlagsFn)(uint32 liquidType); typedef uint32(*GetLiquidFlagsFn)(uint32 liquidType);
GetLiquidFlagsFn GetLiquidFlagsPtr; GetLiquidFlagsFn GetLiquidFlagsPtr;
typedef bool(*IsVMAPDisabledForFn)(uint32 entry, uint8 flags);
IsVMAPDisabledForFn IsVMAPDisabledForPtr;
}; };
} }
#endif #endif
+53
View File
@@ -0,0 +1,53 @@
/*
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3
* Copyright (C) 2008+ TrinityCore <http://www.trinitycore.org/>
*/
#ifndef _MAPDEFINES_H
#define _MAPDEFINES_H
#include "Define.h"
#include "DetourNavMesh.h"
#define MAX_NUMBER_OF_GRIDS 64
#define SIZE_OF_GRIDS 533.3333f
#define MMAP_MAGIC 0x4d4d4150 // 'MMAP'
#define MMAP_VERSION 11
struct MmapTileHeader
{
uint32 mmapMagic{MMAP_MAGIC};
uint32 dtVersion;
uint32 mmapVersion{MMAP_VERSION};
uint32 size{0};
char usesLiquids{true};
char padding[3]{};
MmapTileHeader() : dtVersion(DT_NAVMESH_VERSION) { }
};
// All padding fields must be handled and initialized to ensure mmaps_generator will produce binary-identical *.mmtile files
static_assert(sizeof(MmapTileHeader) == 20, "MmapTileHeader size is not correct, adjust the padding field size");
static_assert(sizeof(MmapTileHeader) == (sizeof(MmapTileHeader::mmapMagic) +
sizeof(MmapTileHeader::dtVersion) +
sizeof(MmapTileHeader::mmapVersion) +
sizeof(MmapTileHeader::size) +
sizeof(MmapTileHeader::usesLiquids) +
sizeof(MmapTileHeader::padding)), "MmapTileHeader has uninitialized padding fields");
enum NavTerrain
{
NAV_EMPTY = 0x00,
NAV_GROUND = 0x01,
NAV_MAGMA = 0x02,
NAV_SLIME = 0x04,
NAV_WATER = 0x08,
NAV_UNUSED1 = 0x10,
NAV_UNUSED2 = 0x20,
NAV_UNUSED3 = 0x40,
NAV_UNUSED4 = 0x80
// we only have 8 bits
};
#endif
+6
View File
@@ -462,4 +462,10 @@ namespace VMAP
} }
iLoadedTiles.erase(tile); iLoadedTiles.erase(tile);
} }
void StaticMapTree::getModelInstances(ModelInstance*& models, uint32& count)
{
models = iTreeValues;
count = iNTreeValues;
}
} }
+1 -1
View File
@@ -8,7 +8,7 @@
#include "MapTree.h" #include "MapTree.h"
#include "BoundingIntervalHierarchy.h" #include "BoundingIntervalHierarchy.h"
#include "VMapDefinitions.h" #include "VMapDefinitions.h"
#include "SharedDefines.h" #include "MapDefines.h"
#include <set> #include <set>
#include <sstream> #include <sstream>
#include <iomanip> #include <iomanip>
+26 -39
View File
@@ -4,19 +4,13 @@
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*/ */
#include "GameObjectModel.h"
#include "VMapFactory.h" #include "VMapFactory.h"
#include "VMapManager2.h" #include "VMapManager2.h"
#include "VMapDefinitions.h" #include "VMapDefinitions.h"
#include "WorldModel.h" #include "WorldModel.h"
#include "GameObjectModel.h"
#include "Log.h" #include "Log.h"
#include "GameObject.h" #include "Timer.h"
#include "Creature.h"
#include "TemporarySummon.h"
#include "Object.h"
#include "DBCStores.h"
#include "World.h"
using G3D::Vector3; using G3D::Vector3;
using G3D::Ray; using G3D::Ray;
@@ -35,16 +29,14 @@ struct GameobjectModelData
typedef std::unordered_map<uint32, GameobjectModelData> ModelList; typedef std::unordered_map<uint32, GameobjectModelData> ModelList;
ModelList model_list; ModelList model_list;
void LoadGameObjectModelList() void LoadGameObjectModelList(std::string const& dataPath)
{ {
//#ifndef NO_CORE_FUNCS
uint32 oldMSTime = getMSTime(); uint32 oldMSTime = getMSTime();
//#endif
FILE* model_list_file = fopen((sWorld->GetDataPath() + "vmaps/" + VMAP::GAMEOBJECT_MODELS).c_str(), "rb"); FILE* model_list_file = fopen((dataPath + "vmaps/" + VMAP::GAMEOBJECT_MODELS).c_str(), "rb");
if (!model_list_file) if (!model_list_file)
{ {
LOG_ERROR("server", "Unable to open '%s' file.", VMAP::GAMEOBJECT_MODELS); LOG_ERROR("maps", "Unable to open '%s' file.", VMAP::GAMEOBJECT_MODELS);
return; return;
} }
@@ -72,7 +64,8 @@ void LoadGameObjectModelList()
|| fread(&v1, sizeof(Vector3), 1, model_list_file) != 1 || fread(&v1, sizeof(Vector3), 1, model_list_file) != 1
|| fread(&v2, sizeof(Vector3), 1, model_list_file) != 1) || fread(&v2, sizeof(Vector3), 1, model_list_file) != 1)
{ {
LOG_ERROR("server", "File '%s' seems to be corrupted!", VMAP::GAMEOBJECT_MODELS); LOG_ERROR("maps", "File '%s' seems to be corrupted!", VMAP::GAMEOBJECT_MODELS);
fclose(model_list_file);
break; break;
} }
@@ -95,12 +88,12 @@ void LoadGameObjectModelList()
GameObjectModel::~GameObjectModel() GameObjectModel::~GameObjectModel()
{ {
if (iModel) if (iModel)
((VMAP::VMapManager2*)VMAP::VMapFactory::createOrGetVMapManager())->releaseModelInstance(name); VMAP::VMapFactory::createOrGetVMapManager()->releaseModelInstance(name);
} }
bool GameObjectModel::initialize(const GameObject& go, const GameObjectDisplayInfoEntry& info) bool GameObjectModel::initialize(std::unique_ptr<GameObjectModelOwnerBase> modelOwner, std::string const& dataPath)
{ {
ModelList::const_iterator it = model_list.find(info.Displayid); ModelList::const_iterator it = model_list.find(modelOwner->GetDisplayId());
if (it == model_list.end()) if (it == model_list.end())
return false; return false;
@@ -112,24 +105,18 @@ bool GameObjectModel::initialize(const GameObject& go, const GameObjectDisplayIn
return false; return false;
} }
iModel = ((VMAP::VMapManager2*)VMAP::VMapFactory::createOrGetVMapManager())->acquireModelInstance(sWorld->GetDataPath() + "vmaps/", it->second.name); iModel = VMAP::VMapFactory::createOrGetVMapManager()->acquireModelInstance(dataPath + "vmaps/", it->second.name);
if (!iModel) if (!iModel)
return false; return false;
name = it->second.name; name = it->second.name;
//flags = VMAP::MOD_M2; iPos = modelOwner->GetPosition();
//adtId = 0; phasemask = modelOwner->GetPhaseMask();
//ID = 0; iScale = modelOwner->GetScale();
iPos = Vector3(go.GetPositionX(), go.GetPositionY(), go.GetPositionZ());
// pussywizard:
phasemask = (go.GetGoState() == GO_STATE_READY || go.IsTransport()) ? go.GetPhaseMask() : 0;
iScale = go.GetFloatValue(OBJECT_FIELD_SCALE_X);
iInvScale = 1.f / iScale; iInvScale = 1.f / iScale;
G3D::Matrix3 iRotation = G3D::Matrix3::fromEulerAnglesZYX(go.GetOrientation(), 0, 0); G3D::Matrix3 iRotation = G3D::Matrix3::fromEulerAnglesZYX(modelOwner->GetOrientation(), 0, 0);
iInvRot = iRotation.inverse(); iInvRot = iRotation.inverse();
// transform bounding box: // transform bounding box:
mdl_box = AABox(mdl_box.low() * iScale, mdl_box.high() * iScale); mdl_box = AABox(mdl_box.low() * iScale, mdl_box.high() * iScale);
@@ -138,27 +125,24 @@ bool GameObjectModel::initialize(const GameObject& go, const GameObjectDisplayIn
rotated_bounds.merge(iRotation * mdl_box.corner(i)); rotated_bounds.merge(iRotation * mdl_box.corner(i));
iBound = rotated_bounds + iPos; iBound = rotated_bounds + iPos;
#ifdef SPAWN_CORNERS #ifdef SPAWN_CORNERS
// test: // test:
for (int i = 0; i < 8; ++i) for (int i = 0; i < 8; ++i)
{ {
Vector3 pos(iBound.corner(i)); Vector3 pos(iBound.corner(i));
const_cast<GameObject&>(go).SummonCreature(1, pos.x, pos.y, pos.z, 0, TEMPSUMMON_MANUAL_DESPAWN); modelOwner->DebugVisualizeCorner(pos);
} }
#endif #endif
owner = &go; owner = std::move(modelOwner);
return true; return true;
} }
GameObjectModel* GameObjectModel::Create(const GameObject& go) GameObjectModel* GameObjectModel::Create(std::unique_ptr<GameObjectModelOwnerBase> modelOwner, std::string const& dataPath)
{ {
const GameObjectDisplayInfoEntry* info = sGameObjectDisplayInfoStore.LookupEntry(go.GetDisplayId());
if (!info)
return nullptr;
GameObjectModel* mdl = new GameObjectModel(); GameObjectModel* mdl = new GameObjectModel();
if (!mdl->initialize(go, *info)) if (!mdl->initialize(std::move(modelOwner), dataPath))
{ {
delete mdl; delete mdl;
return nullptr; return nullptr;
@@ -169,7 +153,7 @@ GameObjectModel* GameObjectModel::Create(const GameObject& go)
bool GameObjectModel::intersectRay(const G3D::Ray& ray, float& MaxDist, bool StopAtFirstHit, uint32 ph_mask) const bool GameObjectModel::intersectRay(const G3D::Ray& ray, float& MaxDist, bool StopAtFirstHit, uint32 ph_mask) const
{ {
if (!(phasemask & ph_mask) || !owner->isSpawned()) if (!(phasemask & ph_mask) || !owner->IsSpawned())
return false; return false;
float time = ray.intersectionTime(iBound); float time = ray.intersectionTime(iBound);
@@ -199,6 +183,7 @@ bool GameObjectModel::UpdatePosition()
return false; return false;
G3D::AABox mdl_box(it->second.bound); G3D::AABox mdl_box(it->second.bound);
// ignore models with no bounds // ignore models with no bounds
if (mdl_box == G3D::AABox::zero()) if (mdl_box == G3D::AABox::zero())
{ {
@@ -206,12 +191,14 @@ bool GameObjectModel::UpdatePosition()
return false; return false;
} }
iPos = Vector3(owner->GetPositionX(), owner->GetPositionY(), owner->GetPositionZ()); iPos = owner->GetPosition();
G3D::Matrix3 iRotation = G3D::Matrix3::fromEulerAnglesZYX(owner->GetOrientation(), 0, 0); G3D::Matrix3 iRotation = G3D::Matrix3::fromEulerAnglesZYX(owner->GetOrientation(), 0, 0);
iInvRot = iRotation.inverse(); iInvRot = iRotation.inverse();
// transform bounding box: // transform bounding box:
mdl_box = AABox(mdl_box.low() * iScale, mdl_box.high() * iScale); mdl_box = AABox(mdl_box.low() * iScale, mdl_box.high() * iScale);
AABox rotated_bounds; AABox rotated_bounds;
for (int i = 0; i < 8; ++i) for (int i = 0; i < 8; ++i)
rotated_bounds.merge(iRotation * mdl_box.corner(i)); rotated_bounds.merge(iRotation * mdl_box.corner(i));
@@ -221,7 +208,7 @@ bool GameObjectModel::UpdatePosition()
for (int i = 0; i < 8; ++i) for (int i = 0; i < 8; ++i)
{ {
Vector3 pos(iBound.corner(i)); Vector3 pos(iBound.corner(i));
owner->SummonCreature(1, pos.x, pos.y, pos.z, 0.0f, TEMPSUMMON_TIMED_DESPAWN, 10000); owner->DebugVisualizeCorner(pos);
} }
#endif #endif
+37 -21
View File
@@ -7,13 +7,12 @@
#ifndef _GAMEOBJECT_MODEL_H #ifndef _GAMEOBJECT_MODEL_H
#define _GAMEOBJECT_MODEL_H #define _GAMEOBJECT_MODEL_H
#include "Define.h"
#include <G3D/Matrix3.h> #include <G3D/Matrix3.h>
#include <G3D/Vector3.h> #include <G3D/Vector3.h>
#include <G3D/AABox.h> #include <G3D/AABox.h>
#include <G3D/Ray.h> #include <G3D/Ray.h>
#include "Define.h"
namespace VMAP namespace VMAP
{ {
class WorldModel; class WorldModel;
@@ -22,20 +21,23 @@ namespace VMAP
class GameObject; class GameObject;
struct GameObjectDisplayInfoEntry; struct GameObjectDisplayInfoEntry;
class GameObjectModel /*, public Intersectable*/ class GameObjectModelOwnerBase
{ {
uint32 phasemask{0}; public:
G3D::AABox iBound; virtual ~GameObjectModelOwnerBase() = default;
G3D::Matrix3 iInvRot;
G3D::Vector3 iPos;
//G3D::Vector3 iRot;
float iInvScale{0};
float iScale{0};
VMAP::WorldModel* iModel;
GameObject const* owner;
GameObjectModel() : iModel(nullptr), owner(nullptr) { } virtual bool IsSpawned() const = 0;
bool initialize(const GameObject& go, const GameObjectDisplayInfoEntry& info); virtual uint32 GetDisplayId() const = 0;
virtual uint32 GetPhaseMask() const = 0;
virtual G3D::Vector3 GetPosition() const = 0;
virtual float GetOrientation() const = 0;
virtual float GetScale() const = 0;
virtual void DebugVisualizeCorner(G3D::Vector3 const& /*corner*/) const = 0;
};
class GameObjectModel
{
GameObjectModel() : phasemask(0), iInvScale(0), iScale(0), iModel(nullptr) { }
public: public:
std::string name; std::string name;
@@ -44,19 +46,33 @@ public:
~GameObjectModel(); ~GameObjectModel();
[[nodiscard]] const G3D::Vector3& getPosition() const { return iPos;} [[nodiscard]] const G3D::Vector3& getPosition() const { return iPos; }
/** Enables\disables collision. */ /** Enables\disables collision. */
void disable() { phasemask = 0;} void disable() { phasemask = 0; }
void enable(uint32 ph_mask) { phasemask = ph_mask;} void enable(uint32 ph_mask) { phasemask = ph_mask; }
[[nodiscard]] bool isEnabled() const {return phasemask != 0;} [[nodiscard]] bool isEnabled() const { return phasemask != 0; }
bool intersectRay(const G3D::Ray& Ray, float& MaxDist, bool StopAtFirstHit, uint32 ph_mask) const; bool intersectRay(const G3D::Ray& Ray, float& MaxDist, bool StopAtFirstHit, uint32 ph_mask) const;
static GameObjectModel* Create(const GameObject& go); static GameObjectModel* Create(std::unique_ptr<GameObjectModelOwnerBase> modelOwner, std::string const& dataPath);
bool UpdatePosition(); bool UpdatePosition();
private:
bool initialize(std::unique_ptr<GameObjectModelOwnerBase> modelOwner, std::string const& dataPath);
uint32 phasemask;
G3D::AABox iBound;
G3D::Matrix3 iInvRot;
G3D::Vector3 iPos;
float iInvScale;
float iScale;
VMAP::WorldModel* iModel;
std::unique_ptr<GameObjectModelOwnerBase> owner;
}; };
#endif // _GAMEOBJECT_MODEL_H void LoadGameObjectModelList(std::string const& dataPath);
#endif // _GAMEOBJECT_MODEL_H
+2 -4
View File
@@ -7,13 +7,12 @@
#ifndef _MODELINSTANCE_H_ #ifndef _MODELINSTANCE_H_
#define _MODELINSTANCE_H_ #define _MODELINSTANCE_H_
#include "Define.h"
#include <G3D/Matrix3.h> #include <G3D/Matrix3.h>
#include <G3D/Vector3.h> #include <G3D/Vector3.h>
#include <G3D/AABox.h> #include <G3D/AABox.h>
#include <G3D/Ray.h> #include <G3D/Ray.h>
#include "Define.h"
namespace VMAP namespace VMAP
{ {
class WorldModel; class WorldModel;
@@ -58,12 +57,11 @@ namespace VMAP
void intersectPoint(const G3D::Vector3& p, AreaInfo& info) const; void intersectPoint(const G3D::Vector3& p, AreaInfo& info) const;
bool GetLocationInfo(const G3D::Vector3& p, LocationInfo& info) const; bool GetLocationInfo(const G3D::Vector3& p, LocationInfo& info) const;
bool GetLiquidLevel(const G3D::Vector3& p, LocationInfo& info, float& liqHeight) const; bool GetLiquidLevel(const G3D::Vector3& p, LocationInfo& info, float& liqHeight) const;
WorldModel* getWorldModel() { return iModel; }
protected: protected:
G3D::Matrix3 iInvRot; G3D::Matrix3 iInvRot;
float iInvScale{0.0f}; float iInvScale{0.0f};
WorldModel* iModel{nullptr}; WorldModel* iModel{nullptr};
public:
WorldModel* getWorldModel();
}; };
} // namespace VMAP } // namespace VMAP
@@ -241,6 +241,13 @@ namespace VMAP
return result; return result;
} }
void WmoLiquid::getPosInfo(uint32& tilesX, uint32& tilesY, G3D::Vector3& corner) const
{
tilesX = iTilesX;
tilesY = iTilesY;
corner = iCorner;
}
// ===================== GroupModel ================================== // ===================== GroupModel ==================================
GroupModel::GroupModel(const GroupModel& other): GroupModel::GroupModel(const GroupModel& other):
@@ -401,6 +408,13 @@ namespace VMAP
return 0; return 0;
} }
void GroupModel::getMeshData(std::vector<G3D::Vector3>& outVertices, std::vector<MeshTriangle>& outTriangles, WmoLiquid*& liquid)
{
outVertices = vertices;
outTriangles = triangles;
liquid = iLiquid;
}
// ===================== WorldModel ================================== // ===================== WorldModel ==================================
void WorldModel::setGroupModels(std::vector<GroupModel>& models) void WorldModel::setGroupModels(std::vector<GroupModel>& models)
@@ -575,4 +589,9 @@ namespace VMAP
fclose(rf); fclose(rf);
return result; return result;
} }
void WorldModel::getGroupModels(std::vector<GroupModel>& outGroupModels)
{
outGroupModels = groupModels;
}
} }
+5 -9
View File
@@ -7,13 +7,12 @@
#ifndef _WORLDMODEL_H #ifndef _WORLDMODEL_H
#define _WORLDMODEL_H #define _WORLDMODEL_H
#include "Define.h"
#include "BoundingIntervalHierarchy.h"
#include <G3D/HashTrait.h> #include <G3D/HashTrait.h>
#include <G3D/Vector3.h> #include <G3D/Vector3.h>
#include <G3D/AABox.h> #include <G3D/AABox.h>
#include <G3D/Ray.h> #include <G3D/Ray.h>
#include "BoundingIntervalHierarchy.h"
#include "Define.h"
namespace VMAP namespace VMAP
{ {
@@ -46,6 +45,7 @@ namespace VMAP
uint32 GetFileSize(); uint32 GetFileSize();
bool writeToFile(FILE* wf); bool writeToFile(FILE* wf);
static bool readFromFile(FILE* rf, WmoLiquid*& liquid); static bool readFromFile(FILE* rf, WmoLiquid*& liquid);
void getPosInfo(uint32& tilesX, uint32& tilesY, G3D::Vector3& corner) const;
private: private:
WmoLiquid() { } WmoLiquid() { }
uint32 iTilesX{0}; //!< number of tiles in x direction, each uint32 iTilesX{0}; //!< number of tiles in x direction, each
@@ -54,8 +54,6 @@ namespace VMAP
uint32 iType{0}; //!< liquid type uint32 iType{0}; //!< liquid type
float* iHeight{nullptr}; //!< (tilesX + 1)*(tilesY + 1) height values float* iHeight{nullptr}; //!< (tilesX + 1)*(tilesY + 1) height values
uint8* iFlags{nullptr}; //!< info if liquid tile is used uint8* iFlags{nullptr}; //!< info if liquid tile is used
public:
void getPosInfo(uint32& tilesX, uint32& tilesY, G3D::Vector3& corner) const;
}; };
/*! holding additional info for WMO group files */ /*! holding additional info for WMO group files */
@@ -80,6 +78,7 @@ namespace VMAP
[[nodiscard]] const G3D::AABox& GetBound() const { return iBound; } [[nodiscard]] const G3D::AABox& GetBound() const { return iBound; }
[[nodiscard]] uint32 GetMogpFlags() const { return iMogpFlags; } [[nodiscard]] uint32 GetMogpFlags() const { return iMogpFlags; }
[[nodiscard]] uint32 GetWmoID() const { return iGroupWMOID; } [[nodiscard]] uint32 GetWmoID() const { return iGroupWMOID; }
void getMeshData(std::vector<G3D::Vector3>& outVertices, std::vector<MeshTriangle>& outTriangles, WmoLiquid*& liquid);
protected: protected:
G3D::AABox iBound; G3D::AABox iBound;
uint32 iMogpFlags{0};// 0x8 outdor; 0x2000 indoor uint32 iMogpFlags{0};// 0x8 outdor; 0x2000 indoor
@@ -88,8 +87,6 @@ namespace VMAP
std::vector<MeshTriangle> triangles; std::vector<MeshTriangle> triangles;
BIH meshTree; BIH meshTree;
WmoLiquid* iLiquid{nullptr}; WmoLiquid* iLiquid{nullptr};
public:
void getMeshData(std::vector<G3D::Vector3>& vertices, std::vector<MeshTriangle>& triangles, WmoLiquid*& liquid);
}; };
/*! Holds a model (converted M2 or WMO) in its original coordinate space */ /*! Holds a model (converted M2 or WMO) in its original coordinate space */
class WorldModel class WorldModel
@@ -105,12 +102,11 @@ namespace VMAP
bool GetLocationInfo(const G3D::Vector3& p, const G3D::Vector3& down, float& dist, LocationInfo& info) const; bool GetLocationInfo(const G3D::Vector3& p, const G3D::Vector3& down, float& dist, LocationInfo& info) const;
bool writeFile(const std::string& filename); bool writeFile(const std::string& filename);
bool readFile(const std::string& filename); bool readFile(const std::string& filename);
void getGroupModels(std::vector<GroupModel>& outGroupModels);
protected: protected:
uint32 RootWMOID{0}; uint32 RootWMOID{0};
std::vector<GroupModel> groupModels; std::vector<GroupModel> groupModels;
BIH groupTree; BIH groupTree;
public:
void getGroupModels(std::vector<GroupModel>& groupModels);
}; };
} // namespace VMAP } // namespace VMAP
+1 -3
View File
@@ -7,11 +7,10 @@
#ifndef _VMAPTOOLS_H #ifndef _VMAPTOOLS_H
#define _VMAPTOOLS_H #define _VMAPTOOLS_H
#include "Define.h"
#include <G3D/CollisionDetection.h> #include <G3D/CollisionDetection.h>
#include <G3D/AABox.h> #include <G3D/AABox.h>
#include "NodeValueAccess.h"
/** /**
The Class is mainly taken from G3D/AABSPTree.h but modified to be able to use our internal data structure. The Class is mainly taken from G3D/AABSPTree.h but modified to be able to use our internal data structure.
This is an iterator that helps us analysing the BSP-Trees. This is an iterator that helps us analysing the BSP-Trees.
@@ -40,7 +39,6 @@ namespace VMAP
class MyCollisionDetection class MyCollisionDetection
{ {
private:
public: public:
static bool collisionLocationForMovingPointFixedAABox( static bool collisionLocationForMovingPointFixedAABox(
const G3D::Vector3& origin, const G3D::Vector3& origin,
@@ -2,7 +2,5 @@
#include "Common.h" #include "Common.h"
#include "Log.h" #include "Log.h"
#include "DatabaseWorker.h"
#include "SQLOperation.h"
#include "Errors.h" #include "Errors.h"
#include "TypeList.h" #include "TypeList.h"
+1 -2
View File
@@ -8,10 +8,9 @@
#include "Common.h" #include "Common.h"
#include "utf8.h" #include "utf8.h"
#include "Log.h" #include "Log.h"
#include "DatabaseWorker.h"
#include "SQLOperation.h"
#include "Errors.h" #include "Errors.h"
#include "TypeList.h" #include "TypeList.h"
#include <ace/Task.h>
#include "SFMT.h" #include "SFMT.h"
#include "Errors.h" // for ASSERT #include "Errors.h" // for ASSERT
#include <ace/TSS_T.h> #include <ace/TSS_T.h>
+23 -10
View File
@@ -5,16 +5,16 @@
*/ */
#include "DisableMgr.h" #include "DisableMgr.h"
#include "MMapFactory.h"
#include "ObjectMgr.h" #include "ObjectMgr.h"
#include "OutdoorPvP.h" #include "OutdoorPvP.h"
#include "Player.h" #include "Player.h"
#include "SpellInfo.h" #include "SpellInfo.h"
#include "SpellMgr.h" #include "SpellMgr.h"
#include "VMapManager2.h" #include "World.h"
namespace DisableMgr namespace DisableMgr
{ {
namespace namespace
{ {
struct DisableData struct DisableData
@@ -197,28 +197,28 @@ namespace DisableMgr
switch (mapEntry->map_type) switch (mapEntry->map_type)
{ {
case MAP_COMMON: case MAP_COMMON:
if (flags & VMAP_DISABLE_AREAFLAG) if (flags & VMAP::VMAP_DISABLE_AREAFLAG)
LOG_INFO("server", "Areaflag disabled for world map %u.", entry); LOG_INFO("server", "Areaflag disabled for world map %u.", entry);
if (flags & VMAP_DISABLE_LIQUIDSTATUS) if (flags & VMAP::VMAP_DISABLE_LIQUIDSTATUS)
LOG_INFO("server", "Liquid status disabled for world map %u.", entry); LOG_INFO("server", "Liquid status disabled for world map %u.", entry);
break; break;
case MAP_INSTANCE: case MAP_INSTANCE:
case MAP_RAID: case MAP_RAID:
if (flags & VMAP_DISABLE_HEIGHT) if (flags & VMAP::VMAP_DISABLE_HEIGHT)
LOG_INFO("server", "Height disabled for instance map %u.", entry); LOG_INFO("server", "Height disabled for instance map %u.", entry);
if (flags & VMAP_DISABLE_LOS) if (flags & VMAP::VMAP_DISABLE_LOS)
LOG_INFO("server", "LoS disabled for instance map %u.", entry); LOG_INFO("server", "LoS disabled for instance map %u.", entry);
break; break;
case MAP_BATTLEGROUND: case MAP_BATTLEGROUND:
if (flags & VMAP_DISABLE_HEIGHT) if (flags & VMAP::VMAP_DISABLE_HEIGHT)
LOG_INFO("server", "Height disabled for battleground map %u.", entry); LOG_INFO("server", "Height disabled for battleground map %u.", entry);
if (flags & VMAP_DISABLE_LOS) if (flags & VMAP::VMAP_DISABLE_LOS)
LOG_INFO("server", "LoS disabled for battleground map %u.", entry); LOG_INFO("server", "LoS disabled for battleground map %u.", entry);
break; break;
case MAP_ARENA: case MAP_ARENA:
if (flags & VMAP_DISABLE_HEIGHT) if (flags & VMAP::VMAP_DISABLE_HEIGHT)
LOG_INFO("server", "Height disabled for arena map %u.", entry); LOG_INFO("server", "Height disabled for arena map %u.", entry);
if (flags & VMAP_DISABLE_LOS) if (flags & VMAP::VMAP_DISABLE_LOS)
LOG_INFO("server", "LoS disabled for arena map %u.", entry); LOG_INFO("server", "LoS disabled for arena map %u.", entry);
break; break;
default: default:
@@ -360,4 +360,17 @@ namespace DisableMgr
return false; return false;
} }
bool IsVMAPDisabledFor(uint32 entry, uint8 flags)
{
return IsDisabledFor(DISABLE_TYPE_VMAP, entry, nullptr, flags);
}
bool IsPathfindingEnabled(const Map* map)
{
if (!map)
return false;
return !MMAP::MMapFactory::forbiddenMaps[map->GetId()] && (sWorld->getBoolConfig(CONFIG_ENABLE_MMAPS) ? true : map->IsBattlegroundOrArena());
}
} // Namespace } // Namespace
+4 -8
View File
@@ -8,6 +8,8 @@
#define ACORE_DISABLEMGR_H #define ACORE_DISABLEMGR_H
#include "Define.h" #include "Define.h"
#include "Map.h"
#include "VMapManager2.h"
class Unit; class Unit;
@@ -38,19 +40,13 @@ enum SpellDisableTypes
SPELL_DISABLE_LOS) SPELL_DISABLE_LOS)
}; };
enum VmapDisableTypes
{
VMAP_DISABLE_AREAFLAG = 0x1,
VMAP_DISABLE_HEIGHT = 0x2,
VMAP_DISABLE_LOS = 0x4,
VMAP_DISABLE_LIQUIDSTATUS = 0x8,
};
namespace DisableMgr namespace DisableMgr
{ {
void LoadDisables(); void LoadDisables();
bool IsDisabledFor(DisableType type, uint32 entry, Unit const* unit, uint8 flags = 0); bool IsDisabledFor(DisableType type, uint32 entry, Unit const* unit, uint8 flags = 0);
void CheckQuestDisables(); void CheckQuestDisables();
bool IsVMAPDisabledFor(uint32 entry, uint8 flags);
bool IsPathfindingEnabled(const Map* map);
} }
#endif //ACORE_DISABLEMGR_H #endif //ACORE_DISABLEMGR_H
@@ -21,8 +21,8 @@ struct FormationInfo
float follow_dist; float follow_dist;
float follow_angle; float follow_angle;
uint8 groupAI; uint8 groupAI;
uint16 point_1; uint32 point_1;
uint16 point_2; uint32 point_2;
}; };
typedef std::unordered_map<ObjectGuid::LowType/*memberDBGUID*/, FormationInfo*> CreatureGroupInfoType; typedef std::unordered_map<ObjectGuid::LowType/*memberDBGUID*/, FormationInfo*> CreatureGroupInfoType;
@@ -311,7 +311,7 @@ bool GameObject::Create(ObjectGuid::LowType guidlow, uint32 name_id, Map* map, u
SetDisplayId(goinfo->displayId); SetDisplayId(goinfo->displayId);
if (!m_model) if (!m_model)
m_model = GameObjectModel::Create(*this); m_model = CreateModel();
switch (goinfo->type) switch (goinfo->type)
{ {
@@ -1961,7 +1961,7 @@ bool GameObject::IsInRange(float x, float y, float z, float radius) const
if (G3D::fuzzyEq(dist, 0.0f)) if (G3D::fuzzyEq(dist, 0.0f))
return true; return true;
float scale = GetFloatValue(OBJECT_FIELD_SCALE_X); float scale = GetObjectScale();
float sinB = dx / dist; float sinB = dx / dist;
float cosB = dy / dist; float cosB = dy / dist;
dx = dist * (cosA * cosB + sinA * sinB); dx = dist * (cosA * cosB + sinA * sinB);
@@ -2298,7 +2298,7 @@ void GameObject::UpdateModel()
if (GetMap()->ContainsGameObjectModel(*m_model)) if (GetMap()->ContainsGameObjectModel(*m_model))
GetMap()->RemoveGameObjectModel(*m_model); GetMap()->RemoveGameObjectModel(*m_model);
delete m_model; delete m_model;
m_model = GameObjectModel::Create(*this); m_model = CreateModel();
if (m_model) if (m_model)
GetMap()->InsertGameObjectModel(*m_model); GetMap()->InsertGameObjectModel(*m_model);
} }
@@ -2517,4 +2517,26 @@ void GameObject::UpdateModelPosition()
} }
} }
std::unordered_map<int, goEventFlag> GameObject::gameObjectToEventFlag = {}; std::unordered_map<int, goEventFlag> GameObject::gameObjectToEventFlag = { };
class GameObjectModelOwnerImpl : public GameObjectModelOwnerBase
{
public:
explicit GameObjectModelOwnerImpl(GameObject* owner) : _owner(owner) { }
bool IsSpawned() const override { return _owner->isSpawned(); }
uint32 GetDisplayId() const override { return _owner->GetDisplayId(); }
uint32 GetPhaseMask() const override { return (_owner->GetGoState() == GO_STATE_READY || _owner->IsTransport()) ? _owner->GetPhaseMask() : 0; }
G3D::Vector3 GetPosition() const override { return G3D::Vector3(_owner->GetPositionX(), _owner->GetPositionY(), _owner->GetPositionZ()); }
float GetOrientation() const override { return _owner->GetOrientation(); }
float GetScale() const override { return _owner->GetObjectScale(); }
void DebugVisualizeCorner(G3D::Vector3 const& corner) const override { const_cast<GameObject*>(_owner)->SummonCreature(1, corner.x, corner.y, corner.z, 0.0f, TEMPSUMMON_TIMED_DESPAWN, 10000); }
private:
GameObject* _owner;
};
GameObjectModel* GameObject::CreateModel()
{
return GameObjectModel::Create(std::make_unique<GameObjectModelOwnerImpl>(this), sWorld->GetDataPath());
}
@@ -953,6 +953,7 @@ public:
protected: protected:
bool AIM_Initialize(); bool AIM_Initialize();
GameObjectModel* CreateModel();
void UpdateModel(); // updates model in case displayId were changed void UpdateModel(); // updates model in case displayId were changed
uint32 m_spellId; uint32 m_spellId;
time_t m_respawnTime; // (secs) time of next respawn (or despawn if GO have owner()), time_t m_respawnTime; // (secs) time of next respawn (or despawn if GO have owner()),
@@ -91,7 +91,7 @@ bool MotionTransport::CreateMoTrans(ObjectGuid::LowType guidlow, uint32 entry, u
// pussywizard: no PathRotation for MotionTransports // pussywizard: no PathRotation for MotionTransports
SetTransportPathRotation(0.0f, 0.0f, 0.0f, 1.0f); SetTransportPathRotation(0.0f, 0.0f, 0.0f, 1.0f);
m_model = GameObjectModel::Create(*this); m_model = CreateModel();
return true; return true;
} }
@@ -722,7 +722,7 @@ bool StaticTransport::Create(ObjectGuid::LowType guidlow, uint32 name_id, Map* m
SetDisplayId(goinfo->displayId); SetDisplayId(goinfo->displayId);
if (!m_model) if (!m_model)
m_model = GameObjectModel::Create(*this); m_model = CreateModel();
SetGoType(GameobjectTypes(goinfo->type)); SetGoType(GameobjectTypes(goinfo->type));
SetGoState(go_state); SetGoState(go_state);
+2 -1
View File
@@ -16,6 +16,7 @@
#include "CreatureAI.h" #include "CreatureAI.h"
#include "CreatureAIImpl.h" #include "CreatureAIImpl.h"
#include "CreatureGroups.h" #include "CreatureGroups.h"
#include "DisableMgr.h"
#include "DynamicVisibility.h" #include "DynamicVisibility.h"
#include "Formulas.h" #include "Formulas.h"
#include "GridNotifiersImpl.h" #include "GridNotifiersImpl.h"
@@ -19518,7 +19519,7 @@ void Unit::PetSpellFail(const SpellInfo* spellInfo, Unit* target, uint32 result)
if (!charmInfo || GetTypeId() != TYPEID_UNIT) if (!charmInfo || GetTypeId() != TYPEID_UNIT)
return; return;
if ((MMAP::MMapFactory::IsPathfindingEnabled(GetMap()) || result != SPELL_FAILED_LINE_OF_SIGHT) && target) if ((DisableMgr::IsPathfindingEnabled(GetMap()) || result != SPELL_FAILED_LINE_OF_SIGHT) && target)
{ {
if ((result == SPELL_FAILED_LINE_OF_SIGHT || result == SPELL_FAILED_OUT_OF_RANGE) || !ToCreature()->HasReactState(REACT_PASSIVE)) if ((result == SPELL_FAILED_LINE_OF_SIGHT || result == SPELL_FAILED_OUT_OF_RANGE) || !ToCreature()->HasReactState(REACT_PASSIVE))
if (Unit* owner = GetOwner()) if (Unit* owner = GetOwner())
+2 -4
View File
@@ -9,6 +9,7 @@
#include "Common.h" #include "Common.h"
#include "NGrid.h" #include "NGrid.h"
#include "MapDefines.h"
#include <cmath> #include <cmath>
// Forward class definitions // Forward class definitions
@@ -22,10 +23,7 @@ class ObjectGuid;
#define MAX_NUMBER_OF_CELLS 8 #define MAX_NUMBER_OF_CELLS 8
#define MAX_NUMBER_OF_GRIDS 64 #define CENTER_GRID_ID (MAX_NUMBER_OF_GRIDS/2)
#define SIZE_OF_GRIDS 533.3333f
#define CENTER_GRID_ID (MAX_NUMBER_OF_GRIDS/2)
#define CENTER_GRID_OFFSET (SIZE_OF_GRIDS/2) #define CENTER_GRID_OFFSET (SIZE_OF_GRIDS/2)
+2 -1
View File
@@ -7,6 +7,7 @@
#include "Chat.h" #include "Chat.h"
#include "Common.h" #include "Common.h"
#include "CreatureAI.h" #include "CreatureAI.h"
#include "DisableMgr.h"
#include "Group.h" #include "Group.h"
#include "Log.h" #include "Log.h"
#include "ObjectAccessor.h" #include "ObjectAccessor.h"
@@ -559,7 +560,7 @@ void WorldSession::HandlePetActionHelper(Unit* pet, ObjectGuid guid1, uint16 spe
return; return;
// Not let attack through obstructions // Not let attack through obstructions
bool checkLos = !MMAP::MMapFactory::IsPathfindingEnabled(pet->GetMap()) || bool checkLos = !DisableMgr::IsPathfindingEnabled(pet->GetMap()) ||
(TargetUnit->GetTypeId() == TYPEID_UNIT && (TargetUnit->ToCreature()->isWorldBoss() || TargetUnit->ToCreature()->IsDungeonBoss())); (TargetUnit->GetTypeId() == TYPEID_UNIT && (TargetUnit->ToCreature()->isWorldBoss() || TargetUnit->ToCreature()->IsDungeonBoss()));
if (checkLos && !pet->IsWithinLOSInMap(TargetUnit)) if (checkLos && !pet->IsWithinLOSInMap(TargetUnit))
+4 -2
View File
@@ -7,6 +7,7 @@
#include "Battleground.h" #include "Battleground.h"
#include "CellImpl.h" #include "CellImpl.h"
#include "Chat.h" #include "Chat.h"
#include "DisableMgr.h"
#include "DynamicTree.h" #include "DynamicTree.h"
#include "Geometry.h" #include "Geometry.h"
#include "GridNotifiers.h" #include "GridNotifiers.h"
@@ -24,6 +25,7 @@
#include "Transport.h" #include "Transport.h"
#include "Vehicle.h" #include "Vehicle.h"
#include "VMapFactory.h" #include "VMapFactory.h"
#include "VMapManager2.h"
#ifdef ELUNA #ifdef ELUNA
#include "LuaEngine.h" #include "LuaEngine.h"
@@ -111,7 +113,7 @@ bool Map::ExistVMap(uint32 mapid, int gx, int gy)
void Map::LoadMMap(int gx, int gy) void Map::LoadMMap(int gx, int gy)
{ {
if (!MMAP::MMapFactory::IsPathfindingEnabled(this)) // pussywizard if (!DisableMgr::IsPathfindingEnabled(this)) // pussywizard
return; return;
int mmapLoadResult = MMAP::MMapFactory::createOrGetMMapManager()->loadMap(GetId(), gx, gy); int mmapLoadResult = MMAP::MMapFactory::createOrGetMMapManager()->loadMap(GetId(), gx, gy);
@@ -138,7 +140,7 @@ void Map::LoadMMap(int gx, int gy)
void Map::LoadVMap(int gx, int gy) void Map::LoadVMap(int gx, int gy)
{ {
// x and y are swapped !! // x and y are swapped !!
int vmapLoadResult = VMAP::VMapFactory::createOrGetVMapManager()->loadMap((sWorld->GetDataPath() + "vmaps").c_str(), GetId(), gx, gy); int vmapLoadResult = VMAP::VMapFactory::createOrGetVMapManager()->loadMap((sWorld->GetDataPath() + "vmaps").c_str(), GetId(), gx, gy);
switch (vmapLoadResult) switch (vmapLoadResult)
{ {
case VMAP::VMAP_LOAD_RESULT_OK: case VMAP::VMAP_LOAD_RESULT_OK:
@@ -4,9 +4,10 @@
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*/ */
#include "HomeMovementGenerator.h"
#include "Creature.h" #include "Creature.h"
#include "CreatureAI.h" #include "CreatureAI.h"
#include "HomeMovementGenerator.h" #include "DisableMgr.h"
#include "MoveSpline.h" #include "MoveSpline.h"
#include "MoveSplineInit.h" #include "MoveSplineInit.h"
#include "WorldPacket.h" #include "WorldPacket.h"
@@ -55,7 +56,7 @@ void HomeMovementGenerator<Creature>::_setTargetLocation(Creature* owner)
} }
owner->UpdateAllowedPositionZ(x, y, z); owner->UpdateAllowedPositionZ(x, y, z);
init.MoveTo(x, y, z, MMAP::MMapFactory::IsPathfindingEnabled(owner->FindMap()), true); init.MoveTo(x, y, z, DisableMgr::IsPathfindingEnabled(owner->FindMap()), true);
init.SetWalk(false); init.SetWalk(false);
init.Launch(); init.Launch();
@@ -24,7 +24,7 @@ PathGenerator::PathGenerator(WorldObject const* owner) :
memset(_pathPolyRefs, 0, sizeof(_pathPolyRefs)); memset(_pathPolyRefs, 0, sizeof(_pathPolyRefs));
uint32 mapId = _source->GetMapId(); uint32 mapId = _source->GetMapId();
//if (MMAP::MMapFactory::IsPathfindingEnabled(_sourceUnit->FindMap())) //if (DisableMgr::IsPathfindingEnabled(_sourceUnit->FindMap()))
{ {
MMAP::MMapManager* mmap = MMAP::MMapFactory::createOrGetMMapManager(); MMAP::MMapManager* mmap = MMAP::MMapFactory::createOrGetMMapManager();
_navMesh = mmap->GetNavMesh(mapId); _navMesh = mmap->GetNavMesh(mapId);
@@ -9,6 +9,7 @@
#include "DetourNavMesh.h" #include "DetourNavMesh.h"
#include "DetourNavMeshQuery.h" #include "DetourNavMeshQuery.h"
#include "MapDefines.h"
#include "MMapFactory.h" #include "MMapFactory.h"
#include "MMapManager.h" #include "MMapManager.h"
#include "MoveSplineInitArgs.h" #include "MoveSplineInitArgs.h"
@@ -2339,7 +2339,7 @@ void AuraEffect::HandleAuraModScale(AuraApplication const* aurApp, uint8 mode, b
Unit* target = aurApp->GetTarget(); Unit* target = aurApp->GetTarget();
float scale = target->GetFloatValue(OBJECT_FIELD_SCALE_X); float scale = target->GetObjectScale();
ApplyPercentModFloatVar(scale, float(GetAmount()), apply); ApplyPercentModFloatVar(scale, float(GetAmount()), apply);
target->SetObjectScale(scale); target->SetObjectScale(scale);
} }
@@ -2359,7 +2359,6 @@ void AuraEffect::HandleAuraCloneCaster(AuraApplication const* aurApp, uint8 mode
// What must be cloned? at least display and scale // What must be cloned? at least display and scale
target->SetDisplayId(caster->GetDisplayId()); target->SetDisplayId(caster->GetDisplayId());
//target->SetObjectScale(caster->GetFloatValue(OBJECT_FIELD_SCALE_X)); // we need retail info about how scaling is handled (aura maybe?)
target->SetFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_MIRROR_IMAGE); target->SetFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_MIRROR_IMAGE);
} }
else else
+1 -7
View File
@@ -5678,7 +5678,7 @@ SpellCastResult Spell::CheckCast(bool strict)
return SPELL_FAILED_BAD_TARGETS; return SPELL_FAILED_BAD_TARGETS;
// Xinef: Pass only explicit unit target spells // Xinef: Pass only explicit unit target spells
// pussywizard: // pussywizard:
if (MMAP::MMapFactory::IsPathfindingEnabled(m_caster->FindMap()) && m_spellInfo->NeedsExplicitUnitTarget()) if (DisableMgr::IsPathfindingEnabled(m_caster->FindMap()) && m_spellInfo->NeedsExplicitUnitTarget())
{ {
Unit* target = m_targets.GetUnitTarget(); Unit* target = m_targets.GetUnitTarget();
if (!target) if (!target)
@@ -7337,12 +7337,6 @@ bool Spell::CheckEffectTarget(Unit const* target, uint32 eff) const
return false; return false;
} }
break; break;
/*case SPELL_EFFECT_CHARGE:
if (MMAP::MMapFactory::IsPathfindingEnabled(m_caster->FindMap()))
break;
[[fallthrough]];
*/
case SPELL_EFFECT_SUMMON_RAF_FRIEND: case SPELL_EFFECT_SUMMON_RAF_FRIEND:
if (m_caster->GetTypeId() != TYPEID_PLAYER || target->GetTypeId() != TYPEID_PLAYER) if (m_caster->GetTypeId() != TYPEID_PLAYER || target->GetTypeId() != TYPEID_PLAYER)
return false; return false;
+13 -7
View File
@@ -1415,8 +1415,6 @@ void World::LoadConfigSettings(bool reload)
sScriptMgr->OnAfterConfigLoad(reload); sScriptMgr->OnAfterConfigLoad(reload);
} }
extern void LoadGameObjectModelList();
/// Initialize the World /// Initialize the World
void World::SetInitialWorldSettings() void World::SetInitialWorldSettings()
{ {
@@ -1433,10 +1431,9 @@ void World::SetInitialWorldSettings()
sScriptMgr->Initialize(); sScriptMgr->Initialize();
///- Initialize VMapManager function pointers (to untangle game/collision circular deps) ///- Initialize VMapManager function pointers (to untangle game/collision circular deps)
if (VMAP::VMapManager2* vmmgr2 = dynamic_cast<VMAP::VMapManager2*>(VMAP::VMapFactory::createOrGetVMapManager())) VMAP::VMapManager2* vmmgr2 = VMAP::VMapFactory::createOrGetVMapManager();
{ vmmgr2->GetLiquidFlagsPtr = &GetLiquidFlags;
vmmgr2->GetLiquidFlagsPtr = &GetLiquidFlags; vmmgr2->IsVMAPDisabledForPtr = &DisableMgr::IsVMAPDisabledFor;
}
///- Initialize config settings ///- Initialize config settings
LoadConfigSettings(); LoadConfigSettings();
@@ -1498,6 +1495,15 @@ void World::SetInitialWorldSettings()
LoadDBCStores(m_dataPath); LoadDBCStores(m_dataPath);
DetectDBCLang(); DetectDBCLang();
std::vector<uint32> mapIds;
for (auto const& map : sMapStore)
mapIds.emplace_back(map->MapID);
vmmgr2->InitializeThreadUnsafe(mapIds);
MMAP::MMapManager* mmmgr = MMAP::MMapFactory::createOrGetMMapManager();
mmmgr->InitializeThreadUnsafe(mapIds);
LOG_INFO("server", "Loading Game Graveyard..."); LOG_INFO("server", "Loading Game Graveyard...");
sGraveyard->LoadGraveyardFromDB(); sGraveyard->LoadGraveyardFromDB();
@@ -1520,7 +1526,7 @@ void World::SetInitialWorldSettings()
sSpellMgr->LoadSpellCustomAttr(); sSpellMgr->LoadSpellCustomAttr();
LOG_INFO("server", "Loading GameObject models..."); LOG_INFO("server", "Loading GameObject models...");
LoadGameObjectModelList(); LoadGameObjectModelList(m_dataPath);
LOG_INFO("server", "Loading Script Names..."); LOG_INFO("server", "Loading Script Names...");
sObjectMgr->LoadScriptNames(); sObjectMgr->LoadScriptNames();
-38
View File
@@ -3567,42 +3567,4 @@ enum PartyResult
ERR_PARTY_LFG_TELEPORT_IN_COMBAT = 30 ERR_PARTY_LFG_TELEPORT_IN_COMBAT = 30
}; };
#define MMAP_MAGIC 0x4d4d4150 // 'MMAP'
#define MMAP_VERSION 11
struct MmapTileHeader
{
uint32 mmapMagic{MMAP_MAGIC};
uint32 dtVersion;
uint32 mmapVersion{MMAP_VERSION};
uint32 size{0};
char usesLiquids{true};
char padding[3]{};
MmapTileHeader() : dtVersion(DT_NAVMESH_VERSION) { }
};
// All padding fields must be handled and initialized to ensure mmaps_generator will produce binary-identical *.mmtile files
static_assert(sizeof(MmapTileHeader) == 20, "MmapTileHeader size is not correct, adjust the padding field size");
static_assert(sizeof(MmapTileHeader) == (sizeof(MmapTileHeader::mmapMagic) +
sizeof(MmapTileHeader::dtVersion) +
sizeof(MmapTileHeader::mmapVersion) +
sizeof(MmapTileHeader::size) +
sizeof(MmapTileHeader::usesLiquids) +
sizeof(MmapTileHeader::padding)), "MmapTileHeader has uninitialized padding fields");
enum NavTerrain
{
NAV_EMPTY = 0x00,
NAV_GROUND = 0x01,
NAV_MAGMA = 0x02,
NAV_SLIME = 0x04,
NAV_WATER = 0x08,
NAV_UNUSED1 = 0x10,
NAV_UNUSED2 = 0x20,
NAV_UNUSED3 = 0x40,
NAV_UNUSED4 = 0x80
// we only have 8 bits
};
#endif #endif
+1 -3
View File
@@ -6,6 +6,7 @@
#ifndef UTILS_H #ifndef UTILS_H
#define UTILS_H #define UTILS_H
#include <cstdio> #include <cstdio>
#include <string> #include <string>
#include <sstream> #include <sstream>
@@ -337,9 +338,6 @@ public:
virtual float Scale() const { return 1.0f; }; virtual float Scale() const { return 1.0f; };
}; };
#define MMAP_MAGIC 0x4d4d4150 // 'MMAP'
#define MMAP_VERSION 10
struct MmapTileHeader struct MmapTileHeader
{ {
uint32 mmapMagic; uint32 mmapMagic;
+1 -32
View File
@@ -5,45 +5,14 @@
*/ */
#include "MapBuilder.h" #include "MapBuilder.h"
#include "MapDefines.h"
#include "MapTree.h" #include "MapTree.h"
#include "ModelInstance.h" #include "ModelInstance.h"
#include "PathCommon.h" #include "PathCommon.h"
#include <DetourCommon.h> #include <DetourCommon.h>
#include <DetourNavMesh.h> #include <DetourNavMesh.h>
#include <DetourNavMeshBuilder.h> #include <DetourNavMeshBuilder.h>
#include "DisableMgr.h"
namespace DisableMgr
{
bool IsDisabledFor(DisableType /*type*/, uint32 /*entry*/, Unit const* /*unit*/, uint8 /*flags*/ /*= 0*/) { return false; }
}
#define MMAP_MAGIC 0x4d4d4150 // 'MMAP'
#define MMAP_VERSION 11
struct MmapTileHeader
{
uint32 mmapMagic{MMAP_MAGIC};
uint32 dtVersion;
uint32 mmapVersion{MMAP_VERSION};
uint32 size{0};
char usesLiquids{true};
char padding[3]{};
MmapTileHeader() : dtVersion(DT_NAVMESH_VERSION) {}
};
// All padding fields must be handled and initialized to ensure mmaps_generator will produce binary-identical *.mmtile files
static_assert(sizeof(MmapTileHeader) == 20, "MmapTileHeader size is not correct, adjust the padding field size");
static_assert(sizeof(MmapTileHeader) == (sizeof(MmapTileHeader::mmapMagic) +
sizeof(MmapTileHeader::dtVersion) +
sizeof(MmapTileHeader::mmapVersion) +
sizeof(MmapTileHeader::size) +
sizeof(MmapTileHeader::usesLiquids) +
sizeof(MmapTileHeader::padding)), "MmapTileHeader has uninitialized padding fields");
namespace MMAP namespace MMAP
{ {
MapBuilder::MapBuilder(float maxWalkableAngle, bool skipLiquid, MapBuilder::MapBuilder(float maxWalkableAngle, bool skipLiquid,
-14
View File
@@ -20,20 +20,6 @@
#include <errno.h> #include <errno.h>
#endif #endif
enum NavTerrain
{
NAV_EMPTY = 0x00,
NAV_GROUND = 0x01,
NAV_MAGMA = 0x02,
NAV_SLIME = 0x04,
NAV_WATER = 0x08,
NAV_UNUSED1 = 0x10,
NAV_UNUSED2 = 0x20,
NAV_UNUSED3 = 0x40,
NAV_UNUSED4 = 0x80
// we only have 8 bits
};
namespace MMAP namespace MMAP
{ {
inline bool matchWildcardFilter(const char* filter, const char* str) inline bool matchWildcardFilter(const char* filter, const char* str)
+1 -2
View File
@@ -5,10 +5,9 @@
*/ */
#include "TerrainBuilder.h" #include "TerrainBuilder.h"
#include "PathCommon.h" #include "PathCommon.h"
#include "MapBuilder.h" #include "MapBuilder.h"
#include "MapDefines.h"
#include "VMapManager2.h" #include "VMapManager2.h"
#include "MapTree.h" #include "MapTree.h"
#include "ModelInstance.h" #include "ModelInstance.h"
@@ -1,58 +0,0 @@
/*
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license: http://github.com/azerothcore/azerothcore-wotlk/LICENSE-GPL2
* Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*/
#include <vector>
#include "MapTree.h"
#include "VMapManager2.h"
#include "WorldModel.h"
#include "ModelInstance.h"
namespace VMAP
{
// Need direct access to encapsulated VMAP data, so we add functions for MMAP generator
// maybe add MapBuilder as friend to all of the below classes would be better?
// declared in src/common/vmap/MapTree.h
void StaticMapTree::getModelInstances(ModelInstance*& models, uint32& count)
{
models = iTreeValues;
count = iNTreeValues;
}
// declared in src/common/vmap/VMapManager2.h
void VMapManager2::getInstanceMapTree(InstanceTreeMap& instanceMapTree)
{
instanceMapTree = iInstanceMapTrees;
}
// declared in src/common/vmap/WorldModel.h
void WorldModel::getGroupModels(std::vector<GroupModel>& groupModels)
{
groupModels = this->groupModels;
}
// declared in src/common/vmap/WorldModel.h
void GroupModel::getMeshData(std::vector<G3D::Vector3>& vertices, std::vector<MeshTriangle>& triangles, WmoLiquid*& liquid)
{
vertices = this->vertices;
triangles = this->triangles;
liquid = iLiquid;
}
// declared in src/common/vmap/ModelInstance.h
WorldModel* ModelInstance::getWorldModel()
{
return iModel;
}
// declared in src/common/vmap/WorldModel.h
void WmoLiquid::getPosInfo(uint32& tilesX, uint32& tilesY, G3D::Vector3& corner) const
{
tilesX = iTilesX;
tilesY = iTilesY;
corner = iCorner;
}
}