From de4c2e4250d3071a8de7841a1cb3a63af67c63f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Blot?= Date: Sat, 19 Aug 2017 11:29:46 +0200 Subject: ServerMap saving: cleanups (#6274) * remove sector meta loading/saving from files which targets dead code (differs_from_disk is always empty) * this remove empty ServerMapSector and ClientMapSector, remove MapSector childs --- src/map.cpp | 312 ++++-------------------------------------------------------- 1 file changed, 18 insertions(+), 294 deletions(-) (limited to 'src/map.cpp') diff --git a/src/map.cpp b/src/map.cpp index 88c32bbd8..a12bbe54c 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -1211,14 +1211,6 @@ ServerMap::ServerMap(const std::string &savedir, IGameDef *gamedef, infostream<<"Please remove the map or fix it."<getId() == MAPSECTOR_SERVER); - } - catch(InvalidPositionException &e) - { + sector = createSector(p2d); + } catch (InvalidPositionException &e) { infostream<<"createBlock: createSector() failed"<getBlockNoCreateNoEx(block_y); - if(block) - { + if (block) { if(block->isDummy()) block->unDummify(); return block; @@ -1697,39 +1650,12 @@ MapBlock * ServerMap::emergeBlock(v3s16 p, bool create_blank) } if (create_blank) { - ServerMapSector *sector = createSector(v2s16(p.X, p.Z)); + MapSector *sector = createSector(v2s16(p.X, p.Z)); MapBlock *block = sector->createBlankBlock(p.Y); return block; } -#if 0 - if(allow_generate) - { - std::map modified_blocks; - MapBlock *block = generateBlock(p, modified_blocks); - if(block) - { - MapEditEvent event; - event.type = MEET_OTHER; - event.p = p; - - // Copy modified_blocks to event - for(std::map::iterator - i = modified_blocks.begin(); - i != modified_blocks.end(); ++i) - { - event.modified_blocks.insert(i->first); - } - - // Queue event - dispatchEvent(&event); - - return block; - } - } -#endif - return NULL; } @@ -1918,7 +1844,6 @@ void ServerMap::save(ModifiedState save_level) // Profile modified reasons Profiler modprofiler; - u32 sector_meta_count = 0; u32 block_count = 0; u32 block_count_all = 0; // Number of blocks in memory @@ -1926,13 +1851,7 @@ void ServerMap::save(ModifiedState save_level) bool save_started = false; for (auto §or_it : m_sectors) { - ServerMapSector *sector = (ServerMapSector*) sector_it.second; - assert(sector->getId() == MAPSECTOR_SERVER); - - if(sector->differs_from_disk || save_level == MOD_STATE_CLEAN) { - saveSectorMeta(sector); - sector_meta_count++; - } + MapSector *sector = sector_it.second; MapBlockVect blocks; sector->getBlocks(blocks); @@ -1951,12 +1870,6 @@ void ServerMap::save(ModifiedState save_level) saveBlock(block); block_count++; - - /*infostream<<"ServerMap: Written block (" - <getPos().X<<"," - <getPos().Y<<"," - <getPos().Z<<")" - < &dst) } } -void ServerMap::saveSectorMeta(ServerMapSector *sector) -{ - DSTACK(FUNCTION_NAME); - // Format used for writing - u8 version = SER_FMT_VER_HIGHEST_WRITE; - // Get destination - v2s16 pos = sector->getPos(); - std::string dir = getSectorDir(pos); - createDirs(dir); - - std::string fullpath = dir + DIR_DELIM + "meta"; - std::ostringstream ss(std::ios_base::binary); - - sector->serialize(ss, version); - - if(!fs::safeWriteToFile(fullpath, ss.str())) - throw FileNotGoodException("Cannot write sector metafile"); - - sector->differs_from_disk = false; -} - -MapSector* ServerMap::loadSectorMeta(std::string sectordir, bool save_after_load) -{ - DSTACK(FUNCTION_NAME); - // Get destination - v2s16 p2d = getSectorPos(sectordir); - - ServerMapSector *sector = NULL; - - std::string fullpath = sectordir + DIR_DELIM + "meta"; - std::ifstream is(fullpath.c_str(), std::ios_base::binary); - if (!is.good()) { - // If the directory exists anyway, it probably is in some old - // format. Just go ahead and create the sector. - if(fs::PathExists(sectordir)) - { - /*infostream<<"ServerMap::loadSectorMeta(): Sector metafile " - <differs_from_disk = false; - - return sector; -} - -bool ServerMap::loadSectorMeta(v2s16 p2d) -{ - DSTACK(FUNCTION_NAME); - - // 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. - int loadlayout = 1; - std::string sectordir1 = getSectorDir(p2d, 1); - std::string sectordir; - if(fs::PathExists(sectordir1)) - { - sectordir = sectordir1; - } - else - { - loadlayout = 2; - sectordir = getSectorDir(p2d, 2); - } - - try{ - loadSectorMeta(sectordir, loadlayout != 2); - } - catch(InvalidFilenameException &e) - { - return false; - } - catch(FileNotGoodException &e) - { - return false; - } - catch(std::exception &e) - { - return false; - } - - return true; -} - -#if 0 -bool ServerMap::loadSectorFull(v2s16 p2d) -{ - DSTACK(FUNCTION_NAME); - - MapSector *sector = NULL; - - // 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. - int loadlayout = 1; - std::string sectordir1 = getSectorDir(p2d, 1); - std::string sectordir; - if(fs::PathExists(sectordir1)) - { - sectordir = sectordir1; - } - else - { - loadlayout = 2; - sectordir = getSectorDir(p2d, 2); - } - - try{ - sector = loadSectorMeta(sectordir, loadlayout != 2); - } - catch(InvalidFilenameException &e) - { - return false; - } - catch(FileNotGoodException &e) - { - return false; - } - catch(std::exception &e) - { - return false; - } - - /* - Load blocks - */ - std::vector list2 = fs::GetDirListing - (sectordir); - std::vector::iterator i2; - for(i2=list2.begin(); i2!=list2.end(); i2++) - { - // We want files - if(i2->dir) - continue; - try{ - loadBlock(sectordir, i2->name, sector, loadlayout != 2); - } - catch(InvalidFilenameException &e) - { - // This catches unknown crap in directory - } - } - - if(loadlayout != 2) - { - infostream<<"Sector converted to new layout - deleting "<< - sectordir1<serialize(o, version, true); - std::string data = o.str(); - bool ret = db->saveBlock(p3d, data); + bool ret = db->saveBlock(p3d, o.str()); if (ret) { // We just wrote it to the disk so clear modified flag block->resetModified(); @@ -2414,13 +2151,11 @@ MapBlock* ServerMap::loadBlock(v3s16 blockpos) // 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. - int loadlayout = 1; std::string sectordir1 = getSectorDir(p2d, 1); std::string sectordir; if (fs::PathExists(sectordir1)) { sectordir = sectordir1; } else { - loadlayout = 2; sectordir = getSectorDir(p2d, 2); } @@ -2429,18 +2164,6 @@ MapBlock* ServerMap::loadBlock(v3s16 blockpos) */ MapSector *sector = getSectorNoGenerateNoEx(p2d); - if (sector == NULL) { - try { - sector = loadSectorMeta(sectordir, loadlayout != 2); - } catch(InvalidFilenameException &e) { - return NULL; - } catch(FileNotGoodException &e) { - return NULL; - } catch(std::exception &e) { - return NULL; - } - } - /* Make sure file exists @@ -2455,6 +2178,7 @@ MapBlock* ServerMap::loadBlock(v3s16 blockpos) */ loadBlock(sectordir, blockfilename, sector, true); } + MapBlock *block = getBlockNoCreateNoEx(blockpos); if (created_new && (block != NULL)) { std::map modified_blocks; -- cgit v1.2.3