Obtain database backend type from the world's world.mt file by default
parent
2fabf991ab
commit
721fbfac52
|
@ -122,7 +122,10 @@ max-y:
|
|||
Don't draw nodes above this y value, `--max-y 75`
|
||||
|
||||
backend:
|
||||
Use specific map backend, supported: sqlite3, leveldb, redis, `--backend leveldb`
|
||||
Use specific map backend, supported: auto, sqlite3, leveldb, redis, `--backend leveldb`
|
||||
|
||||
By default, the backend is 'auto', i.e. it is determined from the backend
|
||||
setting in the world's world.mt file (if found).
|
||||
|
||||
geometry <geometry>:
|
||||
(see below, under 'centergeometry')
|
||||
|
|
|
@ -378,27 +378,79 @@ void TileGenerator::parseColorsStream(std::istream &in, const std::string &filen
|
|||
}
|
||||
}
|
||||
|
||||
std::string TileGenerator::getWorldDatabaseBackend(const std::string &input)
|
||||
{
|
||||
string backend;
|
||||
|
||||
std::string worldFile = input + PATH_SEPARATOR + "world.mt";
|
||||
ifstream in;
|
||||
in.open(worldFile.c_str(), ifstream::in);
|
||||
if (!in.is_open())
|
||||
throw std::runtime_error(std::string("Failed to open world.mt file '") + worldFile + "'");
|
||||
|
||||
std::string line;
|
||||
int linenr = 0;
|
||||
for (std::getline(in,line); in.good(); std::getline(in,line)) {
|
||||
linenr++;
|
||||
istringstream iline;
|
||||
iline.str(line);
|
||||
iline >> std::skipws;
|
||||
string variable;
|
||||
string eq;
|
||||
iline >> variable;
|
||||
if (variable != "backend")
|
||||
continue;
|
||||
iline >> eq;
|
||||
iline >> backend;
|
||||
if (in.fail() || eq != "=") {
|
||||
ostringstream oss;
|
||||
oss << "Error parsing 'backend' in world.mt file at line " << linenr;
|
||||
throw std::runtime_error(oss.str());
|
||||
}
|
||||
}
|
||||
in.close();
|
||||
if (backend == "")
|
||||
backend = "sqlite3";
|
||||
return backend;
|
||||
}
|
||||
|
||||
void TileGenerator::openDb(const std::string &input)
|
||||
{
|
||||
if (false) {
|
||||
}
|
||||
string backend = m_backend;
|
||||
bool unsupported = false;
|
||||
if (m_backend == "auto")
|
||||
backend = getWorldDatabaseBackend(input);
|
||||
|
||||
if(backend == "sqlite3") {
|
||||
#if USE_SQLITE3
|
||||
else if(m_backend == "sqlite3") {
|
||||
DBSQLite3 *db;
|
||||
m_db = db = new DBSQLite3(input);
|
||||
db->cacheWorldRow = m_sqliteCacheWorldRow;
|
||||
#else
|
||||
unsupported = true;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
else if (backend == "leveldb") {
|
||||
#if USE_LEVELDB
|
||||
else if(m_backend == "leveldb")
|
||||
m_db = new DBLevelDB(input);
|
||||
#else
|
||||
unsupported = true;
|
||||
#endif
|
||||
}
|
||||
else if (backend == "redis") {
|
||||
#if USE_REDIS
|
||||
else if(m_backend == "redis")
|
||||
m_db = new DBRedis(input);
|
||||
#else
|
||||
unsupported = true;
|
||||
#endif
|
||||
}
|
||||
else if (m_backend == "auto")
|
||||
throw std::runtime_error(((std::string) "World uses unrecognised database backend: ") + backend);
|
||||
else
|
||||
throw std::runtime_error(((std::string) "Unknown map backend: ") + m_backend);
|
||||
throw std::runtime_error(((std::string) "Internal error: unknown database backend: ") + m_backend);
|
||||
|
||||
if (unsupported)
|
||||
throw std::runtime_error(((std::string) "World uses backend '") + backend + ", which was not enabled at compile-time.");
|
||||
}
|
||||
|
||||
void TileGenerator::loadBlocks()
|
||||
|
|
|
@ -73,6 +73,7 @@ public:
|
|||
|
||||
private:
|
||||
void parseColorsStream(std::istream &in, const std::string &filename);
|
||||
std::string getWorldDatabaseBackend(const std::string &input);
|
||||
void openDb(const std::string &input);
|
||||
void loadBlocks();
|
||||
BlockPos decodeBlockPos(int64_t blockId) const;
|
||||
|
|
43
config.h
43
config.h
|
@ -21,45 +21,44 @@
|
|||
#ifdef USE_CMAKE_CONFIG_H
|
||||
#include "cmake_config.h"
|
||||
#else
|
||||
#define USE_SQLITE3 1
|
||||
#define USE_LEVELDB 0
|
||||
#define USE_REDIS 0
|
||||
#endif
|
||||
|
||||
// List of possible database names (for usage message)
|
||||
#if USE_SQLITE3
|
||||
#define USAGE_NAME_SQLITE "sqlite3"
|
||||
#define USAGE_NAME_SQLITE "/sqlite3"
|
||||
#else
|
||||
#define USAGE_NAME_SQLITE
|
||||
#endif
|
||||
#if USE_SQLITE3 && USE_LEVELDB
|
||||
#define USAGE_SEP_SQLITE_LEVELDB "/"
|
||||
#else
|
||||
#define USAGE_SEP_SQLITE_LEVELDB
|
||||
#endif
|
||||
|
||||
#if USE_LEVELDB
|
||||
#define USAGE_NAME_LEVELDB "leveldb"
|
||||
#define USAGE_NAME_LEVELDB "/leveldb"
|
||||
#else
|
||||
#define USAGE_NAME_LEVELDB
|
||||
#endif
|
||||
#if USE_LEVELDB && USE_REDIS
|
||||
#define USAGE_SEP_LEVELDB_REDIS "/"
|
||||
#else
|
||||
#define USAGE_SEP_LEVELDB_REDIS
|
||||
#endif
|
||||
|
||||
#if USE_REDIS
|
||||
#define USAGE_NAME_REDIS "redis"
|
||||
#define USAGE_NAME_REDIS "/redis"
|
||||
#else
|
||||
#define USAGE_NAME_REDIS
|
||||
#endif
|
||||
#define USAGE_DATABASES USAGE_NAME_SQLITE USAGE_SEP_SQLITE_LEVELDB USAGE_NAME_LEVELDB USAGE_SEP_LEVELDB_REDIS USAGE_NAME_REDIS
|
||||
|
||||
// default database to use
|
||||
#if USE_SQLITE3
|
||||
#define DEFAULT_BACKEND "sqlite3"
|
||||
#elif USE_LEVELDB
|
||||
#define DEFAULT_BACKEND "leveldb"
|
||||
#elif USE_REDIS
|
||||
#define DEFAULT_BACKEND "redis"
|
||||
#else
|
||||
#define USAGE_DATABASES "auto" USAGE_NAME_SQLITE USAGE_NAME_LEVELDB USAGE_NAME_REDIS
|
||||
|
||||
#if !USE_SQLITE3 && !USE_LEVELDB && !USE_REDIS
|
||||
#error No database backends configured !
|
||||
#endif
|
||||
|
||||
// default database to use
|
||||
#if USE_SQLITE3 && !USE_LEVELDB && !USE_REDIS
|
||||
#define DEFAULT_BACKEND "sqlite3"
|
||||
#elif !USE_SQLITE3 && USE_LEVELDB && !USE_REDIS
|
||||
#define DEFAULT_BACKEND "leveldb"
|
||||
#elif !USE_SQLITE3 && !USE_LEVELDB && USE_REDIS
|
||||
#define DEFAULT_BACKEND "redis"
|
||||
#else
|
||||
#define DEFAULT_BACKEND "auto"
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in New Issue