Skip to content

Commit 2f3c96b

Browse files
random-geeksfan5
authored andcommitted
Remove legacy flat-file map code
1 parent 2ecf57c commit 2f3c96b

File tree

3 files changed

+4
-216
lines changed

3 files changed

+4
-216
lines changed

doc/world_format.txt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ The block serialization version does not fully specify every aspect of this
1313
format; if compliance with this format is to be checked, it needs to be
1414
done by detecting if the files and data indeed follows it.
1515

16-
Legacy stuff
17-
=============
18-
Data can, in theory, be contained in the flat file directory structure
19-
described below in Version 17, but it is not officially supported. Also you
20-
may stumble upon all kinds of oddities in not-so-recent formats.
21-
2216
Files
2317
======
2418
Everything is contained in a directory, the name of which is freeform, but
@@ -569,9 +563,9 @@ EndInventoryList
569563
EndInventory
570564
---
571565

572-
==============================================
573-
Minetest World Format used as of 2011-05 or so
574-
==============================================
566+
===========================================================
567+
Minetest World Format used as of 2011-05 or so (deprecated)
568+
===========================================================
575569

576570
Map data serialization format version 17.
577571

src/map.cpp

Lines changed: 1 addition & 195 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,13 +1762,6 @@ s16 ServerMap::findGroundLevel(v2s16 p2d)
17621762
//return (s16)level;
17631763
}
17641764

1765-
bool ServerMap::loadFromFolders() {
1766-
if (!dbase->initialized() &&
1767-
!fs::PathExists(m_savedir + DIR_DELIM + "map.sqlite"))
1768-
return true;
1769-
return false;
1770-
}
1771-
17721765
void ServerMap::createDirs(const std::string &path)
17731766
{
17741767
if (!fs::CreateAllDirs(path)) {
@@ -1778,80 +1771,6 @@ void ServerMap::createDirs(const std::string &path)
17781771
}
17791772
}
17801773

