Skip to content

Commit

Permalink
Tools/MMapsGenerator: Improve mmaps generation time on multi-core CPUs
Browse files Browse the repository at this point in the history
Queue biggest maps first for mmaps generation to avoid waiting for last map, usually map id 571.
Fix wrong maps count being printed on startup.
  • Loading branch information
jackpoz committed Jun 25, 2014
1 parent afd9315 commit ff25736
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
32 changes: 20 additions & 12 deletions src/tools/mmaps_generator/MapBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ namespace MMAP
{
for (TileList::iterator it = m_tiles.begin(); it != m_tiles.end(); ++it)
{
(*it).second->clear();
delete (*it).second;
(*it).m_tiles->clear();
delete (*it).m_tiles;
}

delete m_terrainBuilder;
Expand All @@ -97,9 +97,9 @@ namespace MMAP
for (uint32 i = 0; i < files.size(); ++i)
{
mapID = uint32(atoi(files[i].substr(0,3).c_str()));
if (m_tiles.find(mapID) == m_tiles.end())
if (std::find(m_tiles.begin(), m_tiles.end(), mapID) == m_tiles.end())
{
m_tiles.insert(std::pair<uint32, std::set<uint32>*>(mapID, new std::set<uint32>));
m_tiles.emplace_back(MapTiles(mapID, new std::set<uint32>));
count++;
}
}
Expand All @@ -109,17 +109,20 @@ namespace MMAP
for (uint32 i = 0; i < files.size(); ++i)
{
mapID = uint32(atoi(files[i].substr(0,3).c_str()));
m_tiles.insert(std::pair<uint32, std::set<uint32>*>(mapID, new std::set<uint32>));
count++;
if (std::find(m_tiles.begin(), m_tiles.end(), mapID) == m_tiles.end())
{
m_tiles.emplace_back(MapTiles(mapID, new std::set<uint32>));
count++;
}
}
printf("found %u.\n", count);

count = 0;
printf("Discovering tiles... ");
for (TileList::iterator itr = m_tiles.begin(); itr != m_tiles.end(); ++itr)
{
std::set<uint32>* tiles = (*itr).second;
mapID = (*itr).first;
std::set<uint32>* tiles = (*itr).m_tiles;
mapID = (*itr).m_mapId;

sprintf(filter, "%03u*.vmtile", mapID);
files.clear();
Expand Down Expand Up @@ -153,12 +156,12 @@ namespace MMAP
/**************************************************************************/
std::set<uint32>* MapBuilder::getTileList(uint32 mapID)
{
TileList::iterator itr = m_tiles.find(mapID);
TileList::iterator itr = std::find(m_tiles.begin(), m_tiles.end(), mapID);
if (itr != m_tiles.end())
return (*itr).second;
return (*itr).m_tiles;

std::set<uint32>* tiles = new std::set<uint32>();
m_tiles.insert(std::pair<uint32, std::set<uint32>*>(mapID, tiles));
m_tiles.emplace_back(MapTiles(mapID, tiles));
return tiles;
}

Expand All @@ -169,9 +172,14 @@ namespace MMAP

BuilderThreadPool* pool = threads > 0 ? new BuilderThreadPool() : NULL;

m_tiles.sort([](MapTiles a, MapTiles b)
{
return a.m_tiles->size() > b.m_tiles->size();
});

for (TileList::iterator it = m_tiles.begin(); it != m_tiles.end(); ++it)
{
uint32 mapID = it->first;
uint32 mapID = it->m_mapId;
if (!shouldSkipMap(mapID))
{
if (threads > 0)
Expand Down
20 changes: 19 additions & 1 deletion src/tools/mmaps_generator/MapBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <vector>
#include <set>
#include <map>
#include <list>

#include "TerrainBuilder.h"
#include "IntermediateValues.h"
Expand All @@ -39,7 +40,24 @@ using namespace VMAP;

namespace MMAP
{
typedef std::map<uint32, std::set<uint32>*> TileList;
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) {}
Expand Down

4 comments on commit ff25736

@soulfrost
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now it'll use all cpu cores ? :S

@HelloKitty
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@soulfrost Which would be the most ideal case.

@Killyana
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can choose: --threads [#] Max number of threads used by the generator Default: 3

@jackpoz
Copy link
Member Author

@jackpoz jackpoz commented on ff25736 Apr 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a 6 years old commit, so many more things changed after that, i.e. now all threads are used by default. Go check the whole commit history

Please sign in to comment.