@@ -1762,13 +1762,6 @@ s16 ServerMap::findGroundLevel(v2s16 p2d)
1762
1762
// return (s16)level;
1763
1763
}
1764
1764
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
-
1772
1765
void ServerMap::createDirs (const std::string &path)
1773
1766
{
1774
1767
if (!fs::CreateAllDirs (path)) {
@@ -1778,80 +1771,6 @@ void ServerMap::createDirs(const std::string &path)
1778
1771
}
1779
1772
}
1780
1773
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 §ordir, 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
-
1855
1774
void ServerMap::save (ModifiedState save_level)
1856
1775
{
1857
1776
if (!m_map_saving_enabled) {
@@ -1921,10 +1840,6 @@ void ServerMap::save(ModifiedState save_level)
1921
1840
1922
1841
void ServerMap::listAllLoadableBlocks (std::vector<v3s16> &dst)
1923
1842
{
1924
- if (loadFromFolders ()) {
1925
- errorstream << " Map::listAllLoadableBlocks(): Result will be missing "
1926
- << " all blocks that are stored in flat files." << std::endl;
1927
- }
1928
1843
dbase->listAllLoadableBlocks (dst);
1929
1844
if (dbase_ro)
1930
1845
dbase_ro->listAllLoadableBlocks (dst);
@@ -2018,83 +1933,6 @@ bool ServerMap::saveBlock(MapBlock *block, MapDatabase *db)
2018
1933
return ret;
2019
1934
}
2020
1935
2021
- void ServerMap::loadBlock (const std::string §ordir, 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
-
2098
1936
void ServerMap::loadBlock (std::string *blob, v3s16 p3d, MapSector *sector, bool save_after_load)
2099
1937
{
2100
1938
try {
@@ -2172,39 +2010,7 @@ MapBlock* ServerMap::loadBlock(v3s16 blockpos)
2172
2010
loadBlock (&ret, blockpos, createSector (p2d), false );
2173
2011
}
2174
2012
} 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 ;
2208
2014
}
2209
2015
2210
2016
MapBlock *block = getBlockNoCreateNoEx (blockpos);
0 commit comments