diff --git a/TileGenerator.cpp b/TileGenerator.cpp index da4572a..b08e1db 100644 --- a/TileGenerator.cpp +++ b/TileGenerator.cpp @@ -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(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 TileGenerator::getZValueList() const { std::list 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; +} + diff --git a/TileGenerator.h b/TileGenerator.h index fdf7ee9..f84fa9c 100644 --- a/TileGenerator.h +++ b/TileGenerator.h @@ -98,7 +98,10 @@ private: std::map 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;