summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@outlook.com>2020-12-24 17:26:23 +0100
committerTiger Wang <ziwei.tiger@outlook.com>2020-12-26 18:55:45 +0100
commitabc96bb4ce0bfb5627e74f4f2e66f19eaaa12736 (patch)
tree113bc629a9ee624ac8ec8863567a3ad379347392
parentStreamline ClientHandle chunk send a little (diff)
downloadcuberite-abc96bb4ce0bfb5627e74f4f2e66f19eaaa12736.tar
cuberite-abc96bb4ce0bfb5627e74f4f2e66f19eaaa12736.tar.gz
cuberite-abc96bb4ce0bfb5627e74f4f2e66f19eaaa12736.tar.bz2
cuberite-abc96bb4ce0bfb5627e74f4f2e66f19eaaa12736.tar.lz
cuberite-abc96bb4ce0bfb5627e74f4f2e66f19eaaa12736.tar.xz
cuberite-abc96bb4ce0bfb5627e74f4f2e66f19eaaa12736.tar.zst
cuberite-abc96bb4ce0bfb5627e74f4f2e66f19eaaa12736.zip
Diffstat (limited to '')
-rw-r--r--src/ClientHandle.cpp44
1 files changed, 22 insertions, 22 deletions
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 916de10c7..89fe3d3b9 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -514,37 +514,37 @@ bool cClientHandle::StreamNextChunk(void)
// Low priority: Add all chunks that are in range. (From the center out to the edge)
for (int d = 0; d <= m_CurrentViewDistance; ++d) // cycle through (square) distance, from nearest to furthest
{
- // For each distance add chunks in a hollow square centered around current position:
- cChunkCoordsList CurcleChunks;
- for (int i = -d; i <= d; ++i)
- {
- CurcleChunks.push_back(cChunkCoords(ChunkPosX + d, ChunkPosZ + i));
- CurcleChunks.push_back(cChunkCoords(ChunkPosX - d, ChunkPosZ + i));
- }
- for (int i = -d + 1; i < d; ++i)
- {
- CurcleChunks.push_back(cChunkCoords(ChunkPosX + i, ChunkPosZ + d));
- CurcleChunks.push_back(cChunkCoords(ChunkPosX + i, ChunkPosZ - d));
- }
-
- // For each the CurcleChunks list and send the first unloaded chunk:
- for (cChunkCoordsList::iterator itr = CurcleChunks.begin(), end = CurcleChunks.end(); itr != end; ++itr)
+ const auto StreamIfUnloaded = [this, &Lock](const cChunkCoords Chunk)
{
- cChunkCoords Coords = *itr;
-
// If the chunk already loading / loaded -> skip
if (
- (m_ChunksToSend.find(Coords) != m_ChunksToSend.end()) ||
- (m_LoadedChunks.find(Coords) != m_LoadedChunks.end())
+ (m_ChunksToSend.find(Chunk) != m_ChunksToSend.end()) ||
+ (m_LoadedChunks.find(Chunk) != m_LoadedChunks.end())
)
{
- continue;
+ return false;
}
// Unloaded chunk found -> Send it to the client.
Lock.Unlock();
- StreamChunk(Coords.m_ChunkX, Coords.m_ChunkZ, cChunkSender::Priority::Low);
- return false;
+ StreamChunk(Chunk.m_ChunkX, Chunk.m_ChunkZ, cChunkSender::Priority::Low);
+ return true;
+ };
+
+ // For each distance, send the first unloaded chunk in a hollow square centered around current position:
+ for (int i = -d; i <= d; ++i)
+ {
+ if (StreamIfUnloaded({ ChunkPosX + d, ChunkPosZ + i }) || StreamIfUnloaded({ ChunkPosX - d, ChunkPosZ + i }))
+ {
+ return false;
+ }
+ }
+ for (int i = -d + 1; i < d; ++i)
+ {
+ if (StreamIfUnloaded({ ChunkPosX + i, ChunkPosZ + d }) || StreamIfUnloaded({ ChunkPosX + i, ChunkPosZ - d }))
+ {
+ return false;
+ }
}
}