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:
parent
93adbdce9a
commit
198407807f
@ -770,7 +770,7 @@ void cChunk::BroadcastPendingBlockChanges(void)
|
|||||||
// Resend the full chunk
|
// Resend the full chunk
|
||||||
for (auto ClientHandle : m_LoadedByClient)
|
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
|
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:
|
// Re-send the chunk to all clients:
|
||||||
for (auto ClientHandle : m_LoadedByClient)
|
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[]
|
} // for itr - m_LoadedByClient[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ class cNotifyChunkSender :
|
|||||||
a_Coords.m_ChunkX, a_Coords.m_ChunkZ,
|
a_Coords.m_ChunkX, a_Coords.m_ChunkZ,
|
||||||
[&ChunkSender] (cChunk & a_Chunk) -> bool
|
[&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;
|
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);
|
ASSERT(a_Client != nullptr);
|
||||||
{
|
{
|
||||||
@ -99,7 +99,7 @@ void cChunkSender::QueueSendChunkTo(int a_ChunkX, int a_ChunkZ, eChunkPriority a
|
|||||||
if (iter != m_ChunkInfo.end())
|
if (iter != m_ChunkInfo.end())
|
||||||
{
|
{
|
||||||
auto & info = iter->second;
|
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});
|
m_SendChunks.push(sChunkQueue{a_Priority, Chunk});
|
||||||
info.m_Priority = a_Priority;
|
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};
|
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())
|
if (iter != m_ChunkInfo.end())
|
||||||
{
|
{
|
||||||
auto & info = iter->second;
|
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});
|
m_SendChunks.push(sChunkQueue{a_Priority, Chunk});
|
||||||
info.m_Priority = a_Priority;
|
info.m_Priority = a_Priority;
|
||||||
|
@ -58,20 +58,21 @@ public:
|
|||||||
cChunkSender(cWorld & a_World);
|
cChunkSender(cWorld & a_World);
|
||||||
virtual ~cChunkSender() override;
|
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,
|
Low,
|
||||||
E_CHUNK_PRIORITY_MIDHIGH,
|
Medium,
|
||||||
E_CHUNK_PRIORITY_MEDIUM,
|
High,
|
||||||
E_CHUNK_PRIORITY_LOW,
|
Critical
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void Stop(void);
|
void Stop(void);
|
||||||
|
|
||||||
/** Queues a chunk to be sent to a specific client */
|
/** 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, Priority 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, cChunkClientHandles a_Client);
|
||||||
|
|
||||||
/** Removes the a_Client from all waiting chunk send operations */
|
/** Removes the a_Client from all waiting chunk send operations */
|
||||||
void RemoveClient(cClientHandle * a_Client);
|
void RemoveClient(cClientHandle * a_Client);
|
||||||
@ -80,18 +81,14 @@ protected:
|
|||||||
|
|
||||||
struct sChunkQueue
|
struct sChunkQueue
|
||||||
{
|
{
|
||||||
eChunkPriority m_Priority;
|
Priority m_Priority;
|
||||||
cChunkCoords m_Chunk;
|
cChunkCoords m_Chunk;
|
||||||
|
|
||||||
bool operator <(const sChunkQueue & a_Other) const
|
bool operator <(const sChunkQueue & a_Other) const
|
||||||
{
|
{
|
||||||
/* The Standard Priority Queue sorts from biggest to smallest
|
// The operator will return true to affirm we're less urgent than Other
|
||||||
return true here means you are smaller than the other object, and you get pushed down.
|
// This comparison depends on the Priority enum ordering lower priority as smaller:
|
||||||
|
return m_Priority < a_Other.m_Priority;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -100,8 +97,8 @@ protected:
|
|||||||
{
|
{
|
||||||
cChunkCoords m_Chunk;
|
cChunkCoords m_Chunk;
|
||||||
std::unordered_set<cClientHandle *> m_Clients;
|
std::unordered_set<cClientHandle *> m_Clients;
|
||||||
eChunkPriority m_Priority;
|
Priority m_Priority;
|
||||||
sSendChunk(cChunkCoords a_Chunk, eChunkPriority a_Priority) :
|
sSendChunk(cChunkCoords a_Chunk, Priority a_Priority) :
|
||||||
m_Chunk(a_Chunk),
|
m_Chunk(a_Chunk),
|
||||||
m_Priority(a_Priority)
|
m_Priority(a_Priority)
|
||||||
{
|
{
|
||||||
|
@ -507,7 +507,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, ((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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -545,7 +545,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(Coords.m_ChunkX, Coords.m_ChunkZ, cChunkSender::E_CHUNK_PRIORITY_LOW);
|
StreamChunk(Coords.m_ChunkX, Coords.m_ChunkZ, cChunkSender::Priority::Low);
|
||||||
return false;
|
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)
|
if (m_State >= csDestroying)
|
||||||
{
|
{
|
||||||
|
@ -571,7 +571,7 @@ private:
|
|||||||
bool CheckBlockInteractionsRate(void);
|
bool CheckBlockInteractionsRate(void);
|
||||||
|
|
||||||
/** Adds a single chunk to be streamed to the client; used by StreamChunks() */
|
/** 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: */
|
/** 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);
|
void HandleBlockDigStarted (int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, BLOCKTYPE a_OldBlock, NIBBLETYPE a_OldMeta);
|
||||||
|
@ -2331,7 +2331,7 @@ void cWorld::SetChunkData(cSetChunkData & a_SetChunkData)
|
|||||||
ChunkSender.QueueSendChunkTo(
|
ChunkSender.QueueSendChunkTo(
|
||||||
a_Chunk.GetPosX(),
|
a_Chunk.GetPosX(),
|
||||||
a_Chunk.GetPosZ(),
|
a_Chunk.GetPosZ(),
|
||||||
cChunkSender::E_CHUNK_PRIORITY_MEDIUM,
|
cChunkSender::Priority::Medium,
|
||||||
a_Chunk.GetAllClients()
|
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);
|
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);
|
a_Client->AddWantedChunk(a_ChunkX, a_ChunkZ);
|
||||||
m_ChunkSender.QueueSendChunkTo(a_ChunkX, a_ChunkZ, a_Priority, a_Client);
|
m_ChunkSender.QueueSendChunkTo(a_ChunkX, a_ChunkZ, a_Priority, a_Client);
|
||||||
|
@ -344,11 +344,11 @@ public:
|
|||||||
|
|
||||||
/** Sends the chunk to the client specified, if the client doesn't have the chunk yet.
|
/** 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). */
|
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.
|
/** 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). */
|
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 */
|
/** Removes client from ChunkSender's queue of chunks to be sent */
|
||||||
void RemoveClientFromChunkSender(cClientHandle * a_Client);
|
void RemoveClientFromChunkSender(cClientHandle * a_Client);
|
||||||
|
Loading…
Reference in New Issue
Block a user