1781-
std::string ServerMap::getSectorDir(v2s16 pos, int layout)
1782-
{
1783-
char cc[9];
1784-
switch(layout)
1785-
{
1786-
case 1:
1787-
porting::mt_snprintf(cc, sizeof(cc), "%.4x%.4x",
1788-
(unsigned int) pos.X & 0xffff,
1789-
(unsigned int) pos.Y & 0xffff);
1790-
1791-
return m_savedir + DIR_DELIM + "sectors" + DIR_DELIM + cc;
1792-
case 2:
1793-
porting::mt_snprintf(cc, sizeof(cc), (std::string("%.3x") + DIR_DELIM + "%.3x").c_str(),
1794-
(unsigned int) pos.X & 0xfff,
1795-
(unsigned int) pos.Y & 0xfff);
1796-
1797-
return m_savedir + DIR_DELIM + "sectors2" + DIR_DELIM + cc;
1798-
default:
1799-
assert(false);
1800-
return "";
1801-
}
1802-
}
1803-
1804-
v2s16 ServerMap::getSectorPos(const std::string &dirname)
1805-
{
1806-
unsigned int x = 0, y = 0;
1807-
int r;
1808-
std::string component;
1809-
fs::RemoveLastPathComponent(dirname, &component, 1);
1810-
if(component.size() == 8)
1811-
{
1812-
// Old layout
1813-
r = sscanf(component.c_str(), "%4x%4x", &x, &y);
1814-
}
1815-
else if(component.size() == 3)
1816-
{
1817-
// New layout
1818-
fs::RemoveLastPathComponent(dirname, &component, 2);
1819-
r = sscanf(component.c_str(), (std::string("%3x") + DIR_DELIM + "%3x").c_str(), &x, &y);
1820-
// Sign-extend the 12 bit values up to 16 bits...
1821-
if(x & 0x800) x |= 0xF000;
1822-
if(y & 0x800) y |= 0xF000;
1823-
}
1824-
else
1825-
{
1826-
r = -1;
1827-
}
1828-
1829-
FATAL_ERROR_IF(r != 2, "getSectorPos()");
1830-
v2s16 pos((s16)x, (s16)y);
1831-
return pos;
1832-
}
1833-
1834-
v3s16 ServerMap::getBlockPos(const std::string &sectordir, const std::string &blockfile)
1835-
{
1836-
v2s16 p2d = getSectorPos(sectordir);
1837-
1838-
if(blockfile.size() != 4){
1839-
throw InvalidFilenameException("Invalid block filename");
1840-
}
1841-
unsigned int y;
1842-
int r = sscanf(blockfile.c_str(), "%4x", &y);
1843-
if(r != 1)
1844-
throw InvalidFilenameException("Invalid block filename");
1845-
return v3s16(p2d.X, y, p2d.Y);
1846-
}
1847-
1848-
std::string ServerMap::getBlockFilename(v3s16 p)
1849-
{
1850-
char cc[5];
1851-
porting::mt_snprintf(cc, sizeof(cc), "%.4x", (unsigned int)p.Y&0xffff);
1852-
return cc;
1853-
}
1854-
18551774
void ServerMap::save(ModifiedState save_level)
18561775
{
18571776
if (!m_map_saving_enabled) {
@@ -1921,10 +1840,6 @@ void ServerMap::save(ModifiedState save_level)
19211840

19221841
void ServerMap::listAllLoadableBlocks(std::vector<v3s16> &dst)
19231842
{
1924-
if (loadFromFolders()) {
1925-
errorstream << "Map::listAllLoadableBlocks(): Result will be missing "
1926-
<< "all blocks that are stored in flat files." << std::endl;
1927-
}
19281843
dbase->listAllLoadableBlocks(dst);
19291844
if (dbase_ro)
19301845
dbase_ro->listAllLoadableBlocks(dst);
@@ -2018,83 +1933,6 @@ bool ServerMap::saveBlock(MapBlock *block, MapDatabase *db)
20181933
return ret;
20191934
}
20201935

2021-
void ServerMap::loadBlock(const std::string &sectordir, const std::string &blockfile,
2022-
MapSector *sector, bool save_after_load)
2023-
{
2024-
std::string fullpath = sectordir + DIR_DELIM + blockfile;
2025-
try {
2026-
std::ifstream is(fullpath.c_str(), std::ios_base::binary);
2027-
if (!is.good())
2028-
throw FileNotGoodException("Cannot open block file");
2029-
2030-
v3s16 p3d = getBlockPos(sectordir, blockfile);
2031-
v2s16 p2d(p3d.X, p3d.Z);
2032-
2033-
assert(sector->getPos() == p2d);
2034-
2035-
u8 version = SER_FMT_VER_INVALID;
2036-
is.read((char*)&version, 1);
2037-
2038-
if(is.fail())
2039-
throw SerializationError("ServerMap::loadBlock(): Failed"
2040-
" to read MapBlock version");
2041-
2042-
/*u32 block_size = MapBlock::serializedLength(version);
2043-
SharedBuffer<u8> data(block_size);
2044-
is.read((char*)*data, block_size);*/
2045-
2046-
// This will always return a sector because we're the server
2047-
//MapSector *sector = emergeSector(p2d);
2048-
2049-
MapBlock *block = NULL;
2050-
bool created_new = false;
2051-
block = sector->getBlockNoCreateNoEx(p3d.Y);
2052-
if(block == NULL)
2053-
{
2054-
block = sector->createBlankBlockNoInsert(p3d.Y);
2055-
created_new = true;
2056-
}
2057-
2058-
// Read basic data
2059-
block->deSerialize(is, version, true);
2060-
2061-
// If it's a new block, insert it to the map
2062-
if (created_new) {
2063-
sector->insertBlock(block);
2064-
ReflowScan scanner(this, m_emerge->ndef);
2065-
scanner.scan(block, &m_transforming_liquid);
2066-
}
2067-
2068-
/*
2069-
Save blocks loaded in old format in new format
2070-
*/
2071-
2072-
if(version < SER_FMT_VER_HIGHEST_WRITE || save_after_load)
2073-
{
2074-
saveBlock(block);
2075-
2076-
// Should be in database now, so delete the old file
2077-
fs::RecursiveDelete(fullpath);
2078-
}
2079-
2080-
// We just loaded it from the disk, so it's up-to-date.
2081-
block->resetModified();
2082-
2083-
}
2084-
catch(SerializationError &e)
2085-
{
2086-
warningstream<<"Invalid block data on disk "
2087-
<<"fullpath="<<fullpath
2088-
<<" (SerializationError). "
2089-
<<"what()="<<e.what()
2090-
<<std::endl;
2091-
// Ignoring. A new one will be generated.
2092-
abort();
2093-
2094-
// TODO: Backup file; name is in fullpath.
2095-
}
2096-
}
2097-
20981936
void ServerMap::loadBlock(std::string *blob, v3s16 p3d, MapSector *sector, bool save_after_load)
20991937
{
21001938
try {
@@ -2172,39 +2010,7 @@ MapBlock* ServerMap::loadBlock(v3s16 blockpos)
21722010
loadBlock(&ret, blockpos, createSector(p2d), false);
21732011
}
21742012
} else {
2175-
// Not found in database, try the files
2176-
2177-
// The directory layout we're going to load from.
2178-
// 1 - original sectors/xxxxzzzz/
2179-
// 2 - new sectors2/xxx/zzz/
2180-
// If we load from anything but the latest structure, we will
2181-
// immediately save to the new one, and remove the old.
2182-
std::string sectordir1 = getSectorDir(p2d, 1);
2183-
std::string sectordir;
2184-
if (fs::PathExists(sectordir1)) {
2185-
sectordir = sectordir1;
2186-
} else {
2187-
sectordir = getSectorDir(p2d, 2);
2188-
}
2189-
2190-
/*
2191-
Make sure sector is loaded
2192-
*/
2193-
2194-
MapSector *sector = getSectorNoGenerate(p2d);
2195-
2196-
/*
2197-
Make sure file exists
2198-
*/
2199-
2200-
std::string blockfilename = getBlockFilename(blockpos);
2201-
if (!fs::PathExists(sectordir + DIR_DELIM + blockfilename))
2202-
return NULL;
2203-
2204-
/*
2205-
Load block and save it to the database
2206-
*/
2207-
loadBlock(sectordir, blockfilename, sector, true);
2013+
return NULL;
22082014
}
22092015

22102016
MapBlock *block = getBlockNoCreateNoEx(blockpos);

src/map.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -380,21 +380,12 @@ class ServerMap : public Map
380380
names when saving
381381
*/
382382
void createDirs(const std::string &path);
383-
// returns something like "map/sectors/xxxxxxxx"
384-
std::string getSectorDir(v2s16 pos, int layout = 2);
385-
// dirname: final directory name
386-
v2s16 getSectorPos(const std::string &dirname);
387-
v3s16 getBlockPos(const std::string &sectordir, const std::string &blockfile);
388-
static std::string getBlockFilename(v3s16 p);
389383

390384
/*
391385
Database functions
392386
*/
393387
static MapDatabase *createDatabase(const std::string &name, const std::string &savedir, Settings &conf);
394388

395-
// Returns true if the database file does not exist
396-
bool loadFromFolders();
397-
398389
// Call these before and after saving of blocks
399390
void beginSave();
400391
void endSave();
@@ -407,9 +398,6 @@ class ServerMap : public Map
407398

408399
bool saveBlock(MapBlock *block);
409400
static bool saveBlock(MapBlock *block, MapDatabase *db);
410-
// This will generate a sector with getSector if not found.
411-
void loadBlock(const std::string &sectordir, const std::string &blockfile,
412-
MapSector *sector, bool save_after_load=false);
413401
MapBlock* loadBlock(v3s16 p);
414402
// Database version
415403
void loadBlock(std::string *blob, v3s16 p3d, MapSector *sector, bool save_after_load=false);

0 commit comments

Comments
 (0)