summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/Chunk.cpp4
-rw-r--r--src/ChunkSender.cpp10
-rw-r--r--src/ChunkSender.h33
-rw-r--r--src/ClientHandle.cpp6
-rw-r--r--src/ClientHandle.h2
-rw-r--r--src/World.cpp6
-rw-r--r--src/World.h4
7 files changed, 31 insertions, 34 deletions
diff --git a/src/Chunk.cpp b/src/Chunk.cpp
index 3f6a653a4..3abdc6ff8 100644
--- a/src/Chunk.cpp
+++ b/src/Chunk.cpp
@@ -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[]
}
diff --git a/src/ChunkSender.cpp b/src/ChunkSender.cpp
index e00b86795..c93a764b2 100644
--- a/src/ChunkSender.cpp
+++ b/src/ChunkSender.cpp
@@ -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;
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<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)
{
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 098a67afd..690998711 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -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)
{
diff --git a/src/ClientHandle.h b/src/ClientHandle.h
index cf5139fef..0346e2a24 100644
--- a/src/ClientHandle.h
+++ b/src/ClientHandle.h
@@ -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);
diff --git a/src/World.cpp b/src/World.cpp
index d99c9c607..b1f2a29df 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -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);
diff --git a/src/World.h b/src/World.h
index 8277f8117..b6b8ad8bc 100644
--- a/src/World.h
+++ b/src/World.h
@@ -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);