Tools/MMapsGenerator: Get all tiles in beginning and calulate proper total tile count
This commit is contained in:
1 parent
153c3e79d9
commit
e3435b7471
4 files changed
+187
-25
No files matched your search
@@ -55,7 +55,7 @@ namespace MMAP
|
||||
{
|
||||
MapBuilder::MapBuilder(float maxWalkableAngle, bool skipLiquid,
|
||||
bool skipContinents, bool skipJunkMaps, bool skipBattlegrounds,
|
||||
bool debugOutput, bool bigBaseUnit, const char* offMeshFilePath) :
|
||||
bool debugOutput, bool bigBaseUnit, int mapid, char const* offMeshFilePath) :
|
||||
m_terrainBuilder (NULL),
|
||||
m_debugOutput (debugOutput),
|
||||
m_offMeshFilePath (offMeshFilePath),
|
||||
@@ -64,6 +64,7 @@ namespace MMAP
|
||||
m_skipBattlegrounds (skipBattlegrounds),
|
||||
m_maxWalkableAngle (maxWalkableAngle),
|
||||
m_bigBaseUnit (bigBaseUnit),
|
||||
m_mapid (mapid),
|
||||
m_totalTiles (0u),
|
||||
m_totalTilesProcessed(0u),
|
||||
m_rcContext (NULL),
|
||||
@@ -151,9 +152,29 @@ namespace MMAP
|
||||
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);
|
||||
|
||||
m_totalTiles.store(count, std::memory_order_relaxed);
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
@@ -372,26 +393,8 @@ namespace MMAP
|
||||
/**************************************************************************/
|
||||
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
|
||||
if (!tiles->size())
|
||||
{
|
||||
// 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)
|
||||
++m_totalTiles;
|
||||
}
|
||||
|
||||
if (!tiles->empty())
|
||||
{
|
||||
// build navMesh
|
||||
@@ -413,11 +416,10 @@ namespace MMAP
|
||||
// unpack tile coords
|
||||
StaticMapTree::unpackTileID((*it), tileX, tileY);
|
||||
|
||||
++m_totalTilesProcessed;
|
||||
if (shouldSkipTile(mapID, tileX, tileY))
|
||||
continue;
|
||||
if (!shouldSkipTile(mapID, tileX, tileY))
|
||||
buildTile(mapID, tileX, tileY, navMesh);
|
||||
|
||||
buildTile(mapID, tileX, tileY, navMesh);
|
||||
++m_totalTilesProcessed;
|
||||
}
|
||||
|
||||
dtFreeNavMesh(navMesh);
|
||||
@@ -905,6 +907,9 @@ namespace MMAP
|
||||
/**************************************************************************/
|
||||
bool MapBuilder::shouldSkipMap(uint32 mapID)
|
||||
{
|
||||
if (m_mapid >= 0)
|
||||
return static_cast<uint32>(m_mapid) != mapID;
|
||||
|
||||
if (m_skipContinents)
|
||||
switch (mapID)
|
||||
{
|
||||
|
||||
@@ -81,6 +81,7 @@ namespace MMAP
|
||||
bool skipBattlegrounds = false,
|
||||
bool debugOutput = false,
|
||||
bool bigBaseUnit = false,
|
||||
int mapid = -1,
|
||||
const char* offMeshFilePath = NULL);
|
||||
|
||||
~MapBuilder();
|
||||
@@ -139,6 +140,8 @@ namespace MMAP
|
||||
float m_maxWalkableAngle;
|
||||
bool m_bigBaseUnit;
|
||||
|
||||
int32 m_mapid;
|
||||
|
||||
std::atomic<uint32> m_totalTiles;
|
||||
std::atomic<uint32> m_totalTilesProcessed;
|
||||
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/>
|
||||
* Copyright (C) 2005-2011 MaNGOS <http://getmangos.com/>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _MAP_BUILDER_H
|
||||
#define _MAP_BUILDER_H
|
||||
|
||||
#include "TerrainBuilder.h"
|
||||
|
||||
#include "Recast.h"
|
||||
#include "DetourNavMesh.h"
|
||||
#include "ProducerConsumerQueue.h"
|
||||
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <list>
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
|
||||
using namespace VMAP;
|
||||
|
||||
namespace MMAP
|
||||
{
|
||||
struct MapTiles
|
||||
{
|
||||
MapTiles() : m_mapId(uint32(-1)), m_tiles(NULL) {}
|
||||
|
||||
MapTiles(uint32 id, std::set<uint32>* tiles) : m_mapId(id), m_tiles(tiles) {}
|
||||
~MapTiles() {}
|
||||
|
||||
uint32 m_mapId;
|
||||
std::set<uint32>* m_tiles;
|
||||
|
||||
bool operator==(uint32 id)
|
||||
{
|
||||
return m_mapId == id;
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::list<MapTiles> TileList;
|
||||
|
||||
struct Tile
|
||||
{
|
||||
Tile() : chf(NULL), solid(NULL), cset(NULL), pmesh(NULL), dmesh(NULL) {}
|
||||
~Tile()
|
||||
{
|
||||
rcFreeCompactHeightfield(chf);
|
||||
rcFreeContourSet(cset);
|
||||
rcFreeHeightField(solid);
|
||||
rcFreePolyMesh(pmesh);
|
||||
rcFreePolyMeshDetail(dmesh);
|
||||
}
|
||||
rcCompactHeightfield* chf;
|
||||
rcHeightfield* solid;
|
||||
rcContourSet* cset;
|
||||
rcPolyMesh* pmesh;
|
||||
rcPolyMeshDetail* dmesh;
|
||||
};
|
||||
|
||||
class MapBuilder
|
||||
{
|
||||
public:
|
||||
MapBuilder(float maxWalkableAngle = 70.f,
|
||||
bool skipLiquid = false,
|
||||
bool skipContinents = false,
|
||||
bool skipJunkMaps = true,
|
||||
bool skipBattlegrounds = false,
|
||||
bool debugOutput = false,
|
||||
bool bigBaseUnit = false,
|
||||
const char* offMeshFilePath = NULL);
|
||||
|
||||
~MapBuilder();
|
||||
|
||||
// builds all mmap tiles for the specified map id (ignores skip settings)
|
||||
void buildMap(uint32 mapID);
|
||||
void buildMeshFromFile(char* name);
|
||||
|
||||
// builds an mmap tile for the specified map and its mesh
|
||||
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 WorkerThread();
|
||||
|
||||
private:
|
||||
// detect maps and tiles
|
||||
void discoverTiles();
|
||||
std::set<uint32>* getTileList(uint32 mapID);
|
||||
|
||||
void buildNavMesh(uint32 mapID, dtNavMesh* &navMesh);
|
||||
|
||||
void buildTile(uint32 mapID, uint32 tileX, uint32 tileY, dtNavMesh* navMesh);
|
||||
|
||||
// move map building
|
||||
void buildMoveMapTile(uint32 mapID,
|
||||
uint32 tileX,
|
||||
uint32 tileY,
|
||||
MeshData &meshData,
|
||||
float bmin[3],
|
||||
float bmax[3],
|
||||
dtNavMesh* navMesh);
|
||||
|
||||
void getTileBounds(uint32 tileX, uint32 tileY,
|
||||
float* verts, int vertCount,
|
||||
float* bmin, float* bmax);
|
||||
void getGridBounds(uint32 mapID, uint32 &minX, uint32 &minY, uint32 &maxX, uint32 &maxY) const;
|
||||
|
||||
bool shouldSkipMap(uint32 mapID);
|
||||
bool isTransportMap(uint32 mapID);
|
||||
bool shouldSkipTile(uint32 mapID, uint32 tileX, uint32 tileY);
|
||||
|
||||
uint32 percentageDone(uint32 totalTiles, uint32 totalTilesDone);
|
||||
|
||||
TerrainBuilder* m_terrainBuilder;
|
||||
TileList m_tiles;
|
||||
|
||||
bool m_debugOutput;
|
||||
|
||||
const char* m_offMeshFilePath;
|
||||
bool m_skipContinents;
|
||||
bool m_skipJunkMaps;
|
||||
bool m_skipBattlegrounds;
|
||||
|
||||
float m_maxWalkableAngle;
|
||||
bool m_bigBaseUnit;
|
||||
|
||||
std::atomic<uint32> m_totalTiles;
|
||||
std::atomic<uint32> m_totalTilesProcessed;
|
||||
|
||||
// build performance - not really used for now
|
||||
rcContext* m_rcContext;
|
||||
|
||||
std::vector<std::thread> _workerThreads;
|
||||
ProducerConsumerQueue<uint32> _queue;
|
||||
std::atomic<bool> _cancelationToken;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -279,7 +279,7 @@ int main(int argc, char** argv)
|
||||
return silent ? -3 : finish("Press ENTER to close...", -3);
|
||||
|
||||
MapBuilder builder(maxAngle, skipLiquid, skipContinents, skipJunkMaps,
|
||||
skipBattlegrounds, debugOutput, bigBaseUnit, offMeshInputPath);
|
||||
skipBattlegrounds, debugOutput, bigBaseUnit, mapnum, offMeshInputPath);
|
||||
|
||||
uint32 start = getMSTime();
|
||||
if (file)
|
||||
|
||||
Reference in new issue
Block a user