From 4d65ffffc0b6f35ac84e310fd4bc9739ea7e0c0a Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Mon, 5 Mar 2012 16:41:57 +0000 Subject: ChunkSender: Chunks are now compressed and sent to clients from a separate threads, proper passive waiting between threads. Not much tested, just appears to work :) git-svn-id: http://mc-server.googlecode.com/svn/trunk@365 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cClientHandle.cpp | 55 +++++++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 33 deletions(-) (limited to 'source/cClientHandle.cpp') diff --git a/source/cClientHandle.cpp b/source/cClientHandle.cpp index f27ca9e61..9ea063f11 100644 --- a/source/cClientHandle.cpp +++ b/source/cClientHandle.cpp @@ -1681,35 +1681,6 @@ void cClientHandle::Tick(float a_Dt) Send(Ping); m_LastPingTime = m_PingStartTime; } - - if (m_State >= csDownloadingWorld) - { - cWorld * World = m_Player->GetWorld(); - - cCSLock Lock(m_CSChunkLists); - - // Send the chunks: - int NumSent = 0; - for (cChunkCoordsList::iterator itr = m_ChunksToSend.begin(); itr != m_ChunksToSend.end();) - { - if (!World->SendChunkTo(itr->m_ChunkX, itr->m_ChunkY, itr->m_ChunkZ, this)) - { - ++itr; - continue; - } - itr = m_ChunksToSend.erase(itr); - NumSent++; - if (NumSent > 10) - { - // Only send up to 10 chunks per tick, otherwise we'd choke the tick thread - break; - } - } // for itr - m_ChunksToSend[] - Lock.Unlock(); - - // Check even if we didn't send anything - a chunk may have sent a notification that we'd miss otherwise - CheckIfWorldDownloaded(); - } } @@ -1737,20 +1708,38 @@ void cClientHandle::Send(const cPacket * a_Packet, ENUM_PRIORITY a_Priority /* = case E_PLAYERMOVELOOK: case E_KEEP_ALIVE: case E_PRE_CHUNK: + case E_MAP_CHUNK: { // Allow break; } - case E_MAP_CHUNK: + default: return; + } + } + + // Check chunks being sent, erase them from m_ChunksToSend: + if (a_Packet->m_PacketID == E_MAP_CHUNK) + { + #if (MINECRAFT_1_2_2 == 1) + int ChunkX = ((cPacket_MapChunk *)a_Packet)->m_PosX; + int ChunkZ = ((cPacket_MapChunk *)a_Packet)->m_PosZ; + #else + int ChunkX = ((cPacket_MapChunk *)a_Packet)->m_PosX / cChunk::c_ChunkWidth; + int ChunkZ = ((cPacket_MapChunk *)a_Packet)->m_PosZ / cChunk::c_ChunkWidth; + #endif + cCSLock Lock(m_CSChunkLists); + for (cChunkCoordsList::iterator itr = m_ChunksToSend.begin(); itr != m_ChunksToSend.end(); ++itr) + { + if ((itr->m_ChunkX == ChunkX) && (itr->m_ChunkZ == ChunkZ)) { + m_ChunksToSend.erase(itr); CheckIfWorldDownloaded(); break; } - - default: return; - } + } // for itr - m_ChunksToSend[] } + // Optimize away multiple queued RelativeEntityMoveLook packets: cCSLock Lock(m_CSPackets); if (a_Priority == E_PRIORITY_NORMAL) { -- cgit v1.2.3