//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)
// Load map metadata (seed, chunksize)
loadMapMeta();
- // Load chunk metadata
- loadChunkMeta();
+ try{
+ // Load chunk metadata
+ loadChunkMeta();
+ }
+ catch(FileNotGoodException &e){
+ dstream<<DTIME<<"WARNING: Server: Could not load "
+ <<"chunk metafile. 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()
void ServerMap::saveChunkMeta()
{
DSTACK(__FUNCTION_NAME);
+
+ // This should not be called if chunks are disabled.
+ assert(m_chunksize != 0);
u32 count = m_chunks.size();
// Returns the position of the chunk where the sector is in
v2s16 sector_to_chunk(v2s16 sectorpos)
{
+ if(m_chunksize == 0)
+ return v2s16(0,0);
sectorpos.X += m_chunksize / 2;
sectorpos.Y += m_chunksize / 2;
v2s16 chunkpos = getContainerPos(sectorpos, m_chunksize);
// Returns the position of the (0,0) sector of the chunk
v2s16 chunk_to_sector(v2s16 chunkpos)
{
+ if(m_chunksize == 0)
+ return v2s16(0,0);
v2s16 sectorpos(
chunkpos.X * m_chunksize,
chunkpos.Y * m_chunksize
*/
bool chunkNonVolatile(v2s16 chunkpos)
{
+ if(m_chunksize == 0)
+ return true;
+
/*for(s16 x=-1; x<=1; x++)
for(s16 y=-1; y<=1; y++)*/
s16 x=0;
return true;
}
+ /*
+ Chunks are generated by using these and makeChunk().
+ */
void initChunkMake(ChunkMakeData &data, v2s16 chunkpos);
MapChunk* finishChunkMake(ChunkMakeData &data,
core::map<v3s16, MapBlock*> &changed_blocks);
All chunks touching this one can be altered also.
*/
- MapChunk* generateChunkRaw(v2s16 chunkpos,
+ /*MapChunk* generateChunkRaw(v2s16 chunkpos,
core::map<v3s16, MapBlock*> &changed_blocks,
- bool force=false);
+ bool force=false);*/
/*
Generate a chunk and its neighbors so that it won't be touched
anymore.
*/
- MapChunk* generateChunk(v2s16 chunkpos,
- core::map<v3s16, MapBlock*> &changed_blocks);
+ /*MapChunk* generateChunk(v2s16 chunkpos,
+ core::map<v3s16, MapBlock*> &changed_blocks);*/
/*
Generate a sector.
- Check disk (loads blocks also)
- Generate chunk
*/
- MapSector * emergeSector(v2s16 p,
- core::map<v3s16, MapBlock*> &changed_blocks);
+ /*MapSector * emergeSector(v2s16 p,
+ core::map<v3s16, MapBlock*> &changed_blocks);*/
- MapSector * emergeSector(v2s16 p)
+ /*MapSector * emergeSector(v2s16 p)
{
core::map<v3s16, MapBlock*> changed_blocks;
return emergeSector(p, changed_blocks);
- }
+ }*/
MapBlock * generateBlock(
v3s16 p,
v3s16 getBlockPos(std::string sectordir, std::string blockfile);
void save(bool only_changed);
- void loadAll();
+ //void loadAll();
// Saves map seed and possibly other stuff
void saveMapMeta();
bool m_map_saving_enabled;
// Chunk size in MapSectors
+ // If 0, chunks are disabled.
s16 m_chunksize;
// Chunks
core::map<v2s16, MapChunk*> m_chunks;
struct ChunkMakeData
{
+ bool no_op;
ManualMapVoxelManipulator vmanip;
u64 seed;
v2s16 chunkpos;
v2s16 sectorpos_bigbase;
s16 sectorpos_bigbase_size;
s16 max_spread_amount;
+ UniqueQueue<v3s16> transforming_liquid;
ChunkMakeData():
+ no_op(false),
vmanip(NULL)
{}
};
}
else
{
+ // Get, load or create sector
ServerMapSector *sector =
- (ServerMapSector*)map.getSectorNoGenerateNoEx(p2d);
+ (ServerMapSector*)map.createSector(p2d);
+ // Generate block
block = map.generateBlock(p, block, sector, changed_blocks,
lighting_invalidated_blocks);
+ if(block == NULL)
+ got_block = false;
+ }
+ }
+ else
+ {
+ if(block->getLightingExpired()){
+ lighting_invalidated_blocks[block->getPos()] = block;
}
}
bool send_recommended)
{
assert(m_env);
+
+ const float interval = 0.2;
+ if(m_move_interval.step(dtime, interval))
+ return;
+ dtime = interval;
+
core::aabbox3d<f32> box(-BS/3.,0.0,-BS/3., BS/3.,BS*2./3.,BS/3.);
collisionMoveResult moveresult;
// Apply gravity
RatSAO::RatSAO(ServerEnvironment *env, u16 id, v3f pos):
ServerActiveObject(env, id, pos),
+ m_is_active(false),
m_speed_f(0,0,0)
{
//dstream<<"Server: RatSAO created"<<std::endl;
{
assert(m_env);
+ if(m_is_active == false)
+ {
+ if(m_inactive_interval.step(dtime, 0.5))
+ return;
+ }
+
/*
The AI
*/
break;
}
}
+
+ m_is_active = player_is_close;
if(player_is_close == false)
{
*/
-#if 0
-class IntervalLimiter
-{
-public:
- IntervalLimiter():
- m_accumulator(0)
- {
- }
- /*
- dtime: time from last call to this method
- wanted_interval: interval wanted
- return value:
- true: action should be skipped
- false: action should be done and dtime has been set
- */
- bool step(float &dtime, float wanted_interval)
- {
- accumulator += dtime;
- if(accumulator < wanted_interval)
- {
- dtime = 0;
- return true;
- }
- accumulator -= wanted-interval;
- dtime = wanted_interval;
- return false;
- }
-protected:
- float m_accumulator;
-};
-#endif
-
class ServerEnvironment;
class InventoryItem;
std::string m_inventorystring;
v3f m_speed_f;
v3f m_last_sent_position;
+ IntervalLimiter m_move_interval;
};
class RatSAO : public ServerActiveObject
std::string getStaticData();
InventoryItem* createPickedUpItem();
private:
+ bool m_is_active;
+ IntervalLimiter m_inactive_interval;
v3f m_speed_f;
v3f m_oldpos;
v3f m_last_sent_position;
);
}
+class IntervalLimiter
+{
+public:
+ IntervalLimiter():
+ m_accumulator(0)
+ {
+ }
+ /*
+ dtime: time from last call to this method
+ wanted_interval: interval wanted
+ return value:
+ true: action should be skipped
+ false: action should be done
+ */
+ bool step(float dtime, float wanted_interval)
+ {
+ m_accumulator += dtime;
+ if(m_accumulator < wanted_interval)
+ {
+ dtime = 0;
+ return true;
+ }
+ m_accumulator -= wanted_interval;
+ return false;
+ }
+protected:
+ float m_accumulator;
+};
+
#endif