mirror of
https://github.com/minetest/minetestmapper.git
synced 2025-07-02 00:20:22 +02:00
Added selection of blocks.
This commit is contained in:
@ -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<int, int>(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;
|
||||
|
Reference in New Issue
Block a user