diff options
Diffstat (limited to 'src/map.cpp')
-rw-r--r-- | src/map.cpp | 205 |
1 files changed, 5 insertions, 200 deletions
diff --git a/src/map.cpp b/src/map.cpp index 0a7099a06..40aba067e 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -179,7 +179,7 @@ void Map::setNode(v3s16 p, MapNode & n) v3s16 blockpos = getNodeBlockPos(p); MapBlock *block = getBlockNoCreate(blockpos); v3s16 relpos = p - blockpos*MAP_BLOCKSIZE; - // Never allow placing CONTENT_IGNORE, it fucks up stuff + // Never allow placing CONTENT_IGNORE, it causes problems if(n.getContent() == CONTENT_IGNORE){ bool temp_bool; errorstream<<"Map::setNode(): Not allowing to place CONTENT_IGNORE" @@ -761,8 +761,8 @@ void Map::transformLiquids(std::map<v3s16, MapBlock*> &modified_blocks, // set level to last 3 bits, flowing down bit to 4th bit n0.param2 = (flowing_down ? LIQUID_FLOW_DOWN_MASK : 0x00) | (new_node_level & LIQUID_LEVEL_MASK); } else { - // set the liquid level and flow bit to 0 - n0.param2 = ~(LIQUID_LEVEL_MASK | LIQUID_FLOW_DOWN_MASK); + // set the liquid level and flow bits to 0 + n0.param2 &= ~(LIQUID_LEVEL_MASK | LIQUID_FLOW_DOWN_MASK); } // change the node. @@ -1285,8 +1285,7 @@ ServerMap::~ServerMap() Close database if it was opened */ delete dbase; - if (dbase_ro) - delete dbase_ro; + delete dbase_ro; #if 0 /* @@ -1762,13 +1761,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 +1770,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 §ordir, 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 +1839,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 +1932,6 @@ bool ServerMap::saveBlock(MapBlock *block, MapDatabase *db) return ret; } -void ServerMap::loadBlock(const std::string §ordir, 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 +2009,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); |