1
0

ViewDistance: unsigned -> signed

This commit is contained in:
Tiger Wang 2020-12-23 22:39:53 +00:00
parent 53ae358d8c
commit d9a7c51d4d
8 changed files with 26 additions and 39 deletions

View File

@ -67,7 +67,7 @@ float cClientHandle::FASTBREAK_PERCENTAGE;
////////////////////////////////////////////////////////////////////////////////
// cClientHandle:
cClientHandle::cClientHandle(const AString & a_IPString, unsigned a_ViewDistance) :
cClientHandle::cClientHandle(const AString & a_IPString, int a_ViewDistance) :
m_LastSentDimension(dimNotSet),
m_ForgeHandshake(this),
m_CurrentViewDistance(a_ViewDistance),
@ -473,7 +473,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 (unsigned Range = 0; Range < m_CurrentViewDistance; Range++)
for (int Range = 0; Range < m_CurrentViewDistance; Range++)
{
Vector3d Vector = Position + LookVector * cChunkDef::Width * Range;
@ -513,10 +513,8 @@ bool cClientHandle::StreamNextChunk(void)
}
// Low priority: Add all chunks that are in range. (From the center out to the edge)
for (unsigned Range = 0; Range <= m_CurrentViewDistance; ++Range) // cycle through (square) distance, from nearest to furthest
for (int d = 0; d <= m_CurrentViewDistance; ++d) // cycle through (square) distance, from nearest to furthest
{
const int d = static_cast<int>(Range);
// For each distance add chunks in a hollow square centered around current position:
cChunkCoordsList CurcleChunks;
for (int i = -d; i <= d; ++i)
@ -3271,7 +3269,7 @@ void cClientHandle::SetUsername(const AString & a_Username)
void cClientHandle::SetViewDistance(unsigned a_ViewDistance)
void cClientHandle::SetViewDistance(int a_ViewDistance)
{
m_RequestedViewDistance = a_ViewDistance;
LOGD("%s is requesting ViewDistance of %d!", GetUsername().c_str(), m_RequestedViewDistance);

View File

@ -50,12 +50,12 @@ class cClientHandle // tolua_export
public: // tolua_export
#if defined(ANDROID)
static const unsigned DEFAULT_VIEW_DISTANCE = 4; // The default ViewDistance (used when no value is set in Settings.ini)
static const int DEFAULT_VIEW_DISTANCE = 4; // The default ViewDistance (used when no value is set in Settings.ini)
#else
static const unsigned DEFAULT_VIEW_DISTANCE = 10;
static const int DEFAULT_VIEW_DISTANCE = 10;
#endif
static const unsigned MAX_VIEW_DISTANCE = 32;
static const unsigned MIN_VIEW_DISTANCE = 1;
static const int MAX_VIEW_DISTANCE = 32;
static const int MIN_VIEW_DISTANCE = 1;
/** The percentage how much a block has to be broken.
Should be a value between 0.7 (70% broken) and 1 (100% broken) depending on lag.
@ -63,7 +63,7 @@ public: // tolua_export
static float FASTBREAK_PERCENTAGE;
/** Creates a new client with the specified IP address in its description and the specified initial view distance. */
cClientHandle(const AString & a_IPString, unsigned a_ViewDistance);
cClientHandle(const AString & a_IPString, int a_ViewDistance);
virtual ~cClientHandle() override;
@ -242,13 +242,13 @@ public: // tolua_export
inline short GetPing(void) const { return static_cast<short>(std::chrono::duration_cast<std::chrono::milliseconds>(m_Ping).count()); }
/** Sets the maximal view distance. */
void SetViewDistance(unsigned a_ViewDistance);
void SetViewDistance(int a_ViewDistance);
/** Returns the view distance that the player currently have. */
unsigned GetViewDistance(void) const { return m_CurrentViewDistance; }
int GetViewDistance(void) const { return m_CurrentViewDistance; }
/** Returns the view distance that the player request, not the used view distance. */
unsigned GetRequestedViewDistance(void) const { return m_RequestedViewDistance; }
int GetRequestedViewDistance(void) const { return m_RequestedViewDistance; }
void SetLocale(const AString & a_Locale) { m_Locale = a_Locale; }
AString GetLocale(void) const { return m_Locale; }
@ -422,10 +422,10 @@ private:
AStringMap m_ForgeMods;
/** The actual view distance used, the minimum of client's requested view distance and world's max view distance. */
unsigned m_CurrentViewDistance;
int m_CurrentViewDistance;
/** The requested view distance from the player. It isn't clamped with 1 and the max view distance of the world. */
unsigned m_RequestedViewDistance;
int m_RequestedViewDistance;
AString m_IPString;

View File

@ -489,7 +489,7 @@ inline void VectorToEuler(double a_X, double a_Y, double a_Z, double & a_Pan, do
template <class T, typename = std::enable_if_t<!std::is_integral_v<T>>>
template <class T>
inline T Diff(T a_Val1, T a_Val2)
{
return std::abs(a_Val1 - a_Val2);
@ -499,16 +499,6 @@ inline T Diff(T a_Val1, T a_Val2)
template <class T, typename = std::enable_if_t<std::is_integral_v<T>>>
inline auto Diff(T a_Val1, T a_Val2)
{
return static_cast<std::make_unsigned_t<T>>(std::abs(a_Val1 - a_Val2));
}
// tolua_begin
/** Normalizes an angle in degrees to the [-180, +180) range: */

View File

@ -59,7 +59,7 @@ void cProtocol_1_14::SendLogin(const cPlayer & a_Player, const cWorld & a_World)
Pkt.WriteBEInt32(static_cast<Int32>(a_World.GetDimension()));
Pkt.WriteBEUInt8(static_cast<UInt8>(Clamp<size_t>(Server->GetMaxPlayers(), 0, 255)));
Pkt.WriteString("default");
Pkt.WriteVarInt32(a_World.GetMaxViewDistance());
Pkt.WriteVarInt32(ToUnsigned(a_World.GetMaxViewDistance()));
Pkt.WriteBool(false);
}

View File

@ -214,20 +214,20 @@ bool cServer::InitServer(cSettingsRepositoryInterface & a_Settings, bool a_Shoul
m_ShouldLoadOfflinePlayerData = a_Settings.GetValueSetB("PlayerData", "LoadOfflinePlayerData", false);
m_ShouldLoadNamedPlayerData = a_Settings.GetValueSetB("PlayerData", "LoadNamedPlayerData", true);
const auto ClientViewDistance = a_Settings.GetValueSetI("Server", "DefaultViewDistance", static_cast<int>(cClientHandle::DEFAULT_VIEW_DISTANCE));
if (ClientViewDistance < static_cast<int>(cClientHandle::MIN_VIEW_DISTANCE))
const auto ClientViewDistance = a_Settings.GetValueSetI("Server", "DefaultViewDistance", cClientHandle::DEFAULT_VIEW_DISTANCE);
if (ClientViewDistance < cClientHandle::MIN_VIEW_DISTANCE)
{
m_ClientViewDistance = cClientHandle::MIN_VIEW_DISTANCE;
LOGINFO("Setting default view distance to the minimum of %d", m_ClientViewDistance);
}
else if (ClientViewDistance > static_cast<int>(cClientHandle::MAX_VIEW_DISTANCE))
else if (ClientViewDistance > cClientHandle::MAX_VIEW_DISTANCE)
{
m_ClientViewDistance = cClientHandle::MAX_VIEW_DISTANCE;
LOGINFO("Setting default view distance to the maximum of %d", m_ClientViewDistance);
}
else
{
m_ClientViewDistance = static_cast<unsigned>(ClientViewDistance);
m_ClientViewDistance = ClientViewDistance;
}
PrepareKeys();

View File

@ -206,7 +206,7 @@ private:
cCriticalSection m_CSPendingCommands;
std::vector<std::pair<AString, cCommandOutputCallback *>> m_PendingCommands;
unsigned m_ClientViewDistance; // The default view distance for clients; settable in Settings.ini
int m_ClientViewDistance; // The default view distance for clients; settable in Settings.ini
bool m_bIsConnected; // true - connected false - not connected

View File

@ -262,8 +262,7 @@ cWorld::cWorld(
m_BroadcastDeathMessages = IniFile.GetValueSetB("Broadcasting", "BroadcastDeathMessages", true);
m_BroadcastAchievementMessages = IniFile.GetValueSetB("Broadcasting", "BroadcastAchievementMessages", true);
const auto ClientViewDistance = IniFile.GetValueSetI("SpawnPosition", "MaxViewDistance", static_cast<int>(cClientHandle::DEFAULT_VIEW_DISTANCE));
m_MaxViewDistance = static_cast<unsigned>(std::clamp(ClientViewDistance, static_cast<int>(cClientHandle::MIN_VIEW_DISTANCE), static_cast<int>(cClientHandle::MAX_VIEW_DISTANCE)));
SetMaxViewDistance(IniFile.GetValueSetI("SpawnPosition", "MaxViewDistance", cClientHandle::DEFAULT_VIEW_DISTANCE));
// Try to find the "SpawnPosition" key and coord values in the world configuration, set the flag if found
int KeyNum = IniFile.FindKey("SpawnPosition");
@ -1840,7 +1839,7 @@ bool cWorld::SetAreaBiome(const cCuboid & a_Area, EMCSBiome a_Biome)
void cWorld::SetMaxViewDistance(unsigned a_MaxViewDistance)
void cWorld::SetMaxViewDistance(int a_MaxViewDistance)
{
m_MaxViewDistance = Clamp(a_MaxViewDistance, cClientHandle::MIN_VIEW_DISTANCE, cClientHandle::MAX_VIEW_DISTANCE);
}

View File

@ -896,8 +896,8 @@ public:
eShrapnelLevel GetTNTShrapnelLevel(void) const { return m_TNTShrapnelLevel; }
void SetTNTShrapnelLevel(eShrapnelLevel a_Flag) { m_TNTShrapnelLevel = a_Flag; }
unsigned GetMaxViewDistance(void) const { return m_MaxViewDistance; }
void SetMaxViewDistance(unsigned a_MaxViewDistance);
int GetMaxViewDistance(void) const { return m_MaxViewDistance; }
void SetMaxViewDistance(int a_MaxViewDistance);
bool ShouldUseChatPrefixes(void) const { return m_bUseChatPrefixes; }
void SetShouldUseChatPrefixes(bool a_Flag) { m_bUseChatPrefixes = a_Flag; }
@ -1249,7 +1249,7 @@ private:
eShrapnelLevel m_TNTShrapnelLevel;
/** The maximum view distance that a player can have in this world. */
unsigned m_MaxViewDistance;
int m_MaxViewDistance;
/** Name of the nether world - where Nether portals should teleport.
Only used when this world is an Overworld. */