Remove legacy flat-file map code

master
random-geek 2019-10-21 14:59:58 -07:00 committed by sfan5
parent 2ecf57c640
commit 2f3c96b38d
3 changed files with 4 additions and 216 deletions

View File

@ -13,12 +13,6 @@ The block serialization version does not fully specify every aspect of this
format; if compliance with this format is to be checked, it needs to be
done by detecting if the files and data indeed follows it.
Legacy stuff
=============
Data can, in theory, be contained in the flat file directory structure
described below in Version 17, but it is not officially supported. Also you
may stumble upon all kinds of oddities in not-so-recent formats.
Files
======
Everything is contained in a directory, the name of which is freeform, but
@ -569,9 +563,9 @@ EndInventoryList
EndInventory
---
==============================================
Minetest World Format used as of 2011-05 or so
==============================================
===========================================================
Minetest World Format used as of 2011-05 or so (deprecated)
===========================================================
Map data serialization format version 17.

View File

@ -1762,13 +1762,6 @@ plan_b:
//return (s16)level;
}
bool ServerMap::loadFromFolders() {
if (!dbase->initialized() &&
!fs::PathExists(m_savedir + DIR_DELIM + "map.sqlite"))
return true;
return false;
}
void ServerMap::createDirs(const std::string &path)
{
if (!fs::CreateAllDirs(path)) {
@ -1778,80 +1771,6 @@ void ServerMap::createDirs(const std::string &path)
}
}
std::string ServerMap::getSectorDir(v2s16 pos, int layout)
{
char cc[9];
switch(layout)
{
case 1:
porting::mt_snprintf(cc, sizeof(cc), "%.4x%.4x",
(unsigned int) pos.X & 0xffff,
(unsigned int) pos.Y & 0xffff);
return m_savedir + DIR_DELIM + "sectors" + DIR_DELIM + cc;
case 2:
porting::mt_snprintf(cc, sizeof(cc), (std::string("%.3x") + DIR_DELIM + "%.3x").c_str(),
(unsigned int) pos.X & 0xfff,
(unsigned int) pos.Y & 0xfff);
return m_savedir + DIR_DELIM + "sectors2" + DIR_DELIM + cc;
default:
assert(false);
return "";
}
}
v2s16 ServerMap::getSectorPos(const std::string &dirname)
{
unsigned int x = 0, y = 0;
int r;
std::string component;
fs::RemoveLastPathComponent(dirname, &component, 1);
if(component.size() == 8)
{
// Old layout
r = sscanf(component.c_str(), "%4x%4x", &x, &y);
}
else if(component.size() == 3)
{
// New layout
fs::RemoveLastPathComponent(dirname, &component, 2);
r = sscanf(component.c_str(), (std::string("%3x") + DIR_DELIM + "%3x").c_str(), &x, &y);
// Sign-extend the 12 bit values up to 16 bits...
if(x & 0x800) x |= 0xF000;
if(y & 0x800) y |= 0xF000;
}
else
{
r = -1;
}
FATAL_ERROR_IF(r != 2, "getSectorPos()");
v2s16 pos((s16)x, (s16)y);
return pos;
}
v3s16 ServerMap::getBlockPos(const std::string &sectordir, const std::string &blockfile)
{
v2s16 p2d = getSectorPos(sectordir);
if(blockfile.size() != 4){
throw InvalidFilenameException("Invalid block filename");
}
unsigned int y;
int r = sscanf(blockfile.c_str(), "%4x", &y);
if(r != 1)
throw InvalidFilenameException("Invalid block filename");
return v3s16(p2d.X, y, p2d.Y);
}
std::string ServerMap::getBlockFilename(v3s16 p)
{
char cc[5];
porting::mt_snprintf(cc, sizeof(cc), "%.4x", (unsigned int)p.Y&0xffff);
return cc;
}
void ServerMap::save(ModifiedState save_level)
{
if (!m_map_saving_enabled) {
@ -1921,10 +1840,6 @@ void ServerMap::save(ModifiedState save_level)
void ServerMap::listAllLoadableBlocks(std::vector<v3s16> &dst)
{
if (loadFromFolders()) {
errorstream << "Map::listAllLoadableBlocks(): Result will be missing "
<< "all blocks that are stored in flat files." << std::endl;
}
dbase->listAllLoadableBlocks(dst);
if (dbase_ro)
dbase_ro->listAllLoadableBlocks(dst);
@ -2018,83 +1933,6 @@ bool ServerMap::saveBlock(MapBlock *block, MapDatabase *db)
return ret;
}
void ServerMap::loadBlock(const std::string &sectordir, const std::string &blockfile,
MapSector *sector, bool save_after_load)
{
std::string fullpath = sectordir + DIR_DELIM + blockfile;
try {
std::ifstream is(fullpath.c_str(), std::ios_base::binary);
if (!is.good())
throw FileNotGoodException("Cannot open block file");
v3s16 p3d = getBlockPos(sectordir, blockfile);
v2s16 p2d(p3d.X, p3d.Z);
assert(sector->getPos() == p2d);
u8 version = SER_FMT_VER_INVALID;
is.read((char*)&version, 1);
if(is.fail())
throw SerializationError("ServerMap::loadBlock(): Failed"
" to read MapBlock version");
/*u32 block_size = MapBlock::serializedLength(version);
SharedBuffer<u8> data(block_size);
is.read((char*)*data, block_size);*/
// This will always return a sector because we're the server
//MapSector *sector = emergeSector(p2d);
MapBlock *block = NULL;
bool created_new = false;
block = sector->getBlockNoCreateNoEx(p3d.Y);
if(block == NULL)
{
block = sector->createBlankBlockNoInsert(p3d.Y);
created_new = true;
}
// Read basic data
block->deSerialize(is, version, true);
// If it's a new block, insert it to the map
if (created_new) {
sector->insertBlock(block);
ReflowScan scanner(this, m_emerge->ndef);
scanner.scan(block, &m_transforming_liquid);
}
/*
Save blocks loaded in old format in new format
*/
if(version < SER_FMT_VER_HIGHEST_WRITE || save_after_load)
{
saveBlock(block);
// Should be in database now, so delete the old file
fs::RecursiveDelete(fullpath);
}
// We just loaded it from the disk, so it's up-to-date.
block->resetModified();
}
catch(SerializationError &e)
{
warningstream<<"Invalid block data on disk "
<<"fullpath="<<fullpath
<<" (SerializationError). "
<<"what()="<<e.what()
<<std::endl;
// Ignoring. A new one will be generated.
abort();
// TODO: Backup file; name is in fullpath.
}
}
void ServerMap::loadBlock(std::string *blob, v3s16 p3d, MapSector *sector, bool save_after_load)
{
try {
@ -2172,39 +2010,7 @@ MapBlock* ServerMap::loadBlock(v3s16 blockpos)
loadBlock(&ret, blockpos, createSector(p2d), false);
}
} else {
// Not found in database, try the files
// The directory layout we're going to load from.
// 1 - original sectors/xxxxzzzz/
// 2 - new sectors2/xxx/zzz/
// If we load from anything but the latest structure, we will
// immediately save to the new one, and remove the old.
std::string sectordir1 = getSectorDir(p2d, 1);
std::string sectordir;
if (fs::PathExists(sectordir1)) {
sectordir = sectordir1;
} else {
sectordir = getSectorDir(p2d, 2);
}
/*
Make sure sector is loaded
*/
MapSector *sector = getSectorNoGenerate(p2d);
/*
Make sure file exists
*/
std::string blockfilename = getBlockFilename(blockpos);
if (!fs::PathExists(sectordir + DIR_DELIM + blockfilename))
return NULL;
/*
Load block and save it to the database
*/
loadBlock(sectordir, blockfilename, sector, true);
return NULL;
}
MapBlock *block = getBlockNoCreateNoEx(blockpos);

View File

@ -380,21 +380,12 @@ public:
names when saving
*/
void createDirs(const std::string &path);
// returns something like "map/sectors/xxxxxxxx"
std::string getSectorDir(v2s16 pos, int layout = 2);
// dirname: final directory name
v2s16 getSectorPos(const std::string &dirname);
v3s16 getBlockPos(const std::string &sectordir, const std::string &blockfile);
static std::string getBlockFilename(v3s16 p);
/*
Database functions
*/
static MapDatabase *createDatabase(const std::string &name, const std::string &savedir, Settings &conf);
// Returns true if the database file does not exist
bool loadFromFolders();
// Call these before and after saving of blocks
void beginSave();
void endSave();
@ -407,9 +398,6 @@ public:
bool saveBlock(MapBlock *block);
static bool saveBlock(MapBlock *block, MapDatabase *db);
// This will generate a sector with getSector if not found.
void loadBlock(const std::string &sectordir, const 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);