1
0

Use m_UsedViewDistance and m_SetViewDistance.

This commit is contained in:
Howaner 2014-11-14 22:53:12 +01:00
parent a0e1e43fc1
commit 83d3f3347b
3 changed files with 26 additions and 15 deletions

View File

@ -65,7 +65,8 @@ int cClientHandle::s_ClientCount = 0;
// cClientHandle: // cClientHandle:
cClientHandle::cClientHandle(const cSocket * a_Socket, int a_ViewDistance) : 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_IPString(a_Socket->GetIPString()),
m_OutgoingData(64 KiB), m_OutgoingData(64 KiB),
m_Player(nullptr), m_Player(nullptr),
@ -430,7 +431,7 @@ bool cClientHandle::StreamNextChunk(void)
cCSLock Lock(m_CSChunkLists); cCSLock Lock(m_CSChunkLists);
// High priority: Load the chunks that are in the view-direction of the player (with a radius of 3) // 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; Vector3d Vector = Position + LookVector * cChunkDef::Width * Range;
@ -447,7 +448,7 @@ bool cClientHandle::StreamNextChunk(void)
cChunkCoords Coords(ChunkX, ChunkZ); cChunkCoords Coords(ChunkX, ChunkZ);
// Checks if the chunk is in distance // 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; continue;
} }
@ -470,7 +471,7 @@ bool cClientHandle::StreamNextChunk(void)
} }
// Low priority: Add all chunks that are in range. (From the center out to the edge) // 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: // For each distance add chunks in a hollow square centered around current position:
cChunkCoordsList CurcleChunks; cChunkCoordsList CurcleChunks;
@ -528,7 +529,7 @@ void cClientHandle::UnloadOutOfRangeChunks(void)
{ {
int DiffX = Diff((*itr).m_ChunkX, ChunkPosX); int DiffX = Diff((*itr).m_ChunkX, ChunkPosX);
int DiffZ = Diff((*itr).m_ChunkZ, ChunkPosZ); 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); ChunksToRemove.push_back(*itr);
itr = m_LoadedChunks.erase(itr); itr = m_LoadedChunks.erase(itr);
@ -543,7 +544,7 @@ void cClientHandle::UnloadOutOfRangeChunks(void)
{ {
int DiffX = Diff((*itr).m_ChunkX, ChunkPosX); int DiffX = Diff((*itr).m_ChunkX, ChunkPosX);
int DiffZ = Diff((*itr).m_ChunkZ, ChunkPosZ); 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); itr = m_ChunksToSend.erase(itr);
} }
@ -2849,8 +2850,9 @@ void cClientHandle::SetViewDistance(int a_ViewDistance)
{ {
ASSERT(m_Player->GetWorld() == NULL); ASSERT(m_Player->GetWorld() == NULL);
m_ViewDistance = Clamp(a_ViewDistance, cClientHandle::MIN_VIEW_DISTANCE, m_Player->GetWorld()->GetMaxViewDistance()); m_SetViewDistance = a_ViewDistance;
LOGD("Setted %s's view distance to %i", GetUsername().c_str(), m_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);
} }

View File

@ -217,9 +217,15 @@ public:
inline short GetPing(void) const { return m_Ping; } inline short GetPing(void) const { return m_Ping; }
/** Sets the maximal view distance. */
void SetViewDistance(int a_ViewDistance); 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; } void SetLocale(AString & a_Locale) { m_Locale = a_Locale; }
AString GetLocale(void) const { return m_Locale; } AString GetLocale(void) const { return m_Locale; }
@ -334,11 +340,11 @@ private:
typedef std::set<AString> cChannels; typedef std::set<AString> cChannels;
/** Number of chunks the player can see in each direction */ /** Number of chunks the player can see in each direction */
int m_ViewDistance; int m_UsedViewDistance;
/** Server generates this many chunks AHEAD of player sight. */ /** The original view distance from the player. It isn't clamped with 1 and the max view distance of the world. */
static const int GENERATEDISTANCE = 2; int m_SetViewDistance;
AString m_IPString; AString m_IPString;
AString m_Username; AString m_Username;

View File

@ -1602,6 +1602,9 @@ bool cPlayer::DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn)
a_World->AddPlayer(this); a_World->AddPlayer(this);
SetWorld(a_World); // Chunks may be streamed before cWorld::AddPlayer() sets the world to the new value 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; return true;
} }