#include "porting.h"
#include "mineral.h"
#include "noise.h"
+#include "serverobject.h"
/*
Map
//m_chunksize = 4;
//m_chunksize = 2;
- // TODO: Save to and load from a file
m_seed = (((u64)(myrand()%0xffff)<<0)
+ ((u64)(myrand()%0xffff)<<16)
+ ((u64)(myrand()%0xffff)<<32)
}
else
{
- // Load map metadata (seed, chunksize)
- loadMapMeta();
-
- // Load chunk metadata
- loadChunkMeta();
+ try{
+ // Load map metadata (seed, chunksize)
+ loadMapMeta();
+
+ // Load chunk metadata
+ loadChunkMeta();
+ }
+ catch(FileNotGoodException &e){
+ dstream<<DTIME<<"WARNING: Server: Could not load "
+ <<"metafile(s). Disabling chunk-based "
+ <<"generation."<<std::endl;
+ m_chunksize = 0;
+ }
/*// Load sector (0,0) and throw and exception on fail
if(loadSectorFull(v2s16(0,0)) == false)
void makeChunk(ChunkMakeData *data)
{
+ if(data->no_op)
+ return;
+
s16 y_nodes_min = data->y_blocks_min * MAP_BLOCKSIZE;
s16 y_nodes_max = data->y_blocks_max * MAP_BLOCKSIZE + MAP_BLOCKSIZE - 1;
s16 h_blocks = data->y_blocks_max - data->y_blocks_min + 1;
// Add to transforming liquid queue (in case it'd
// start flowing)
- /*v3s16 p = v3s16(p2d.X, y, p2d.Y);
- m_transforming_liquid.push_back(p);*/
+ v3s16 p = v3s16(p2d.X, y, p2d.Y);
+ data->transforming_liquid.push_back(p);
}
// Next one
void ServerMap::initChunkMake(ChunkMakeData &data, v2s16 chunkpos)
{
+ if(m_chunksize == 0)
+ {
+ data.no_op = true;
+ return;
+ }
+
+ data.no_op = false;
+
// The distance how far into the neighbors the generator is allowed to go.
s16 max_spread_amount_sectors = 2;
assert(max_spread_amount_sectors <= m_chunksize);
Create the whole area of this and the neighboring chunks
*/
{
- TimeTaker timer("generateChunkRaw() create area");
+ TimeTaker timer("initChunkMake() create area");
for(s16 x=0; x<sectorpos_bigbase_size; x++)
for(s16 z=0; z<sectorpos_bigbase_size; z++)
data.vmanip.setMap(this);
// Add the area
{
- TimeTaker timer("generateChunkRaw() initialEmerge");
+ TimeTaker timer("initChunkMake() initialEmerge");
data.vmanip.initialEmerge(bigarea_blocks_min, bigarea_blocks_max);
}
MapChunk* ServerMap::finishChunkMake(ChunkMakeData &data,
core::map<v3s16, MapBlock*> &changed_blocks)
{
+ if(data.no_op)
+ return NULL;
+
/*
Blit generated stuff to map
*/
}
}
+ /*
+ Copy transforming liquid information
+ */
+ while(data.transforming_liquid.size() > 0)
+ {
+ v3s16 p = data.transforming_liquid.pop_front();
+ m_transforming_liquid.push_back(p);
+ }
+
/*
Add random objects to blocks
*/
return chunk;
}
+#if 0
// NOTE: Deprecated
MapChunk* ServerMap::generateChunkRaw(v2s16 chunkpos,
core::map<v3s16, MapBlock*> &changed_blocks,
MapChunk *chunk = getChunk(chunkpos1);
return chunk;
}
+#endif
ServerMapSector * ServerMap::createSector(v2s16 p2d)
{
return sector;
}
+#if 0
MapSector * ServerMap::emergeSector(v2s16 p2d,
core::map<v3s16, MapBlock*> &changed_blocks)
{
*/
//return generateSector();
}
+#endif
/*
NOTE: This is not used for main map generation, only for blocks
DSTACK("%s: p=(%d,%d,%d)",
__FUNCTION_NAME,
p.X, p.Y, p.Z);
+
+ // If chunks are disabled
+ /*if(m_chunksize == 0)
+ {
+ dstream<<"ServerMap::generateBlock(): Chunks disabled -> "
+ <<"not generating."<<std::endl;
+ return NULL;
+ }*/
/*dstream<<"generateBlock(): "
<<"("<<p.X<<","<<p.Y<<","<<p.Z<<")"
s16 surface_y = base_rock_level_2d(m_seed, p2d_nodes+v2s16(x0,z0))
+ AVERAGE_MUD_AMOUNT;
+ // If chunks are disabled
+ if(m_chunksize == 0)
+ surface_y = WATER_LEVEL + 1;
if(surface_y < lowest_ground_y)
lowest_ground_y = surface_y;
<<std::endl;
saveMapMeta();
- saveChunkMeta();
+
+ // Disable saving chunk metadata file if chunks are disabled
+ if(m_chunksize != 0)
+ {
+ saveChunkMeta();
+ }
u32 sector_meta_count = 0;
u32 block_count = 0;
}
}
+#if 0
+// NOTE: Doing this is insane. Deprecated and probably broken.
void ServerMap::loadAll()
{
DSTACK(__FUNCTION_NAME);
}
dstream<<DTIME<<"ServerMap: Map loaded."<<std::endl;
}
+#endif
#if 0
void ServerMap::saveMasterHeightmap()
{
DSTACK(__FUNCTION_NAME);
- dstream<<"INFO: ServerMap::loadMapMeta(): Loading chunk metadata"
+ dstream<<"INFO: ServerMap::loadMapMeta(): Loading map metadata"
<<std::endl;
std::string fullpath = m_savedir + "/map_meta.txt";
{
dstream<<"ERROR: ServerMap::loadMapMeta(): "
<<"could not open"<<fullpath<<std::endl;
- throw FileNotGoodException("Cannot open chunk metadata");
+ throw FileNotGoodException("Cannot open map metadata");
}
Settings params;
void ServerMap::saveChunkMeta()
{
DSTACK(__FUNCTION_NAME);
+
+ // This should not be called if chunks are disabled.
+ assert(m_chunksize != 0);
u32 count = m_chunks.size();
// Get destination
v2s16 p2d = getSectorPos(dirname);
std::string dir = m_savedir + "/sectors/" + dirname;
+
+ ServerMapSector *sector = NULL;
std::string fullpath = dir + "/meta";
std::ifstream is(fullpath.c_str(), std::ios_base::binary);
if(is.good() == false)
- throw FileNotGoodException("Cannot open sector metafile");
-
- ServerMapSector *sector = ServerMapSector::deSerialize
- (is, this, p2d, m_sectors);
+ {
+ // If the directory exists anyway, it probably is in some old
+ // format. Just go ahead and create the sector.
+ if(fs::PathExists(dir))
+ {
+ dstream<<"ServerMap::loadSectorMeta(): Sector metafile "
+ <<fullpath<<" doesn't exist but directory does."
+ <<" Continuing with a sector with no metadata."
+ <<std::endl;
+ sector = createSector(p2d);
+ }
+ else
+ throw FileNotGoodException("Cannot open sector metafile");
+ }
+ else
+ {
+ sector = ServerMapSector::deSerialize
+ (is, this, p2d, m_sectors);
+ }
sector->differs_from_disk = false;