aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSubv <s.v.h21@hotmail.com>2012-08-25 11:38:33 -0500
committerSubv <s.v.h21@hotmail.com>2012-08-25 11:38:33 -0500
commitf8cc38d65a3b8bca5f93f57e7f4cf7f93df2b38b (patch)
treec308ced3dca04ccdc1b999fbba30166357f7cbbe /src
parent9698d295b234bcbda3a52c9a47e57f66a98e5335 (diff)
Core/Mmaps: Make the mmaps_generator multithreaded, you can specify the max number of threads that are spawned at the same time (default 3) by using "--threads x" in the command line, where x is the number of threads you want.
Core/Mmaps: Removed now useless sh script
Diffstat (limited to 'src')
-rw-r--r--src/tools/mmaps_generator/MapBuilder.cpp74
-rw-r--r--src/tools/mmaps_generator/MapBuilder.h20
-rw-r--r--src/tools/mmaps_generator/PathGenerator.cpp17
3 files changed, 78 insertions, 33 deletions
diff --git a/src/tools/mmaps_generator/MapBuilder.cpp b/src/tools/mmaps_generator/MapBuilder.cpp
index e47b2e5b44f..a0c40bc4392 100644
--- a/src/tools/mmaps_generator/MapBuilder.cpp
+++ b/src/tools/mmaps_generator/MapBuilder.cpp
@@ -158,13 +158,31 @@ namespace MMAP
}
/**************************************************************************/
- void MapBuilder::buildAllMaps()
+ void MapBuilder::buildAllMaps(int threads)
{
+ int running = 0;
for (TileList::iterator it = m_tiles.begin(); it != m_tiles.end(); ++it)
{
uint32 mapID = (*it).first;
if (!shouldSkipMap(mapID))
- buildMap(mapID);
+ {
+ if (threads > 1)
+ {
+ BuilderThread* thread = new BuilderThread(this, mapID);
+ thread->activate();
+ ++running;
+ // Do not allow more than {threads} threads running at the same time
+ if (running == threads)
+ {
+ // Wait for previous threads to finish
+ ACE_Thread_Manager::instance()->wait();
+ // Reset the number of running threads
+ running = 0;
+ }
+ }
+ else
+ buildMap(mapID);
+ }
}
}
@@ -306,7 +324,7 @@ namespace MMAP
}
// now start building mmtiles for each tile
- printf("We have %u tiles. \n", (unsigned int)tiles->size());
+ printf("[Map %i] We have %u tiles. \n", mapID, (unsigned int)tiles->size());
for (set<uint32>::iterator it = tiles->begin(); it != tiles->end(); ++it)
{
uint32 tileX, tileY;
@@ -415,10 +433,10 @@ namespace MMAP
navMeshParams.maxPolys = maxPolysPerTile;
navMesh = dtAllocNavMesh();
- printf("Creating navMesh... \r");
+ printf("[Map %i] Creating navMesh...\n", mapID);
if (!navMesh->init(&navMeshParams))
{
- printf("Failed creating navmesh! \n");
+ printf("[Map %i] Failed creating navmesh! \n", mapID);
return;
}
@@ -430,7 +448,7 @@ namespace MMAP
{
dtFreeNavMesh(navMesh);
char message[1024];
- sprintf(message, "Failed to open %s for writing!\n", fileName);
+ sprintf(message, "[Map %i] Failed to open %s for writing!\n", mapID, fileName);
perror(message);
return;
}
@@ -446,9 +464,9 @@ namespace MMAP
dtNavMesh* navMesh)
{
// console output
- char tileString[10];
- sprintf(tileString, "[%02i,%02i]: ", tileX, tileY);
- printf("%s Building movemap tiles... \r", tileString);
+ char tileString[20];
+ sprintf(tileString, "[Map %03i] [%02i,%02i]: ", mapID, tileX, tileY);
+ printf("%s Building movemap tiles...\n", tileString);
IntermediateValues iv;
@@ -510,14 +528,14 @@ namespace MMAP
rcPolyMesh** pmmerge = new rcPolyMesh*[TILES_PER_MAP * TILES_PER_MAP];
if (!pmmerge)
{
- printf("%s alloc pmmerge FIALED! \r", tileString);
+ printf("%s alloc pmmerge FIALED!\n", tileString);
return;
}
rcPolyMeshDetail** dmmerge = new rcPolyMeshDetail*[TILES_PER_MAP * TILES_PER_MAP];
if (!dmmerge)
{
- printf("%s alloc dmmerge FIALED! \r", tileString);
+ printf("%s alloc dmmerge FIALED!\n", tileString);
return;
}
@@ -539,7 +557,7 @@ namespace MMAP
tile.solid = rcAllocHeightfield();
if (!tile.solid || !rcCreateHeightfield(m_rcContext, *tile.solid, tileCfg.width, tileCfg.height, tileCfg.bmin, tileCfg.bmax, tileCfg.cs, tileCfg.ch))
{
- printf("%sFailed building heightfield! \n", tileString);
+ printf("%s Failed building heightfield! \n", tileString);
continue;
}
@@ -560,33 +578,33 @@ namespace MMAP
tile.chf = rcAllocCompactHeightfield();
if (!tile.chf || !rcBuildCompactHeightfield(m_rcContext, tileCfg.walkableHeight, tileCfg.walkableClimb, *tile.solid, *tile.chf))
{
- printf("%sFailed compacting heightfield! \n", tileString);
+ printf("%s Failed compacting heightfield! \n", tileString);
continue;
}
// build polymesh intermediates
if (!rcErodeWalkableArea(m_rcContext, config.walkableRadius, *tile.chf))
{
- printf("%sFailed eroding area! \n", tileString);
+ printf("%s Failed eroding area! \n", tileString);
continue;
}
if (!rcBuildDistanceField(m_rcContext, *tile.chf))
{
- printf("%sFailed building distance field! \n", tileString);
+ printf("%s Failed building distance field! \n", tileString);
continue;
}
if (!rcBuildRegions(m_rcContext, *tile.chf, tileCfg.borderSize, tileCfg.minRegionArea, tileCfg.mergeRegionArea))
{
- printf("%sFailed building regions! \n", tileString);
+ printf("%s Failed building regions! \n", tileString);
continue;
}
tile.cset = rcAllocContourSet();
if (!tile.cset || !rcBuildContours(m_rcContext, *tile.chf, tileCfg.maxSimplificationError, tileCfg.maxEdgeLen, *tile.cset))
{
- printf("%sFailed building contours! \n", tileString);
+ printf("%s Failed building contours! \n", tileString);
continue;
}
@@ -594,14 +612,14 @@ namespace MMAP
tile.pmesh = rcAllocPolyMesh();
if (!tile.pmesh || !rcBuildPolyMesh(m_rcContext, *tile.cset, tileCfg.maxVertsPerPoly, *tile.pmesh))
{
- printf("%sFailed building polymesh! \n", tileString);
+ printf("%s Failed building polymesh! \n", tileString);
continue;
}
tile.dmesh = rcAllocPolyMeshDetail();
if (!tile.dmesh || !rcBuildPolyMeshDetail(m_rcContext, *tile.pmesh, *tile.chf, tileCfg.detailSampleDist, tileCfg .detailSampleMaxError, *tile.dmesh))
{
- printf("%sFailed building polymesh detail! \n", tileString);
+ printf("%s Failed building polymesh detail! \n", tileString);
continue;
}
@@ -627,7 +645,7 @@ namespace MMAP
iv.polyMesh = rcAllocPolyMesh();
if (!iv.polyMesh)
{
- printf("%s alloc iv.polyMesh FIALED! \r", tileString);
+ printf("%s alloc iv.polyMesh FIALED!\n", tileString);
return;
}
rcMergePolyMeshes(m_rcContext, pmmerge, nmerge, *iv.polyMesh);
@@ -635,16 +653,16 @@ namespace MMAP
iv.polyMeshDetail = rcAllocPolyMeshDetail();
if (!iv.polyMeshDetail)
{
- printf("%s alloc m_dmesh FIALED! \r", tileString);
+ printf("%s alloc m_dmesh FIALED!\n", tileString);
return;
}
rcMergePolyMeshDetails(m_rcContext, dmmerge, nmerge, *iv.polyMeshDetail);
// free things up
- delete [] pmmerge;
- delete [] dmmerge;
+ delete[] pmmerge;
+ delete[] dmmerge;
- delete [] tiles;
+ delete[] tiles;
// remove padding for extraction
for (int i = 0; i < iv.polyMesh->nverts; ++i)
@@ -736,7 +754,7 @@ namespace MMAP
continue;
}
- printf("%s Building navmesh tile... \r", tileString);
+ printf("%s Building navmesh tile...\n", tileString);
if (!dtCreateNavMeshData(&params, &navData, &navDataSize))
{
printf("%s Failed building navmesh tile! \n", tileString);
@@ -744,7 +762,7 @@ namespace MMAP
}
dtTileRef tileRef = 0;
- printf("%s Adding tile to navmesh... \r", tileString);
+ printf("%s Adding tile to navmesh...\n", tileString);
// DT_TILE_FREE_DATA tells detour to unallocate memory when the tile
// is removed via removeTile()
dtStatus dtResult = navMesh->addTile(navData, navDataSize, DT_TILE_FREE_DATA, 0, &tileRef);
@@ -761,13 +779,13 @@ namespace MMAP
if (!file)
{
char message[1024];
- sprintf(message, "Failed to open %s for writing!\n", fileName);
+ sprintf(message, "[Map %i] Failed to open %s for writing!\n", mapID, fileName);
perror(message);
navMesh->removeTile(tileRef, NULL, NULL);
continue;
}
- printf("%s Writing to file... \r", tileString);
+ printf("%s Writing to file...\n", tileString);
// write header
MmapTileHeader header;
diff --git a/src/tools/mmaps_generator/MapBuilder.h b/src/tools/mmaps_generator/MapBuilder.h
index 20789bf9bff..0c9dce05992 100644
--- a/src/tools/mmaps_generator/MapBuilder.h
+++ b/src/tools/mmaps_generator/MapBuilder.h
@@ -32,6 +32,8 @@
#include "Recast.h"
#include "DetourNavMesh.h"
+#include "ace/Task.h"
+
using namespace std;
using namespace VMAP;
@@ -80,7 +82,7 @@ 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();
+ void buildAllMaps(int threads);
private:
// detect maps and tiles
@@ -125,6 +127,22 @@ namespace MMAP
// build performance - not really used for now
rcContext* m_rcContext;
};
+
+ class BuilderThread : public ACE_Task<ACE_MT_SYNCH>
+ {
+ private:
+ MapBuilder* _builder;
+ uint32 _mapId;
+ public:
+ BuilderThread(MapBuilder* builder, uint32 mapId) : _builder(builder), _mapId(mapId) {}
+
+ int svc()
+ {
+ if (_builder)
+ _builder->buildMap(_mapId);
+ return 0;
+ }
+ };
}
#endif
diff --git a/src/tools/mmaps_generator/PathGenerator.cpp b/src/tools/mmaps_generator/PathGenerator.cpp
index 7d9f59ed138..45d0aff958c 100644
--- a/src/tools/mmaps_generator/PathGenerator.cpp
+++ b/src/tools/mmaps_generator/PathGenerator.cpp
@@ -71,7 +71,8 @@ bool handleArgs(int argc, char** argv,
bool &silent,
bool &bigBaseUnit,
char* &offMeshInputPath,
- char* &file)
+ char* &file,
+ int& threads)
{
char* param = NULL;
for (int i = 1; i < argc; ++i)
@@ -88,6 +89,14 @@ bool handleArgs(int argc, char** argv,
else
printf("invalid option for '--maxAngle', using default\n");
}
+ else if (strcmp(argv[i], "--threads") == 0)
+ {
+ param = argv[++i];
+ if (!param)
+ return false;
+ threads = atoi(param);
+ printf("Using %i threads to extract mmaps\n", threads);
+ }
else if (strcmp(argv[i], "--file") == 0)
{
param = argv[++i];
@@ -232,7 +241,7 @@ int finish(const char* message, int returnValue)
int main(int argc, char** argv)
{
- int mapnum = -1;
+ int threads = 3, mapnum = -1;
float maxAngle = 60.0f;
int tileX = -1, tileY = -1;
bool skipLiquid = false,
@@ -248,7 +257,7 @@ int main(int argc, char** argv)
bool validParam = handleArgs(argc, argv, mapnum,
tileX, tileY, maxAngle,
skipLiquid, skipContinents, skipJunkMaps, skipBattlegrounds,
- debugOutput, silent, bigBaseUnit, offMeshInputPath, file);
+ debugOutput, silent, bigBaseUnit, offMeshInputPath, file, threads);
if (!validParam)
return silent ? -1 : finish("You have specified invalid parameters", -1);
@@ -278,7 +287,7 @@ int main(int argc, char** argv)
else if (mapnum >= 0)
builder.buildMap(uint32(mapnum));
else
- builder.buildAllMaps();
+ builder.buildAllMaps(threads);
return silent ? 1 : finish("Movemap build is complete!", 1);
}