From ace6f3b5b573a8d696ecd3115ebe3df6aec6bc63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bend=C3=ADk?= Date: Thu, 23 Aug 2012 15:35:00 +0200 Subject: [PATCH] Added selection of blocks. --- TileGenerator.cpp | 38 ++++++++++++++++++++++++++++++++++++++ TileGenerator.h | 4 ++++ 2 files changed, 42 insertions(+) diff --git a/TileGenerator.cpp b/TileGenerator.cpp index a8c24e2..cfcb1e9 100644 --- a/TileGenerator.cpp +++ b/TileGenerator.cpp @@ -137,6 +137,7 @@ void TileGenerator::generate(const std::string &input, const std::string &output openDb(input); loadBlocks(); createImage(); + renderMap(); writeImage(output); } @@ -174,11 +175,14 @@ void TileGenerator::loadBlocks() if (pos.z > m_zMax) { m_zMax = pos.z; } + m_positions.push_back(std::pair(pos.x, pos.z)); } else { break; } } + m_positions.sort(); + m_positions.unique(); } else { throw DbError(); @@ -196,6 +200,11 @@ inline BlockPos TileGenerator::decodeBlockPos(sqlite3_int64 blockId) return pos; } +inline sqlite3_int64 TileGenerator::encodeBlockPos(int x, int y, int z) +{ + return sqlite3_int64(z) * 16777216l + sqlite3_int64(y) * 4096l + sqlite3_int64(x); +} + inline int TileGenerator::unsignedToSigned(long i, long max_positive) { if (i < max_positive) { @@ -215,6 +224,35 @@ void TileGenerator::createImage() gdImageColorAllocate(m_image, m_bgColor.r, m_bgColor.g, m_bgColor.b); } +void TileGenerator::renderMap() +{ + sqlite3_stmt *statement; + string sql = "SELECT pos FROM blocks WHERE pos >= ? AND pos <= ? AND (pos - ?) % 4096 = 0"; + if (sqlite3_prepare_v2(m_db, sql.c_str(), sql.length(), &statement, 0) != SQLITE_OK) { + throw DbError(); + } + + for (auto position = m_positions.begin(); position != m_positions.end(); ++position) { + int xPos = position->first; + int zPos = position->second; + + sqlite3_int64 psMin = encodeBlockPos(xPos, -2048, zPos); + sqlite3_int64 psMax = encodeBlockPos(xPos, 2047, zPos); + sqlite3_bind_int64(statement, 1, psMin); + sqlite3_bind_int64(statement, 2, psMax); + sqlite3_bind_int64(statement, 3, psMin); + int result = 0; + while (true) { + result = sqlite3_step(statement); + if(result == SQLITE_ROW) { + } + else { + break; + } + } + } +} + void TileGenerator::writeImage(const std::string &output) { FILE *out; diff --git a/TileGenerator.h b/TileGenerator.h index f0c328a..f85fd8d 100644 --- a/TileGenerator.h +++ b/TileGenerator.h @@ -11,6 +11,7 @@ #define TILEGENERATOR_H_JJNUCARH #include +#include #include #include #include @@ -58,8 +59,10 @@ private: void openDb(const std::string &input); void loadBlocks(); BlockPos decodeBlockPos(sqlite3_int64 blockId); + sqlite3_int64 encodeBlockPos(int x, int y, int z); int unsignedToSigned(long i, long max_positive); void createImage(); + void renderMap(); void writeImage(const std::string &output); private: @@ -80,6 +83,7 @@ private: int m_zMax; int m_imgWidth; int m_imgHeight; + std::list > m_positions; ColorMap m_colors; static const int SectorXMin = -1500/16;