From fe82551f3211b169928b89b361cd5654f5e8dec2 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 6 Jul 2021 12:03:12 +0100 Subject: Replace chunk coordinates magic with numeric_limits --- src/ClientHandle.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 6c9fa751c..47bbe691a 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -72,10 +72,10 @@ cClientHandle::cClientHandle(const AString & a_IPString, int a_ViewDistance) : m_RequestedViewDistance(a_ViewDistance), m_IPString(a_IPString), m_Player(nullptr), - m_CachedSentChunk(0x7fffffff, 0x7fffffff), + m_CachedSentChunk(std::numeric_limits::max(), std::numeric_limits::max()), m_HasSentDC(false), - m_LastStreamedChunkX(0x7fffffff), // bogus chunk coords to force streaming upon login - m_LastStreamedChunkZ(0x7fffffff), + m_LastStreamedChunkX(std::numeric_limits::max()), // bogus chunk coords to force streaming upon login + m_LastStreamedChunkZ(std::numeric_limits::max()), m_TicksSinceLastPacket(0), m_Ping(1000), m_PingID(1), @@ -401,14 +401,13 @@ void cClientHandle::StreamNextChunks(void) if ((m_LastStreamedChunkX == ChunkPosX) && (m_LastStreamedChunkZ == ChunkPosZ)) { - // All chunks are already loaded. Abort loading. + // All chunks are already loaded and the player has not moved, work is done: return; } - else - { - m_LastStreamedChunkX = 0x7fffffff; - m_LastStreamedChunkZ = 0x7fffffff; - } + + // Player moved chunks and / or loading is not finished, reset to bogus (GH #4531): + m_LastStreamedChunkX = std::numeric_limits::max(); + m_LastStreamedChunkZ = std::numeric_limits::max(); int StreamedChunks = 0; Vector3d Position = m_Player->GetEyePosition(); @@ -1942,11 +1941,11 @@ void cClientHandle::RemoveFromWorld(void) // No need to send Unload Chunk packets, the client unloads automatically. // Here, we set last streamed values to bogus ones so everything is resent: - m_LastStreamedChunkX = 0x7fffffff; - m_LastStreamedChunkZ = 0x7fffffff; + m_LastStreamedChunkX = std::numeric_limits::max(); + m_LastStreamedChunkZ = std::numeric_limits::max(); // Restart player unloaded chunk checking and freezing: - m_CachedSentChunk = cChunkCoords(0x7fffffff, 0x7fffffff); + m_CachedSentChunk = cChunkCoords(std::numeric_limits::max(), std::numeric_limits::max()); } @@ -3166,8 +3165,8 @@ void cClientHandle::SetViewDistance(int a_ViewDistance) m_CurrentViewDistance = Clamp(a_ViewDistance, cClientHandle::MIN_VIEW_DISTANCE, world->GetMaxViewDistance()); // Restart chunk streaming to respond to new view distance: - m_LastStreamedChunkX = 0x7fffffff; - m_LastStreamedChunkZ = 0x7fffffff; + m_LastStreamedChunkX = std::numeric_limits::max(); + m_LastStreamedChunkZ = std::numeric_limits::max(); } } -- cgit v1.2.3