Skip to content

Commit

Permalink
Use m_UsedViewDistance and m_SetViewDistance.
Browse files Browse the repository at this point in the history
  • Loading branch information
Howaner committed Nov 14, 2014
1 parent a0e1e43 commit 83d3f33
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
18 changes: 10 additions & 8 deletions src/ClientHandle.cpp
Expand Up @@ -65,7 +65,8 @@ int cClientHandle::s_ClientCount = 0;
// cClientHandle:

cClientHandle::cClientHandle(const cSocket * a_Socket, int a_ViewDistance) :
m_ViewDistance(a_ViewDistance),
m_UsedViewDistance(a_ViewDistance),
m_SetViewDistance(a_ViewDistance),
m_IPString(a_Socket->GetIPString()),
m_OutgoingData(64 KiB),
m_Player(nullptr),
Expand Down Expand Up @@ -430,7 +431,7 @@ bool cClientHandle::StreamNextChunk(void)
cCSLock Lock(m_CSChunkLists);

// High priority: Load the chunks that are in the view-direction of the player (with a radius of 3)
for (int Range = 0; Range < m_ViewDistance; Range++)
for (int Range = 0; Range < m_UsedViewDistance; Range++)
{
Vector3d Vector = Position + LookVector * cChunkDef::Width * Range;

Expand All @@ -447,7 +448,7 @@ bool cClientHandle::StreamNextChunk(void)
cChunkCoords Coords(ChunkX, ChunkZ);

// Checks if the chunk is in distance
if ((Diff(ChunkX, ChunkPosX) > m_ViewDistance) || (Diff(ChunkZ, ChunkPosZ) > m_ViewDistance))
if ((Diff(ChunkX, ChunkPosX) > m_UsedViewDistance) || (Diff(ChunkZ, ChunkPosZ) > m_UsedViewDistance))
{
continue;
}
Expand All @@ -470,7 +471,7 @@ bool cClientHandle::StreamNextChunk(void)
}

// Low priority: Add all chunks that are in range. (From the center out to the edge)
for (int d = 0; d <= m_ViewDistance; ++d) // cycle through (square) distance, from nearest to furthest
for (int d = 0; d <= m_UsedViewDistance; ++d) // cycle through (square) distance, from nearest to furthest
{
// For each distance add chunks in a hollow square centered around current position:
cChunkCoordsList CurcleChunks;
Expand Down Expand Up @@ -528,7 +529,7 @@ void cClientHandle::UnloadOutOfRangeChunks(void)
{
int DiffX = Diff((*itr).m_ChunkX, ChunkPosX);
int DiffZ = Diff((*itr).m_ChunkZ, ChunkPosZ);
if ((DiffX > m_ViewDistance) || (DiffZ > m_ViewDistance))
if ((DiffX > m_UsedViewDistance) || (DiffZ > m_UsedViewDistance))
{
ChunksToRemove.push_back(*itr);
itr = m_LoadedChunks.erase(itr);
Expand All @@ -543,7 +544,7 @@ void cClientHandle::UnloadOutOfRangeChunks(void)
{
int DiffX = Diff((*itr).m_ChunkX, ChunkPosX);
int DiffZ = Diff((*itr).m_ChunkZ, ChunkPosZ);
if ((DiffX > m_ViewDistance) || (DiffZ > m_ViewDistance))
if ((DiffX > m_UsedViewDistance) || (DiffZ > m_UsedViewDistance))
{
itr = m_ChunksToSend.erase(itr);
}
Expand Down Expand Up @@ -2849,8 +2850,9 @@ void cClientHandle::SetViewDistance(int a_ViewDistance)
{
ASSERT(m_Player->GetWorld() == NULL);

m_ViewDistance = Clamp(a_ViewDistance, cClientHandle::MIN_VIEW_DISTANCE, m_Player->GetWorld()->GetMaxViewDistance());
LOGD("Setted %s's view distance to %i", GetUsername().c_str(), m_ViewDistance);
m_SetViewDistance = a_ViewDistance;
m_UsedViewDistance = Clamp(m_SetViewDistance, cClientHandle::MIN_VIEW_DISTANCE, m_Player->GetWorld()->GetMaxViewDistance());
LOGD("Setted view distance from %s to %i!", GetUsername().c_str(), m_UsedViewDistance);
}


Expand Down
20 changes: 13 additions & 7 deletions src/ClientHandle.h
Expand Up @@ -217,9 +217,15 @@ class cClientHandle : // tolua_export

inline short GetPing(void) const { return m_Ping; }

/** Sets the maximal view distance. */
void SetViewDistance(int a_ViewDistance);
int GetViewDistance(void) const { return m_ViewDistance; }


/** Returns the view distance that the player currently have. */
int GetViewDistance(void) const { return m_UsedViewDistance; }

/** Returns the view distance that the player set, not the used view distance. */
int GetSettedViewDistance(void) const { return m_SetViewDistance; }

void SetLocale(AString & a_Locale) { m_Locale = a_Locale; }
AString GetLocale(void) const { return m_Locale; }

Expand Down Expand Up @@ -334,11 +340,11 @@ class cClientHandle : // tolua_export
typedef std::set<AString> cChannels;

/** Number of chunks the player can see in each direction */
int m_ViewDistance;
/** Server generates this many chunks AHEAD of player sight. */
static const int GENERATEDISTANCE = 2;
int m_UsedViewDistance;

/** The original view distance from the player. It isn't clamped with 1 and the max view distance of the world. */
int m_SetViewDistance;

AString m_IPString;

AString m_Username;
Expand Down
3 changes: 3 additions & 0 deletions src/Entities/Player.cpp
Expand Up @@ -1602,6 +1602,9 @@ bool cPlayer::DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn)
a_World->AddPlayer(this);
SetWorld(a_World); // Chunks may be streamed before cWorld::AddPlayer() sets the world to the new value

// Update the view distance.
m_ClientHandle->SetViewDistance(m_ClientHandle->GetSettedViewDistance());

return true;
}

Expand Down

0 comments on commit 83d3f33

Please sign in to comment.