mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-21 20:56:23 +00:00
refactor(Core/Tools): remove ACE from tools (#3351)
This commit is contained in:
@@ -23,8 +23,8 @@ namespace MMAP
|
||||
rcPolyMesh* polyMesh;
|
||||
rcPolyMeshDetail* polyMeshDetail;
|
||||
|
||||
IntermediateValues() : heightfield(NULL), compactHeightfield(NULL),
|
||||
contours(NULL), polyMesh(NULL), polyMeshDetail(NULL) {}
|
||||
IntermediateValues() : heightfield(nullptr), compactHeightfield(nullptr),
|
||||
contours(nullptr), polyMesh(nullptr), polyMeshDetail(nullptr) {}
|
||||
~IntermediateValues();
|
||||
|
||||
void writeIV(uint32 mapID, uint32 tileX, uint32 tileY);
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace MMAP
|
||||
MapBuilder::MapBuilder(float maxWalkableAngle, bool skipLiquid,
|
||||
bool skipContinents, bool skipJunkMaps, bool skipBattlegrounds,
|
||||
bool debugOutput, bool bigBaseUnit, const char* offMeshFilePath) :
|
||||
m_terrainBuilder (NULL),
|
||||
m_terrainBuilder (nullptr),
|
||||
m_debugOutput (debugOutput),
|
||||
m_offMeshFilePath (offMeshFilePath),
|
||||
m_skipContinents (skipContinents),
|
||||
@@ -58,7 +58,8 @@ namespace MMAP
|
||||
m_skipBattlegrounds (skipBattlegrounds),
|
||||
m_maxWalkableAngle (maxWalkableAngle),
|
||||
m_bigBaseUnit (bigBaseUnit),
|
||||
m_rcContext (NULL)
|
||||
m_rcContext (nullptr),
|
||||
_cancelationToken (false)
|
||||
{
|
||||
m_terrainBuilder = new TerrainBuilder(skipLiquid);
|
||||
|
||||
@@ -88,14 +89,14 @@ namespace MMAP
|
||||
void MapBuilder::discoverTiles()
|
||||
{
|
||||
std::vector<std::string> files;
|
||||
uint32 mapID, tileX, tileY, tileID, count = 0, fsize = 0;
|
||||
uint32 mapID, tileX, tileY, tileID, count = 0;
|
||||
char filter[12];
|
||||
|
||||
printf("Discovering maps... ");
|
||||
getDirContents(files, "maps");
|
||||
for (uint32 i = 0; i < files.size(); ++i)
|
||||
{
|
||||
mapID = uint32(atoi(files[i].substr(0, files[i].size() - 8).c_str()));
|
||||
mapID = uint32(atoi(files[i].substr(0,3).c_str()));
|
||||
if (std::find(m_tiles.begin(), m_tiles.end(), mapID) == m_tiles.end())
|
||||
{
|
||||
m_tiles.emplace_back(MapTiles(mapID, new std::set<uint32>));
|
||||
@@ -107,7 +108,7 @@ namespace MMAP
|
||||
getDirContents(files, "vmaps", "*.vmtree");
|
||||
for (uint32 i = 0; i < files.size(); ++i)
|
||||
{
|
||||
mapID = uint32(atoi(files[i].substr(0, files[i].size() - 7).c_str()));
|
||||
mapID = uint32(atoi(files[i].substr(0,3).c_str()));
|
||||
if (std::find(m_tiles.begin(), m_tiles.end(), mapID) == m_tiles.end())
|
||||
{
|
||||
m_tiles.emplace_back(MapTiles(mapID, new std::set<uint32>));
|
||||
@@ -128,10 +129,8 @@ namespace MMAP
|
||||
getDirContents(files, "vmaps", filter);
|
||||
for (uint32 i = 0; i < files.size(); ++i)
|
||||
{
|
||||
fsize = files[i].size();
|
||||
|
||||
tileY = uint32(atoi(files[i].substr(fsize - 12, 2).c_str()));
|
||||
tileX = uint32(atoi(files[i].substr(fsize - 9, 2).c_str()));
|
||||
tileX = uint32(atoi(files[i].substr(7,2).c_str()));
|
||||
tileY = uint32(atoi(files[i].substr(4,2).c_str()));
|
||||
tileID = StaticMapTree::packTileID(tileY, tileX);
|
||||
|
||||
tiles->insert(tileID);
|
||||
@@ -143,20 +142,36 @@ namespace MMAP
|
||||
getDirContents(files, "maps", filter);
|
||||
for (uint32 i = 0; i < files.size(); ++i)
|
||||
{
|
||||
fsize = files[i].size();
|
||||
|
||||
tileY = uint32(atoi(files[i].substr(fsize - 8, 2).c_str()));
|
||||
tileX = uint32(atoi(files[i].substr(fsize - 6, 2).c_str()));
|
||||
tileY = uint32(atoi(files[i].substr(3,2).c_str()));
|
||||
tileX = uint32(atoi(files[i].substr(5,2).c_str()));
|
||||
tileID = StaticMapTree::packTileID(tileX, tileY);
|
||||
|
||||
if (tiles->insert(tileID).second)
|
||||
count++;
|
||||
}
|
||||
|
||||
// make sure we process maps which don't have tiles
|
||||
if (tiles->empty())
|
||||
{
|
||||
// convert coord bounds to grid bounds
|
||||
uint32 minX, minY, maxX, maxY;
|
||||
getGridBounds(mapID, minX, minY, maxX, maxY);
|
||||
|
||||
// add all tiles within bounds to tile list.
|
||||
for (uint32 i = minX; i <= maxX; ++i)
|
||||
for (uint32 j = minY; j <= maxY; ++j)
|
||||
if (tiles->insert(StaticMapTree::packTileID(i, j)).second)
|
||||
count++;
|
||||
}
|
||||
}
|
||||
printf("found %u.\n\n", count);
|
||||
|
||||
// percentageDone - total tiles to process
|
||||
m_totalTiles = count;
|
||||
// Calculate tiles to process in total
|
||||
for (TileList::iterator it = m_tiles.begin(); it != m_tiles.end(); ++it)
|
||||
{
|
||||
if (!shouldSkipMap(it->m_mapId))
|
||||
m_totalTiles += it->m_tiles->size();
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
@@ -172,11 +187,14 @@ namespace MMAP
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
void MapBuilder::buildAllMaps(int threads)
|
||||
void MapBuilder::buildAllMaps(unsigned int threads)
|
||||
{
|
||||
std::vector<BuilderThread*> _threads;
|
||||
printf("Using %u threads to extract mmaps\n", threads);
|
||||
|
||||
BuilderThreadPool* pool = threads > 0 ? new BuilderThreadPool() : NULL;
|
||||
for (unsigned int i = 0; i < threads; ++i)
|
||||
{
|
||||
_workerThreads.push_back(std::thread(&MapBuilder::WorkerThread, this));
|
||||
}
|
||||
|
||||
m_tiles.sort([](MapTiles a, MapTiles b)
|
||||
{
|
||||
@@ -185,27 +203,29 @@ namespace MMAP
|
||||
|
||||
for (TileList::iterator it = m_tiles.begin(); it != m_tiles.end(); ++it)
|
||||
{
|
||||
uint32 mapID = it->m_mapId;
|
||||
if (!shouldSkipMap(mapID))
|
||||
uint32 mapId = it->m_mapId;
|
||||
if (!shouldSkipMap(mapId))
|
||||
{
|
||||
if (threads > 0)
|
||||
pool->Enqueue(new MapBuildRequest(mapID));
|
||||
_queue.Push(mapId);
|
||||
else
|
||||
buildMap(mapID);
|
||||
buildMap(mapId);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < threads; ++i)
|
||||
_threads.push_back(new BuilderThread(this, pool->Queue()));
|
||||
|
||||
// Free memory
|
||||
for (std::vector<BuilderThread*>::iterator _th = _threads.begin(); _th != _threads.end(); ++_th)
|
||||
while (!_queue.Empty())
|
||||
{
|
||||
(*_th)->wait();
|
||||
delete *_th;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
}
|
||||
|
||||
delete pool;
|
||||
_cancelationToken = true;
|
||||
|
||||
_queue.Cancel();
|
||||
|
||||
for (auto& thread : _workerThreads)
|
||||
{
|
||||
thread.join();
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
@@ -277,7 +297,7 @@ namespace MMAP
|
||||
return;
|
||||
}
|
||||
|
||||
dtNavMesh* navMesh = NULL;
|
||||
dtNavMesh* navMesh = nullptr;
|
||||
buildNavMesh(mapId, navMesh);
|
||||
if (!navMesh)
|
||||
{
|
||||
@@ -341,7 +361,7 @@ namespace MMAP
|
||||
/**************************************************************************/
|
||||
void MapBuilder::buildSingleTile(uint32 mapID, uint32 tileX, uint32 tileY)
|
||||
{
|
||||
dtNavMesh* navMesh = NULL;
|
||||
dtNavMesh* navMesh = nullptr;
|
||||
buildNavMesh(mapID, navMesh);
|
||||
if (!navMesh)
|
||||
{
|
||||
@@ -353,13 +373,24 @@ namespace MMAP
|
||||
dtFreeNavMesh(navMesh);
|
||||
}
|
||||
|
||||
void MapBuilder::WorkerThread()
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
uint32 mapId = 0;
|
||||
|
||||
_queue.WaitAndPop(mapId);
|
||||
|
||||
if (_cancelationToken)
|
||||
return;
|
||||
|
||||
buildMap(mapId);
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
void MapBuilder::buildMap(uint32 mapID)
|
||||
{
|
||||
#ifndef __APPLE__
|
||||
//printf("[Thread %u] Building map %03u:\n", uint32(ACE_Thread::self()), mapID);
|
||||
#endif
|
||||
|
||||
std::set<uint32>* tiles = getTileList(mapID);
|
||||
|
||||
// make sure we process maps which don't have tiles
|
||||
@@ -378,7 +409,7 @@ namespace MMAP
|
||||
if (!tiles->empty())
|
||||
{
|
||||
// build navMesh
|
||||
dtNavMesh* navMesh = NULL;
|
||||
dtNavMesh* navMesh = nullptr;
|
||||
buildNavMesh(mapID, navMesh);
|
||||
if (!navMesh)
|
||||
{
|
||||
@@ -485,7 +516,7 @@ namespace MMAP
|
||||
|
||||
// use Max because '32 - tileX' is negative for values over 32
|
||||
float bmin[3], bmax[3];
|
||||
getTileBounds(tileXMax, tileYMax, NULL, 0, bmin, bmax);
|
||||
getTileBounds(tileXMax, tileYMax, nullptr, 0, bmin, bmax);
|
||||
|
||||
/*** now create the navmesh ***/
|
||||
|
||||
@@ -683,11 +714,11 @@ namespace MMAP
|
||||
// we may want to keep them in the future for debug
|
||||
// but right now, we don't have the code to merge them
|
||||
rcFreeHeightField(tile.solid);
|
||||
tile.solid = NULL;
|
||||
tile.solid = nullptr;
|
||||
rcFreeCompactHeightfield(tile.chf);
|
||||
tile.chf = NULL;
|
||||
tile.chf = nullptr;
|
||||
rcFreeContourSet(tile.cset);
|
||||
tile.cset = NULL;
|
||||
tile.cset = nullptr;
|
||||
|
||||
pmmerge[nmerge] = tile.pmesh;
|
||||
dmmerge[nmerge] = tile.dmesh;
|
||||
@@ -764,7 +795,7 @@ namespace MMAP
|
||||
params.buildBvTree = true;
|
||||
|
||||
// will hold final navmesh
|
||||
unsigned char* navData = NULL;
|
||||
unsigned char* navData = nullptr;
|
||||
int navDataSize = 0;
|
||||
|
||||
do
|
||||
@@ -832,7 +863,7 @@ namespace MMAP
|
||||
char message[1024];
|
||||
sprintf(message, "[Map %03i] Failed to open %s for writing!\n", mapID, fileName);
|
||||
perror(message);
|
||||
navMesh->removeTile(tileRef, NULL, NULL);
|
||||
navMesh->removeTile(tileRef, nullptr, nullptr);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -849,7 +880,7 @@ namespace MMAP
|
||||
fclose(file);
|
||||
|
||||
// now that tile is written to disk, we can unload it
|
||||
navMesh->removeTile(tileRef, NULL, NULL);
|
||||
navMesh->removeTile(tileRef, nullptr, nullptr);
|
||||
}
|
||||
while (0);
|
||||
|
||||
|
||||
@@ -7,31 +7,27 @@
|
||||
#ifndef _MAP_BUILDER_H
|
||||
#define _MAP_BUILDER_H
|
||||
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <atomic>
|
||||
#include <map>
|
||||
#include <list>
|
||||
#include <thread>
|
||||
|
||||
#include "TerrainBuilder.h"
|
||||
#include "IntermediateValues.h"
|
||||
|
||||
#include "Recast.h"
|
||||
#include "DetourNavMesh.h"
|
||||
|
||||
#include <ace/Task.h>
|
||||
#include <ace/Activation_Queue.h>
|
||||
#include <ace/Method_Request.h>
|
||||
#include "PCQueue.h"
|
||||
|
||||
using namespace VMAP;
|
||||
|
||||
// G3D namespace typedefs conflicts with ACE typedefs
|
||||
|
||||
namespace MMAP
|
||||
{
|
||||
struct MapTiles
|
||||
{
|
||||
MapTiles() : m_mapId(uint32(-1)), m_tiles(NULL) {}
|
||||
MapTiles() : m_mapId(uint32(-1)), m_tiles(nullptr) {}
|
||||
|
||||
MapTiles(uint32 id, std::set<uint32>* tiles) : m_mapId(id), m_tiles(tiles) {}
|
||||
~MapTiles() {}
|
||||
@@ -49,7 +45,7 @@ namespace MMAP
|
||||
|
||||
struct Tile
|
||||
{
|
||||
Tile() : chf(NULL), solid(NULL), cset(NULL), pmesh(NULL), dmesh(NULL) {}
|
||||
Tile() : chf(nullptr), solid(nullptr), cset(nullptr), pmesh(nullptr), dmesh(nullptr) {}
|
||||
~Tile()
|
||||
{
|
||||
rcFreeCompactHeightfield(chf);
|
||||
@@ -75,7 +71,7 @@ namespace MMAP
|
||||
bool skipBattlegrounds = false,
|
||||
bool debugOutput = false,
|
||||
bool bigBaseUnit = false,
|
||||
const char* offMeshFilePath = NULL);
|
||||
const char* offMeshFilePath = nullptr);
|
||||
|
||||
~MapBuilder();
|
||||
|
||||
@@ -87,7 +83,9 @@ namespace MMAP
|
||||
void buildSingleTile(uint32 mapID, uint32 tileX, uint32 tileY);
|
||||
|
||||
// builds list of maps, then builds all of mmap tiles (based on the skip settings)
|
||||
void buildAllMaps(int threads);
|
||||
void buildAllMaps(unsigned int threads);
|
||||
|
||||
void WorkerThread();
|
||||
|
||||
private:
|
||||
// detect maps and tiles
|
||||
@@ -131,68 +129,15 @@ namespace MMAP
|
||||
float m_maxWalkableAngle;
|
||||
bool m_bigBaseUnit;
|
||||
// percentageDone - variables to calculate percentage
|
||||
uint32 m_totalTiles;
|
||||
std::atomic<uint32> m_totalTiles;
|
||||
std::atomic<uint32> m_totalTilesBuilt;
|
||||
|
||||
// build performance - not really used for now
|
||||
rcContext* m_rcContext;
|
||||
};
|
||||
|
||||
class MapBuildRequest : public ACE_Method_Request
|
||||
{
|
||||
public:
|
||||
MapBuildRequest(uint32 mapId) : _mapId(mapId) {}
|
||||
|
||||
virtual int call()
|
||||
{
|
||||
/// @ Actually a creative way of unabstracting the class and returning a member variable
|
||||
return (int)_mapId;
|
||||
}
|
||||
|
||||
private:
|
||||
uint32 _mapId;
|
||||
};
|
||||
|
||||
class BuilderThread : public ACE_Task_Base
|
||||
{
|
||||
private:
|
||||
MapBuilder* _builder;
|
||||
ACE_Activation_Queue* _queue;
|
||||
|
||||
public:
|
||||
BuilderThread(MapBuilder* builder, ACE_Activation_Queue* queue) : _builder(builder), _queue(queue) { activate(); }
|
||||
|
||||
int svc()
|
||||
{
|
||||
/// @ Set a timeout for dequeue attempts (only used when the queue is empty) as it will never get populated after thread starts
|
||||
ACE_Time_Value timeout(5);
|
||||
ACE_Method_Request* request = NULL;
|
||||
while ((request = _queue->dequeue(&timeout)) != NULL)
|
||||
{
|
||||
_builder->buildMap(request->call());
|
||||
delete request;
|
||||
request = NULL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
class BuilderThreadPool
|
||||
{
|
||||
public:
|
||||
BuilderThreadPool() : _queue(new ACE_Activation_Queue()) {}
|
||||
~BuilderThreadPool() { _queue->queue()->close(); delete _queue; }
|
||||
|
||||
void Enqueue(MapBuildRequest* request)
|
||||
{
|
||||
_queue->enqueue(request);
|
||||
}
|
||||
|
||||
ACE_Activation_Queue* Queue() { return _queue; }
|
||||
|
||||
private:
|
||||
ACE_Activation_Queue* _queue;
|
||||
std::vector<std::thread> _workerThreads;
|
||||
ProducerConsumerQueue<uint32> _queue;
|
||||
std::atomic<bool> _cancelationToken;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -106,7 +106,7 @@ namespace MMAP
|
||||
while (dirp)
|
||||
{
|
||||
errno = 0;
|
||||
if ((dp = readdir(dirp)) != NULL)
|
||||
if ((dp = readdir(dirp)) != nullptr)
|
||||
{
|
||||
if (matchWildcardFilter(filter.c_str(), dp->d_name))
|
||||
fileList.push_back(std::string(dp->d_name));
|
||||
|
||||
@@ -61,9 +61,9 @@ bool handleArgs(int argc, char** argv,
|
||||
bool &bigBaseUnit,
|
||||
char* &offMeshInputPath,
|
||||
char* &file,
|
||||
int& threads)
|
||||
unsigned int& threads)
|
||||
{
|
||||
char* param = NULL;
|
||||
char* param = nullptr;
|
||||
for (int i = 1; i < argc; ++i)
|
||||
{
|
||||
if (strcmp(argv[i], "--maxAngle") == 0)
|
||||
@@ -83,8 +83,7 @@ bool handleArgs(int argc, char** argv,
|
||||
param = argv[++i];
|
||||
if (!param)
|
||||
return false;
|
||||
threads = atoi(param);
|
||||
printf("Using %i threads to extract mmaps\n", threads);
|
||||
threads = static_cast<unsigned int>(std::max(0, atoi(param)));
|
||||
}
|
||||
else if (strcmp(argv[i], "--file") == 0)
|
||||
{
|
||||
@@ -100,7 +99,7 @@ bool handleArgs(int argc, char** argv,
|
||||
return false;
|
||||
|
||||
char* stileX = strtok(param, ",");
|
||||
char* stileY = strtok(NULL, ",");
|
||||
char* stileY = strtok(nullptr, ",");
|
||||
int tilex = atoi(stileX);
|
||||
int tiley = atoi(stileY);
|
||||
|
||||
@@ -230,7 +229,8 @@ int finish(const char* message, int returnValue)
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int threads = 3, mapnum = -1;
|
||||
unsigned int threads = std::thread::hardware_concurrency();
|
||||
int mapnum = -1;
|
||||
float maxAngle = 70.0f;
|
||||
int tileX = -1, tileY = -1;
|
||||
bool skipLiquid = false,
|
||||
@@ -240,8 +240,8 @@ int main(int argc, char** argv)
|
||||
debugOutput = false,
|
||||
silent = false,
|
||||
bigBaseUnit = false;
|
||||
char* offMeshInputPath = NULL;
|
||||
char* file = NULL;
|
||||
char* offMeshInputPath = nullptr;
|
||||
char* file = nullptr;
|
||||
|
||||
bool validParam = handleArgs(argc, argv, mapnum,
|
||||
tileX, tileY, maxAngle,
|
||||
|
||||
@@ -270,7 +270,7 @@ namespace MMAP
|
||||
printf("TerrainBuilder::loadMap: Failed to read some data expected 1, read 0\n");
|
||||
|
||||
|
||||
float* liquid_map = NULL;
|
||||
float* liquid_map = nullptr;
|
||||
|
||||
if (!(lheader.flags & MAP_LIQUID_NO_TYPE))
|
||||
if (fread(liquid_type, sizeof(liquid_type), 1, mapFile) != 1)
|
||||
@@ -363,7 +363,7 @@ namespace MMAP
|
||||
|
||||
// make a copy of liquid vertices
|
||||
// used to pad right-bottom frame due to lost vertex data at extraction
|
||||
float* lverts_copy = NULL;
|
||||
float* lverts_copy = nullptr;
|
||||
if (meshData.liquidVerts.size())
|
||||
{
|
||||
lverts_copy = new float[meshData.liquidVerts.size()];
|
||||
@@ -636,7 +636,7 @@ namespace MMAP
|
||||
if (!instanceTrees[mapID])
|
||||
break;
|
||||
|
||||
ModelInstance* models = NULL;
|
||||
ModelInstance* models = nullptr;
|
||||
uint32 count = 0;
|
||||
instanceTrees[mapID]->getModelInstances(models, count);
|
||||
|
||||
@@ -673,7 +673,7 @@ namespace MMAP
|
||||
std::vector<G3D::Vector3> tempVertices;
|
||||
std::vector<G3D::Vector3> transformedVertices;
|
||||
std::vector<MeshTriangle> tempTriangles;
|
||||
WmoLiquid* liquid = NULL;
|
||||
WmoLiquid* liquid = nullptr;
|
||||
|
||||
it->getMeshData(tempVertices, tempTriangles, liquid);
|
||||
|
||||
@@ -884,7 +884,7 @@ namespace MMAP
|
||||
void TerrainBuilder::loadOffMeshConnections(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData, const char* offMeshFilePath)
|
||||
{
|
||||
// no meshfile input given?
|
||||
if (offMeshFilePath == NULL)
|
||||
if (offMeshFilePath == nullptr)
|
||||
return;
|
||||
|
||||
FILE* fp = fopen(offMeshFilePath, "rb");
|
||||
|
||||
Reference in New Issue
Block a user