summaryrefslogtreecommitdiffstats
path: root/src/Chunk.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Chunk.cpp')
-rw-r--r--src/Chunk.cpp88
1 files changed, 49 insertions, 39 deletions
diff --git a/src/Chunk.cpp b/src/Chunk.cpp
index 4aa28d257..5d54f3c16 100644
--- a/src/Chunk.cpp
+++ b/src/Chunk.cpp
@@ -116,6 +116,55 @@ cChunk::~cChunk()
+void cChunk::BroadcastPendingChanges(void)
+{
+ if (const auto PendingBlocksCount = m_PendingSendBlocks.size(); PendingBlocksCount >= 10240)
+ {
+ // Resend the full chunk:
+ for (const auto ClientHandle : m_LoadedByClient)
+ {
+ m_World->ForceSendChunkTo(m_PosX, m_PosZ, cChunkSender::Priority::Medium, ClientHandle);
+ }
+ }
+ else if (PendingBlocksCount == 0)
+ {
+ // Only send block entity changes:
+ for (const auto ClientHandle : m_LoadedByClient)
+ {
+ for (const auto BlockEntity : m_PendingSendBlockEntities)
+ {
+ BlockEntity->SendTo(*ClientHandle);
+ }
+ }
+ }
+ else
+ {
+ // Send block and block entity changes:
+ for (const auto ClientHandle : m_LoadedByClient)
+ {
+ ClientHandle->SendBlockChanges(m_PosX, m_PosZ, m_PendingSendBlocks);
+
+ for (const auto BlockEntity : m_PendingSendBlockEntities)
+ {
+ BlockEntity->SendTo(*ClientHandle);
+ }
+ }
+ }
+
+ // Flush out all buffered data:
+ for (const auto ClientHandle : m_LoadedByClient)
+ {
+ ClientHandle->ProcessProtocolOut();
+ }
+
+ m_PendingSendBlocks.clear();
+ m_PendingSendBlockEntities.clear();
+}
+
+
+
+
+
void cChunk::SetPresence(cChunk::ePresence a_Presence)
{
m_Presence = a_Presence;
@@ -707,9 +756,6 @@ void cChunk::Tick(std::chrono::milliseconds a_Dt)
// Check blocks after everything else to apply at least one round of queued ticks (i.e. cBlockHandler::Check) this tick:
CheckBlocks();
-
- // Finally, tell the client about all block changes:
- BroadcastPendingBlockChanges();
}
@@ -771,42 +817,6 @@ void cChunk::MoveEntityToNewChunk(OwnedEntity a_Entity)
-void cChunk::BroadcastPendingBlockChanges(void)
-{
- if (const auto PendingBlocksCount = m_PendingSendBlocks.size(); PendingBlocksCount >= 10240)
- {
- // Resend the full chunk:
- for (const auto ClientHandle : m_LoadedByClient)
- {
- m_World->ForceSendChunkTo(m_PosX, m_PosZ, cChunkSender::Priority::Medium, ClientHandle);
- }
- }
- else if (PendingBlocksCount != 0)
- {
- // Send block changes:
- for (const auto ClientHandle : m_LoadedByClient)
- {
- ClientHandle->SendBlockChanges(m_PosX, m_PosZ, m_PendingSendBlocks);
- }
- }
-
- // Send block entity changes:
- for (const auto Entity : m_PendingSendBlockEntities)
- {
- for (const auto ClientHandle : m_LoadedByClient)
- {
- Entity->SendTo(*ClientHandle);
- }
- }
-
- m_PendingSendBlocks.clear();
- m_PendingSendBlockEntities.clear();
-}
-
-
-
-
-
void cChunk::CheckBlocks()
{
cChunkInterface ChunkInterface(m_World->GetChunkMap());