Added border support.

This commit is contained in:
Miroslav Bendík 2012-08-25 14:11:55 +02:00
parent 5be190b5a1
commit a009d3e191
2 changed files with 32 additions and 6 deletions

View File

@ -122,6 +122,7 @@ TileGenerator::TileGenerator():
m_drawPlayers(false),
m_drawScale(false),
m_drawUnderground(false),
m_border(0),
m_db(0),
m_image(0),
m_xMin(0),
@ -190,6 +191,9 @@ void TileGenerator::setDrawPlayers(bool drawPlayers)
void TileGenerator::setDrawScale(bool drawScale)
{
m_drawScale = drawScale;
if (m_drawScale) {
m_border = 40;
}
}
void TileGenerator::setDrawUnderground(bool drawUnderground)
@ -236,6 +240,9 @@ void TileGenerator::generate(const std::string &input, const std::string &output
loadBlocks();
createImage();
renderMap();
if (m_drawScale) {
renderScale();
}
writeImage(output);
}
@ -302,10 +309,10 @@ void TileGenerator::createImage()
{
m_mapWidth = (m_xMax - m_xMin + 1) * 16;
m_mapHeight = (m_zMax - m_zMin + 1) * 16;
m_image = gdImageCreateTrueColor(m_mapWidth, m_mapHeight);
m_image = gdImageCreateTrueColor(m_mapWidth + m_border, m_mapHeight + m_border);
m_blockPixelAttributes.setWidth(m_mapWidth);
// Background
gdImageFilledRectangle(m_image, 0, 0, m_mapWidth - 1, m_mapHeight -1, rgb2int(m_bgColor.r, m_bgColor.g, m_bgColor.b));
gdImageFilledRectangle(m_image, 0, 0, m_mapWidth + m_border - 1, m_mapHeight + m_border -1, rgb2int(m_bgColor.r, m_bgColor.g, m_bgColor.b));
}
void TileGenerator::renderMap()
@ -437,12 +444,12 @@ inline void TileGenerator::renderMapBlock(const std::string &mapBlock, const Blo
int zBegin = (m_zMax - pos.z) * 16;
const unsigned char *mapData = reinterpret_cast<const unsigned char *>(mapBlock.c_str());
for (int z = 0; z < 16; ++z) {
int imageY = zBegin + 15 - z;
int imageY = getImageY(zBegin + 15 - z);
for (int x = 0; x < 16; ++x) {
if (m_readedPixels[z] & (1 << x)) {
continue;
}
int imageX = xBegin + x;
int imageX = getImageX(xBegin + x);
for (int y = 15; y >= 0; --y) {
int position = x + (y << 4) + (z << 8);
int content = readBlockContent(mapData, version, position);
@ -474,6 +481,7 @@ inline void TileGenerator::renderShading(int zPos)
if (imageY >= m_mapHeight) {
continue;
}
imageY = getImageY(imageY);
for (int x = 0; x < m_mapWidth; ++x) {
if (!m_blockPixelAttributes.attribute(z, x).valid_height() || !m_blockPixelAttributes.attribute(z, x - 1).valid_height() || !m_blockPixelAttributes.attribute(z - 1, x).valid_height()) {
continue;
@ -485,19 +493,23 @@ inline void TileGenerator::renderShading(int zPos)
if (d > 36) {
d = 36;
}
int sourceColor = m_image->tpixels[imageY][x] & 0xffffff;
int sourceColor = m_image->tpixels[imageY][getImageX(x)] & 0xffffff;
int r = (sourceColor & 0xff0000) >> 16;
int g = (sourceColor & 0x00ff00) >> 8;
int b = (sourceColor & 0x0000ff);
r = colorSafeBounds(r + d);
g = colorSafeBounds(g + d);
b = colorSafeBounds(b + d);
m_image->tpixels[imageY][x] = rgb2int(r, g, b);
m_image->tpixels[imageY][getImageX(x)] = rgb2int(r, g, b);
}
}
m_blockPixelAttributes.scroll();
}
void TileGenerator::renderScale()
{
}
inline std::list<int> TileGenerator::getZValueList() const
{
std::list<int> zlist;
@ -549,3 +561,13 @@ void TileGenerator::writeImage(const std::string &output)
gdImageDestroy(m_image);
}
inline int TileGenerator::getImageX(int val) const
{
return val + m_border;
}
inline int TileGenerator::getImageY(int val) const
{
return val + m_border;
}

View File

@ -98,7 +98,10 @@ private:
std::map<int, BlockList> getBlocksOnZ(int zPos, sqlite3_stmt *statement) const;
void renderMapBlock(const std::string &mapBlock, const BlockPos &pos, int version);
void renderShading(int zPos);
void renderScale();
void writeImage(const std::string &output);
int getImageX(int val) const;
int getImageY(int val) const;
private:
Color m_bgColor;
@ -109,6 +112,7 @@ private:
bool m_drawPlayers;
bool m_drawScale;
bool m_drawUnderground;
int m_border;
sqlite3 *m_db;
gdImagePtr m_image;