summaryrefslogtreecommitdiffstats
path: root/source/cClientHandle.cpp
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-02-23 23:51:03 +0100
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-02-23 23:51:03 +0100
commitbf19f7ae9ceacf9e6a65e097be443ae3f5c85232 (patch)
tree339caeecf7ad34b10c24310dd74dadccbeeed3a9 /source/cClientHandle.cpp
parentPlain pointer cChunkPtr finishing touches; removed cChunk's critical sections (diff)
downloadcuberite-bf19f7ae9ceacf9e6a65e097be443ae3f5c85232.tar
cuberite-bf19f7ae9ceacf9e6a65e097be443ae3f5c85232.tar.gz
cuberite-bf19f7ae9ceacf9e6a65e097be443ae3f5c85232.tar.bz2
cuberite-bf19f7ae9ceacf9e6a65e097be443ae3f5c85232.tar.lz
cuberite-bf19f7ae9ceacf9e6a65e097be443ae3f5c85232.tar.xz
cuberite-bf19f7ae9ceacf9e6a65e097be443ae3f5c85232.tar.zst
cuberite-bf19f7ae9ceacf9e6a65e097be443ae3f5c85232.zip
Diffstat (limited to '')
-rw-r--r--source/cClientHandle.cpp33
1 files changed, 27 insertions, 6 deletions
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