From 3a8d2aa421fcfa11a84a911aaaa6b5aa4e16cab3 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Sat, 18 Feb 2012 20:10:57 +0000 Subject: Substantial cWorld::FastSetBlock() speed up by queueing all such calls and processing them later chunk-wise (makes growing trees in the generator fast again) git-svn-id: http://mc-server.googlecode.com/svn/trunk@295 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cWorld.cpp | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) (limited to 'source/cWorld.cpp') diff --git a/source/cWorld.cpp b/source/cWorld.cpp index 41b9c5068..f5e40ec0b 100644 --- a/source/cWorld.cpp +++ b/source/cWorld.cpp @@ -503,17 +503,18 @@ void cWorld::Tick(float a_Dt) TickWeather(a_Dt); - // Asynchronously set blocks - FastSetBlockList FastSetBlockQueueCopy; + // Asynchronously set blocks: + sSetBlockList FastSetBlockQueueCopy; { cCSLock Lock(m_CSFastSetBlock); - FastSetBlockQueueCopy = m_FastSetBlockQueue; - m_FastSetBlockQueue.clear(); + std::swap(FastSetBlockQueueCopy, m_FastSetBlockQueue); } - for ( FastSetBlockList::iterator itr = FastSetBlockQueueCopy.begin(); itr != FastSetBlockQueueCopy.end(); ++itr ) + m_ChunkMap->FastSetBlocks(FastSetBlockQueueCopy); + if (FastSetBlockQueueCopy.size() > 0) { - sSetBlockData & SetBlockData = *itr; - FastSetBlock( SetBlockData.x, SetBlockData.y, SetBlockData.z, SetBlockData.BlockID, SetBlockData.BlockMeta ); // If unable to set block, it's added to FastSetBlockQueue again + // Some blocks failed, store them for next tick: + cCSLock Lock(m_CSFastSetBlock); + m_FastSetBlockQueue.splice(m_FastSetBlockQueue.end(), FastSetBlockQueueCopy); } if( m_Time - m_LastSave > 60 * 5 ) // Save each 5 minutes @@ -847,20 +848,8 @@ void cWorld::SetBlock( int a_X, int a_Y, int a_Z, char a_BlockType, char a_Block void cWorld::FastSetBlock( int a_X, int a_Y, int a_Z, char a_BlockType, char a_BlockMeta ) { - int ChunkX, ChunkY, ChunkZ, X = a_X, Y = a_Y, Z = a_Z; - - AbsoluteToRelative( X, Y, Z, ChunkX, ChunkY, ChunkZ ); - - cChunkPtr Chunk = GetChunkNoGen( ChunkX, ChunkY, ChunkZ ); - if (Chunk->IsValid()) - { - Chunk->FastSetBlock(X, Y, Z, a_BlockType, a_BlockMeta ); - return; - } - - // Unable to set block right now, try again later cCSLock Lock(m_CSFastSetBlock); - m_FastSetBlockQueue.push_back( sSetBlockData( a_X, a_Y, a_Z, a_BlockType, a_BlockMeta ) ); + m_FastSetBlockQueue.push_back(sSetBlock(a_X, a_Y, a_Z, a_BlockType, a_BlockMeta)); } -- cgit v1.2.3