From bf19f7ae9ceacf9e6a65e097be443ae3f5c85232 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Thu, 23 Feb 2012 22:51:03 +0000 Subject: Made the viewdistance settable by users and default in settings.ini. The default is 9. git-svn-id: http://mc-server.googlecode.com/svn/trunk@326 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cClientHandle.cpp | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'source/cClientHandle.cpp') diff --git a/source/cClientHandle.cpp b/source/cClientHandle.cpp index 70fa8e455..78032611e 100644 --- a/source/cClientHandle.cpp +++ b/source/cClientHandle.cpp @@ -86,8 +86,9 @@ /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cClientHandle: -cClientHandle::cClientHandle(const cSocket & a_Socket) - : m_ProtocolVersion(23) +cClientHandle::cClientHandle(const cSocket & a_Socket, int a_ViewDistance) + : m_ViewDistance(a_ViewDistance) + , m_ProtocolVersion(23) , m_pSendThread(NULL) , m_Socket(a_Socket) , m_Semaphore(MAX_SEMAPHORES) @@ -342,7 +343,7 @@ void cClientHandle::StreamChunks(void) { int RelX = (*itr).m_ChunkX - ChunkPosX; int RelZ = (*itr).m_ChunkZ - ChunkPosZ; - if ((RelX > VIEWDISTANCE) || (RelX < -VIEWDISTANCE) || (RelZ > VIEWDISTANCE) || (RelZ < -VIEWDISTANCE)) + 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 ) ); @@ -357,7 +358,7 @@ void cClientHandle::StreamChunks(void) { int RelX = (*itr).m_ChunkX - ChunkPosX; int RelZ = (*itr).m_ChunkZ - ChunkPosZ; - if ((RelX > VIEWDISTANCE) || (RelX < -VIEWDISTANCE) || (RelZ > VIEWDISTANCE) || (RelZ < -VIEWDISTANCE)) + if ((RelX > m_ViewDistance) || (RelX < -m_ViewDistance) || (RelZ > m_ViewDistance) || (RelZ < -m_ViewDistance)) { itr = m_ChunksToSend.erase(itr); } @@ -370,7 +371,7 @@ void cClientHandle::StreamChunks(void) // Add all chunks that are in range and not yet in m_LoadedChunks: // Queue these smartly - from the center out to the edge - for (int d = 0; d <= VIEWDISTANCE; ++d) // cycle through (square) distance, from nearest to furthest + for (int d = 0; d <= m_ViewDistance; ++d) // cycle through (square) distance, from nearest to furthest { // For each distance add chunks in a hollow square centered around current position: for (int i = -d; i <= d; ++i) @@ -386,7 +387,7 @@ void cClientHandle::StreamChunks(void) } // for d // Touch chunks GENERATEDISTANCE ahead to let them generate: - for (int d = VIEWDISTANCE + 1; d <= VIEWDISTANCE + GENERATEDISTANCE; ++d) // cycle through (square) distance, from nearest to furthest + for (int d = m_ViewDistance + 1; d <= m_ViewDistance + GENERATEDISTANCE; ++d) // cycle through (square) distance, from nearest to furthest { // For each distance touch chunks in a hollow square centered around current position: for (int i = -d; i <= d; ++i) @@ -1890,6 +1891,26 @@ const AString & cClientHandle::GetUsername(void) const +void cClientHandle::SetViewDistance(int a_ViewDistance) +{ + if (a_ViewDistance < MIN_VIEW_DISTANCE) + { + a_ViewDistance = MIN_VIEW_DISTANCE; + } + if (a_ViewDistance > MAX_VIEW_DISTANCE) + { + a_ViewDistance = MAX_VIEW_DISTANCE; + } + m_ViewDistance = a_ViewDistance; + + // Need to re-stream chunks for the change to become apparent: + StreamChunks(); +} + + + + + void cClientHandle::DataReceived(const char * a_Data, int a_Size) { // Data is received from the client -- cgit v1.2.3