1
0
mirror of https://github.com/luanti-org/minetestmapper.git synced 2025-10-06 13:55:22 +02:00

Add support for new SQLite map schema

(added in Luanti 5.12.0-dev)
This commit is contained in:
sfan5
2025-02-18 17:13:40 +01:00
parent bbe2f8f404
commit 6947c5c4e4
3 changed files with 118 additions and 36 deletions

View File

@@ -14,13 +14,28 @@ public:
const std::vector<BlockPos> &positions) override;
~DBSQLite3() override;
bool preferRangeQueries() const override { return false; }
bool preferRangeQueries() const override { return newFormat; }
private:
static inline void getPosRange(int64_t &min, int64_t &max, int16_t zPos,
int16_t zPos2);
void loadBlockCache(int16_t zPos);
// bind pos to statement. returns index of next column.
inline int bind_pos(sqlite3_stmt *stmt, int iCol, BlockPos pos)
{
if (newFormat) {
sqlite3_bind_int(stmt, iCol, pos.x);
sqlite3_bind_int(stmt, iCol + 1, pos.y);
sqlite3_bind_int(stmt, iCol + 2, pos.z);
return iCol + 3;
} else {
sqlite3_bind_int64(stmt, iCol, encodeBlockPos(pos));
return iCol + 1;
}
}
// read blob from statement
static inline ustring read_blob(sqlite3_stmt *stmt, int iCol)
{
auto *data = reinterpret_cast<const unsigned char *>(
@@ -32,10 +47,12 @@ private:
sqlite3 *db = NULL;
sqlite3_stmt *stmt_get_block_pos = NULL;
sqlite3_stmt *stmt_get_block_pos_z = NULL;
sqlite3_stmt *stmt_get_block_pos_range = NULL;
sqlite3_stmt *stmt_get_blocks_z = NULL;
sqlite3_stmt *stmt_get_blocks_xz_range = NULL;
sqlite3_stmt *stmt_get_block_exact = NULL;
bool newFormat = false;
int16_t blockCachedZ = -10000;
std::unordered_map<int16_t, BlockList> blockCache; // indexed by X
};