From d1a16f24cfb360a0a6e60fc76ea87d7c4cf24618 Mon Sep 17 00:00:00 2001 From: JacobF Date: Fri, 2 Sep 2011 19:07:14 -0400 Subject: Initial sqlite3 maps. * The map will reside in world/map.sqlite * It will load from the sectors folder but will not save there --- src/map.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/map.h') diff --git a/src/map.h b/src/map.h index a8aa8e679..411a7ae51 100644 --- a/src/map.h +++ b/src/map.h @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include #include +#include #include "common_irrlicht.h" #include "mapnode.h" @@ -31,6 +32,10 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "constants.h" #include "voxel.h" +extern "C" { + #include "sqlite3.h" +} + class MapSector; class ServerMapSector; class ClientMapSector; @@ -220,6 +225,10 @@ public: //core::aabbox3d getDisplayedBlockArea(); //bool updateChangedVisibleArea(); + + // Call these before and after saving of many blocks + virtual void beginSave() {return;}; + virtual void endSave() {return;}; virtual void save(bool only_changed){assert(0);}; @@ -361,6 +370,23 @@ public: v3s16 getBlockPos(std::string sectordir, std::string blockfile); static std::string getBlockFilename(v3s16 p); + /* + Database functions + */ + // Create the database structure + void createDatabase(); + // Verify we can read/write to the database + void verifyDatabase(); + // Get an integer suitable for a block + static int getBlockAsInteger(const v3s16 pos); + + // Returns true if the database file does not exist + bool loadFromFolders(); + + // Call these before and after saving of blocks + void beginSave(); + void endSave(); + void save(bool only_changed); //void loadAll(); @@ -391,6 +417,8 @@ public: // This will generate a sector with getSector if not found. void loadBlock(std::string sectordir, std::string blockfile, MapSector *sector, bool save_after_load=false); MapBlock* loadBlock(v3s16 p); + // Database version + void loadBlock(std::string *blob, v3s16 p3d, MapSector *sector, bool save_after_load=false); // For debug printing virtual void PrintInfo(std::ostream &out); @@ -419,6 +447,13 @@ private: This is reset to false when written on disk. */ bool m_map_metadata_changed; + + /* + SQLite database and statements + */ + sqlite3 *m_database; + sqlite3_stmt *m_database_read; + sqlite3_stmt *m_database_write; }; /* -- cgit v1.2.3 From d670c831c2183967a5b5e2cdd104fd07a40bb3f4 Mon Sep 17 00:00:00 2001 From: JacobF Date: Sun, 4 Sep 2011 17:01:28 -0400 Subject: These numbers were well exceeding 2^32... --- src/map.cpp | 9 +++++---- src/map.h | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'src/map.h') diff --git a/src/map.cpp b/src/map.cpp index 41c4e17d2..46ee5b53f 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -2849,8 +2849,9 @@ bool ServerMap::loadFromFolders() { return false; } -int ServerMap::getBlockAsInteger(const v3s16 pos) { - return (pos.Z+2048)*16777216 + (pos.Y+2048)*4096 + pos.X; +sqlite3_int64 ServerMap::getBlockAsInteger(const v3s16 pos) { + return (sqlite3_int64)pos.Z*16777216 + + (sqlite3_int64)pos.Y*4096 + (sqlite3_int64)pos.X; } void ServerMap::createDirs(std::string path) @@ -3318,7 +3319,7 @@ void ServerMap::saveBlock(MapBlock *block) std::string tmp = o.str(); const char *bytes = tmp.c_str(); - if(sqlite3_bind_int(m_database_write, 1, getBlockAsInteger(p3d)) != SQLITE_OK) + if(sqlite3_bind_int64(m_database_write, 1, getBlockAsInteger(p3d)) != SQLITE_OK) dstream<<"WARNING: Block position failed to bind: "<