diff --git a/src/environment.cpp b/src/environment.cpp index d2fb8a39..77746c5b 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -429,7 +429,7 @@ void ServerEnvironment::step(float dtime) bool send_recommended = false; m_send_recommended_timer += dtime; - if(m_send_recommended_timer > 0.1) + if(m_send_recommended_timer > 0.15) { m_send_recommended_timer = 0; send_recommended = true; diff --git a/src/map.cpp b/src/map.cpp index 334de40d..8d79ae36 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -2170,23 +2170,6 @@ void addRandomObjects(MapBlock *block) This is the main map generation method */ -struct ChunkMakeData -{ - ManualMapVoxelManipulator vmanip; - u64 seed; - s16 y_blocks_min; - s16 y_blocks_max; - v2s16 sectorpos_base; - s16 sectorpos_base_size; - v2s16 sectorpos_bigbase; - s16 sectorpos_bigbase_size; - s16 max_spread_amount; - - ChunkMakeData(): - vmanip(NULL) - {} -}; - void makeChunk(ChunkMakeData *data) { s16 y_nodes_min = data->y_blocks_min * MAP_BLOCKSIZE; @@ -2235,11 +2218,11 @@ void makeChunk(ChunkMakeData *data) /* Skip of already generated */ - { + /*{ v3s16 p(p2d.X, y_nodes_min, p2d.Y); if(data->vmanip.m_data[data->vmanip.m_area.index(p)].d != CONTENT_AIR) continue; - } + }*/ // Ground height at this point float surface_y_f = 0.0; @@ -2270,6 +2253,13 @@ void makeChunk(ChunkMakeData *data) u32 i = data->vmanip.m_area.index(v3s16(p2d.X, y_nodes_min, p2d.Y)); for(s16 y=y_nodes_min; yvmanip.m_data[i].d != CONTENT_AIR) + break; + data->vmanip.m_data[i].d = CONTENT_STONE; data->vmanip.m_area.add_y(em, i, 1); @@ -3426,33 +3416,8 @@ void makeChunk(ChunkMakeData *data) //################################################################### //################################################################### -MapChunk* ServerMap::generateChunkRaw(v2s16 chunkpos, - core::map &changed_blocks, - bool force) +void ServerMap::initChunkMake(ChunkMakeData &data, v2s16 chunkpos) { - DSTACK(__FUNCTION_NAME); - - /* - Don't generate if already fully generated - */ - if(force == false) - { - MapChunk *chunk = getChunk(chunkpos); - if(chunk != NULL && chunk->getGenLevel() == GENERATED_FULLY) - { - dstream<<"generateChunkRaw(): Chunk " - <<"("< &changed_blocks) +{ /* Blit generated stuff to map */ @@ -3569,14 +3536,14 @@ MapChunk* ServerMap::generateChunkRaw(v2s16 chunkpos, Add random objects to blocks */ { - for(s16 x=0; xsetIsVolatile(false); @@ -3618,6 +3585,48 @@ MapChunk* ServerMap::generateChunkRaw(v2s16 chunkpos, Save changed parts of map */ save(true); + + return chunk; +} + +// NOTE: Deprecated +MapChunk* ServerMap::generateChunkRaw(v2s16 chunkpos, + core::map &changed_blocks, + bool force) +{ + DSTACK(__FUNCTION_NAME); + + /* + Don't generate if already fully generated + */ + if(force == false) + { + MapChunk *chunk = getChunk(chunkpos); + if(chunk != NULL && chunk->getGenLevel() == GENERATED_FULLY) + { + dstream<<"generateChunkRaw(): Chunk " + <<"("< &changed_blocks) { diff --git a/src/map.h b/src/map.h index 8a004ee6..e2cd432b 100644 --- a/src/map.h +++ b/src/map.h @@ -318,6 +318,8 @@ protected: This is the only map class that is able to generate map. */ +struct ChunkMakeData; + class ServerMap : public Map { public: @@ -391,6 +393,10 @@ public: return true; } + void initChunkMake(ChunkMakeData &data, v2s16 chunkpos); + MapChunk* finishChunkMake(ChunkMakeData &data, + core::map &changed_blocks); + /* Generate a chunk. @@ -746,5 +752,25 @@ protected: bool m_create_area; }; +struct ChunkMakeData +{ + ManualMapVoxelManipulator vmanip; + u64 seed; + v2s16 chunkpos; + s16 y_blocks_min; + s16 y_blocks_max; + v2s16 sectorpos_base; + s16 sectorpos_base_size; + v2s16 sectorpos_bigbase; + s16 sectorpos_bigbase_size; + s16 max_spread_amount; + + ChunkMakeData(): + vmanip(NULL) + {} +}; + +void makeChunk(ChunkMakeData *data); + #endif diff --git a/src/server.cpp b/src/server.cpp index c5703bf3..63d8e31d 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -72,7 +72,7 @@ void * EmergeThread::Thread() DSTACK(__FUNCTION_NAME); - bool debug=false; + //bool debug=false; BEGIN_DEBUG_EXCEPTION_HANDLER @@ -91,7 +91,19 @@ void * EmergeThread::Thread() SharedPtr q(qptr); v3s16 &p = q->pos; - + v2s16 p2d(p.X,p.Z); + + /* + Do not generate over-limit + */ + if(p.X < -MAP_GENERATION_LIMIT / MAP_BLOCKSIZE + || p.X > MAP_GENERATION_LIMIT / MAP_BLOCKSIZE + || 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) + continue; + //derr_server<<"EmergeThread::Thread(): running"<m_env_mutex); - - //envlockwaittimer.stop(); - - //TimeTaker timer("block emerge (while env locked)"); + bool generate_chunk = false; + if(only_from_disk == false) + { + JMutexAutoLock envlock(m_server->m_env_mutex); + if(map.chunkNonVolatile(chunkpos) == false) + generate_chunk = true; + } + if(generate_chunk) + { + ChunkMakeData data; - try{ - - // First check if the block already exists - //block = map.getBlockNoCreate(p); - - if(block == NULL) { - //dstream<<"Calling emergeBlock"<m_env_mutex); + map.initChunkMake(data, chunkpos); } - // If it is a dummy, block was not found on disk - if(block->isDummy()) - { - //dstream<<"EmergeThread: Got a dummy block"<m_env_mutex); + map.finishChunkMake(data, changed_blocks); + } + } + + /* + Fetch block from map or generate a single block + */ + { + JMutexAutoLock envlock(m_server->m_env_mutex); + + // Load sector if it isn't loaded + if(map.getSectorNoGenerateNoEx(p2d) == NULL) + map.loadSectorFull(p2d); + + block = map.getBlockNoCreateNoEx(p); + if(!block || block->isDummy()) + { + if(only_from_disk) { - dstream<<"EmergeThread: wanted to generate a block but got a dummy"<m_env_mutex); if(got_block) { - if(debug && changed_blocks.size() > 0) - { - dout_server<::Iterator i = changed_blocks.getIterator(); - i.atEnd() == false; i++) - { - MapBlock *block = i.getNode()->getValue(); - v3s16 p = block->getPos(); - dout_server<<"("<