From a6abd1445d03925952ca83828132bdae2cb58b1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bend=C3=ADk?= Date: Thu, 23 Aug 2012 14:06:16 +0200 Subject: [PATCH] Added calculation of image size. --- TileGenerator.cpp | 30 +++++++++++++++++++++++++----- TileGenerator.h | 12 ++++++++++++ 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/TileGenerator.cpp b/TileGenerator.cpp index cfc2619..d0cca87 100644 --- a/TileGenerator.cpp +++ b/TileGenerator.cpp @@ -23,7 +23,11 @@ TileGenerator::TileGenerator(): m_drawPlayers(false), m_drawScale(false), m_drawUnderground(false), - m_db(0) + m_db(0), + m_xMin(0), + m_xMax(0), + m_zMin(0), + m_zMax(0) { } @@ -127,18 +131,34 @@ void TileGenerator::loadBlocks() sqlite3_stmt *statement; string sql = "SELECT pos FROM blocks"; if (sqlite3_prepare_v2(m_db, sql.c_str(), sql.length(), &statement, 0) == SQLITE_OK) { - //int cols = sqlite3_column_count(statement); int result = 0; while (true) { result = sqlite3_step(statement); if(result == SQLITE_ROW) { sqlite3_int64 blocknum = sqlite3_column_int64(statement, 0); - decodeBlockPos(blocknum); + BlockPos pos = decodeBlockPos(blocknum); + if (pos.x > SectorXMax || pos.x < SectorXMin || pos.z > SectorZMax || pos.z < SectorZMin) { + continue; + } + if (pos.x < m_xMin) { + m_xMin = pos.x; + } + if (pos.x > m_xMax) { + m_xMax = pos.x; + } + if (pos.z < m_zMin) { + m_zMin = pos.z; + } + if (pos.z > m_zMax) { + m_zMax = pos.z; + } } else { break; } } + m_imgWidth = (m_xMax - m_xMin) * 16; + m_imgHeight = (m_zMax - m_zMin) * 16; } else { throw DbError(); @@ -149,9 +169,9 @@ inline BlockPos TileGenerator::decodeBlockPos(sqlite3_int64 blockId) { BlockPos pos; pos.x = unsignedToSigned(blockId % 4096, 2048); - blockId = blockId / 4096; + blockId = (blockId - pos.x) / 4096; pos.y = unsignedToSigned(blockId % 4096, 2048); - blockId = blockId / 4096; + blockId = (blockId - pos.y) / 4096; pos.z = unsignedToSigned(blockId % 4096, 2048); return pos; } diff --git a/TileGenerator.h b/TileGenerator.h index 5ce5bfc..35338fc 100644 --- a/TileGenerator.h +++ b/TileGenerator.h @@ -64,8 +64,20 @@ private: bool m_drawPlayers; bool m_drawScale; bool m_drawUnderground; + sqlite3 *m_db; + int m_xMin; + int m_xMax; + int m_zMin; + int m_zMax; + int m_imgWidth; + int m_imgHeight; ColorMap m_colors; + + static const int SectorXMin = -1500/16; + static const int SectorXMax = 1500/16; + static const int SectorZMin = -1500/16; + static const int SectorZMax = 1500/16; }; /* ----- end of class TileGenerator ----- */ #endif /* end of include guard: TILEGENERATOR_H_JJNUCARH */