From 198407807f1241ea2b06179bcc036f9373c7258e Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 12 Sep 2020 20:43:18 +0100 Subject: Reverse order of ChunkSender priorities (#4858) * Reduces confusion when using overloaded operator< and priority_queue Co-authored-by: peterbell10 --- src/ChunkSender.h | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) (limited to 'src/ChunkSender.h') diff --git a/src/ChunkSender.h b/src/ChunkSender.h index 2d9c478e9..be7b55b16 100644 --- a/src/ChunkSender.h +++ b/src/ChunkSender.h @@ -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 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) { -- cgit v1.2.3