1
0
Fork 0

Reverse order of ChunkSender priorities (#4858)

* Reduces confusion when using overloaded operator< and priority_queue

Co-authored-by: peterbell10 <peterbell10@live.co.uk>
This commit is contained in:
Tiger Wang 2020-09-12 20:43:18 +01:00 committed by GitHub
parent 93adbdce9a
commit 198407807f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 31 additions and 34 deletions

View File

@ -770,7 +770,7 @@ void cChunk::BroadcastPendingBlockChanges(void)
// Resend the full chunk
for (auto ClientHandle : m_LoadedByClient)
{
m_World->ForceSendChunkTo(m_PosX, m_PosZ, cChunkSender::E_CHUNK_PRIORITY_MEDIUM, ClientHandle);
m_World->ForceSendChunkTo(m_PosX, m_PosZ, cChunkSender::Priority::Medium, ClientHandle);
}
}
else
@ -1443,7 +1443,7 @@ void cChunk::SetAreaBiome(int a_MinRelX, int a_MaxRelX, int a_MinRelZ, int a_Max
// Re-send the chunk to all clients:
for (auto ClientHandle : m_LoadedByClient)
{
m_World->ForceSendChunkTo(m_PosX, m_PosZ, cChunkSender::E_CHUNK_PRIORITY_MEDIUM, ClientHandle);
m_World->ForceSendChunkTo(m_PosX, m_PosZ, cChunkSender::Priority::Medium, ClientHandle);
} // for itr - m_LoadedByClient[]
}

View File

