diff --git a/TileGenerator.cpp b/TileGenerator.cpp index 4f6495f..54adab2 100644 --- a/TileGenerator.cpp +++ b/TileGenerator.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include "TileGenerator.h" using namespace std; @@ -251,9 +252,9 @@ inline std::list TileGenerator::getZValueList() const return zlist; } -void TileGenerator::getBlocksOnZ(int zPos, sqlite3_stmt *statement) const +std::map TileGenerator::getBlocksOnZ(int zPos, sqlite3_stmt *statement) const { - map > > blocks; + map blocks; sqlite3_int64 psMin = encodeBlockPos(-2048, -2048, zPos); sqlite3_int64 psMax = encodeBlockPos( 2047, 2047, zPos); @@ -270,27 +271,18 @@ void TileGenerator::getBlocksOnZ(int zPos, sqlite3_stmt *statement) const result = sqlite3_step(statement); if(result == SQLITE_ROW) { sqlite3_int64 blocknum = sqlite3_column_int64(statement, 0); - const void *data = sqlite3_column_blob(statement, 1); - - uint8_t version = static_cast(data)[0]; - uint8_t flags = static_cast(data)[1]; - if (version >= 22) { - data += 4; - } - else { - data += 2; - } - - + const char *data = reinterpret_cast(sqlite3_column_blob(statement, 1)); + int size = sqlite3_column_bytes(statement, 1); BlockPos pos = decodeBlockPos(blocknum); - blocks[pos.x].push_back(pair (pos, "")); - + blocks[pos.x].push_back(Block(pos, string(data, size))); } else { break; } } sqlite3_reset(statement); + + return blocks; } void TileGenerator::writeImage(const std::string &output) diff --git a/TileGenerator.h b/TileGenerator.h index 33a46eb..e05f385 100644 --- a/TileGenerator.h +++ b/TileGenerator.h @@ -37,10 +37,15 @@ class DbError { class ColorError { }; +class DecompressError { +}; + class TileGenerator { private: typedef std::map ColorMap; + typedef std::pair Block; + typedef std::list BlockList; public: TileGenerator(); @@ -48,8 +53,7 @@ public: void setBgColor(const std::string &bgColor); void setScaleColor(const std::string &scaleColor); void setOriginColor(const std::string &originColor); - void setPlayerColor(const std::string &playerColor); - Color parseColor(const std::string &color); + void setPlayerColor(const std::string &playerColor); Color parseColor(const std::string &color); void setDrawOrigin(bool drawOrigin); void setDrawPlayers(bool drawPlayers); void setDrawScale(bool drawScale); @@ -66,8 +70,9 @@ private: void createImage(); void renderMap(); std::list getZValueList() const; - void getBlocksOnZ(int zPos, sqlite3_stmt *statement) const; + std::map getBlocksOnZ(int zPos, sqlite3_stmt *statement) const; void writeImage(const std::string &output); + void *zlibDecompress(const void *data, std::size_t *processed) const; private: Color m_bgColor;