diff options
author | tycho <work.tycho@gmail.com> | 2015-05-31 19:51:31 +0200 |
---|---|---|
committer | tycho <work.tycho@gmail.com> | 2015-06-05 23:31:22 +0200 |
commit | 9ebbe969c887d4fbb0c681b80eae589ce79dbd5d (patch) | |
tree | abfdf76c2cd59b260ba408078dfc00bea93a7198 /src | |
parent | Rewrote ChunkSending queue for significantly improved performance (diff) | |
download | cuberite-9ebbe969c887d4fbb0c681b80eae589ce79dbd5d.tar cuberite-9ebbe969c887d4fbb0c681b80eae589ce79dbd5d.tar.gz cuberite-9ebbe969c887d4fbb0c681b80eae589ce79dbd5d.tar.bz2 cuberite-9ebbe969c887d4fbb0c681b80eae589ce79dbd5d.tar.lz cuberite-9ebbe969c887d4fbb0c681b80eae589ce79dbd5d.tar.xz cuberite-9ebbe969c887d4fbb0c681b80eae589ce79dbd5d.tar.zst cuberite-9ebbe969c887d4fbb0c681b80eae589ce79dbd5d.zip |
Diffstat (limited to 'src')
-rw-r--r-- | src/ChunkSender.cpp | 8 | ||||
-rw-r--r-- | src/ClientHandle.cpp | 27 | ||||
-rw-r--r-- | src/ClientHandle.h | 8 | ||||
-rw-r--r-- | src/World.cpp | 4 |
4 files changed, 22 insertions, 25 deletions
diff --git a/src/ChunkSender.cpp b/src/ChunkSender.cpp index 43b65014a..5790accdb 100644 --- a/src/ChunkSender.cpp +++ b/src/ChunkSender.cpp @@ -31,7 +31,7 @@ class cNotifyChunkSender : { cChunkSender & ChunkSender = m_ChunkSender; m_World.DoWithChunk( - a_ChunkX, a_ChunkZ, + a_ChunkX, a_ChunkZ, [&ChunkSender] (cChunk & a_Chunk) -> bool { ChunkSender.QueueSendChunkTo(a_Chunk.GetPosX(), a_Chunk.GetPosZ(), cChunkSender::PRIORITY_BROADCAST, a_Chunk.GetAllClients()); @@ -161,7 +161,7 @@ void cChunkSender::RemoveClient(cClientHandle * a_Client) for (auto && pair : m_ChunkInfo) { auto && clients = pair.second.m_Clients; - clients.erase(a_Client); // nop for sets that do not contain a_Client + clients.erase(a_Client); // nop for sets that do not contain a_Client } m_RemoveCount++; @@ -222,9 +222,9 @@ void cChunkSender::SendChunk(int a_ChunkX, int a_ChunkZ, std::unordered_set<cCli { // Ask the client if it still wants the chunk: - for(auto itr = a_Clients.begin(); itr != a_Clients.end();) + for (auto itr = a_Clients.begin(); itr != a_Clients.end();) { - if(!(*itr)->WantsSendChunk(a_ChunkX, a_ChunkZ)) + if (!(*itr)->WantsSendChunk(a_ChunkX, a_ChunkZ)) { auto toremove = itr; itr++; diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index d89f7ab77..9ed89e0a3 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -456,7 +456,7 @@ bool cClientHandle::StreamNextChunk(void) // If the chunk already loading / loaded -> skip if ( - (std::find(m_ChunksToSend.begin(), m_ChunksToSend.end(), Coords) != m_ChunksToSend.end()) || + (m_ChunksToSend.find(Coords) != m_ChunksToSend.end()) || (std::find(m_LoadedChunks.begin(), m_LoadedChunks.end(), Coords) != m_LoadedChunks.end()) ) { @@ -494,7 +494,7 @@ bool cClientHandle::StreamNextChunk(void) // If the chunk already loading / loaded -> skip if ( - (std::find(m_ChunksToSend.begin(), m_ChunksToSend.end(), Coords) != m_ChunksToSend.end()) || + (m_ChunksToSend.find(Coords) != m_ChunksToSend.end()) || (std::find(m_LoadedChunks.begin(), m_LoadedChunks.end(), Coords) != m_LoadedChunks.end()) ) { @@ -541,7 +541,7 @@ void cClientHandle::UnloadOutOfRangeChunks(void) } } - for (cChunkCoordsList::iterator itr = m_ChunksToSend.begin(); itr != m_ChunksToSend.end();) + for (auto itr = m_ChunksToSend.begin(); itr != m_ChunksToSend.end();) { int DiffX = Diff((*itr).m_ChunkX, ChunkPosX); int DiffZ = Diff((*itr).m_ChunkZ, ChunkPosZ); @@ -583,7 +583,7 @@ void cClientHandle::StreamChunk(int a_ChunkX, int a_ChunkZ, cChunkSender::eChunk { cCSLock Lock(m_CSChunkLists); m_LoadedChunks.push_back(cChunkCoords(a_ChunkX, a_ChunkZ)); - m_ChunksToSend.push_back(cChunkCoords(a_ChunkX, a_ChunkZ)); + m_ChunksToSend.emplace(a_ChunkX, a_ChunkZ); } World->SendChunkTo(a_ChunkX, a_ChunkZ, a_Priority, this); } @@ -2179,15 +2179,12 @@ void cClientHandle::SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializ bool Found = false; { cCSLock Lock(m_CSChunkLists); - for (cChunkCoordsList::iterator itr = m_ChunksToSend.begin(); itr != m_ChunksToSend.end(); ++itr) + auto itr = m_ChunksToSend.find(cChunkCoords{a_ChunkX, a_ChunkZ}); + if (itr != m_ChunksToSend.end()) { - if ((itr->m_ChunkX == a_ChunkX) && (itr->m_ChunkZ == a_ChunkZ)) - { - m_ChunksToSend.erase(itr); - Found = true; - break; - } - } // for itr - m_ChunksToSend[] + m_ChunksToSend.erase(itr); + Found = true; + } } if (!Found) { @@ -2950,7 +2947,7 @@ bool cClientHandle::WantsSendChunk(int a_ChunkX, int a_ChunkZ) } cCSLock Lock(m_CSChunkLists); - return (std::find(m_ChunksToSend.begin(), m_ChunksToSend.end(), cChunkCoords(a_ChunkX, a_ChunkZ)) != m_ChunksToSend.end()); + return m_ChunksToSend.find(cChunkCoords(a_ChunkX, a_ChunkZ)) != m_ChunksToSend.end(); } @@ -2966,9 +2963,9 @@ void cClientHandle::AddWantedChunk(int a_ChunkX, int a_ChunkZ) LOGD("Adding chunk [%d, %d] to wanted chunks for client %p", a_ChunkX, a_ChunkZ, this); cCSLock Lock(m_CSChunkLists); - if (std::find(m_ChunksToSend.begin(), m_ChunksToSend.end(), cChunkCoords(a_ChunkX, a_ChunkZ)) == m_ChunksToSend.end()) + if (m_ChunksToSend.find(cChunkCoords(a_ChunkX, a_ChunkZ)) == m_ChunksToSend.end()) { - m_ChunksToSend.push_back(cChunkCoords(a_ChunkX, a_ChunkZ)); + m_ChunksToSend.emplace(a_ChunkX, a_ChunkZ); } } diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 13b5f87e4..27acc4d37 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -377,10 +377,10 @@ private: AString m_Password; Json::Value m_Properties; - cCriticalSection m_CSChunkLists; - cChunkCoordsList m_LoadedChunks; // Chunks that the player belongs to - cChunkCoordsList m_ChunksToSend; // Chunks that need to be sent to the player (queued because they weren't generated yet or there's not enough time to send them) - cChunkCoordsList m_SentChunks; // Chunks that are currently sent to the client + cCriticalSection m_CSChunkLists; + cChunkCoordsList m_LoadedChunks; // Chunks that the player belongs to + std::unordered_set<cChunkCoords, cChunkCoordsHash> m_ChunksToSend; // Chunks that need to be sent to the player (queued because they weren't generated yet or there's not enough time to send them) + cChunkCoordsList m_SentChunks; // Chunks that are currently sent to the client cProtocol * m_Protocol; diff --git a/src/World.cpp b/src/World.cpp index ccb6abd0b..3ff8e0723 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -2479,13 +2479,13 @@ void cWorld::SetChunkData(cSetChunkData & a_SetChunkData) int ChunkZ = a_SetChunkData.GetChunkZ(); cChunkSender & ChunkSender = m_ChunkSender; DoWithChunk( - ChunkX, ChunkZ, + ChunkX, ChunkZ, [&ChunkSender] (cChunk & a_Chunk) -> bool { if (a_Chunk.HasAnyClients()) { ChunkSender.QueueSendChunkTo( - a_Chunk.GetPosX(), + a_Chunk.GetPosX(), a_Chunk.GetPosZ(), cChunkSender::PRIORITY_BROADCAST, a_Chunk.GetAllClients() |