diff options
author | Mattes D <github@xoft.cz> | 2014-10-16 21:12:26 +0200 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2014-10-16 21:12:26 +0200 |
commit | 8c2a99711e98ccfc2f6f31777a8b4e74e40c616c (patch) | |
tree | 64b8f0a43f1f71444b7d544f4240b95bde29ed6d /src | |
parent | Merge pull request #1541 from mc-server/VariadicTemplates (diff) | |
download | cuberite-8c2a99711e98ccfc2f6f31777a8b4e74e40c616c.tar cuberite-8c2a99711e98ccfc2f6f31777a8b4e74e40c616c.tar.gz cuberite-8c2a99711e98ccfc2f6f31777a8b4e74e40c616c.tar.bz2 cuberite-8c2a99711e98ccfc2f6f31777a8b4e74e40c616c.tar.lz cuberite-8c2a99711e98ccfc2f6f31777a8b4e74e40c616c.tar.xz cuberite-8c2a99711e98ccfc2f6f31777a8b4e74e40c616c.tar.zst cuberite-8c2a99711e98ccfc2f6f31777a8b4e74e40c616c.zip |
Diffstat (limited to 'src')
-rw-r--r-- | src/ClientHandle.cpp | 37 | ||||
-rw-r--r-- | src/ClientHandle.h | 1 |
2 files changed, 35 insertions, 3 deletions
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 344b2f2c2..f244e8fea 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -540,9 +540,11 @@ void cClientHandle::RemoveFromAllChunks() } { + // Reset all chunk lists: cCSLock Lock(m_CSChunkLists); m_LoadedChunks.clear(); m_ChunksToSend.clear(); + m_SentChunks.clear(); // Also reset the LastStreamedChunk coords to bogus coords, // so that all chunks are streamed in subsequent StreamChunks() call (FS #407) @@ -2027,7 +2029,17 @@ void cClientHandle::SendBlockBreakAnim(int a_EntityID, int a_BlockX, int a_Block void cClientHandle::SendBlockChange(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) { - m_Protocol->SendBlockChange(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta); + int ChunkX, ChunkZ = 0; + cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, ChunkX, ChunkZ); + cChunkCoords ChunkCoords = cChunkCoords(ChunkX, ChunkZ); + + // Do not send block changes in chunks that weren't sent to the client yet: + cCSLock Lock(m_CSChunkLists); + if (std::find(m_SentChunks.begin(), m_SentChunks.end(), ChunkCoords) != m_SentChunks.end()) + { + Lock.Unlock(); + m_Protocol->SendBlockChange(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta); + } } @@ -2037,8 +2049,15 @@ void cClientHandle::SendBlockChange(int a_BlockX, int a_BlockY, int a_BlockZ, BL void cClientHandle::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes) { ASSERT(!a_Changes.empty()); // We don't want to be sending empty change packets! - - m_Protocol->SendBlockChanges(a_ChunkX, a_ChunkZ, a_Changes); + + // Do not send block changes in chunks that weren't sent to the client yet: + cChunkCoords ChunkCoords = cChunkCoords(a_ChunkX, a_ChunkZ); + cCSLock Lock(m_CSChunkLists); + if (std::find(m_SentChunks.begin(), m_SentChunks.end(), ChunkCoords) != m_SentChunks.end()) + { + Lock.Unlock(); + m_Protocol->SendBlockChanges(a_ChunkX, a_ChunkZ, a_Changes); + } } @@ -2102,6 +2121,12 @@ void cClientHandle::SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializ m_Protocol->SendChunkData(a_ChunkX, a_ChunkZ, a_Serializer); + // Add the chunk to the list of chunks sent to the player: + { + cCSLock Lock(m_CSChunkLists); + m_SentChunks.push_back(cChunkCoords(a_ChunkX, a_ChunkZ)); + } + // If it is the chunk the player's in, make them spawn (in the tick thread): if ((m_State == csAuthenticated) || (m_State == csDownloadingWorld)) { @@ -2631,6 +2656,12 @@ void cClientHandle::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_D void cClientHandle::SendUnloadChunk(int a_ChunkX, int a_ChunkZ) { + // Remove the chunk from the list of chunks sent to the client: + { + cCSLock Lock(m_CSChunkLists); + m_SentChunks.remove(cChunkCoords(a_ChunkX, a_ChunkZ)); + } + m_Protocol->SendUnloadChunk(a_ChunkX, a_ChunkZ); } diff --git a/src/ClientHandle.h b/src/ClientHandle.h index a9cc29d50..1fc915280 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -343,6 +343,7 @@ private: 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; // Store the coordinates of the chunks that the client has loaded cProtocol * m_Protocol; |