Add --min-y and --max-y options

This commit is contained in:
Sfan5 2014-03-05 18:06:05 +01:00
parent 33f323b1e3
commit 15444ff8f6
4 changed files with 55 additions and 4 deletions

@ -53,6 +53,15 @@ drawplayers:
draworigin: draworigin:
Draw origin indicator, `--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: geometry:
Limit area to specific geometry, `--geometry -800:-800+1600+1600` Limit area to specific geometry, `--geometry -800:-800+1600+1600`

@ -102,6 +102,8 @@ TileGenerator::TileGenerator():
m_xMax(INT_MIN), m_xMax(INT_MIN),
m_zMin(INT_MAX), m_zMin(INT_MAX),
m_zMax(INT_MIN), m_zMax(INT_MIN),
m_yMin(-30000),
m_yMax(30000),
m_geomX(-50), m_geomX(-50),
m_geomY(-50), m_geomY(-50),
m_geomX2(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) void TileGenerator::parseColorsFile(const std::string &fileName)
{ {
ifstream in; 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) { if (pos.x < m_geomX || pos.x >= m_geomX2 || pos.z < m_geomY || pos.z >= m_geomY2) {
continue; continue;
} }
if (pos.y < m_yMin) {
continue;
}
if (pos.y > m_yMax) {
continue;
}
if (pos.x < m_xMin) { if (pos.x < m_xMin) {
m_xMin = pos.x; m_xMin = pos.x;
} }
@ -479,7 +497,9 @@ inline void TileGenerator::renderMapBlock(const unsigned_string &mapBlock, const
continue; continue;
} }
int imageX = getImageX(xBegin + x); 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 position = x + (y << 4) + (z << 8);
int content = readBlockContent(mapData, version, position); int content = readBlockContent(mapData, version, position);
if (content == m_blockIgnoreId || content == m_blockAirId) { if (content == m_blockIgnoreId || content == m_blockAirId) {

@ -77,6 +77,8 @@ public:
void setDrawScale(bool drawScale); void setDrawScale(bool drawScale);
void setShading(bool shading); void setShading(bool shading);
void setGeometry(int x, int y, int w, int h); 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 parseColorsFile(const std::string &fileName);
void generate(const std::string &input, const std::string &output); void generate(const std::string &input, const std::string &output);
@ -117,6 +119,8 @@ private:
int m_xMax; int m_xMax;
int m_zMin; int m_zMin;
int m_zMax; int m_zMax;
int m_yMin;
int m_yMax;
int m_geomX; int m_geomX;
int m_geomY; int m_geomY;
int m_geomX2; int m_geomX2;

@ -51,6 +51,8 @@ int main(int argc, char *argv[])
{"drawscale", no_argument, 0, 'S'}, {"drawscale", no_argument, 0, 'S'},
{"noshading", no_argument, 0, 'H'}, {"noshading", no_argument, 0, 'H'},
{"geometry", required_argument, 0, 'g'}, {"geometry", required_argument, 0, 'g'},
{"min-y", required_argument, 0, 'a'},
{"max-y", required_argument, 0, 'c'},
}; };
string input; string input;
@ -65,7 +67,7 @@ int main(int argc, char *argv[])
if (c == -1) { if (c == -1) {
if (input.empty() || output.empty()) { if (input.empty() || output.empty()) {
usage(); usage();
return -1; return 0;
} }
break; break;
} }
@ -104,6 +106,22 @@ int main(int argc, char *argv[])
case 'H': case 'H':
generator.setShading(false); generator.setShading(false);
break; 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': { case 'g': {
istringstream geometry; istringstream geometry;
geometry.str(optarg); geometry.str(optarg);
@ -112,13 +130,13 @@ int main(int argc, char *argv[])
geometry >> x >> c >> y >> w >> h; geometry >> x >> c >> y >> w >> h;
if (geometry.fail() || c != ':' || w < 1 || h < 1) { if (geometry.fail() || c != ':' || w < 1 || h < 1) {
usage(); usage();
exit(-1); exit(1);
} }
generator.setGeometry(x, y, w, h); generator.setGeometry(x, y, w, h);
} }
break; break;
default: default:
abort(); exit(1);
} }
} }
try { try {