From 8cdd63f06c692f117088909ea5c9b950bba34376 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Tue, 6 Mar 2012 14:52:44 +0000 Subject: Fixed rev368's ChunkSender, now sends properly even chunks that are loaded. Fixed a deadlock in cClientHandle vs TickThread over cClientHandle::m_CSChunkLists git-svn-id: http://mc-server.googlecode.com/svn/trunk@371 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cClientHandle.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'source/cClientHandle.cpp') diff --git a/source/cClientHandle.cpp b/source/cClientHandle.cpp index 9ea063f11..ee9f0ab3a 100644 --- a/source/cClientHandle.cpp +++ b/source/cClientHandle.cpp @@ -240,6 +240,7 @@ void cClientHandle::Destroy() if ((m_Player != NULL) && (m_Player->GetWorld() != NULL)) { RemoveFromAllChunks(); + m_Player->GetWorld()->RemoveClientFromChunkSender(this); } m_bDestroyed = true; @@ -355,7 +356,8 @@ void cClientHandle::StreamChunks(void) cWorld * World = m_Player->GetWorld(); ASSERT(World != NULL); - // Remove all loaded chunks that are no longer in range: + // Remove all loaded chunks that are no longer in range; deferred to out-of-CS: + cChunkCoordsList RemoveChunks; { cCSLock Lock(m_CSChunkLists); for (cChunkCoordsList::iterator itr = m_LoadedChunks.begin(); itr != m_LoadedChunks.end();) @@ -364,8 +366,7 @@ void cClientHandle::StreamChunks(void) int RelZ = (*itr).m_ChunkZ - ChunkPosZ; if ((RelX > m_ViewDistance) || (RelX < -m_ViewDistance) || (RelZ > m_ViewDistance) || (RelZ < -m_ViewDistance)) { - World->RemoveChunkClient(itr->m_ChunkX, itr->m_ChunkY, itr->m_ChunkZ, this); - Send( cPacket_PreChunk( itr->m_ChunkX, itr->m_ChunkZ, false ) ); + RemoveChunks.push_back(*itr); itr = m_LoadedChunks.erase(itr); } else @@ -385,8 +386,13 @@ void cClientHandle::StreamChunks(void) { ++itr; } - } + } // for itr - m_ChunksToSend[] } + for (cChunkCoordsList::iterator itr = RemoveChunks.begin(); itr != RemoveChunks.end(); ++itr) + { + World->RemoveChunkClient(itr->m_ChunkX, itr->m_ChunkY, itr->m_ChunkZ, this); + Send(cPacket_PreChunk(itr->m_ChunkX, itr->m_ChunkZ, false)); + } // for itr - RemoveChunks[] // Add all chunks that are in range and not yet in m_LoadedChunks: // Queue these smartly - from the center out to the edge @@ -435,6 +441,7 @@ void cClientHandle::StreamChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ) cCSLock Lock(m_CSChunkLists); m_LoadedChunks.push_back(cChunkCoords(a_ChunkX, a_ChunkY, a_ChunkZ)); m_ChunksToSend.push_back(cChunkCoords(a_ChunkX, a_ChunkY, a_ChunkZ)); + World->SendChunkTo(a_ChunkX, a_ChunkY, a_ChunkZ, this); } } -- cgit v1.2.3