1
0

Use 3 priorities.

This commit is contained in:
Howaner 2014-10-23 21:19:43 +02:00
parent 72bb299a4a
commit 9af58a81d6
4 changed files with 45 additions and 7 deletions

View File

@ -1742,7 +1742,7 @@ void cChunk::SetAreaBiome(int a_MinRelX, int a_MaxRelX, int a_MinRelZ, int a_Max
// Re-send the chunk to all clients: // Re-send the chunk to all clients:
for (cClientHandleList::iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr) for (cClientHandleList::iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
{ {
m_World->ForceSendChunkTo(m_PosX, m_PosZ, cChunkSender::E_CHUNK_PRIORITY_HIGH, (*itr)); m_World->ForceSendChunkTo(m_PosX, m_PosZ, cChunkSender::E_CHUNK_PRIORITY_MEDIUM, (*itr));
} // for itr - m_LoadedByClient[] } // for itr - m_LoadedByClient[]
} }

View File

@ -100,6 +100,7 @@ void cChunkSender::QueueSendChunkTo(int a_ChunkX, int a_ChunkZ, eChunkPriority a
cCSLock Lock(m_CS); cCSLock Lock(m_CS);
if ( if (
std::find(m_SendChunksLowPriority.begin(), m_SendChunksLowPriority.end(), Chunk) != m_SendChunksLowPriority.end() || std::find(m_SendChunksLowPriority.begin(), m_SendChunksLowPriority.end(), Chunk) != m_SendChunksLowPriority.end() ||
std::find(m_SendChunksMediumPriority.begin(), m_SendChunksMediumPriority.end(), Chunk) != m_SendChunksMediumPriority.end() ||
std::find(m_SendChunksHighPriority.begin(), m_SendChunksHighPriority.end(), Chunk) != m_SendChunksHighPriority.end() std::find(m_SendChunksHighPriority.begin(), m_SendChunksHighPriority.end(), Chunk) != m_SendChunksHighPriority.end()
) )
{ {
@ -107,10 +108,27 @@ void cChunkSender::QueueSendChunkTo(int a_ChunkX, int a_ChunkZ, eChunkPriority a
return; return;
} }
if (a_Priority == E_CHUNK_PRIORITY_LOW) { switch (a_Priority)
{
case E_CHUNK_PRIORITY_LOW:
{
m_SendChunksLowPriority.push_back(Chunk); m_SendChunksLowPriority.push_back(Chunk);
} else if (a_Priority == E_CHUNK_PRIORITY_HIGH) { break;
}
case E_CHUNK_PRIORITY_MEDIUM:
{
m_SendChunksMediumPriority.push_back(Chunk);
break;
}
case E_CHUNK_PRIORITY_HIGH:
{
m_SendChunksHighPriority.push_back(Chunk); m_SendChunksHighPriority.push_back(Chunk);
break;
}
default:
{
ASSERT(!"Unknown chunk priority!");
}
} }
} }
m_evtQueue.Set(); m_evtQueue.Set();
@ -133,6 +151,15 @@ void cChunkSender::RemoveClient(cClientHandle * a_Client)
} }
++itr; ++itr;
} // for itr - m_SendChunksLowPriority[] } // for itr - m_SendChunksLowPriority[]
for (sSendChunkList::iterator itr = m_SendChunksMediumPriority.begin(); itr != m_SendChunksMediumPriority.end();)
{
if (itr->m_Client == a_Client)
{
itr = m_SendChunksMediumPriority.erase(itr);
continue;
}
++itr;
} // for itr - m_SendChunksMediumPriority[]
for (sSendChunkList::iterator itr = m_SendChunksHighPriority.begin(); itr != m_SendChunksHighPriority.end();) for (sSendChunkList::iterator itr = m_SendChunksHighPriority.begin(); itr != m_SendChunksHighPriority.end();)
{ {
if (itr->m_Client == a_Client) if (itr->m_Client == a_Client)
@ -191,6 +218,15 @@ void cChunkSender::Execute(void)
SendChunk(Coords.m_ChunkX, Coords.m_ChunkZ, nullptr); SendChunk(Coords.m_ChunkX, Coords.m_ChunkZ, nullptr);
} }
else if (!m_SendChunksMediumPriority.empty())
{
// Take one from the queue:
sSendChunk Chunk(m_SendChunksMediumPriority.front());
m_SendChunksMediumPriority.pop_front();
Lock.Unlock();
SendChunk(Chunk.m_ChunkX, Chunk.m_ChunkZ, Chunk.m_Client);
}
else else
{ {
// Take one from the queue: // Take one from the queue:

View File

@ -79,7 +79,8 @@ public:
enum eChunkPriority enum eChunkPriority
{ {
E_CHUNK_PRIORITY_HIGH = 0, E_CHUNK_PRIORITY_HIGH = 0,
E_CHUNK_PRIORITY_LOW = 1, E_CHUNK_PRIORITY_MEDIUM = 1,
E_CHUNK_PRIORITY_LOW = 2,
}; };
bool Start(cWorld * a_World); bool Start(cWorld * a_World);
@ -143,6 +144,7 @@ protected:
cCriticalSection m_CS; cCriticalSection m_CS;
cChunkCoordsList m_ChunksReady; cChunkCoordsList m_ChunksReady;
sSendChunkList m_SendChunksLowPriority; sSendChunkList m_SendChunksLowPriority;
sSendChunkList m_SendChunksMediumPriority;
sSendChunkList m_SendChunksHighPriority; sSendChunkList m_SendChunksHighPriority;
cEvent m_evtQueue; // Set when anything is added to m_ChunksReady cEvent m_evtQueue; // Set when anything is added to m_ChunksReady
cEvent m_evtRemoved; // Set when removed clients are safe to be deleted cEvent m_evtRemoved; // Set when removed clients are safe to be deleted

View File

@ -463,7 +463,7 @@ bool cClientHandle::StreamNextChunk(void)
// Unloaded chunk found -> Send it to the client. // Unloaded chunk found -> Send it to the client.
Lock.Unlock(); Lock.Unlock();
StreamChunk(ChunkX, ChunkZ, cChunkSender::E_CHUNK_PRIORITY_HIGH); StreamChunk(ChunkX, ChunkZ, ((Range <= 2) ? cChunkSender::E_CHUNK_PRIORITY_HIGH : cChunkSender::E_CHUNK_PRIORITY_MEDIUM));
return false; return false;
} }
} }