Use std::queue for the block tick queue
This commit is contained in:
parent
71ffa76847
commit
b205d233bd
|
@ -812,23 +812,21 @@ void cChunk::BroadcastPendingBlockChanges(void)
|
||||||
|
|
||||||
void cChunk::CheckBlocks()
|
void cChunk::CheckBlocks()
|
||||||
{
|
{
|
||||||
if (m_ToTickBlocks.empty())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
std::vector<Vector3i> ToTickBlocks;
|
|
||||||
std::swap(m_ToTickBlocks, ToTickBlocks);
|
|
||||||
|
|
||||||
cChunkInterface ChunkInterface(m_World->GetChunkMap());
|
cChunkInterface ChunkInterface(m_World->GetChunkMap());
|
||||||
cBlockInServerPluginInterface PluginInterface(*m_World);
|
cBlockInServerPluginInterface PluginInterface(*m_World);
|
||||||
|
|
||||||
for (std::vector<Vector3i>::const_iterator itr = ToTickBlocks.begin(), end = ToTickBlocks.end(); itr != end; ++itr)
|
// Process a limited number of blocks since cBlockHandler::Check may queue more to tick
|
||||||
|
auto Count = m_ToTickBlocks.size();
|
||||||
|
|
||||||
|
while (Count != 0)
|
||||||
{
|
{
|
||||||
Vector3i Pos = (*itr);
|
Vector3i Pos = m_ToTickBlocks.front();
|
||||||
|
m_ToTickBlocks.pop();
|
||||||
|
Count--;
|
||||||
|
|
||||||
cBlockHandler * Handler = BlockHandler(GetBlock(Pos));
|
cBlockHandler * Handler = BlockHandler(GetBlock(Pos));
|
||||||
Handler->Check(ChunkInterface, PluginInterface, Pos, *this);
|
Handler->Check(ChunkInterface, PluginInterface, Pos, *this);
|
||||||
} // for itr - ToTickBlocks[]
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -594,7 +594,7 @@ private:
|
||||||
bool m_IsSaving; // True if the chunk is being saved
|
bool m_IsSaving; // True if the chunk is being saved
|
||||||
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
|
||||||
|
|
||||||
std::vector<Vector3i> m_ToTickBlocks;
|
std::queue<Vector3i> m_ToTickBlocks;
|
||||||
sSetBlockVector m_PendingSendBlocks; ///< Blocks that have changed and need to be sent to all clients
|
sSetBlockVector m_PendingSendBlocks; ///< Blocks that have changed and need to be sent to all clients
|
||||||
|
|
||||||
// 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
|
||||||
|
|
Loading…
Reference in New Issue