Allow air nodes to have a color.

As this comes with a significant performance penalty, this
feature must be enabled using the command-line option --drawair

For best results, the color of air should be fully transparent,
so that underlying nodes will override it.
This commit is contained in:
Rogier 2014-05-22 17:46:16 +02:00
parent ced0390611
commit f832530bf8
6 changed files with 32 additions and 1 deletions

View File

@ -12,6 +12,12 @@
are: point, line, rectangle, ellipse (circle), text.
Translucency (alpha) is supported, although for ellipses, it does not
work as expected (due to a bug in libgd)
- 'air' nodes can now have a color. Their color should be defined as fully
transparent (alpha = 0), so that they don't obscure underlying blocks.
In that case, air will only be drawn if no other blocks are beneath it.
Nodes with alpha value 0 never participate in shading.
As this comes at a significant performance penalty, this feature is
subject to a command-line option: --drawair.
- A default color can be specified for invisible/undefined nodes in rendered
blocks Normally, such nodes are not drawn, so they have the background
color; If a different default color is specified, undefined/invisible

View File

@ -171,6 +171,14 @@ draworigin:
drawalpha:
Allow blocks to be drawn with transparency, `--drawalpha`
drawair:
Draw air blocks (at a significant performance penalty). `--drawair`
For best results, the air color should be defined as fully transparent
so that the color of underlying blocks overrides it.
This option has a significant performance impact.
noshading:
Don't draw shading on nodes, `--noshading`

View File

@ -131,6 +131,7 @@ TileGenerator::TileGenerator():
m_drawPlayers(false),
m_drawScale(false),
m_drawAlpha(false),
m_drawAir(false),
m_shading(true),
m_border(0),
m_backend(DEFAULT_BACKEND),
@ -268,6 +269,11 @@ void TileGenerator::setDrawAlpha(bool drawAlpha)
m_drawAlpha = drawAlpha;
}
void TileGenerator::setDrawAir(bool drawAir)
{
m_drawAir = drawAir;
}
void TileGenerator::setShading(bool shading)
{
m_shading = shading;
@ -1089,7 +1095,9 @@ void TileGenerator::processMapBlock(const DB::Block &block)
readString(name, data, dataOffset, nameLen, length);
name = name.c_str(); // Truncate any trailing NUL bytes
if (name == "air") {
m_blockAirId = nodeId;
ColorMap::const_iterator color = m_colors.find(name);
if (!m_drawAir || color == m_colors.end())
m_blockAirId = nodeId;
}
else if (name == "ignore") {
m_blockIgnoreId = nodeId;

View File

@ -92,6 +92,7 @@ public:
void setDrawPlayers(bool drawPlayers);
void setDrawScale(bool drawScale);
void setDrawAlpha(bool drawAlpha);
void setDrawAir(bool drawAir);
void drawObject(const DrawObject &object) { m_drawObjects.push_back(object); }
void setShading(bool shading);
void setGeometry(const NodeCoord &corner1, const NodeCoord &corner2);
@ -169,6 +170,7 @@ private:
bool m_drawPlayers;
bool m_drawScale;
bool m_drawAlpha;
bool m_drawAir;
bool m_shading;
int m_border;
std::string m_backend;

View File

@ -1,3 +1,4 @@
air 220 220 255 0
mesecons_pistons:piston_up_sticky_on 160 160 160
mesecons_pistons:piston_normal_off 125 125 125
mesecons_pistons:piston_up_pusher_sticky 123 124 124

View File

@ -26,6 +26,7 @@ using namespace std;
#define OPT_PROGRESS_INDICATOR 0x82
#define OPT_DRAW_OBJECT 0x83
#define OPT_BLOCKCOLOR 0x84
#define OPT_DRAWAIR 0x85
#define OPT_VERBOSE_SEARCH_COLORS 0x86
// Will be replaced with the actual name and location of the executable (if found)
@ -71,6 +72,7 @@ void usage()
" --drawplayers\n"
" --draworigin\n"
" --drawalpha\n"
" --drawair\n"
" --draw[map]point \"<x>,<y> color\"\n"
" --draw[map]line \"<geometry> color\"\n"
" --draw[map]circle \"<geometry> color\"\n"
@ -526,6 +528,7 @@ int main(int argc, char *argv[])
{"drawplayers", no_argument, 0, 'P'},
{"drawscale", no_argument, 0, 'S'},
{"drawalpha", no_argument, 0, 'e'},
{"drawair", no_argument, 0, OPT_DRAWAIR},
{"drawpoint", required_argument, 0, OPT_DRAW_OBJECT},
{"drawline", required_argument, 0, OPT_DRAW_OBJECT},
{"drawcircle", required_argument, 0, OPT_DRAW_OBJECT},
@ -647,6 +650,9 @@ int main(int argc, char *argv[])
case 'e':
generator.setDrawAlpha(true);
break;
case OPT_DRAWAIR:
generator.setDrawAir(true);
break;
case 'H':
generator.setShading(false);
break;