1
0

Server uses ~40% less CPU now

git-svn-id: http://mc-server.googlecode.com/svn/trunk@339 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
faketruth 2012-02-28 14:22:03 +00:00
parent 0f88ed7c72
commit ac117959d3
2 changed files with 95 additions and 89 deletions

View File

@ -393,15 +393,20 @@ void cChunk::Tick(float a_Dt, MTRand & a_TickRandom)
} }
cCSLock Lock2(m_CSBlockLists); cCSLock Lock2(m_CSBlockLists);
std::map< unsigned int, int > ToTickBlocks = m_ToTickBlocks; unsigned int NumTickBlocks = m_ToTickBlocks.size();
Lock2.Unlock();
if( NumTickBlocks > 0 )
{
Lock2.Lock();
std::deque< unsigned int > ToTickBlocks = m_ToTickBlocks;
m_ToTickBlocks.clear(); m_ToTickBlocks.clear();
Lock2.Unlock(); Lock2.Unlock();
bool isRedstone = false; bool isRedstone = false;
for( std::map< unsigned int, int>::iterator itr = ToTickBlocks.begin(); itr != ToTickBlocks.end(); ++itr ) for( std::deque< unsigned int >::iterator itr = ToTickBlocks.begin(); itr != ToTickBlocks.end(); ++itr )
{ {
if( (*itr).second < 0 ) continue; unsigned int index = (*itr);
unsigned int index = (*itr).first;
int Y = index % 128; int Y = index % 128;
int Z = (index / 128) % 16; int Z = (index / 128) % 16;
int X = (index / (128*16)); int X = (index / (128*16));
@ -487,6 +492,7 @@ void cChunk::Tick(float a_Dt, MTRand & a_TickRandom)
break; break;
}; };
} }
}
// Tick dem blocks // Tick dem blocks
int RandomX = a_TickRandom.randInt(); int RandomX = a_TickRandom.randInt();
@ -899,13 +905,13 @@ void cChunk::SetBlock( int a_X, int a_Y, int a_Z, char a_BlockType, char a_Block
} }
} }
m_ToTickBlocks[ MakeIndex( a_X, a_Y, a_Z ) ]++; m_ToTickBlocks.push_back( MakeIndex( a_X, a_Y, a_Z ) );
m_ToTickBlocks[ MakeIndex( a_X+1, a_Y, a_Z ) ]++; m_ToTickBlocks.push_back( MakeIndex( a_X+1, a_Y, a_Z ) );
m_ToTickBlocks[ MakeIndex( a_X-1, a_Y, a_Z ) ]++; m_ToTickBlocks.push_back( MakeIndex( a_X-1, a_Y, a_Z ) );
m_ToTickBlocks[ MakeIndex( a_X, a_Y+1, a_Z ) ]++; m_ToTickBlocks.push_back( MakeIndex( a_X, a_Y+1, a_Z ) );
m_ToTickBlocks[ MakeIndex( a_X, a_Y-1, a_Z ) ]++; m_ToTickBlocks.push_back( MakeIndex( a_X, a_Y-1, a_Z ) );
m_ToTickBlocks[ MakeIndex( a_X, a_Y, a_Z+1 ) ]++; m_ToTickBlocks.push_back( MakeIndex( a_X, a_Y, a_Z+1 ) );
m_ToTickBlocks[ MakeIndex( a_X, a_Y, a_Z-1 ) ]++; m_ToTickBlocks.push_back( MakeIndex( a_X, a_Y, a_Z-1 ) );
cBlockEntity* BlockEntity = GetBlockEntity( a_X + m_PosX * 16, a_Y + m_PosY * 128, a_Z + m_PosZ * 16 ); cBlockEntity* BlockEntity = GetBlockEntity( a_X + m_PosX * 16, a_Y + m_PosY * 128, a_Z + m_PosZ * 16 );
if( BlockEntity ) if( BlockEntity )

View File

@ -236,7 +236,7 @@ private:
bool m_HasLoadFailed; // True if chunk failed to load and hasn't been generated yet since then bool m_HasLoadFailed; // True if chunk failed to load and hasn't been generated yet since then
cCriticalSection m_CSBlockLists; cCriticalSection m_CSBlockLists;
std::map< unsigned int, int > m_ToTickBlocks; std::deque< unsigned int > m_ToTickBlocks;
std::vector< unsigned int > m_PendingSendBlocks; std::vector< unsigned int > m_PendingSendBlocks;
// A critical section is not needed, because all chunk access is protected by its parent ChunkMap's csLayers // A critical section is not needed, because all chunk access is protected by its parent ChunkMap's csLayers