diff --git a/README.rst b/README.rst index ccd18f1..993e29c 100644 --- a/README.rst +++ b/README.rst @@ -83,6 +83,9 @@ extent: noshading: Don't draw shading on nodes, ``--noshading`` +noemptyimage: + Don't output anything when the image would be empty, ``--noemptyimage`` + min-y: Don't draw nodes below this y value, e.g. ``--min-y -25`` diff --git a/TileGenerator.cpp b/TileGenerator.cpp index b46edd5..90e311b 100644 --- a/TileGenerator.cpp +++ b/TileGenerator.cpp @@ -79,6 +79,7 @@ TileGenerator::TileGenerator(): m_drawScale(false), m_drawAlpha(false), m_shading(true), + m_dontWriteEmpty(false), m_backend(""), m_xBorder(0), m_yBorder(0), @@ -228,6 +229,10 @@ void TileGenerator::printGeometry(const std::string &input) } +void TileGenerator::setDontWriteEmpty(bool f) +{ + m_dontWriteEmpty = f; +} void TileGenerator::generate(const std::string &input, const std::string &output) { @@ -238,6 +243,13 @@ void TileGenerator::generate(const std::string &input, const std::string &output openDb(input_path); loadBlocks(); + + if (m_dontWriteEmpty && ! m_positions.size()) + { + closeDatabase(); + return; + } + createImage(); renderMap(); closeDatabase(); diff --git a/include/TileGenerator.h b/include/TileGenerator.h index 1ef23cd..6c97a7a 100644 --- a/include/TileGenerator.h +++ b/include/TileGenerator.h @@ -89,6 +89,7 @@ public: void printGeometry(const std::string &input); void setZoom(int zoom); void setScales(uint flags); + void setDontWriteEmpty(bool f); private: void parseColorsStream(std::istream &in); @@ -120,6 +121,7 @@ private: bool m_drawScale; bool m_drawAlpha; bool m_shading; + bool m_dontWriteEmpty; std::string m_backend; int m_xBorder, m_yBorder; diff --git a/mapper.cpp b/mapper.cpp index 8518d5b..7acb7a0 100644 --- a/mapper.cpp +++ b/mapper.cpp @@ -24,6 +24,7 @@ void usage() " --draworigin\n" " --drawalpha\n" " --noshading\n" + " --noemptyimage\n" " --min-y \n" " --max-y \n" " --backend \n" @@ -87,6 +88,7 @@ int main(int argc, char *argv[]) {"zoom", required_argument, 0, 'z'}, {"colors", required_argument, 0, 'C'}, {"scales", required_argument, 0, 'f'}, + {"noemptyimage", no_argument, 0, 'n'}, {0, 0, 0, 0} }; @@ -195,6 +197,9 @@ int main(int argc, char *argv[]) case 'C': colors = optarg; break; + case 'n': + generator.setDontWriteEmpty(true); + break; default: exit(1); } diff --git a/minetestmapper.6 b/minetestmapper.6 index 72b1ced..961e993 100644 --- a/minetestmapper.6 +++ b/minetestmapper.6 @@ -56,6 +56,10 @@ Allow nodes to be drawn with transparency .BR \-\-noshading Don't draw shading on nodes +.TP +.BR \-\-noemptyimage +Don't output anything when the image would be empty. + .TP .BR \-\-min-y " " \fInumber\fR Don't draw nodes below this y value, e.g. "--min-y -25"