Skip to content

Commit e85a498

Browse files
committedJul 8, 2014
Fix --drawalpha
1 parent 2069118 commit e85a498

File tree

2 files changed

+57
-16
lines changed

2 files changed

+57
-16
lines changed
 

Diff for: ‎TileGenerator.cpp

+53-16
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,14 @@ void TileGenerator::renderMap()
360360

361361
for (int i = 0; i < 16; ++i) {
362362
m_readedPixels[i] = 0;
363+
m_readInfo[i] = 0;
364+
}
365+
for (int i = 0; i < 16; i++) {
366+
for (int j = 0; j < 16; j++) {
367+
m_col[i][j] = m_bgColor; // This will be drawn by renderMapBlockBottom() for y-rows with only 'air', 'ignore' or unknown nodes if --drawalpha is used
368+
m_col[i][j].a = 0; // ..but set alpha to 0 to tell renderMapBlock() not to use this color to mix a shade
369+
m_th[i][j] = 0;
370+
}
363371
}
364372

365373
int xPos = position->first;
@@ -460,6 +468,15 @@ void TileGenerator::renderMap()
460468
break;
461469
}
462470
}
471+
bool allReaded = true;
472+
for (int i = 0; i < 16; ++i) {
473+
if (m_readedPixels[i] != 0xffff) {
474+
allReaded = false;
475+
}
476+
}
477+
if (!allReaded) {
478+
renderMapBlockBottom(blockStack.begin()->first);
479+
}
463480
}
464481
if(m_shading)
465482
renderShading(zPos);
@@ -473,19 +490,13 @@ inline void TileGenerator::renderMapBlock(const ustring &mapBlock, const BlockPo
473490
const unsigned char *mapData = mapBlock.c_str();
474491
int minY = (pos.y * 16 > m_yMin) ? 0 : m_yMin - pos.y * 16;
475492
int maxY = (pos.y * 16 < m_yMax) ? 15 : m_yMax - pos.y * 16;
476-
Color col;
477-
uint8_t th;
478493
for (int z = 0; z < 16; ++z) {
479494
int imageY = getImageY(zBegin + 15 - z);
480495
for (int x = 0; x < 16; ++x) {
481496
if (m_readedPixels[z] & (1 << x)) {
482497
continue;
483498
}
484499
int imageX = getImageX(xBegin + x);
485-
if(m_drawAlpha) {
486-
col = Color(0,0,0,0);
487-
th = 0;
488-
}
489500

490501
for (int y = maxY; y >= minY; --y) {
491502
int position = x + (y << 4) + (z << 8);
@@ -501,21 +512,26 @@ inline void TileGenerator::renderMapBlock(const ustring &mapBlock, const BlockPo
501512
if (color != m_colors.end()) {
502513
const Color c = color->second.to_color();
503514
if (m_drawAlpha) {
504-
if (col.a == 0)
505-
col = c;
515+
if (m_col[z][x].a == 0)
516+
m_col[z][x] = c;
506517
else
507-
col = mixColors(col, c);
508-
if(col.a == 0xFF || y == minY) {
509-
m_image->tpixels[imageY][imageX] = color2int(col);
510-
m_blockPixelAttributes.attribute(15 - z, xBegin + x).thicken = th;
518+
m_col[z][x] = mixColors(m_col[z][x], c);
519+
if(m_col[z][x].a == 0xFF) {
520+
m_image->tpixels[imageY][imageX] = color2int(m_col[z][x]);
521+
m_readedPixels[z] |= (1 << x);
522+
m_blockPixelAttributes.attribute(15 - z, xBegin + x).thicken = m_th[z][x];
511523
} else {
512-
th = (th + color->second.t) / 2.0;
524+
m_th[z][x] = (m_th[z][x] + color->second.t) / 2.0;
513525
continue;
514526
}
515-
} else
527+
} else {
516528
m_image->tpixels[imageY][imageX] = color2int(c);
517-
m_readedPixels[z] |= (1 << x);
518-
m_blockPixelAttributes.attribute(15 - z, xBegin + x).height = pos.y * 16 + y;
529+
m_readedPixels[z] |= (1 << x);
530+
}
531+
if(!(m_readInfo[z] & (1 << x))) {
532+
m_blockPixelAttributes.attribute(15 - z, xBegin + x).height = pos.y * 16 + y;
533+
m_readInfo[z] |= (1 << x);
534+
}
519535
} else {
520536
m_unknownNodes.insert(name);
521537
continue;
@@ -526,6 +542,27 @@ inline void TileGenerator::renderMapBlock(const ustring &mapBlock, const BlockPo
526542
}
527543
}
528544

545+
inline void TileGenerator::renderMapBlockBottom(const BlockPos &pos)
546+
{
547+
int xBegin = (pos.x - m_xMin) * 16;
548+
int zBegin = (m_zMax - pos.z) * 16;
549+
for (int z = 0; z < 16; ++z) {
550+
int imageY = getImageY(zBegin + 15 - z);
551+
for (int x = 0; x < 16; ++x) {
552+
if (m_readedPixels[z] & (1 << x)) {
553+
continue;
554+
}
555+
int imageX = getImageX(xBegin + x);
556+
557+
if (m_drawAlpha) {
558+
m_image->tpixels[imageY][imageX] = color2int(m_col[z][x]);
559+
m_readedPixels[z] |= (1 << x);
560+
m_blockPixelAttributes.attribute(15 - z, xBegin + x).thicken = m_th[z][x];
561+
}
562+
}
563+
}
564+
}
565+
529566
inline void TileGenerator::renderShading(int zPos)
530567
{
531568
int zBegin = (m_zMax - zPos) * 16;

Diff for: ‎TileGenerator.h

+4
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class TileGenerator
6666
void renderMap();
6767
std::list<int> getZValueList() const;
6868
void renderMapBlock(const ustring &mapBlock, const BlockPos &pos, int version);
69+
void renderMapBlockBottom(const BlockPos &pos);
6970
void renderShading(int zPos);
7071
void renderScale();
7172
void renderOrigin();
@@ -106,7 +107,10 @@ class TileGenerator
106107
std::map<int, std::string> m_nameMap;
107108
ColorMap m_colors;
108109
uint16_t m_readedPixels[16];
110+
uint16_t m_readInfo[16];
109111
std::set<std::string> m_unknownNodes;
112+
Color m_col[16][16];
113+
uint8_t m_th[16][16];
110114

111115
int m_blockAirId;
112116
int m_blockIgnoreId;

0 commit comments

Comments
 (0)
Please sign in to comment.