diff --git a/README.rst b/README.rst index b8aeaf0..69d093a 100644 --- a/README.rst +++ b/README.rst @@ -55,6 +55,9 @@ drawplayers: draworigin: Draw origin indicator, `--draworigin` +geometry: + Limit area to specific geometry, `--geometry -800:-800+1600+1600` + Customization of colors.txt ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/TileGenerator.cpp b/TileGenerator.cpp index 9feabd6..77f8681 100644 --- a/TileGenerator.cpp +++ b/TileGenerator.cpp @@ -97,7 +97,11 @@ TileGenerator::TileGenerator(): m_xMin(0), m_xMax(0), m_zMin(0), - m_zMax(0) + m_zMax(0), + m_geomX(-50), + m_geomY(-50), + m_geomX2(50), + m_geomY2(50) { string colors_txt_data(reinterpret_cast(colors_txt), colors_txt_len); istringstream colors_stream(colors_txt_data); @@ -168,6 +172,38 @@ void TileGenerator::setDrawScale(bool drawScale) } } +void TileGenerator::setGeometry(int x, int y, int w, int h) +{ + if (x > 0) { + m_geomX = (x + 15) / 16; + } + else { + m_geomX = (x - 15) / 16; + } + if (y > 0) { + m_geomY = (y + 15) / 16; + } + else { + m_geomY = (y - 15) / 16; + } + + int x2 = x + w; + int y2 = y + h; + + if (x2 > 0) { + m_geomX2 = (x2 + 15) / 16; + } + else { + m_geomX2 = (x2 - 15) / 16; + } + if (y2 > 0) { + m_geomY2 = (y2 + 15) / 16; + } + else { + m_geomY2 = (y2 - 15) / 16; + } +} + void TileGenerator::parseColorsFile(const std::string &fileName) { ifstream in; @@ -248,6 +284,9 @@ void TileGenerator::loadBlocks() if(result == SQLITE_ROW) { sqlite3_int64 blocknum = sqlite3_column_int64(statement, 0); BlockPos pos = decodeBlockPos(blocknum); + if (pos.x < m_geomX || pos.x >= m_geomX2 || pos.z < m_geomY || pos.z >= m_geomY2) { + continue; + } if (pos.x < m_xMin) { m_xMin = pos.x; } diff --git a/TileGenerator.h b/TileGenerator.h index acd9dbb..a877eea 100644 --- a/TileGenerator.h +++ b/TileGenerator.h @@ -84,6 +84,7 @@ public: void setDrawOrigin(bool drawOrigin); void setDrawPlayers(bool drawPlayers); void setDrawScale(bool drawScale); + void setGeometry(int x, int y, int w, int h); void parseColorsFile(const std::string &fileName); void generate(const std::string &input, const std::string &output); @@ -123,6 +124,10 @@ private: int m_xMax; int m_zMin; int m_zMax; + int m_geomX; + int m_geomY; + int m_geomX2; + int m_geomY2; int m_mapWidth; int m_mapHeight; std::list > m_positions; diff --git a/mapper.cpp b/mapper.cpp index 70482ed..99b3b99 100644 --- a/mapper.cpp +++ b/mapper.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include "TileGenerator.h" using namespace std; @@ -28,6 +29,7 @@ void usage() --drawscale\n\ --drawplayers\n\ --draworigin\n\ + --geometry x:y+w+h\n\ Color format: '#000000'\n"; std::cout << usage_text; } @@ -46,6 +48,7 @@ int main(int argc, char *argv[]) {"draworigin", no_argument, 0, 'R'}, {"drawplayers", no_argument, 0, 'P'}, {"drawscale", no_argument, 0, 'S'}, + {"geometry", required_argument, 0, 'g'}, }; string input; @@ -96,6 +99,19 @@ int main(int argc, char *argv[]) case 'S': generator.setDrawScale(true); break; + case 'g': { + istringstream geometry; + geometry.str(optarg); + int x, y, w, h; + char c; + geometry >> x >> c >> y >> w >> h; + if (geometry.fail() || c != ':' || w < 1 || h < 1) { + usage(); + exit(-1); + } + generator.setGeometry(x, y, w, h); + } + break; default: abort(); }