2014-04-19 08:13:34 +02:00
|
|
|
#ifndef DB_LEVELDB_HEADER
|
|
|
|
#define DB_LEVELDB_HEADER
|
2014-03-05 21:41:27 +01:00
|
|
|
|
|
|
|
#include "db.h"
|
2020-03-27 16:12:26 +01:00
|
|
|
#include <unordered_map>
|
|
|
|
#include <utility>
|
2014-03-05 21:41:27 +01:00
|
|
|
#include <leveldb/db.h>
|
|
|
|
|
|
|
|
class DBLevelDB : public DB {
|
|
|
|
public:
|
|
|
|
DBLevelDB(const std::string &mapdir);
|
2020-03-27 16:12:26 +01:00
|
|
|
std::vector<BlockPos> getBlockPos(BlockPos min, BlockPos max) override;
|
|
|
|
void getBlocksOnXZ(BlockList &blocks, int16_t x, int16_t z,
|
|
|
|
int16_t min_y, int16_t max_y) override;
|
2020-03-27 21:10:00 +01:00
|
|
|
void getBlocksByPos(BlockList &blocks,
|
|
|
|
const std::vector<BlockPos> &positions) override;
|
2020-03-27 16:12:26 +01:00
|
|
|
~DBLevelDB() override;
|
|
|
|
|
2020-03-27 21:10:00 +01:00
|
|
|
bool preferRangeQueries() const override { return false; }
|
|
|
|
|
2014-03-05 21:41:27 +01:00
|
|
|
private:
|
2020-03-27 16:12:26 +01:00
|
|
|
using pos2d = std::pair<int16_t, int16_t>;
|
2014-03-28 21:47:19 +01:00
|
|
|
|
2020-03-27 16:12:26 +01:00
|
|
|
void loadPosCache();
|
2014-03-28 21:47:19 +01:00
|
|
|
|
2020-03-27 16:12:26 +01:00
|
|
|
// indexed by Z, contains all (x,y) position pairs
|
|
|
|
std::unordered_map<int16_t, std::vector<pos2d>> posCache;
|
2014-04-19 08:13:34 +02:00
|
|
|
leveldb::DB *db;
|
2014-03-05 21:41:27 +01:00
|
|
|
};
|
|
|
|
|
2014-04-19 08:13:34 +02:00
|
|
|
#endif // DB_LEVELDB_HEADER
|