Added calculation of image size.

This commit is contained in:
Miroslav Bendík 2012-08-23 14:06:16 +02:00
parent 65ae97f54b
commit a6abd1445d
2 changed files with 37 additions and 5 deletions

@ -23,7 +23,11 @@ TileGenerator::TileGenerator():
m_drawPlayers(false), m_drawPlayers(false),
m_drawScale(false), m_drawScale(false),
m_drawUnderground(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; sqlite3_stmt *statement;
string sql = "SELECT pos FROM blocks"; string sql = "SELECT pos FROM blocks";
if (sqlite3_prepare_v2(m_db, sql.c_str(), sql.length(), &statement, 0) == SQLITE_OK) { if (sqlite3_prepare_v2(m_db, sql.c_str(), sql.length(), &statement, 0) == SQLITE_OK) {
//int cols = sqlite3_column_count(statement);
int result = 0; int result = 0;
while (true) { while (true) {
result = sqlite3_step(statement); result = sqlite3_step(statement);
if(result == SQLITE_ROW) { if(result == SQLITE_ROW) {
sqlite3_int64 blocknum = sqlite3_column_int64(statement, 0); 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 { else {
break; break;
} }
} }
m_imgWidth = (m_xMax - m_xMin) * 16;
m_imgHeight = (m_zMax - m_zMin) * 16;
} }
else { else {
throw DbError(); throw DbError();
@ -149,9 +169,9 @@ inline BlockPos TileGenerator::decodeBlockPos(sqlite3_int64 blockId)
{ {
BlockPos pos; BlockPos pos;
pos.x = unsignedToSigned(blockId % 4096, 2048); pos.x = unsignedToSigned(blockId % 4096, 2048);
blockId = blockId / 4096; blockId = (blockId - pos.x) / 4096;
pos.y = unsignedToSigned(blockId % 4096, 2048); pos.y = unsignedToSigned(blockId % 4096, 2048);
blockId = blockId / 4096; blockId = (blockId - pos.y) / 4096;
pos.z = unsignedToSigned(blockId % 4096, 2048); pos.z = unsignedToSigned(blockId % 4096, 2048);
return pos; return pos;
} }

@ -64,8 +64,20 @@ private:
bool m_drawPlayers; bool m_drawPlayers;
bool m_drawScale; bool m_drawScale;
bool m_drawUnderground; bool m_drawUnderground;
sqlite3 *m_db; sqlite3 *m_db;
int m_xMin;
int m_xMax;
int m_zMin;
int m_zMax;
int m_imgWidth;
int m_imgHeight;
ColorMap m_colors; 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 ----- */ }; /* ----- end of class TileGenerator ----- */
#endif /* end of include guard: TILEGENERATOR_H_JJNUCARH */ #endif /* end of include guard: TILEGENERATOR_H_JJNUCARH */