From 741776313a0be27de722bc9894a9cc987db433b0 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Wed, 16 Feb 2011 22:53:35 +0200 Subject: [PATCH] fixed invalid block loading (the action is to generate a new one) --- src/map.cpp | 148 ++++++++++++++++++++++++---------------------------- 1 file changed, 68 insertions(+), 80 deletions(-) diff --git a/src/map.cpp b/src/map.cpp index ca2cdbc39..159682696 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -2004,34 +2004,13 @@ double tree_amount_2d(u64 seed, v2s16 p) return 0.04 * (noise-zeroval) / (1.0-zeroval); } -/*double base_rock_level_2d(u64 seed, v2s16 p) -{ - return WATER_LEVEL - 6.0 + 25. * noise2d_perlin( - 0.5+(float)p.X/500., 0.5+(float)p.Y/500., - seed, 6, 0.6); -}*/ - -/*double highlands_level_2d(u64 seed, v2s16 p) -{ - double a = noise2d_perlin( - 0.5+(float)p.X/1000., 0.5+(float)p.Y/1000., - seed-359, 6, 0.65); - if(a > 0.0) - //if(1) - { - return WATER_LEVEL + 25; - return WATER_LEVEL + 55. * noise2d_perlin( - 0.5+(float)p.X/500., 0.5+(float)p.Y/500., - seed+85039, 6, 0.69); - } - else - return -100000; -}*/ +#define AVERAGE_MUD_AMOUNT 4 double base_rock_level_2d(u64 seed, v2s16 p) { // The base ground level - double base = (double)WATER_LEVEL - 4.0 + 25. * noise2d_perlin( + double base = (double)WATER_LEVEL - (double)AVERAGE_MUD_AMOUNT + + 25. * noise2d_perlin( 0.5+(float)p.X/500., 0.5+(float)p.Y/500., (seed>>32)+654879876, 6, 0.6); @@ -3837,6 +3816,7 @@ MapBlock * ServerMap::generateBlock( v2s16 p2d(p.X, p.Z); s16 block_y = p.Y; + v2s16 p2d_nodes = p2d * MAP_BLOCKSIZE; /* Do not generate over-limit @@ -3875,14 +3855,17 @@ MapBlock * ServerMap::generateBlock( { //dstream<<"generateBlock: x0="<getPos() == p2d); - - u8 version = SER_FMT_VER_INVALID; - is.read((char*)&version, 1); + 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); - /*u32 block_size = MapBlock::serializedLength(version); - SharedBuffer data(block_size); - is.read((char*)*data, block_size);*/ + if(is.fail()) + throw SerializationError("ServerMap::loadBlock(): Failed" + " to read MapBlock version"); - // This will always return a sector because we're the server - //MapSector *sector = emergeSector(p2d); + /*u32 block_size = MapBlock::serializedLength(version); + SharedBuffer data(block_size); + is.read((char*)*data, block_size);*/ - MapBlock *block = NULL; - bool created_new = false; - try{ - block = sector->getBlockNoCreate(p3d.Y); - } - catch(InvalidPositionException &e) - { - block = sector->createBlankBlockNoInsert(p3d.Y); - created_new = true; - } - - // deserialize block data - block->deSerialize(is, version); - - /* - Versions up from 9 have block objects. - */ - if(version >= 9) - { - block->updateObjects(is, version, NULL, 0); - } + // This will always return a sector because we're the server + //MapSector *sector = emergeSector(p2d); - if(created_new) - sector->insertBlock(block); - - /* - Convert old formats to new and save - */ + MapBlock *block = NULL; + bool created_new = false; + try{ + block = sector->getBlockNoCreate(p3d.Y); + } + catch(InvalidPositionException &e) + { + block = sector->createBlankBlockNoInsert(p3d.Y); + created_new = true; + } + + // deserialize block data + block->deSerialize(is, version); + + /* + Versions up from 9 have block objects. + */ + if(version >= 9) + { + block->updateObjects(is, version, NULL, 0); + } - // Save old format blocks in new format - if(version < SER_FMT_VER_HIGHEST) - { - saveBlock(block); - } - - // We just loaded it from the disk, so it's up-to-date. - block->resetChangedFlag(); + if(created_new) + sector->insertBlock(block); + + /* + Convert old formats to new and save + */ + + // Save old format blocks in new format + if(version < SER_FMT_VER_HIGHEST) + { + saveBlock(block); + } + + // We just loaded it from the disk, so it's up-to-date. + block->resetChangedFlag(); } catch(SerializationError &e) { dstream<<"WARNING: Invalid block data on disk " - "(SerializationError). Ignoring." + "(SerializationError). Ignoring. " + "A new one will be generated." <