From 15444ff8f65ed35a48cc31830b756e5e6f2c0abd Mon Sep 17 00:00:00 2001 From: Sfan5 Date: Wed, 5 Mar 2014 18:06:05 +0100 Subject: [PATCH] Add --min-y and --max-y options --- README.rst | 9 +++++++++ TileGenerator.cpp | 22 +++++++++++++++++++++- TileGenerator.h | 4 ++++ mapper.cpp | 24 +++++++++++++++++++++--- 4 files changed, 55 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index a5e3a57..dff4a4a 100644 --- a/README.rst +++ b/README.rst @@ -53,6 +53,15 @@ drawplayers: draworigin: Draw origin indicator, `--draworigin` +noshading: + Don't draw shading on nodes, `--noshading` + +min-y: + Don't draw nodes below this y value, `--min-y -25` + +max-y: + Don't draw nodes above this y value, `--max-y 75` + geometry: Limit area to specific geometry, `--geometry -800:-800+1600+1600` diff --git a/TileGenerator.cpp b/TileGenerator.cpp index 4617aea..ccf7559 100644 --- a/TileGenerator.cpp +++ b/TileGenerator.cpp @@ -102,6 +102,8 @@ TileGenerator::TileGenerator(): m_xMax(INT_MIN), m_zMin(INT_MAX), m_zMax(INT_MIN), + m_yMin(-30000), + m_yMax(30000), m_geomX(-50), m_geomY(-50), m_geomX2(50), @@ -213,6 +215,16 @@ void TileGenerator::setGeometry(int x, int y, int w, int h) } } +void TileGenerator::setMinY(int y) +{ + m_yMin = y; +} + +void TileGenerator::setMaxY(int y) +{ + m_yMax = y; +} + void TileGenerator::parseColorsFile(const std::string &fileName) { ifstream in; @@ -295,6 +307,12 @@ void TileGenerator::loadBlocks() if (pos.x < m_geomX || pos.x >= m_geomX2 || pos.z < m_geomY || pos.z >= m_geomY2) { continue; } + if (pos.y < m_yMin) { + continue; + } + if (pos.y > m_yMax) { + continue; + } if (pos.x < m_xMin) { m_xMin = pos.x; } @@ -479,7 +497,9 @@ inline void TileGenerator::renderMapBlock(const unsigned_string &mapBlock, const continue; } int imageX = getImageX(xBegin + x); - for (int y = 15; y >= 0; --y) { + int minY = (pos.y * 16 > m_yMin) ? 0 : m_yMin - pos.y * 16; + int maxY = (pos.y * 16 < m_yMax) ? 15 : m_yMax - pos.y * 16; + for (int y = maxY; y >= minY; --y) { int position = x + (y << 4) + (z << 8); int content = readBlockContent(mapData, version, position); if (content == m_blockIgnoreId || content == m_blockAirId) { diff --git a/TileGenerator.h b/TileGenerator.h index 1a445e5..2f6ddc9 100644 --- a/TileGenerator.h +++ b/TileGenerator.h @@ -77,6 +77,8 @@ public: void setDrawScale(bool drawScale); void setShading(bool shading); void setGeometry(int x, int y, int w, int h); + void setMinY(int y); + void setMaxY(int y); void parseColorsFile(const std::string &fileName); void generate(const std::string &input, const std::string &output); @@ -117,6 +119,8 @@ private: int m_xMax; int m_zMin; int m_zMax; + int m_yMin; + int m_yMax; int m_geomX; int m_geomY; int m_geomX2; diff --git a/mapper.cpp b/mapper.cpp index 0d653a4..f73d192 100644 --- a/mapper.cpp +++ b/mapper.cpp @@ -51,6 +51,8 @@ int main(int argc, char *argv[]) {"drawscale", no_argument, 0, 'S'}, {"noshading", no_argument, 0, 'H'}, {"geometry", required_argument, 0, 'g'}, + {"min-y", required_argument, 0, 'a'}, + {"max-y", required_argument, 0, 'c'}, }; string input; @@ -65,7 +67,7 @@ int main(int argc, char *argv[]) if (c == -1) { if (input.empty() || output.empty()) { usage(); - return -1; + return 0; } break; } @@ -104,6 +106,22 @@ int main(int argc, char *argv[]) case 'H': generator.setShading(false); break; + case 'a': { + istringstream iss; + iss.str(optarg); + int miny; + iss >> miny; + generator.setMinY(miny); + } + break; + case 'c': { + istringstream iss; + iss.str(optarg); + int maxy; + iss >> maxy; + generator.setMaxY(maxy); + } + break; case 'g': { istringstream geometry; geometry.str(optarg); @@ -112,13 +130,13 @@ int main(int argc, char *argv[]) geometry >> x >> c >> y >> w >> h; if (geometry.fail() || c != ':' || w < 1 || h < 1) { usage(); - exit(-1); + exit(1); } generator.setGeometry(x, y, w, h); } break; default: - abort(); + exit(1); } } try {