Skip to content

Commit

Permalink
Use 3 priorities.
Browse files Browse the repository at this point in the history
  • Loading branch information
Howaner committed Oct 23, 2014
1 parent 72bb299 commit 9af58a8
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Chunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
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[]
}

Expand Down
44 changes: 40 additions & 4 deletions src/ChunkSender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,35 @@ void cChunkSender::QueueSendChunkTo(int a_ChunkX, int a_ChunkZ, eChunkPriority a
cCSLock Lock(m_CS);
if (
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()
)
{
// Already queued, bail out
return;
}

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);
switch (a_Priority)
{
case E_CHUNK_PRIORITY_LOW:
{
m_SendChunksLowPriority.push_back(Chunk);
break;
}
case E_CHUNK_PRIORITY_MEDIUM:
{
m_SendChunksMediumPriority.push_back(Chunk);
break;
}
case E_CHUNK_PRIORITY_HIGH:
{
m_SendChunksHighPriority.push_back(Chunk);
break;
}
default:
{
ASSERT(!"Unknown chunk priority!");
}
}
}
m_evtQueue.Set();
Expand All @@ -133,6 +151,15 @@ void cChunkSender::RemoveClient(cClientHandle * a_Client)
}
++itr;
} // 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();)
{
if (itr->m_Client == a_Client)
Expand Down Expand Up @@ -191,6 +218,15 @@ void cChunkSender::Execute(void)

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
{
// Take one from the queue:
Expand Down
4 changes: 3 additions & 1 deletion src/ChunkSender.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ class cChunkSender:
enum eChunkPriority
{
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);
Expand Down Expand Up @@ -143,6 +144,7 @@ class cChunkSender:
cCriticalSection m_CS;
cChunkCoordsList m_ChunksReady;
sSendChunkList m_SendChunksLowPriority;
sSendChunkList m_SendChunksMediumPriority;
sSendChunkList m_SendChunksHighPriority;
cEvent m_evtQueue; // Set when anything is added to m_ChunksReady
cEvent m_evtRemoved; // Set when removed clients are safe to be deleted
Expand Down
2 changes: 1 addition & 1 deletion src/ClientHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ bool cClientHandle::StreamNextChunk(void)

// Unloaded chunk found -> Send it to the client.
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;
}
}
Expand Down

0 comments on commit 9af58a8

Please sign in to comment.