Add an option to print progress information while generating the map.

This commit is contained in:
Rogier 2014-04-10 00:55:50 +02:00
parent db2d27c077
commit c1f2df705b
3 changed files with 19 additions and 0 deletions

View File

@ -13,6 +13,7 @@
#include <fstream> #include <fstream>
#include <gdfontmb.h> #include <gdfontmb.h>
#include <iostream> #include <iostream>
#include <iomanip>
#include <sstream> #include <sstream>
#include <stdexcept> #include <stdexcept>
#include <cerrno> #include <cerrno>
@ -113,6 +114,7 @@ static inline Color mixColors(Color a, Color b)
TileGenerator::TileGenerator(): TileGenerator::TileGenerator():
verboseCoordinates(false), verboseCoordinates(false),
verboseStatistics(false), verboseStatistics(false),
progressIndicator(false),
m_bgColor(255, 255, 255), m_bgColor(255, 255, 255),
m_scaleColor(0, 0, 0), m_scaleColor(0, 0, 0),
m_originColor(255, 0, 0), m_originColor(255, 0, 0),
@ -254,6 +256,11 @@ void TileGenerator::setShading(bool shading)
m_shading = shading; m_shading = shading;
} }
void TileGenerator::enableProgressIndicator(void)
{
progressIndicator = true;
}
void TileGenerator::setGeometry(int x, int y, int w, int h) void TileGenerator::setGeometry(int x, int y, int w, int h)
{ {
if (x > 0) { if (x > 0) {
@ -665,6 +672,8 @@ void TileGenerator::renderMap()
area_rendered++; area_rendered++;
if (currentPos.z != pos.z && currentPos.z != INT_MIN && m_shading) if (currentPos.z != pos.z && currentPos.z != INT_MIN && m_shading)
renderShading(currentPos.z); renderShading(currentPos.z);
if (progressIndicator && currentPos.z != pos.z)
cout << "Processing Z-coordinate: " << std::setw(5) << pos.z*16 << "\r" << std::flush;
for (int i = 0; i < 16; ++i) { for (int i = 0; i < 16; ++i) {
m_readedPixels[i] = 0; m_readedPixels[i] = 0;
} }
@ -779,6 +788,8 @@ void TileGenerator::renderMap()
<< "/" << (m_xMax-m_xMin+1) * (m_zMax-m_zMin+1) << "/" << (m_xMax-m_xMin+1) * (m_zMax-m_zMin+1)
<< " (" << (long long)area_rendered*16*16 << " nodes)" << " (" << (long long)area_rendered*16*16 << " nodes)"
<< std::endl; << std::endl;
else if (progressIndicator)
cout << std::setw(40) << "" << "\r";
} }
inline void TileGenerator::renderMapBlock(const unsigned_string &mapBlock, const BlockPos &pos, int version) inline void TileGenerator::renderMapBlock(const unsigned_string &mapBlock, const BlockPos &pos, int version)

View File

@ -126,6 +126,7 @@ public:
void setTileBorderSize(int size); void setTileBorderSize(int size);
void setTileSize(int width, int heigth); void setTileSize(int width, int heigth);
void setTileOrigin(int x, int y); void setTileOrigin(int x, int y);
void enableProgressIndicator(void);
void parseColorsFile(const std::string &fileName); void parseColorsFile(const std::string &fileName);
void setBackend(std::string backend); void setBackend(std::string backend);
void generate(const std::string &input, const std::string &output); void generate(const std::string &input, const std::string &output);
@ -152,6 +153,7 @@ private:
public: public:
bool verboseCoordinates; bool verboseCoordinates;
bool verboseStatistics; bool verboseStatistics;
bool progressIndicator;
private: private:
Color m_bgColor; Color m_bgColor;

View File

@ -19,6 +19,7 @@
using namespace std; using namespace std;
#define OPT_SQLITE_CACHEWORLDROW 0x81 #define OPT_SQLITE_CACHEWORLDROW 0x81
#define OPT_PROGRESS_INDICATOR 0x82
void usage() void usage()
{ {
@ -44,6 +45,7 @@ void usage()
" --tiles <tilesize>[+<border>]\n" " --tiles <tilesize>[+<border>]\n"
" --tileorigin x:y|center-world|center-map\n" " --tileorigin x:y|center-world|center-map\n"
" --verbose\n" " --verbose\n"
" --progress\n"
"Color format: '#000000'\n"; "Color format: '#000000'\n";
std::cout << usage_text; std::cout << usage_text;
} }
@ -74,6 +76,7 @@ int main(int argc, char *argv[])
{"tileorigin", required_argument, 0, 'T'}, {"tileorigin", required_argument, 0, 'T'},
{"tilebordercolor", required_argument, 0, 'B'}, {"tilebordercolor", required_argument, 0, 'B'},
{"verbose", no_argument, 0, 'v'}, {"verbose", no_argument, 0, 'v'},
{"progress", no_argument, 0, OPT_PROGRESS_INDICATOR},
}; };
string input; string input;
@ -140,6 +143,9 @@ int main(int argc, char *argv[])
case OPT_SQLITE_CACHEWORLDROW: case OPT_SQLITE_CACHEWORLDROW:
generator.setSqliteCacheWorldRow(true); generator.setSqliteCacheWorldRow(true);
break; break;
case OPT_PROGRESS_INDICATOR:
generator.enableProgressIndicator();
break;
case 'a': { case 'a': {
istringstream iss; istringstream iss;
iss.str(optarg); iss.str(optarg);