mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-17 19:05:42 +00:00
refactor(Core/Tools): remove ACE from tools (#3351)
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user