Skip to content

Commit

Permalink
Add a flag to never output empty images.
Browse files Browse the repository at this point in the history
  • Loading branch information
Martijn Versteegh authored and sfan5 committed Nov 1, 2018
1 parent ac15bac commit ee5b8a9
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.rst
Expand Up @@ -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``

Expand Down
12 changes: 12 additions & 0 deletions TileGenerator.cpp
Expand Up @@ -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),
Expand Down Expand Up @@ -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)
{
Expand All @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions include/TileGenerator.h
Expand Up @@ -89,6 +89,7 @@ class TileGenerator
void printGeometry(const std::string &input);
void setZoom(int zoom);
void setScales(uint flags);
void setDontWriteEmpty(bool f);

private:
void parseColorsStream(std::istream &in);
Expand Down Expand Up @@ -120,6 +121,7 @@ class TileGenerator
bool m_drawScale;
bool m_drawAlpha;
bool m_shading;
bool m_dontWriteEmpty;
std::string m_backend;
int m_xBorder, m_yBorder;

Expand Down
5 changes: 5 additions & 0 deletions mapper.cpp
Expand Up @@ -24,6 +24,7 @@ void usage()
" --draworigin\n"
" --drawalpha\n"
" --noshading\n"
" --noemptyimage\n"
" --min-y <y>\n"
" --max-y <y>\n"
" --backend <backend>\n"
Expand Down Expand Up @@ -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}
};

Expand Down Expand Up @@ -195,6 +197,9 @@ int main(int argc, char *argv[])
case 'C':
colors = optarg;
break;
case 'n':
generator.setDontWriteEmpty(true);
break;
default:
exit(1);
}
Expand Down
4 changes: 4 additions & 0 deletions minetestmapper.6
Expand Up @@ -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"
Expand Down

0 comments on commit ee5b8a9

Please sign in to comment.