diff --git a/src/content_mapnode.cpp b/src/content_mapnode.cpp index bc01495..94773eb 100644 --- a/src/content_mapnode.cpp +++ b/src/content_mapnode.cpp @@ -46,64 +46,14 @@ #define WATER_VISC 1 #define LAVA_VISC 7 -/* - A conversion table for backwards compatibility. - Maps <=v19 content types to current ones. - Should never be touched. -*/ -content_t trans_table_19[21][2] = { - {CONTENT_GRASS, 1}, - {CONTENT_TREE, 4}, - {CONTENT_LEAVES, 5}, - {CONTENT_FARM_DIRT, 6}, - {CONTENT_MESE, 7}, - {CONTENT_MUD, 8}, - {CONTENT_COTTON, 10}, - {CONTENT_BORDERSTONE, 11}, - {CONTENT_WOOD, 12}, - {CONTENT_SAND, 13}, - {CONTENT_COBBLE, 18}, - {CONTENT_STEEL, 19}, - {CONTENT_GLASS, 20}, - {CONTENT_MOSSYCOBBLE, 22}, - {CONTENT_GRAVEL, 23}, - {CONTENT_SANDSTONE, 24}, - {CONTENT_CACTUS, 25}, - {CONTENT_BRICK, 26}, - {CONTENT_CLAY, 27}, - {CONTENT_PAPYRUS, 28}, - {CONTENT_BOOKSHELF, 29}, -}; MapNode mapnode_translate_from_internal(MapNode n_from, u8 version) { - MapNode result = n_from; - if(version <= 19) - { - content_t c_from = n_from.getContent(); - for(u32 i=0; i::Iterator i = m_sectors.getIterator(); - for(; i.atEnd() == false; i++) - { + for (core::map::Iterator i = m_sectors.getIterator(); i.atEnd() == false; i++) { ServerMapSector *sector = (ServerMapSector*)i.getNode()->getValue(); assert(sector->getId() == MAPSECTOR_SERVER); - - if(sector->differs_from_disk || only_changed == false) - { - saveSectorMeta(sector); - sector_meta_count++; - } core::list blocks; sector->getBlocks(blocks); core::list::Iterator j; - for(j=blocks.begin(); j!=blocks.end(); j++) - { + for (j=blocks.begin(); j!=blocks.end(); j++) { MapBlock *block = *j; block_count_all++; - if(block->getModified() >= MOD_STATE_WRITE_NEEDED - || only_changed == false) - { + if ( + block->getModified() >= MOD_STATE_WRITE_NEEDED + || only_changed == false + ) { // Lazy beginSave() - if(!save_started){ + if (!save_started) { beginSave(); save_started = true; } @@ -2664,11 +2646,8 @@ void ServerMap::save(bool only_changed) /* Only print if something happened or saved whole map */ - if(only_changed == false || sector_meta_count != 0 - || block_count != 0) - { + if (only_changed == false || block_count != 0) { infostream<<"ServerMap: Written: " - <= 0) + if (i >= 0) return i % mod; return mod - ((-i) % mod); } @@ -2703,21 +2681,12 @@ v3s16 ServerMap::getIntegerAsBlock(sqlite3_int64 i) void ServerMap::listAllLoadableBlocks(core::list &dst) { - if(loadFromFolders()){ - errorstream<<"Map::listAllLoadableBlocks(): Result will be missing " - <<"all blocks that are stored in flat files"<serialize(o, version); - - 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() == false) - { - // 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); - - 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; - } - - 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<::Iterator i = m_blocks.getIterator(); - for(; i.atEnd() == false; i++) - { + for (; i.atEnd() == false; i++) { delete i.getNode()->getValue(); } @@ -60,22 +58,16 @@ void MapSector::deleteBlocks() MapBlock * MapSector::getBlockBuffered(s16 y) { - MapBlock *block; + MapBlock *block = NULL; - if(m_block_cache != NULL && y == m_block_cache_y){ + if (m_block_cache != NULL && y == m_block_cache_y) return m_block_cache; - } // If block doesn't exist, return NULL core::map::Node *n = m_blocks.find(y); - if(n == NULL) - { - block = NULL; - } // If block exists, return it - else{ + if (n != NULL) block = n->getValue(); - } // Cache the last result m_block_cache_y = y; @@ -114,9 +106,8 @@ void MapSector::insertBlock(MapBlock *block) s16 block_y = block->getPos().Y; MapBlock *block2 = getBlockBuffered(block_y); - if(block2 != NULL){ + if (block2 != NULL) throw AlreadyExistsException("Block already exists"); - } v2s16 p2d(block->getPos().X, block->getPos().Z); assert(p2d == m_pos); @@ -146,8 +137,7 @@ void MapSector::getBlocks(core::list &dest) core::map::Iterator bi; bi = m_blocks.getIterator(); - for(; bi.atEnd() == false; bi++) - { + for (; bi.atEnd() == false; bi++) { MapBlock *b = bi.getNode()->getValue(); dest.push_back(b); } @@ -168,7 +158,7 @@ ServerMapSector::~ServerMapSector() void ServerMapSector::serialize(std::ostream &os, u8 version) { - if(!ser_ver_supported(version)) + if (!ser_ver_supported(version)) throw VersionMismatchException("ERROR: MapSector format not supported"); /* @@ -208,7 +198,7 @@ ServerMapSector* ServerMapSector::deSerialize( u8 version = SER_FMT_VER_INVALID; is.read((char*)&version, 1); - if(!ser_ver_supported(version)) + if (!ser_ver_supported(version)) throw VersionMismatchException("ERROR: MapSector format not supported"); /* @@ -223,8 +213,7 @@ ServerMapSector* ServerMapSector::deSerialize( core::map::Node *n = sectors.find(p2d); - if(n != NULL) - { + if (n != NULL) { dstream<<"WARNING: deSerializing existent sectors not supported " "at the moment, because code hasn't been tested." <getValue(); assert(sector->getId() == MAPSECTOR_SERVER); return (ServerMapSector*)sector; - } - else - { + }else{ sector = new ServerMapSector(parent, p2d); sectors.insert(p2d, sector); } diff --git a/src/mapsector.h b/src/mapsector.h index f3eac2a..97fc510 100644 --- a/src/mapsector.h +++ b/src/mapsector.h @@ -67,9 +67,6 @@ public: void getBlocks(core::list &dest); - // Always false at the moment, because sector contains no metadata. - bool differs_from_disk; - protected: // The pile of MapBlocks diff --git a/src/server.cpp b/src/server.cpp index f120d96..3efa298 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -213,9 +213,7 @@ void * EmergeThread::Thread() JMutexAutoLock envlock(m_server->m_env_mutex); // Load sector if it isn't loaded - if(map.getSectorNoGenerateNoEx(p2d) == NULL) - //map.loadSectorFull(p2d); - map.loadSectorMeta(p2d); + map.getSectorNoGenerateNoEx(p2d); block = map.getBlockNoCreateNoEx(p); if(!block || block->isDummy() || !block->isGenerated())