1
0
mirror of https://github.com/moparisthebest/minetest synced 2024-11-17 23:05:07 -05:00

fixed invalid block loading (the action is to generate a new one)

This commit is contained in:
Perttu Ahola 2011-02-16 22:53:35 +02:00
parent 92432a28c0
commit 741776313a

View File

@ -2004,34 +2004,13 @@ double tree_amount_2d(u64 seed, v2s16 p)
return 0.04 * (noise-zeroval) / (1.0-zeroval); return 0.04 * (noise-zeroval) / (1.0-zeroval);
} }
/*double base_rock_level_2d(u64 seed, v2s16 p) #define AVERAGE_MUD_AMOUNT 4
{
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;
}*/
double base_rock_level_2d(u64 seed, v2s16 p) double base_rock_level_2d(u64 seed, v2s16 p)
{ {
// The base ground level // 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., 0.5+(float)p.X/500., 0.5+(float)p.Y/500.,
(seed>>32)+654879876, 6, 0.6); (seed>>32)+654879876, 6, 0.6);
@ -3837,6 +3816,7 @@ MapBlock * ServerMap::generateBlock(
v2s16 p2d(p.X, p.Z); v2s16 p2d(p.X, p.Z);
s16 block_y = p.Y; s16 block_y = p.Y;
v2s16 p2d_nodes = p2d * MAP_BLOCKSIZE;
/* /*
Do not generate over-limit Do not generate over-limit
@ -3875,14 +3855,17 @@ MapBlock * ServerMap::generateBlock(
{ {
//dstream<<"generateBlock: x0="<<x0<<", z0="<<z0<<std::endl; //dstream<<"generateBlock: x0="<<x0<<", z0="<<z0<<std::endl;
s16 surface_y = 0; //s16 surface_y = 0;
s16 surface_y = base_rock_level_2d(m_seed, p2d_nodes+v2s16(x0,z0))
+ AVERAGE_MUD_AMOUNT;
if(surface_y < lowest_ground_y) if(surface_y < lowest_ground_y)
lowest_ground_y = surface_y; lowest_ground_y = surface_y;
if(surface_y > highest_ground_y) if(surface_y > highest_ground_y)
highest_ground_y = surface_y; highest_ground_y = surface_y;
s32 surface_depth = 2; s32 surface_depth = AVERAGE_MUD_AMOUNT;
for(s16 y0=0; y0<MAP_BLOCKSIZE; y0++) for(s16 y0=0; y0<MAP_BLOCKSIZE; y0++)
{ {
@ -4500,7 +4483,7 @@ MapBlock * ServerMap::emergeBlock(
|| p.Y > MAP_GENERATION_LIMIT / MAP_BLOCKSIZE || p.Y > MAP_GENERATION_LIMIT / MAP_BLOCKSIZE
|| p.Z < -MAP_GENERATION_LIMIT / MAP_BLOCKSIZE || p.Z < -MAP_GENERATION_LIMIT / MAP_BLOCKSIZE
|| p.Z > MAP_GENERATION_LIMIT / MAP_BLOCKSIZE) || p.Z > MAP_GENERATION_LIMIT / MAP_BLOCKSIZE)
throw InvalidPositionException("generateBlock(): pos. over limit"); throw InvalidPositionException("emergeBlock(): pos. over limit");
v2s16 p2d(p.X, p.Z); v2s16 p2d(p.X, p.Z);
s16 block_y = p.Y; s16 block_y = p.Y;
@ -5155,70 +5138,75 @@ void ServerMap::loadBlock(std::string sectordir, std::string blockfile, MapSecto
try{ try{
// Block file is map/sectors/xxxxxxxx/xxxx // Block file is map/sectors/xxxxxxxx/xxxx
std::string fullpath = m_savedir+"/sectors/"+sectordir+"/"+blockfile; std::string fullpath = m_savedir+"/sectors/"+sectordir+"/"+blockfile;
std::ifstream is(fullpath.c_str(), std::ios_base::binary); std::ifstream is(fullpath.c_str(), std::ios_base::binary);
if(is.good() == false) if(is.good() == false)
throw FileNotGoodException("Cannot open block file"); throw FileNotGoodException("Cannot open block file");
v3s16 p3d = getBlockPos(sectordir, blockfile); v3s16 p3d = getBlockPos(sectordir, blockfile);
v2s16 p2d(p3d.X, p3d.Z); v2s16 p2d(p3d.X, p3d.Z);
assert(sector->getPos() == p2d); assert(sector->getPos() == p2d);
u8 version = SER_FMT_VER_INVALID; u8 version = SER_FMT_VER_INVALID;
is.read((char*)&version, 1); is.read((char*)&version, 1);
/*u32 block_size = MapBlock::serializedLength(version); if(is.fail())
SharedBuffer<u8> data(block_size); throw SerializationError("ServerMap::loadBlock(): Failed"
is.read((char*)*data, block_size);*/ " to read MapBlock version");
// This will always return a sector because we're the server /*u32 block_size = MapBlock::serializedLength(version);
//MapSector *sector = emergeSector(p2d); SharedBuffer<u8> data(block_size);
is.read((char*)*data, block_size);*/
MapBlock *block = NULL; // This will always return a sector because we're the server
bool created_new = false; //MapSector *sector = emergeSector(p2d);
try{
block = sector->getBlockNoCreate(p3d.Y);
}
catch(InvalidPositionException &e)
{
block = sector->createBlankBlockNoInsert(p3d.Y);
created_new = true;
}
// deserialize block data MapBlock *block = NULL;
block->deSerialize(is, version); bool created_new = false;
try{
block = sector->getBlockNoCreate(p3d.Y);
}
catch(InvalidPositionException &e)
{
block = sector->createBlankBlockNoInsert(p3d.Y);
created_new = true;
}
/* // deserialize block data
Versions up from 9 have block objects. block->deSerialize(is, version);
*/
if(version >= 9)
{
block->updateObjects(is, version, NULL, 0);
}
if(created_new) /*
sector->insertBlock(block); Versions up from 9 have block objects.
*/
if(version >= 9)
{
block->updateObjects(is, version, NULL, 0);
}
/* if(created_new)
Convert old formats to new and save sector->insertBlock(block);
*/
// Save old format blocks in new format /*
if(version < SER_FMT_VER_HIGHEST) Convert old formats to new and save
{ */
saveBlock(block);
}
// We just loaded it from the disk, so it's up-to-date. // Save old format blocks in new format
block->resetChangedFlag(); 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) catch(SerializationError &e)
{ {
dstream<<"WARNING: Invalid block data on disk " dstream<<"WARNING: Invalid block data on disk "
"(SerializationError). Ignoring." "(SerializationError). Ignoring. "
"A new one will be generated."
<<std::endl; <<std::endl;
} }
} }