summaryrefslogtreecommitdiffstats
path: root/src/ChunkSender.cpp
diff options
context:
space:
mode:
authorHowaner <franzi.moos@googlemail.com>2014-10-21 17:35:23 +0200
committerHowaner <franzi.moos@googlemail.com>2014-10-21 17:35:23 +0200
commitb0988e65aadc1a9d33065cf6afefc05dbf768ef8 (patch)
treead2b28cef36bfb02e5b51e9394f064c2dec7a4a9 /src/ChunkSender.cpp
parentNew c++11 stuff. (diff)
downloadcuberite-b0988e65aadc1a9d33065cf6afefc05dbf768ef8.tar
cuberite-b0988e65aadc1a9d33065cf6afefc05dbf768ef8.tar.gz
cuberite-b0988e65aadc1a9d33065cf6afefc05dbf768ef8.tar.bz2
cuberite-b0988e65aadc1a9d33065cf6afefc05dbf768ef8.tar.lz
cuberite-b0988e65aadc1a9d33065cf6afefc05dbf768ef8.tar.xz
cuberite-b0988e65aadc1a9d33065cf6afefc05dbf768ef8.tar.zst
cuberite-b0988e65aadc1a9d33065cf6afefc05dbf768ef8.zip
Diffstat (limited to '')
-rw-r--r--src/ChunkSender.cpp48
1 files changed, 35 insertions, 13 deletions
diff --git a/src/ChunkSender.cpp b/src/ChunkSender.cpp
index 2a953db1f..680f34bce 100644
--- a/src/ChunkSender.cpp
+++ b/src/ChunkSender.cpp
@@ -95,18 +95,23 @@ void cChunkSender::QueueSendChunkTo(int a_ChunkX, int a_ChunkZ, eChunkPriority a
{
ASSERT(a_Client != NULL);
{
- sSendChunk Chunk(a_ChunkX, a_ChunkZ, a_Priority, a_Client);
+ sSendChunk Chunk(a_ChunkX, a_ChunkZ, a_Client);
cCSLock Lock(m_CS);
- if (std::find(m_SendChunks.begin(), m_SendChunks.end(), Chunk) != m_SendChunks.end())
+ if (
+ std::find(m_SendChunksLowPriority.begin(), m_SendChunksLowPriority.end(), Chunk) != m_SendChunksLowPriority.end() ||
+ std::find(m_SendChunksHighPriority.begin(), m_SendChunksHighPriority.end(), Chunk) != m_SendChunksHighPriority.end()
+ )
{
// Already queued, bail out
return;
}
- m_SendChunks.push_back(Chunk);
- // Sort the list:
- m_SendChunks.sort();
+ if (a_Priority == E_CHUNK_PRIORITY_LOW) {
+ m_SendChunksLowPriority.push_back(Chunk);
+ } else if (a_Priority == E_CHUNK_PRIORITY_HIGH) {
+ m_SendChunksHighPriority.push_back(Chunk);
+ }
}
m_evtQueue.Set();
}
@@ -119,15 +124,23 @@ void cChunkSender::RemoveClient(cClientHandle * a_Client)
{
{
cCSLock Lock(m_CS);
- for (sSendChunkList::iterator itr = m_SendChunks.begin(); itr != m_SendChunks.end();)
+ for (sSendChunkList::iterator itr = m_SendChunksLowPriority.begin(); itr != m_SendChunksLowPriority.end();)
{
if (itr->m_Client == a_Client)
{
- itr = m_SendChunks.erase(itr);
+ itr = m_SendChunksLowPriority.erase(itr);
+ continue;
+ }
+ ++itr;
+ } // for itr - m_SendChunksLowPriority[]
+ for (sSendChunkList::iterator itr = m_SendChunksHighPriority.begin(); itr != m_SendChunksHighPriority.end();)
+ {
+ if (itr->m_Client == a_Client) {
+ itr = m_SendChunksHighPriority.erase(itr);
continue;
}
++itr;
- } // for itr - m_SendChunks[]
+ } // for itr - m_SendChunksHighPriority[]
m_RemoveCount++;
}
m_evtQueue.Set();
@@ -143,7 +156,7 @@ void cChunkSender::Execute(void)
while (!m_ShouldTerminate)
{
cCSLock Lock(m_CS);
- while (m_ChunksReady.empty() && m_SendChunks.empty())
+ while (m_ChunksReady.empty() && m_SendChunksLowPriority.empty() && m_SendChunksHighPriority.empty())
{
int RemoveCount = m_RemoveCount;
m_RemoveCount = 0;
@@ -158,8 +171,17 @@ void cChunkSender::Execute(void)
return;
}
} // while (empty)
-
- if (!m_ChunksReady.empty())
+
+ if (!m_SendChunksHighPriority.empty())
+ {
+ // Take one from the queue:
+ sSendChunk Chunk(m_SendChunksHighPriority.front());
+ m_SendChunksHighPriority.pop_front();
+ Lock.Unlock();
+
+ SendChunk(Chunk.m_ChunkX, Chunk.m_ChunkZ, Chunk.m_Client);
+ }
+ else if (!m_ChunksReady.empty())
{
// Take one from the queue:
cChunkCoords Coords(m_ChunksReady.front());
@@ -171,8 +193,8 @@ void cChunkSender::Execute(void)
else
{
// Take one from the queue:
- sSendChunk Chunk(m_SendChunks.front());
- m_SendChunks.pop_front();
+ sSendChunk Chunk(m_SendChunksLowPriority.front());
+ m_SendChunksLowPriority.pop_front();
Lock.Unlock();
SendChunk(Chunk.m_ChunkX, Chunk.m_ChunkZ, Chunk.m_Client);