@ -33,7 +33,7 @@ class cNotifyChunkSender :
a_Coords.m_ChunkX, a_Coords.m_ChunkZ,
[&ChunkSender] (cChunk & a_Chunk) -> bool
{
ChunkSender.QueueSendChunkTo(a_Chunk.GetPosX(), a_Chunk.GetPosZ(), cChunkSender::E_CHUNK_PRIORITY_MIDHIGH, a_Chunk.GetAllClients());
ChunkSender.QueueSendChunkTo(a_Chunk.GetPosX(), a_Chunk.GetPosZ(), cChunkSender::Priority::High, a_Chunk.GetAllClients());
return true;
}
);
@ -89,7 +89,7 @@ void cChunkSender::Stop(void)
void cChunkSender::QueueSendChunkTo(int a_ChunkX, int a_ChunkZ, eChunkPriority a_Priority, cClientHandle * a_Client)
void cChunkSender::QueueSendChunkTo(int a_ChunkX, int a_ChunkZ, Priority a_Priority, cClientHandle * a_Client)
{
ASSERT(a_Client != nullptr);
{
@ -99,7 +99,7 @@ void cChunkSender::QueueSendChunkTo(int a_ChunkX, int a_ChunkZ, eChunkPriority a
if (iter != m_ChunkInfo.end())
{
auto & info = iter->second;
if (info.m_Priority > a_Priority)
if (info.m_Priority < a_Priority) // Was the chunk's priority boosted?
{
m_SendChunks.push(sChunkQueue{a_Priority, Chunk});
info.m_Priority = a_Priority;
@ -121,7 +121,7 @@ void cChunkSender::QueueSendChunkTo(int a_ChunkX, int a_ChunkZ, eChunkPriority a
void cChunkSender::QueueSendChunkTo(int a_ChunkX, int a_ChunkZ, eChunkPriority a_Priority, cChunkClientHandles a_Clients)
void cChunkSender::QueueSendChunkTo(int a_ChunkX, int a_ChunkZ, Priority a_Priority, cChunkClientHandles a_Clients)
{
{
cChunkCoords Chunk{a_ChunkX, a_ChunkZ};
@ -130,7 +130,7 @@ void cChunkSender::QueueSendChunkTo(int a_ChunkX, int a_ChunkZ, eChunkPriority a
if (iter != m_ChunkInfo.end())
{
auto & info = iter->second;
if (info.m_Priority > a_Priority)
if (info.m_Priority < a_Priority) // Was the chunk's priority boosted?
{
m_SendChunks.push(sChunkQueue{a_Priority, Chunk});
info.m_Priority = a_Priority;

View File

@ -58,20 +58,21 @@ public:
cChunkSender(cWorld & a_World);
virtual ~cChunkSender() override;
enum eChunkPriority
/** Tag indicating urgency of chunk to be sent.
Order MUST be from least to most urgent. */
enum class Priority
{
E_CHUNK_PRIORITY_HIGH = 0,
E_CHUNK_PRIORITY_MIDHIGH,
E_CHUNK_PRIORITY_MEDIUM,
E_CHUNK_PRIORITY_LOW,
Low,
Medium,
High,
Critical
};
void Stop(void);
/** Queues a chunk to be sent to a specific client */
void QueueSendChunkTo(int a_ChunkX, int a_ChunkZ, eChunkPriority a_Priority, cClientHandle * a_Client);
void QueueSendChunkTo(int a_ChunkX, int a_ChunkZ, eChunkPriority a_Priority, cChunkClientHandles a_Client);
void QueueSendChunkTo(int a_ChunkX, int a_ChunkZ, Priority a_Priority, cClientHandle * a_Client);
void QueueSendChunkTo(int a_ChunkX, int a_ChunkZ, Priority a_Priority, cChunkClientHandles a_Client);
/** Removes the a_Client from all waiting chunk send operations */
void RemoveClient(cClientHandle * a_Client);
@ -80,18 +81,14 @@ protected:
struct sChunkQueue
{
eChunkPriority m_Priority;
Priority m_Priority;
cChunkCoords m_Chunk;
bool operator <(const sChunkQueue & a_Other) const
{
/* The Standard Priority Queue sorts from biggest to smallest
return true here means you are smaller than the other object, and you get pushed down.
The priorities go from HIGH (0) to LOW (2), so a smaller priority should mean further up the list
therefore, return true (affirm we're "smaller", and get pushed down) only if our priority is bigger than theirs (they're more urgent)
*/
return this->m_Priority > a_Other.m_Priority;
// The operator will return true to affirm we're less urgent than Other
// This comparison depends on the Priority enum ordering lower priority as smaller:
return m_Priority < a_Other.m_Priority;
}
};
@ -100,8 +97,8 @@ protected:
{
cChunkCoords m_Chunk;
std::unordered_set<cClientHandle *> m_Clients;
eChunkPriority m_Priority;
sSendChunk(cChunkCoords a_Chunk, eChunkPriority a_Priority) :
Priority m_Priority;
sSendChunk(cChunkCoords a_Chunk, Priority a_Priority) :
m_Chunk(a_Chunk),
m_Priority(a_Priority)
{

View File

@ -507,7 +507,7 @@ bool cClientHandle::StreamNextChunk(void)
// Unloaded chunk found -> Send it to the client.
Lock.Unlock();
StreamChunk(ChunkX, ChunkZ, ((Range <= 2) ? cChunkSender::E_CHUNK_PRIORITY_HIGH : cChunkSender::E_CHUNK_PRIORITY_MEDIUM));
StreamChunk(ChunkX, ChunkZ, ((Range <= 2) ? cChunkSender::Priority::Critical : cChunkSender::Priority::Medium));
return false;
}
}
@ -545,7 +545,7 @@ bool cClientHandle::StreamNextChunk(void)
// Unloaded chunk found -> Send it to the client.
Lock.Unlock();
StreamChunk(Coords.m_ChunkX, Coords.m_ChunkZ, cChunkSender::E_CHUNK_PRIORITY_LOW);
StreamChunk(Coords.m_ChunkX, Coords.m_ChunkZ, cChunkSender::Priority::Low);
return false;
}
}
@ -609,7 +609,7 @@ void cClientHandle::UnloadOutOfRangeChunks(void)
void cClientHandle::StreamChunk(int a_ChunkX, int a_ChunkZ, cChunkSender::eChunkPriority a_Priority)
void cClientHandle::StreamChunk(int a_ChunkX, int a_ChunkZ, cChunkSender::Priority a_Priority)
{
if (m_State >= csDestroying)
{

View File

@ -571,7 +571,7 @@ private:
bool CheckBlockInteractionsRate(void);
/** Adds a single chunk to be streamed to the client; used by StreamChunks() */
void StreamChunk(int a_ChunkX, int a_ChunkZ, cChunkSender::eChunkPriority a_Priority);
void StreamChunk(int a_ChunkX, int a_ChunkZ, cChunkSender::Priority a_Priority);
/** Handles the DIG_STARTED dig packet: */
void HandleBlockDigStarted (int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, BLOCKTYPE a_OldBlock, NIBBLETYPE a_OldMeta);

View File

@ -2331,7 +2331,7 @@ void cWorld::SetChunkData(cSetChunkData & a_SetChunkData)
ChunkSender.QueueSendChunkTo(
a_Chunk.GetPosX(),
a_Chunk.GetPosZ(),
cChunkSender::E_CHUNK_PRIORITY_MEDIUM,
cChunkSender::Priority::Medium,
a_Chunk.GetAllClients()
);
}
@ -2803,7 +2803,7 @@ void cWorld::RemoveClientFromChunks(cClientHandle * a_Client)
void cWorld::SendChunkTo(int a_ChunkX, int a_ChunkZ, cChunkSender::eChunkPriority a_Priority, cClientHandle * a_Client)
void cWorld::SendChunkTo(int a_ChunkX, int a_ChunkZ, cChunkSender::Priority a_Priority, cClientHandle * a_Client)
{
m_ChunkSender.QueueSendChunkTo(a_ChunkX, a_ChunkZ, a_Priority, a_Client);
}
@ -2812,7 +2812,7 @@ void cWorld::SendChunkTo(int a_ChunkX, int a_ChunkZ, cChunkSender::eChunkPriorit
void cWorld::ForceSendChunkTo(int a_ChunkX, int a_ChunkZ, cChunkSender::eChunkPriority a_Priority, cClientHandle * a_Client)
void cWorld::ForceSendChunkTo(int a_ChunkX, int a_ChunkZ, cChunkSender::Priority a_Priority, cClientHandle * a_Client)
{
a_Client->AddWantedChunk(a_ChunkX, a_ChunkZ);
m_ChunkSender.QueueSendChunkTo(a_ChunkX, a_ChunkZ, a_Priority, a_Client);

View File

@ -344,11 +344,11 @@ public:
/** Sends the chunk to the client specified, if the client doesn't have the chunk yet.
If chunk not valid, the request is postponed (ChunkSender will send that chunk when it becomes valid + lighted). */
void SendChunkTo(int a_ChunkX, int a_ChunkZ, cChunkSender::eChunkPriority a_Priority, cClientHandle * a_Client);
void SendChunkTo(int a_ChunkX, int a_ChunkZ, cChunkSender::Priority a_Priority, cClientHandle * a_Client);
/** Sends the chunk to the client specified, even if the client already has the chunk.
If the chunk's not valid, the request is postponed (ChunkSender will send that chunk when it becomes valid + lighted). */
void ForceSendChunkTo(int a_ChunkX, int a_ChunkZ, cChunkSender::eChunkPriority a_Priority, cClientHandle * a_Client);
void ForceSendChunkTo(int a_ChunkX, int a_ChunkZ, cChunkSender::Priority a_Priority, cClientHandle * a_Client);
/** Removes client from ChunkSender's queue of chunks to be sent */
void RemoveClientFromChunkSender(cClientHandle * a_Client);