From 8c144207dc6bcbc9871c3a577b864f7c3fcd074c Mon Sep 17 00:00:00 2001 From: Scott Moore Date: Wed, 8 Apr 2015 00:41:19 +1000 Subject: Implement backend for /title command --- src/ClientHandle.cpp | 63 +++++++++++++++++++++++++++ src/ClientHandle.h | 7 +++ src/Protocol/Protocol.h | 7 +++ src/Protocol/Protocol17x.cpp | 63 +++++++++++++++++++++++++++ src/Protocol/Protocol17x.h | 7 +++ src/Protocol/Protocol18x.cpp | 86 +++++++++++++++++++++++++++++++++++++ src/Protocol/Protocol18x.h | 7 +++ src/Protocol/ProtocolRecognizer.cpp | 70 ++++++++++++++++++++++++++++++ src/Protocol/ProtocolRecognizer.h | 7 +++ 9 files changed, 317 insertions(+) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 28fccb68e..2ce212421 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -2320,6 +2320,15 @@ void cClientHandle::SendHealth(void) +void cClientHandle::SendHideTitle(void) +{ + m_Protocol->SendHideTitle(); +} + + + + + void cClientHandle::SendInventorySlot(char a_WindowID, short a_SlotNum, const cItem & a_Item) { m_Protocol->SendInventorySlot(a_WindowID, a_SlotNum, a_Item); @@ -2514,6 +2523,15 @@ void cClientHandle::SendRemoveEntityEffect(const cEntity & a_Entity, int a_Effec +void cClientHandle::SendResetTitle() +{ + m_Protocol->SendResetTitle(); +} + + + + + void cClientHandle::SendRespawn(eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks) { m_Protocol->SendRespawn(a_Dimension, a_ShouldIgnoreDimensionChecks); @@ -2568,6 +2586,42 @@ void cClientHandle::SendDisplayObjective(const AString & a_Objective, cScoreboar +void cClientHandle::SendSetSubTitle(const cCompositeChat & a_SubTitle) +{ + m_Protocol->SendSetSubTitle(a_SubTitle); +} + + + + + +void cClientHandle::SendSetRawSubTitle(const AString & a_SubTitle) +{ + m_Protocol->SendSetRawSubTitle(a_SubTitle); +} + + + + + +void cClientHandle::SendSetTitle(const cCompositeChat & a_Title) +{ + m_Protocol->SendSetTitle(a_Title); +} + + + + + +void cClientHandle::SendSetRawTitle(const AString & a_Title) +{ + m_Protocol->SendSetRawTitle(a_Title); +} + + + + + void cClientHandle::SendSoundEffect(const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch) { m_Protocol->SendSoundEffect(a_SoundName, a_X, a_Y, a_Z, a_Volume, a_Pitch); @@ -2658,6 +2712,15 @@ void cClientHandle::SendThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ) +void cClientHandle::SendTitleTimes(int a_FadeInTicks, int a_DisplayTicks, int a_FadeOutTicks) +{ + m_Protocol->SendTitleTimes(a_FadeInTicks, a_DisplayTicks, a_FadeOutTicks); +} + + + + + void cClientHandle::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle) { m_Protocol->SendTimeUpdate(a_WorldAge, a_TimeOfDay, a_DoDaylightCycle); diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 9e5287985..e004c3bfb 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -171,6 +171,7 @@ public: // tolua_export void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion); void SendGameMode (eGameMode a_GameMode); void SendHealth (void); + void SendHideTitle (void); void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item); void SendMapColumn (int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length, unsigned int m_Scale); void SendMapDecorators (int a_ID, const cMapDecoratorList & a_Decorators, unsigned int m_Scale); @@ -190,9 +191,14 @@ public: // tolua_export void SendPlayerSpawn (const cPlayer & a_Player); void SendPluginMessage (const AString & a_Channel, const AString & a_Message); // Exported in ManualBindings.cpp void SendRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID); + void SendResetTitle (void); void SendRespawn (eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks = false); void SendScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode); void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode); + void SendSetSubTitle (const cCompositeChat & a_SubTitle); + void SendSetRawSubTitle (const AString & a_SubTitle); + void SendSetTitle (const cCompositeChat & a_Title); + void SendSetRawTitle (const AString & a_Title); void SendSoundEffect (const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch); // tolua_export void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data); void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock); @@ -203,6 +209,7 @@ public: // tolua_export void SendTabCompletionResults (const AStringVector & a_Results); void SendTeleportEntity (const cEntity & a_Entity); void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ); + void SendTitleTimes (int a_FadeInTicks, int a_DisplayTicks, int a_FadeOutTicks); void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle); // tolua_export void SendUnloadChunk (int a_ChunkX, int a_ChunkZ); void SendUpdateBlockEntity (cBlockEntity & a_BlockEntity); diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h index d8399049e..95adc23e9 100644 --- a/src/Protocol/Protocol.h +++ b/src/Protocol/Protocol.h @@ -86,6 +86,7 @@ public: virtual void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) = 0; virtual void SendGameMode (eGameMode a_GameMode) = 0; virtual void SendHealth (void) = 0; + virtual void SendHideTitle (void) = 0; virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) = 0; virtual void SendKeepAlive (int a_PingID) = 0; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) = 0; @@ -109,12 +110,17 @@ public: virtual void SendPlayerSpawn (const cPlayer & a_Player) = 0; virtual void SendPluginMessage (const AString & a_Channel, const AString & a_Message) = 0; virtual void SendRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID) = 0; + virtual void SendResetTitle (void) = 0; virtual void SendRespawn (eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks) = 0; virtual void SendExperience (void) = 0; virtual void SendExperienceOrb (const cExpOrb & a_ExpOrb) = 0; virtual void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) = 0; virtual void SendScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) = 0; virtual void SendDisplayObjective (const AString & a_Objective, cScoreboard::eDisplaySlot a_Display) = 0; + virtual void SendSetSubTitle (const cCompositeChat & a_SubTitle) = 0; + virtual void SendSetRawSubTitle (const AString & a_SubTitle) = 0; + virtual void SendSetTitle (const cCompositeChat & a_Title) = 0; + virtual void SendSetRawTitle (const AString & a_Title) = 0; virtual void SendSoundEffect (const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch) = 0; virtual void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) = 0; virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) = 0; @@ -125,6 +131,7 @@ public: virtual void SendTabCompletionResults (const AStringVector & a_Results) = 0; virtual void SendTeleportEntity (const cEntity & a_Entity) = 0; virtual void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) = 0; + virtual void SendTitleTimes (int a_FadeInTicks, int a_DisplayTicks, int a_FadeOutTicks) = 0; virtual void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle) = 0; virtual void SendUnloadChunk (int a_ChunkX, int a_ChunkZ) = 0; virtual void SendUpdateBlockEntity (cBlockEntity & a_BlockEntity) = 0; diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 2bc58e7e5..e1e48e43f 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -555,6 +555,15 @@ void cProtocol172::SendHealth(void) +void cProtocol172::SendHideTitle(void) +{ + // Not implemented in this protocol version +} + + + + + void cProtocol172::SendInventorySlot(char a_WindowID, short a_SlotNum, const cItem & a_Item) { ASSERT(m_State == 3); // In game mode? @@ -985,6 +994,15 @@ void cProtocol172::SendRemoveEntityEffect(const cEntity & a_Entity, int a_Effect +void cProtocol172::SendResetTitle(void) +{ + // Not implemented in this protocol version +} + + + + + void cProtocol172::SendRespawn(eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks) { if ((m_LastSentDimension == a_Dimension) && !a_ShouldIgnoreDimensionChecks) @@ -1084,6 +1102,42 @@ void cProtocol172::SendDisplayObjective(const AString & a_Objective, cScoreboard +void cProtocol172::SendSetSubTitle(const cCompositeChat & a_SubTitle) +{ + // Not implemented in this protocol version +} + + + + + +void cProtocol172::SendSetRawSubTitle(const AString & a_SubTitle) +{ + // Not implemented in this protocol version +} + + + + + +void cProtocol172::SendSetTitle(const cCompositeChat & a_Title) +{ + // Not implemented in this protocol version +} + + + + + +void cProtocol172::SendSetRawTitle(const AString & a_Title) +{ + // Not implemented in this protocol version +} + + + + + void cProtocol172::SendSoundEffect(const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch) { ASSERT(m_State == 3); // In game mode? @@ -1286,6 +1340,15 @@ void cProtocol172::SendThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ) +void cProtocol172::SendTitleTimes(int a_FadeInTicks, int a_DisplayTicks, int a_FadeOutTicks) +{ + // Not implemented in this protocol version +} + + + + + void cProtocol172::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle) { ASSERT(m_State == 3); // In game mode? diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index 1212cc325..553856eaa 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -90,6 +90,7 @@ public: virtual void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) override; virtual void SendGameMode (eGameMode a_GameMode) override; virtual void SendHealth (void) override; + virtual void SendHideTitle (void) override; virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override; virtual void SendKeepAlive (int a_PingID) override; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override; @@ -112,9 +113,14 @@ public: virtual void SendPlayerSpawn (const cPlayer & a_Player) override; virtual void SendPluginMessage (const AString & a_Channel, const AString & a_Message) override; virtual void SendRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID) override; + virtual void SendResetTitle (void) override; virtual void SendRespawn (eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks) override; virtual void SendScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) override; virtual void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) override; + virtual void SendSetSubTitle (const cCompositeChat & a_SubTitle) override; + virtual void SendSetRawSubTitle (const AString & a_SubTitle) override; + virtual void SendSetTitle (const cCompositeChat & a_Title) override; + virtual void SendSetRawTitle (const AString & a_Title) override; virtual void SendSoundEffect (const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch) override; virtual void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) override; virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) override; @@ -125,6 +131,7 @@ public: virtual void SendTabCompletionResults (const AStringVector & a_Results) override; virtual void SendTeleportEntity (const cEntity & a_Entity) override; virtual void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) override; + virtual void SendTitleTimes (int a_FadeInTicks, int a_DisplayTicks, int a_FadeOutTicks) override; virtual void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle) override; virtual void SendUnloadChunk (int a_ChunkX, int a_ChunkZ) override; virtual void SendUpdateBlockEntity (cBlockEntity & a_BlockEntity) override; diff --git a/src/Protocol/Protocol18x.cpp b/src/Protocol/Protocol18x.cpp index a1ca25200..20b55f461 100644 --- a/src/Protocol/Protocol18x.cpp +++ b/src/Protocol/Protocol18x.cpp @@ -542,6 +542,18 @@ void cProtocol180::SendHealth(void) +void cProtocol180::SendHideTitle(void) +{ + ASSERT(m_State == 3); // In game mode? + + cPacketizer Pkt(*this, 0x45); // Title packet + Pkt.WriteVarInt32(3); // Hide title +} + + + + + void cProtocol180::SendInventorySlot(char a_WindowID, short a_SlotNum, const cItem & a_Item) { ASSERT(m_State == 3); // In game mode? @@ -1021,6 +1033,18 @@ void cProtocol180::SendRemoveEntityEffect(const cEntity & a_Entity, int a_Effect +void cProtocol180::SendResetTitle(void) +{ + ASSERT(m_State == 3); // In game mode? + + cPacketizer Pkt(*this, 0x45); // Title packet + Pkt.WriteVarInt32(4); // Reset title +} + + + + + void cProtocol180::SendRespawn(eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks) { if ((m_LastSentDimension == a_Dimension) && !a_ShouldIgnoreDimensionChecks) @@ -1123,6 +1147,52 @@ void cProtocol180::SendDisplayObjective(const AString & a_Objective, cScoreboard +void cProtocol180::SendSetSubTitle(const cCompositeChat & a_SubTitle) +{ + SendSetRawSubTitle(a_SubTitle.CreateJsonString(false)); +} + + + + + +void cProtocol180::SendSetRawSubTitle(const AString & a_SubTitle) +{ + ASSERT(m_State == 3); // In game mode? + + cPacketizer Pkt(*this, 0x45); // Title packet + Pkt.WriteVarInt32(1); // Set subtitle + + Pkt.WriteString(a_SubTitle); +} + + + + + +void cProtocol180::SendSetTitle(const cCompositeChat & a_Title) +{ + SendSetRawTitle(a_Title.CreateJsonString(false)); +} + + + + + +void cProtocol180::SendSetRawTitle(const AString & a_Title) +{ + ASSERT(m_State == 3); // In game mode? + + cPacketizer Pkt(*this, 0x45); // Title packet + Pkt.WriteVarInt32(0); // Set title + + Pkt.WriteString(a_Title); +} + + + + + void cProtocol180::SendSoundEffect(const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch) { ASSERT(m_State == 3); // In game mode? @@ -1330,6 +1400,22 @@ void cProtocol180::SendThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ) +void cProtocol180::SendTitleTimes(int a_FadeInTicks, int a_DisplayTicks, int a_FadeOutTicks) +{ + ASSERT(m_State == 3); // In game mode? + + cPacketizer Pkt(*this, 0x45); // Title packet + Pkt.WriteVarInt32(2); // Set title display times + + Pkt.WriteBEInt32(a_FadeInTicks); + Pkt.WriteBEInt32(a_DisplayTicks); + Pkt.WriteBEInt32(a_FadeOutTicks); +} + + + + + void cProtocol180::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle) { ASSERT(m_State == 3); // In game mode? diff --git a/src/Protocol/Protocol18x.h b/src/Protocol/Protocol18x.h index 9aa5ed827..06a57b216 100644 --- a/src/Protocol/Protocol18x.h +++ b/src/Protocol/Protocol18x.h @@ -85,6 +85,7 @@ public: virtual void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) override; virtual void SendGameMode (eGameMode a_GameMode) override; virtual void SendHealth (void) override; + virtual void SendHideTitle (void) override; virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override; virtual void SendKeepAlive (int a_PingID) override; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override; @@ -108,6 +109,7 @@ public: virtual void SendPlayerSpawn (const cPlayer & a_Player) override; virtual void SendPluginMessage (const AString & a_Channel, const AString & a_Message) override; virtual void SendRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID) override; + virtual void SendResetTitle (void) override; virtual void SendRespawn (eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks) override; virtual void SendSoundEffect (const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch) override; virtual void SendExperience (void) override; @@ -115,6 +117,10 @@ public: virtual void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) override; virtual void SendScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) override; virtual void SendDisplayObjective (const AString & a_Objective, cScoreboard::eDisplaySlot a_Display) override; + virtual void SendSetSubTitle (const cCompositeChat & a_SubTitle) override; + virtual void SendSetRawSubTitle (const AString & a_SubTitle) override; + virtual void SendSetTitle (const cCompositeChat & a_Title) override; + virtual void SendSetRawTitle (const AString & a_Title) override; virtual void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) override; virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) override; virtual void SendSpawnMob (const cMonster & a_Mob) override; @@ -124,6 +130,7 @@ public: virtual void SendTabCompletionResults (const AStringVector & a_Results) override; virtual void SendTeleportEntity (const cEntity & a_Entity) override; virtual void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) override; + virtual void SendTitleTimes (int a_FadeInTicks, int a_DisplayTicks, int a_FadeOutTicks) override; virtual void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle) override; virtual void SendUnloadChunk (int a_ChunkX, int a_ChunkZ) override; virtual void SendUpdateBlockEntity (cBlockEntity & a_BlockEntity) override; diff --git a/src/Protocol/ProtocolRecognizer.cpp b/src/Protocol/ProtocolRecognizer.cpp index 36f8bc791..6c599dedc 100644 --- a/src/Protocol/ProtocolRecognizer.cpp +++ b/src/Protocol/ProtocolRecognizer.cpp @@ -350,6 +350,16 @@ void cProtocolRecognizer::SendHealth(void) +void cProtocolRecognizer::SendHideTitle(void) +{ + ASSERT(m_Protocol != nullptr); + m_Protocol->SendHideTitle(); +} + + + + + void cProtocolRecognizer::SendWindowProperty(const cWindow & a_Window, short a_Property, short a_Value) { ASSERT(m_Protocol != nullptr); @@ -588,6 +598,16 @@ void cProtocolRecognizer::SendRemoveEntityEffect(const cEntity & a_Entity, int a +void cProtocolRecognizer::SendResetTitle(void) +{ + ASSERT(m_Protocol != nullptr); + m_Protocol->SendResetTitle(); +} + + + + + void cProtocolRecognizer::SendRespawn(eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks) { ASSERT(m_Protocol != nullptr); @@ -648,6 +668,46 @@ void cProtocolRecognizer::SendDisplayObjective(const AString & a_Objective, cSco +void cProtocolRecognizer::SendSetSubTitle(const cCompositeChat & a_SubTitle) +{ + ASSERT(m_Protocol != nullptr); + m_Protocol->SendSetSubTitle(a_SubTitle); +} + + + + + +void cProtocolRecognizer::SendSetRawSubTitle(const AString & a_SubTitle) +{ + ASSERT(m_Protocol != nullptr); + m_Protocol->SendSetRawSubTitle(a_SubTitle); +} + + + + + +void cProtocolRecognizer::SendSetTitle(const cCompositeChat & a_Title) +{ + ASSERT(m_Protocol != nullptr); + m_Protocol->SendSetTitle(a_Title); +} + + + + + +void cProtocolRecognizer::SendSetRawTitle(const AString & a_Title) +{ + ASSERT(m_Protocol != nullptr); + m_Protocol->SendSetRawTitle(a_Title); +} + + + + + void cProtocolRecognizer::SendSoundEffect(const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch) { ASSERT(m_Protocol != nullptr); @@ -748,6 +808,16 @@ void cProtocolRecognizer::SendThunderbolt(int a_BlockX, int a_BlockY, int a_Bloc +void cProtocolRecognizer::SendTitleTimes(int a_FadeInTicks, int a_DisplayTicks, int a_FadeOutTicks) +{ + ASSERT(m_Protocol != nullptr); + m_Protocol->SendTitleTimes(a_FadeInTicks, a_DisplayTicks, a_FadeOutTicks); +} + + + + + void cProtocolRecognizer::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle) { ASSERT(m_Protocol != nullptr); diff --git a/src/Protocol/ProtocolRecognizer.h b/src/Protocol/ProtocolRecognizer.h index d46d31cb1..8454549e3 100644 --- a/src/Protocol/ProtocolRecognizer.h +++ b/src/Protocol/ProtocolRecognizer.h @@ -73,6 +73,7 @@ public: virtual void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) override; virtual void SendGameMode (eGameMode a_GameMode) override; virtual void SendHealth (void) override; + virtual void SendHideTitle (void) override; virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override; virtual void SendKeepAlive (int a_PingID) override; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override; @@ -96,12 +97,17 @@ public: virtual void SendPlayerSpawn (const cPlayer & a_Player) override; virtual void SendPluginMessage (const AString & a_Channel, const AString & a_Message) override; virtual void SendRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID) override; + virtual void SendResetTitle (void) override; virtual void SendRespawn (eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks) override; virtual void SendExperience (void) override; virtual void SendExperienceOrb (const cExpOrb & a_ExpOrb) override; virtual void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) override; virtual void SendScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) override; virtual void SendDisplayObjective (const AString & a_Objective, cScoreboard::eDisplaySlot a_Display) override; + virtual void SendSetSubTitle (const cCompositeChat & a_SubTitle) override; + virtual void SendSetRawSubTitle (const AString & a_SubTitle) override; + virtual void SendSetTitle (const cCompositeChat & a_Title) override; + virtual void SendSetRawTitle (const AString & a_Title) override; virtual void SendSoundEffect (const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch) override; virtual void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) override; virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) override; @@ -112,6 +118,7 @@ public: virtual void SendTabCompletionResults (const AStringVector & a_Results) override; virtual void SendTeleportEntity (const cEntity & a_Entity) override; virtual void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) override; + virtual void SendTitleTimes (int a_FadeInTicks, int a_DisplayTicks, int a_FadeOutTicks) override; virtual void SendTimeUpdate (Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle) override; virtual void SendUnloadChunk (int a_ChunkX, int a_ChunkZ) override; virtual void SendUpdateBlockEntity (cBlockEntity & a_BlockEntity) override; -- cgit v1.2.3 From 0dbba305b6b96f81fe5f9b457dfb4f63d4a420c9 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 18 May 2015 14:30:16 +0100 Subject: Fixes #2052 --- src/Entities/Pickup.cpp | 1 + src/Inventory.cpp | 30 ++++++++++++++++++++++++++---- src/Inventory.h | 10 ++-------- src/Items/ItemBucket.h | 4 ++-- src/Items/ItemEmptyMap.h | 2 +- src/Items/ItemMushroomSoup.h | 2 +- 6 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src/Entities/Pickup.cpp b/src/Entities/Pickup.cpp index f2f76dbf9..520765b29 100644 --- a/src/Entities/Pickup.cpp +++ b/src/Entities/Pickup.cpp @@ -228,6 +228,7 @@ bool cPickup::CollectedBy(cPlayer & a_Dest) m_Item.m_ItemCount -= NumAdded; m_World->BroadcastCollectEntity(*this, a_Dest); + // Also send the "pop" sound effect with a somewhat random pitch (fast-random using EntityID ;) m_World->BroadcastSoundEffect("random.pop", GetPosX(), GetPosY(), GetPosZ(), 0.5, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); if (m_Item.m_ItemCount <= 0) diff --git a/src/Inventory.cpp b/src/Inventory.cpp index c595da5b0..f08dd1896 100644 --- a/src/Inventory.cpp +++ b/src/Inventory.cpp @@ -98,7 +98,7 @@ int cInventory::HowManyCanFit(const cItem & a_ItemStack, int a_BeginSlotNum, int -int cInventory::AddItem(const cItem & a_Item, bool a_AllowNewStacks, bool a_tryToFillEquippedFirst) +int cInventory::AddItem(const cItem & a_Item, bool a_AllowNewStacks) { cItem ToAdd(a_Item); int res = 0; @@ -116,8 +116,30 @@ int cInventory::AddItem(const cItem & a_Item, bool a_AllowNewStacks, bool a_tryT } } - res += m_HotbarSlots.AddItem(ToAdd, a_AllowNewStacks, a_tryToFillEquippedFirst ? m_EquippedSlotNum : -1); + for (int SlotIdx = 0; SlotIdx < m_InventorySlots.GetNumSlots(); ++SlotIdx) + { + auto & Slot = m_InventorySlots.GetSlot(SlotIdx); + if (Slot.IsEqual(a_Item)) + { + cItemHandler Handler(Slot.m_ItemType); + int AmountToAdd = std::min(static_cast(Handler.GetMaxStackSize() - Slot.m_ItemCount), ToAdd.m_ItemCount); + res += AmountToAdd; + + cItem SlotAdjusted(Slot); + SlotAdjusted.m_ItemCount += AmountToAdd; + m_InventorySlots.SetSlot(SlotIdx, SlotAdjusted); + + ToAdd.m_ItemCount -= AmountToAdd; + if (ToAdd.m_ItemCount == 0) + { + return res; + } + } + } + + res += m_HotbarSlots.AddItem(ToAdd, a_AllowNewStacks); ToAdd.m_ItemCount = a_Item.m_ItemCount - res; + if (ToAdd.m_ItemCount == 0) { return res; @@ -131,12 +153,12 @@ int cInventory::AddItem(const cItem & a_Item, bool a_AllowNewStacks, bool a_tryT -int cInventory::AddItems(cItems & a_ItemStackList, bool a_AllowNewStacks, bool a_tryToFillEquippedFirst) +int cInventory::AddItems(cItems & a_ItemStackList, bool a_AllowNewStacks) { int TotalAdded = 0; for (cItems::iterator itr = a_ItemStackList.begin(); itr != a_ItemStackList.end();) { - int NumAdded = AddItem(*itr, a_AllowNewStacks, a_tryToFillEquippedFirst); + int NumAdded = AddItem(*itr, a_AllowNewStacks); if (itr->m_ItemCount == NumAdded) { itr = a_ItemStackList.erase(itr); diff --git a/src/Inventory.h b/src/Inventory.h index b2a8f658b..5501399bd 100644 --- a/src/Inventory.h +++ b/src/Inventory.h @@ -70,23 +70,17 @@ public: /** Adds as many items out of a_ItemStack as can fit. If a_AllowNewStacks is set to false, only existing stacks can be topped up; if a_AllowNewStacks is set to true, empty slots can be used for the rest. - If a_tryToFillEquippedFirst is set to true, the currently equipped slot will be used first (if empty or - compatible with added items) - if a_tryToFillEquippedFirst is set to false, the regular order applies. Returns the number of items that fit. */ - int AddItem(const cItem & a_ItemStack, bool a_AllowNewStacks = true, bool a_tryToFillEquippedFirst = false); + int AddItem(const cItem & a_ItemStack, bool a_AllowNewStacks = true); /** Same as AddItem, but works on an entire list of item stacks. The a_ItemStackList is modified to reflect the leftover items. If a_AllowNewStacks is set to false, only existing stacks can be topped up; if a_AllowNewStacks is set to true, empty slots can be used for the rest. - If a_tryToFillEquippedFirst is set to true, the currently equipped slot will be used first (if empty or - compatible with added items) - if a_tryToFillEquippedFirst is set to false, the regular order applies. Returns the total number of items that fit. */ - int AddItems(cItems & a_ItemStackList, bool a_AllowNewStacks, bool a_tryToFillEquippedFirst); + int AddItems(cItems & a_ItemStackList, bool a_AllowNewStacks); /** Removes the specified item from the inventory, as many as possible, up to a_ItemStack.m_ItemCount. Returns the number of items that were removed. */ diff --git a/src/Items/ItemBucket.h b/src/Items/ItemBucket.h index 015720415..47429551a 100644 --- a/src/Items/ItemBucket.h +++ b/src/Items/ItemBucket.h @@ -96,7 +96,7 @@ public: ASSERT(!"Inventory bucket mismatch"); return true; } - if (a_Player->GetInventory().AddItem(cItem(NewItem), true, true) != 1) + if (a_Player->GetInventory().AddItem(cItem(NewItem)) != 1) { // The bucket didn't fit, toss it as a pickup: a_Player->TossPickup(cItem(NewItem)); @@ -137,7 +137,7 @@ public: return false; } cItem Item(E_ITEM_BUCKET, 1); - if (!a_Player->GetInventory().AddItem(Item, true, true)) + if (!a_Player->GetInventory().AddItem(Item)) { return false; } diff --git a/src/Items/ItemEmptyMap.h b/src/Items/ItemEmptyMap.h index 6e944b4da..fba8c0a2c 100644 --- a/src/Items/ItemEmptyMap.h +++ b/src/Items/ItemEmptyMap.h @@ -60,7 +60,7 @@ public: return true; } - a_Player->GetInventory().AddItem(cItem(E_ITEM_MAP, 1, (short)(NewMap->GetID() & 0x7fff)), true, true); + a_Player->GetInventory().AddItem(cItem(E_ITEM_MAP, 1, (short)(NewMap->GetID() & 0x7fff))); return true; } diff --git a/src/Items/ItemMushroomSoup.h b/src/Items/ItemMushroomSoup.h index dba313ec5..1a761cbf1 100644 --- a/src/Items/ItemMushroomSoup.h +++ b/src/Items/ItemMushroomSoup.h @@ -41,7 +41,7 @@ public: // Return a bowl to the inventory if (!a_Player->IsGameModeCreative()) { - a_Player->GetInventory().AddItem(cItem(E_ITEM_BOWL), true, true); + a_Player->GetInventory().AddItem(cItem(E_ITEM_BOWL)); } return true; } -- cgit v1.2.3 From 1632d5f8f1f3f1edb7ac2d0f4c79be9fbdae91ca Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 18 May 2015 15:43:24 +0100 Subject: Fixes #2003 --- src/UI/SlotArea.cpp | 2 +- src/UI/Window.cpp | 14 ++++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 37683a8e5..accd44b06 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -1394,7 +1394,7 @@ void cSlotAreaBeacon::OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum) // cSlotAreaEnchanting: cSlotAreaEnchanting::cSlotAreaEnchanting(cWindow & a_ParentWindow, int a_BlockX, int a_BlockY, int a_BlockZ) : - cSlotAreaTemporary(1, a_ParentWindow), + cSlotAreaTemporary(2, a_ParentWindow), m_BlockX(a_BlockX), m_BlockY(a_BlockY), m_BlockZ(a_BlockZ) diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index d1c08acec..61e25651b 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -92,9 +92,9 @@ const AString cWindow::GetWindowTypeName(void) const int cWindow::GetNumSlots(void) const { int res = 0; - for (cSlotAreas::const_iterator itr = m_SlotAreas.begin(), end = m_SlotAreas.end(); itr != end; ++itr) + for (const auto & itr : m_SlotAreas) { - res += (*itr)->GetNumSlots(); + res += itr->GetNumSlots(); } // for itr - m_SlotAreas[] return res; } @@ -261,16 +261,14 @@ void cWindow::Clicked( } int LocalSlotNum = a_SlotNum; - int idx = 0; - for (cSlotAreas::iterator itr = m_SlotAreas.begin(), end = m_SlotAreas.end(); itr != end; ++itr) + for (const auto & itr : m_SlotAreas) { - if (LocalSlotNum < (*itr)->GetNumSlots()) + if (LocalSlotNum < itr->GetNumSlots()) { - (*itr)->Clicked(a_Player, LocalSlotNum, a_ClickAction, a_ClickedItem); + itr->Clicked(a_Player, LocalSlotNum, a_ClickAction, a_ClickedItem); return; } - LocalSlotNum -= (*itr)->GetNumSlots(); - idx++; + LocalSlotNum -= itr->GetNumSlots(); } LOGWARNING("Slot number higher than available window slots: %d, max %d received from \"%s\"; ignoring.", -- cgit v1.2.3 From f2689c4887e6bd66af34de81cd793322f1dd57c4 Mon Sep 17 00:00:00 2001 From: tycho Date: Tue, 19 May 2015 11:50:59 +0100 Subject: Fixed a lot of warnings --- src/Blocks/BlockAnvil.h | 8 +- src/Blocks/BlockButton.h | 2 +- src/Blocks/BlockCocoaPod.h | 4 +- src/Blocks/BlockHopper.h | 2 +- src/Blocks/BlockLadder.h | 7 +- src/Blocks/BlockLeaves.h | 2 +- src/Blocks/BlockWallSign.h | 12 +- src/ChunkDef.h | 4 +- src/Defines.h | 21 ++- src/Generating/BioGen.cpp | 32 ++-- src/Generating/BioGen.h | 8 +- src/Generating/ChunkDesc.cpp | 12 +- src/Generating/ChunkDesc.h | 4 +- src/Generating/CompoGenBiomal.cpp | 15 +- src/Generating/ComposableGenerator.cpp | 4 +- src/Generating/FinishGen.cpp | 16 +- src/Generating/HeiGen.cpp | 26 +-- src/Generating/HeiGen.h | 2 +- src/Generating/MineShafts.cpp | 1 - src/Generating/ProtIntGen.h | 286 ++++++++++++++++----------------- src/HTTPServer/HTTPFormParser.cpp | 7 +- src/HTTPServer/HTTPServer.cpp | 4 +- src/Noise/Noise.cpp | 32 ++-- src/Noise/Noise.h | 4 +- src/OSSupport/File.cpp | 26 ++- src/OSSupport/File.h | 6 +- src/Protocol/Packetizer.h | 2 +- src/Protocol/Protocol17x.cpp | 4 +- src/StringUtils.h | 4 +- src/World.h | 2 +- 30 files changed, 286 insertions(+), 273 deletions(-) diff --git a/src/Blocks/BlockAnvil.h b/src/Blocks/BlockAnvil.h index abfa0f782..154394550 100644 --- a/src/Blocks/BlockAnvil.h +++ b/src/Blocks/BlockAnvil.h @@ -46,10 +46,10 @@ public: switch (Direction) { - case 0: a_BlockMeta = 0x2 | Meta << 2; break; - case 1: a_BlockMeta = 0x3 | Meta << 2; break; - case 2: a_BlockMeta = 0x0 | Meta << 2; break; - case 3: a_BlockMeta = 0x1 | Meta << 2; break; + case 0: a_BlockMeta = static_cast(0x2 | Meta << 2); break; + case 1: a_BlockMeta = static_cast(0x3 | Meta << 2); break; + case 2: a_BlockMeta = static_cast(0x0 | Meta << 2); break; + case 3: a_BlockMeta = static_cast(0x1 | Meta << 2); break; default: { return false; diff --git a/src/Blocks/BlockButton.h b/src/Blocks/BlockButton.h index d24c7d952..d65d9722d 100644 --- a/src/Blocks/BlockButton.h +++ b/src/Blocks/BlockButton.h @@ -67,7 +67,7 @@ public: case BLOCK_FACE_XM: return 0x2; case BLOCK_FACE_XP: return 0x1; case BLOCK_FACE_YM: return 0x0; - default: + case BLOCK_FACE_NONE: { ASSERT(!"Unhandled block face!"); return 0x0; diff --git a/src/Blocks/BlockCocoaPod.h b/src/Blocks/BlockCocoaPod.h index 1b659d48f..50552c788 100644 --- a/src/Blocks/BlockCocoaPod.h +++ b/src/Blocks/BlockCocoaPod.h @@ -81,7 +81,9 @@ public: case BLOCK_FACE_XM: return 3; case BLOCK_FACE_XP: return 1; case BLOCK_FACE_ZP: return 2; - default: + case BLOCK_FACE_NONE: + case BLOCK_FACE_YM: + case BLOCK_FACE_YP: { ASSERT(!"Unknown face"); return 0; diff --git a/src/Blocks/BlockHopper.h b/src/Blocks/BlockHopper.h index 4a5d32dd5..06e2b0e9f 100644 --- a/src/Blocks/BlockHopper.h +++ b/src/Blocks/BlockHopper.h @@ -35,7 +35,7 @@ public: case BLOCK_FACE_NORTH: a_BlockMeta = E_META_HOPPER_FACING_ZP; break; case BLOCK_FACE_SOUTH: a_BlockMeta = E_META_HOPPER_FACING_ZM; break; case BLOCK_FACE_WEST: a_BlockMeta = E_META_HOPPER_FACING_XP; break; - default: a_BlockMeta = E_META_HOPPER_UNATTACHED; break; + case BLOCK_FACE_NONE: a_BlockMeta = E_META_HOPPER_UNATTACHED; break; } return true; } diff --git a/src/Blocks/BlockLadder.h b/src/Blocks/BlockLadder.h index ab3f55439..f49f1adc7 100644 --- a/src/Blocks/BlockLadder.h +++ b/src/Blocks/BlockLadder.h @@ -57,7 +57,12 @@ public: case BLOCK_FACE_ZP: return 0x3; case BLOCK_FACE_XM: return 0x4; case BLOCK_FACE_XP: return 0x5; - default: return 0x2; + case BLOCK_FACE_NONE: + case BLOCK_FACE_YM: + case BLOCK_FACE_YP: + { + return 0x2; + } } } diff --git a/src/Blocks/BlockLeaves.h b/src/Blocks/BlockLeaves.h index 8e44c94ac..b7b2cc127 100644 --- a/src/Blocks/BlockLeaves.h +++ b/src/Blocks/BlockLeaves.h @@ -47,7 +47,7 @@ public: cItem( E_BLOCK_SAPLING, 1, - (m_BlockType == E_BLOCK_LEAVES) ? (a_BlockMeta & 0x03) : (2 << (a_BlockMeta & 0x01)) + (m_BlockType == E_BLOCK_LEAVES) ? (a_BlockMeta & 0x03) : static_cast(2 << (a_BlockMeta & 0x01)) ) ); } diff --git a/src/Blocks/BlockWallSign.h b/src/Blocks/BlockWallSign.h index b6599d033..9b90b78bf 100644 --- a/src/Blocks/BlockWallSign.h +++ b/src/Blocks/BlockWallSign.h @@ -55,11 +55,13 @@ public: { switch (a_Direction) { - case 0x2: return 0x2; - case 0x3: return 0x3; - case 0x4: return 0x4; - case 0x5: return 0x5; - default: + case BLOCK_FACE_ZM: return 0x2; + case BLOCK_FACE_ZP: return 0x3; + case BLOCK_FACE_XM: return 0x4; + case BLOCK_FACE_XP: return 0x5; + case BLOCK_FACE_NONE: + case BLOCK_FACE_YP: + case BLOCK_FACE_YM: { break; } diff --git a/src/ChunkDef.h b/src/ChunkDef.h index 2bfa2949c..b03a03bff 100644 --- a/src/ChunkDef.h +++ b/src/ChunkDef.h @@ -190,7 +190,7 @@ public: } - inline static int GetHeight(const HeightMap & a_HeightMap, int a_X, int a_Z) + inline static HEIGHTTYPE GetHeight(const HeightMap & a_HeightMap, int a_X, int a_Z) { ASSERT((a_X >= 0) && (a_X < Width)); ASSERT((a_Z >= 0) && (a_Z < Width)); @@ -198,7 +198,7 @@ public: } - inline static void SetHeight(HeightMap & a_HeightMap, int a_X, int a_Z, unsigned char a_Height) + inline static void SetHeight(HeightMap & a_HeightMap, int a_X, int a_Z, HEIGHTTYPE a_Height) { ASSERT((a_X >= 0) && (a_X < Width)); ASSERT((a_Z >= 0) && (a_Z < Width)); diff --git a/src/Defines.h b/src/Defines.h index 787eacab8..71288b430 100644 --- a/src/Defines.h +++ b/src/Defines.h @@ -238,7 +238,10 @@ inline eBlockFace MirrorBlockFaceY(eBlockFace a_BlockFace) case BLOCK_FACE_XP: return BLOCK_FACE_XM; case BLOCK_FACE_ZM: return BLOCK_FACE_ZP; case BLOCK_FACE_ZP: return BLOCK_FACE_ZM; - default: return a_BlockFace; + case BLOCK_FACE_NONE: + case BLOCK_FACE_YM: + case BLOCK_FACE_YP: + return a_BlockFace; } } @@ -255,7 +258,10 @@ inline eBlockFace RotateBlockFaceCCW(eBlockFace a_BlockFace) case BLOCK_FACE_XP: return BLOCK_FACE_ZM; case BLOCK_FACE_ZM: return BLOCK_FACE_XM; case BLOCK_FACE_ZP: return BLOCK_FACE_XP; - default: return a_BlockFace; + case BLOCK_FACE_NONE: + case BLOCK_FACE_YM: + case BLOCK_FACE_YP: + return a_BlockFace; } } @@ -271,7 +277,10 @@ inline eBlockFace RotateBlockFaceCW(eBlockFace a_BlockFace) case BLOCK_FACE_XP: return BLOCK_FACE_ZP; case BLOCK_FACE_ZM: return BLOCK_FACE_XP; case BLOCK_FACE_ZP: return BLOCK_FACE_XM; - default: return a_BlockFace; + case BLOCK_FACE_NONE: + case BLOCK_FACE_YM: + case BLOCK_FACE_YP: + return a_BlockFace; } } @@ -285,7 +294,7 @@ inline eBlockFace ReverseBlockFace(eBlockFace a_BlockFace) case BLOCK_FACE_YM: return BLOCK_FACE_YP; case BLOCK_FACE_XM: return BLOCK_FACE_XP; case BLOCK_FACE_ZM: return BLOCK_FACE_ZP; - default: return a_BlockFace; + case BLOCK_FACE_NONE: return a_BlockFace; } } @@ -436,7 +445,7 @@ inline void AddFaceDirection(int & a_BlockX, int & a_BlockY, int & a_BlockZ, eBl case BLOCK_FACE_ZP: a_BlockZ++; break; case BLOCK_FACE_XP: a_BlockX++; break; case BLOCK_FACE_XM: a_BlockX--; break; - default: + case BLOCK_FACE_NONE: { LOGWARNING("%s: Unknown face: %d", __FUNCTION__, a_BlockFace); ASSERT(!"AddFaceDirection(): Unknown face"); @@ -454,7 +463,7 @@ inline void AddFaceDirection(int & a_BlockX, int & a_BlockY, int & a_BlockZ, eBl case BLOCK_FACE_ZP: a_BlockZ--; break; case BLOCK_FACE_XP: a_BlockX--; break; case BLOCK_FACE_XM: a_BlockX++; break; - default: + case BLOCK_FACE_NONE: { LOGWARNING("%s: Unknown inv face: %d", __FUNCTION__, a_BlockFace); ASSERT(!"AddFaceDirection(): Unknown face"); diff --git a/src/Generating/BioGen.cpp b/src/Generating/BioGen.cpp index 867155ad2..2c6af27a4 100644 --- a/src/Generating/BioGen.cpp +++ b/src/Generating/BioGen.cpp @@ -49,18 +49,18 @@ void cBioGenConstant::InitializeBiomeGen(cIniFile & a_IniFile) //////////////////////////////////////////////////////////////////////////////// // cBioGenCache: -cBioGenCache::cBioGenCache(cBiomeGenPtr a_BioGenToCache, int a_CacheSize) : +cBioGenCache::cBioGenCache(cBiomeGenPtr a_BioGenToCache, size_t a_CacheSize) : m_BioGenToCache(a_BioGenToCache), m_CacheSize(a_CacheSize), - m_CacheOrder(new int[a_CacheSize]), + m_CacheOrder(new size_t[a_CacheSize]), m_CacheData(new sCacheData[a_CacheSize]), m_NumHits(0), m_NumMisses(0), m_TotalChain(0) { - for (int i = 0; i < m_CacheSize; i++) + for (size_t i = 0; i < m_CacheSize; i++) { - m_CacheOrder[i] = i; + m_CacheOrder[i] = static_cast(i); m_CacheData[i].m_ChunkX = 0x7fffffff; m_CacheData[i].m_ChunkZ = 0x7fffffff; } @@ -90,7 +90,7 @@ void cBioGenCache::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a LOGD("BioGenCache: Avg cache chain length: %.2f", (float)m_TotalChain / m_NumHits); } - for (int i = 0; i < m_CacheSize; i++) + for (size_t i = 0; i < m_CacheSize; i++) { if ( (m_CacheData[m_CacheOrder[i]].m_ChunkX != a_ChunkX) || @@ -100,10 +100,10 @@ void cBioGenCache::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a continue; } // Found it in the cache - int Idx = m_CacheOrder[i]; + size_t Idx = m_CacheOrder[i]; // Move to front: - for (int j = i; j > 0; j--) + for (size_t j = i; j > 0; j--) { m_CacheOrder[j] = m_CacheOrder[j - 1]; } @@ -122,8 +122,8 @@ void cBioGenCache::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a m_BioGenToCache->GenBiomes(a_ChunkX, a_ChunkZ, a_BiomeMap); // Insert it as the first item in the MRU order: - int Idx = m_CacheOrder[m_CacheSize - 1]; - for (int i = m_CacheSize - 1; i > 0; i--) + size_t Idx = m_CacheOrder[m_CacheSize - 1]; + for (size_t i = m_CacheSize - 1; i > 0; i--) { m_CacheOrder[i] = m_CacheOrder[i - 1]; } // for i - m_CacheOrder[] @@ -278,7 +278,7 @@ void cBioGenCheckerboard::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::Biome for (int x = 0; x < cChunkDef::Width; x++) { int Add = cChunkDef::Width * a_ChunkX + x; - int BiomeIdx = (((Base + Add / m_BiomeSize) % m_BiomesCount) + m_BiomesCount) % m_BiomesCount; // Need to add and modulo twice because of negative numbers + size_t BiomeIdx = static_cast((((Base + Add / m_BiomeSize) % m_BiomesCount) + m_BiomesCount) % m_BiomesCount); // Need to add and modulo twice because of negative numbers a_BiomeMap[x + cChunkDef::Width * z] = m_Biomes[BiomeIdx]; } } @@ -314,7 +314,7 @@ void cBioGenVoronoi::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & for (int x = 0; x < cChunkDef::Width; x++) { int VoronoiCellValue = m_Voronoi.GetValueAt(BaseX + x, AbsoluteZ) / 8; - cChunkDef::SetBiome(a_BiomeMap, x, z, m_Biomes[VoronoiCellValue % m_BiomesCount]); + cChunkDef::SetBiome(a_BiomeMap, x, z, m_Biomes[static_cast(VoronoiCellValue % m_BiomesCount)]); } // for x } // for z } @@ -363,7 +363,7 @@ void cBioGenDistortedVoronoi::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::B for (int x = 0; x < cChunkDef::Width; x++) { int VoronoiCellValue = m_Voronoi.GetValueAt(DistortX[x][z], DistortZ[x][z]) / 8; - cChunkDef::SetBiome(a_BiomeMap, x, z, m_Biomes[VoronoiCellValue % m_BiomesCount]); + cChunkDef::SetBiome(a_BiomeMap, x, z, m_Biomes[static_cast(VoronoiCellValue % m_BiomesCount)]); } // for x } // for z } @@ -785,7 +785,7 @@ void cBioGenTwoLevel::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap { int SeedX, SeedZ, MinDist2; int BiomeGroup = m_VoronoiLarge.GetValueAt(DistortX[x][z], DistortZ[x][z], SeedX, SeedZ, MinDist2) / 7; - int BiomeIdx = m_VoronoiSmall.GetValueAt(DistortX[x][z], DistortZ[x][z], SeedX, SeedZ, MinDist2) / 11; + size_t BiomeIdx = static_cast(m_VoronoiSmall.GetValueAt(DistortX[x][z], DistortZ[x][z], SeedX, SeedZ, MinDist2) / 11); int MinDist1 = (DistortX[x][z] - SeedX) * (DistortX[x][z] - SeedX) + (DistortZ[x][z] - SeedZ) * (DistortZ[x][z] - SeedZ); cChunkDef::SetBiome(a_BiomeMap, x, z, SelectBiome(BiomeGroup, BiomeIdx, (MinDist1 < MinDist2 / 4) ? 1 : 0)); } @@ -796,7 +796,7 @@ void cBioGenTwoLevel::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap -EMCSBiome cBioGenTwoLevel::SelectBiome(int a_BiomeGroup, int a_BiomeIdx, int a_DistLevel) +EMCSBiome cBioGenTwoLevel::SelectBiome(int a_BiomeGroup, size_t a_BiomeIdx, int a_DistLevel) { // TODO: Move this into settings struct BiomeLevels @@ -900,7 +900,7 @@ EMCSBiome cBioGenTwoLevel::SelectBiome(int a_BiomeGroup, int a_BiomeIdx, int a_D { bgMesa, ARRAYCOUNT(bgMesa), }, { bgDenseTrees, ARRAYCOUNT(bgDenseTrees), }, } ; - size_t Group = a_BiomeGroup % ARRAYCOUNT(BiomeGroups); + size_t Group = static_cast(a_BiomeGroup) % ARRAYCOUNT(BiomeGroups); size_t Index = a_BiomeIdx % BiomeGroups[Group].Count; return (a_DistLevel > 0) ? BiomeGroups[Group].Biomes[Index].InnerBiome : BiomeGroups[Group].Biomes[Index].OuterBiome; } @@ -1121,7 +1121,7 @@ public: virtual void GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_Biomes) override { int vals[16 * 16]; - m_Gen->GetInts(a_ChunkX * cChunkDef::Width, a_ChunkZ * cChunkDef::Width, 16, 16, vals); + m_Gen->GetInts(static_cast(a_ChunkX * cChunkDef::Width), static_cast(a_ChunkZ * cChunkDef::Width), 16, 16, vals); for (int z = 0; z < cChunkDef::Width; z++) { for (int x = 0; x < cChunkDef::Width; x++) diff --git a/src/Generating/BioGen.h b/src/Generating/BioGen.h index 13fb40c5f..2580bf53a 100644 --- a/src/Generating/BioGen.h +++ b/src/Generating/BioGen.h @@ -48,7 +48,7 @@ class cBioGenCache : typedef cBiomeGen super; public: - cBioGenCache(cBiomeGenPtr a_BioGenToCache, int a_CacheSize); + cBioGenCache(cBiomeGenPtr a_BioGenToCache, size_t a_CacheSize); virtual ~cBioGenCache(); protected: @@ -63,8 +63,8 @@ protected: } ; // To avoid moving large amounts of data for the MRU behavior, we MRU-ize indices to an array of the actual data - int m_CacheSize; - int * m_CacheOrder; // MRU-ized order, indices into m_CacheData array + size_t m_CacheSize; + size_t * m_CacheOrder; // MRU-ized order, indices into m_CacheData array sCacheData * m_CacheData; // m_CacheData[m_CacheOrder[0]] is the most recently used // Cache statistics @@ -311,7 +311,7 @@ protected: /// Selects biome from the specified biome group, based on the specified index. /// Note that both params may overflow /// a_DistLevel is either 0 or 1; zero when it is at the edge of the small Voronoi cell, 1 near the center - EMCSBiome SelectBiome(int a_BiomeGroup, int a_BiomeIdx, int a_DistLevel); + EMCSBiome SelectBiome(int a_BiomeGroup, size_t a_BiomeIdx, int a_DistLevel); } ; diff --git a/src/Generating/ChunkDesc.cpp b/src/Generating/ChunkDesc.cpp index 4a5ac5a18..fe5182004 100644 --- a/src/Generating/ChunkDesc.cpp +++ b/src/Generating/ChunkDesc.cpp @@ -134,7 +134,7 @@ EMCSBiome cChunkDesc::GetBiome(int a_RelX, int a_RelZ) -void cChunkDesc::SetHeight(int a_RelX, int a_RelZ, int a_Height) +void cChunkDesc::SetHeight(int a_RelX, int a_RelZ, HEIGHTTYPE a_Height) { cChunkDef::SetHeight(m_HeightMap, a_RelX, a_RelZ, a_Height); } @@ -143,7 +143,7 @@ void cChunkDesc::SetHeight(int a_RelX, int a_RelZ, int a_Height) -int cChunkDesc::GetHeight(int a_RelX, int a_RelZ) +HEIGHTTYPE cChunkDesc::GetHeight(int a_RelX, int a_RelZ) { return cChunkDef::GetHeight(m_HeightMap, a_RelX, a_RelZ); } @@ -158,7 +158,7 @@ void cChunkDesc::SetHeightFromShape(const Shape & a_Shape) { for (int x = 0; x < cChunkDef::Width; x++) { - for (int y = cChunkDef::Height - 1; y > 0; y--) + for (unsigned char y = cChunkDef::Height - 1; y > 0; y--) { if (a_Shape[y + x * 256 + z * 16 * 256] != 0) { @@ -612,8 +612,8 @@ void cChunkDesc::UpdateHeightmap(void) { for (int z = 0; z < cChunkDef::Width; z++) { - int Height = 0; - for (int y = cChunkDef::Height - 1; y > 0; y--) + HEIGHTTYPE Height = 0; + for (HEIGHTTYPE y = cChunkDef::Height - 1; y > 0; y--) { BLOCKTYPE BlockType = GetBlockType(x, y, z); if (BlockType != E_BLOCK_AIR) @@ -636,7 +636,7 @@ void cChunkDesc::CompressBlockMetas(cChunkDef::BlockNibbles & a_DestMetas) const NIBBLETYPE * AreaMetas = m_BlockArea.GetBlockMetas(); for (size_t i = 0; i < ARRAYCOUNT(a_DestMetas); i++) { - a_DestMetas[i] = AreaMetas[2 * i] | (AreaMetas[2 * i + 1] << 4); + a_DestMetas[i] = static_cast(AreaMetas[2 * i] | (AreaMetas[2 * i + 1] << 4)); } } diff --git a/src/Generating/ChunkDesc.h b/src/Generating/ChunkDesc.h index 480106fb5..8308aae41 100644 --- a/src/Generating/ChunkDesc.h +++ b/src/Generating/ChunkDesc.h @@ -65,8 +65,8 @@ public: // These operate on the heightmap, so they could get out of sync with the data // Use UpdateHeightmap() to re-calculate heightmap from the block data - void SetHeight(int a_RelX, int a_RelZ, int a_Height); - int GetHeight(int a_RelX, int a_RelZ); + void SetHeight(int a_RelX, int a_RelZ, HEIGHTTYPE a_Height); + HEIGHTTYPE GetHeight(int a_RelX, int a_RelZ); // tolua_end diff --git a/src/Generating/CompoGenBiomal.cpp b/src/Generating/CompoGenBiomal.cpp index 3140bd754..1385bd523 100644 --- a/src/Generating/CompoGenBiomal.cpp +++ b/src/Generating/CompoGenBiomal.cpp @@ -4,6 +4,9 @@ // Implements the cCompoGenBiomal class representing the biome-aware composition generator #include "Globals.h" + +#include "CompoGenBiomal.h" + #include "ComposableGenerator.h" #include "../IniFile.h" #include "../Noise/Noise.h" @@ -192,7 +195,7 @@ public: protected: /** The block height at which water is generated instead of air. */ - int m_SeaLevel; + HEIGHTTYPE m_SeaLevel; /** The pattern used for mesa biomes. Initialized by seed on generator creation. */ cPattern::BlockInfo m_MesaPattern[2 * cChunkDef::Height]; @@ -221,7 +224,7 @@ protected: virtual void InitializeCompoGen(cIniFile & a_IniFile) override { - m_SeaLevel = a_IniFile.GetValueSetI("Generator", "SeaLevel", m_SeaLevel); + m_SeaLevel = static_cast(a_IniFile.GetValueSetI("Generator", "SeaLevel", m_SeaLevel)); } @@ -231,7 +234,7 @@ protected: { // In a loop, choose whether to use one, two or three layers of stained clay, then choose a color and width for each layer // Separate each group with another layer of hardened clay - cNoise patternNoise((unsigned)a_Seed); + cNoise patternNoise(a_Seed); static NIBBLETYPE allowedColors[] = { E_META_STAINED_CLAY_YELLOW, @@ -265,8 +268,8 @@ protected: rnd /= 2; for (int lay = 0; lay < numLayers; lay++) { - int numBlocks = layerSizes[(rnd % ARRAYCOUNT(layerSizes))]; - NIBBLETYPE Color = allowedColors[(rnd / 4) % ARRAYCOUNT(allowedColors)]; + int numBlocks = layerSizes[(static_cast(rnd) % ARRAYCOUNT(layerSizes))]; + NIBBLETYPE Color = allowedColors[static_cast(rnd / 4) % ARRAYCOUNT(allowedColors)]; if ( ((numBlocks == 3) && (numLayers == 2)) || // In two-layer mode disallow the 3-high layers: (Color == E_META_STAINED_CLAY_WHITE)) // White stained clay can ever be only 1 block high @@ -427,7 +430,7 @@ protected: { bool HasHadWater = false; int PatternIdx = 0; - int top = std::max(m_SeaLevel, a_ChunkDesc.GetHeight(a_RelX, a_RelZ)); + HEIGHTTYPE top = std::max(m_SeaLevel, a_ChunkDesc.GetHeight(a_RelX, a_RelZ)); for (int y = top; y > 0; y--) { if (a_ShapeColumn[y] > 0) diff --git a/src/Generating/ComposableGenerator.cpp b/src/Generating/ComposableGenerator.cpp index 6b7643ddb..f9a4d7609 100644 --- a/src/Generating/ComposableGenerator.cpp +++ b/src/Generating/ComposableGenerator.cpp @@ -221,11 +221,11 @@ void cComposableGenerator::InitBiomeGen(cIniFile & a_IniFile) if (MultiCacheLength > 0) { LOGD("Enabling multicache for biomegen of length %d.", MultiCacheLength); - m_BiomeGen = cBiomeGenPtr(new cBioGenMulticache(m_BiomeGen, CacheSize, MultiCacheLength)); + m_BiomeGen = cBiomeGenPtr(new cBioGenMulticache(m_BiomeGen, static_cast(CacheSize), static_cast(MultiCacheLength))); } else { - m_BiomeGen = cBiomeGenPtr(new cBioGenCache(m_BiomeGen, CacheSize)); + m_BiomeGen = cBiomeGenPtr(new cBioGenCache(m_BiomeGen, static_cast(CacheSize))); } } diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index 00b34bddd..af4056e8c 100644 --- a/src/Generating/FinishGen.cpp +++ b/src/Generating/FinishGen.cpp @@ -260,13 +260,13 @@ void cFinishGenGlowStone::TryPlaceGlowstone(cChunkDesc & a_ChunkDesc, int a_RelX for (int j = 0; j < a_Size; j++) { - Vector3i Direction = AvailableDirections[m_Noise.IntNoise3DInt(CurrentPos.x, CurrentPos.y * i, CurrentPos.z) % ARRAYCOUNT(AvailableDirections)]; + Vector3i Direction = AvailableDirections[static_cast(m_Noise.IntNoise3DInt(CurrentPos.x, CurrentPos.y * i, CurrentPos.z)) % ARRAYCOUNT(AvailableDirections)]; int Attempts = 2; // multiply by 1 would make no difference, so multiply by 2 instead while (Direction.Equals(PreviousDirection)) { // To make the glowstone branches look better we want to make the direction change every time. - Direction = AvailableDirections[m_Noise.IntNoise3DInt(CurrentPos.x, CurrentPos.y * i * Attempts, CurrentPos.z) % ARRAYCOUNT(AvailableDirections)]; + Direction = AvailableDirections[static_cast(m_Noise.IntNoise3DInt(CurrentPos.x, CurrentPos.y * i * Attempts, CurrentPos.z)) % ARRAYCOUNT(AvailableDirections)]; Attempts++; } @@ -438,7 +438,7 @@ void cFinishGenVines::GenFinish(cChunkDesc & a_ChunkDesc) continue; } - NIBBLETYPE Meta = Places[m_Noise.IntNoise3DInt(xx, y, zz) % Places.size()]; + NIBBLETYPE Meta = Places[static_cast(m_Noise.IntNoise3DInt(xx, y, zz)) % Places.size()]; a_ChunkDesc.SetBlockTypeMeta(x, y, z, E_BLOCK_VINES, Meta); } } @@ -515,7 +515,7 @@ void cFinishGenSprinkleFoliage::GenFinish(cChunkDesc & a_ChunkDesc) { continue; } - int Top = a_ChunkDesc.GetHeight(x, z); + HEIGHTTYPE Top = a_ChunkDesc.GetHeight(x, z); if (Top > 250) { // Nothing grows above Y=250 @@ -676,7 +676,7 @@ void cFinishGenSnow::GenFinish(cChunkDesc & a_ChunkDesc) { for (int x = 0; x < cChunkDef::Width; x++) { - int Height = a_ChunkDesc.GetHeight(x, z); + HEIGHTTYPE Height = a_ChunkDesc.GetHeight(x, z); if (GetSnowStartHeight(a_ChunkDesc.GetBiome(x, z)) > Height) { // Height isn't high enough for snow to start forming. @@ -775,7 +775,7 @@ void cFinishGenSingleTopBlock::GenFinish(cChunkDesc & a_ChunkDesc) continue; } - int Height = a_ChunkDesc.GetHeight(x, z); + HEIGHTTYPE Height = a_ChunkDesc.GetHeight(x, z); if (Height >= cChunkDef::Height - 1) { // Too high up @@ -918,7 +918,7 @@ void cFinishGenPreSimulator::CollapseSandGravel( } } // switch (GetBlock) } // for y - cChunkDef::SetHeight(a_HeightMap, x, z, HeightY); + cChunkDef::SetHeight(a_HeightMap, x, z, static_cast(HeightY)); } // for x } // for z } @@ -1374,7 +1374,7 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc) return mtInvalidType; } - int RandMob = (m_Noise.IntNoise2DInt(chunkX - chunkZ + 2, chunkX + 5) / 7) % ListOfSpawnables.size(); + size_t RandMob = static_cast((m_Noise.IntNoise2DInt(chunkX - chunkZ + 2, chunkX + 5) / 7)) % ListOfSpawnables.size(); auto MobIter = ListOfSpawnables.begin(); std::advance(MobIter, RandMob); diff --git a/src/Generating/HeiGen.cpp b/src/Generating/HeiGen.cpp index e34ffc57c..e44885135 100644 --- a/src/Generating/HeiGen.cpp +++ b/src/Generating/HeiGen.cpp @@ -58,7 +58,7 @@ public: virtual void GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMap & a_HeightMap) override { int heights[cChunkDef::Width * cChunkDef::Width]; - m_Gen->GetInts(a_ChunkX * cChunkDef::Width, a_ChunkZ * cChunkDef::Width, cChunkDef::Width, cChunkDef::Width, heights); + m_Gen->GetInts(static_cast(a_ChunkX * cChunkDef::Width), static_cast(a_ChunkZ * cChunkDef::Width), static_cast(cChunkDef::Width), static_cast(cChunkDef::Width), heights); for (size_t i = 0; i < ARRAYCOUNT(heights); i++) { a_HeightMap[i] = static_cast(std::max(std::min(60 + heights[i], cChunkDef::Height - 60), 40)); @@ -92,7 +92,7 @@ void cHeiGenFlat::GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMap void cHeiGenFlat::InitializeHeightGen(cIniFile & a_IniFile) { - m_Height = a_IniFile.GetValueSetI("Generator", "FlatHeight", m_Height); + m_Height = static_cast(a_IniFile.GetValueSetI("Generator", "FlatHeight", m_Height)); } @@ -300,15 +300,7 @@ void cHeiGenClassic::GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightM { const float xx = (float)(a_ChunkX * cChunkDef::Width + x); - int hei = 64 + (int)(GetNoise(xx * 0.05f, zz * 0.05f) * 16); - if (hei < 10) - { - hei = 10; - } - if (hei > 250) - { - hei = 250; - } + HEIGHTTYPE hei = static_cast(Clamp(static_cast(64 + (GetNoise(xx * 0.05f, zz * 0.05f) * 16)), 10, 250)); cChunkDef::SetHeight(a_HeightMap, x, z, hei); } // for x } // for z @@ -366,15 +358,7 @@ void cHeiGenMountains::GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::Heigh for (int x = 0; x < cChunkDef::Width; x++) { int idx = IdxZ + x; - int hei = 100 - (int)((MountainNoise[idx] - DitchNoise[idx] + PerlinNoise[idx]) * 15); - if (hei < 10) - { - hei = 10; - } - if (hei > 250) - { - hei = 250; - } + HEIGHTTYPE hei = static_cast(Clamp(100 - static_cast((MountainNoise[idx] - DitchNoise[idx] + PerlinNoise[idx]) * 15), 10, 250)); cChunkDef::SetHeight(a_HeightMap, x, z, hei); } // for x } // for z @@ -536,7 +520,7 @@ void cHeiGenBiomal::GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMa { for (int x = 0; x < cChunkDef::Width; x++) { - cChunkDef::SetHeight(a_HeightMap, x, z, (int)Height[x + 17 * z]); + cChunkDef::SetHeight(a_HeightMap, x, z, static_cast(Height[x + 17 * z])); } } //*/ diff --git a/src/Generating/HeiGen.h b/src/Generating/HeiGen.h index 62bb227c6..e2998bfb8 100644 --- a/src/Generating/HeiGen.h +++ b/src/Generating/HeiGen.h @@ -103,7 +103,7 @@ public: protected: - int m_Height; + HEIGHTTYPE m_Height; // cTerrainHeightGen overrides: virtual void GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMap & a_HeightMap) override; diff --git a/src/Generating/MineShafts.cpp b/src/Generating/MineShafts.cpp index 65588ce4b..61f29b762 100644 --- a/src/Generating/MineShafts.cpp +++ b/src/Generating/MineShafts.cpp @@ -781,7 +781,6 @@ void cMineShaftCorridor::PlaceChest(cChunkDesc & a_ChunkDesc) case dirZM: case dirZP: - default: { x = m_BoundingBox.p1.x - BlockX; z = m_BoundingBox.p1.z + m_ChestPosition - BlockZ; diff --git a/src/Generating/ProtIntGen.h b/src/Generating/ProtIntGen.h index 9e471e8bb..a7625731a 100644 --- a/src/Generating/ProtIntGen.h +++ b/src/Generating/ProtIntGen.h @@ -47,7 +47,7 @@ public: virtual ~cProtIntGen() {} /** Generates the array of specified size into a_Values, based on given min coords. */ - virtual void GetInts(int a_MinX, int a_MinZ, int a_SizeX, int a_SizeZ, int * a_Values) = 0; + virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) = 0; }; @@ -109,14 +109,14 @@ public: } - virtual void GetInts(int a_MinX, int a_MinZ, int a_SizeX, int a_SizeZ, int * a_Values) override + virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { - for (int z = 0; z < a_SizeZ; z++) + for (size_t z = 0; z < a_SizeZ; z++) { - int BaseZ = a_MinZ + z; - for (int x = 0; x < a_SizeX; x++) + size_t BaseZ = a_MinZ + z; + for (size_t x = 0; x < a_SizeX; x++) { - a_Values[x + a_SizeX * z] = (super::m_Noise.IntNoise2DInt(a_MinX + x, BaseZ) / 7) % m_Range; + a_Values[x + a_SizeX * z] = (super::m_Noise.IntNoise2DInt(static_cast(a_MinX + x), static_cast(BaseZ)) / 7) % m_Range; } } // for z } @@ -146,14 +146,14 @@ public: } - virtual void GetInts(int a_MinX, int a_MinZ, int a_SizeX, int a_SizeZ, int * a_Values) override + virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { - for (int z = 0; z < a_SizeZ; z++) + for (size_t z = 0; z < a_SizeZ; z++) { - int BaseZ = a_MinZ + z; - for (int x = 0; x < a_SizeX; x++) + size_t BaseZ = a_MinZ + z; + for (size_t x = 0; x < a_SizeX; x++) { - int rnd = (super::m_Noise.IntNoise2DInt(a_MinX + x, BaseZ) / 7); + int rnd = (super::m_Noise.IntNoise2DInt(static_cast(a_MinX + x), static_cast(BaseZ)) / 7); a_Values[x + a_SizeX * z] = ((rnd % 100) < m_Threshold) ? ((rnd / 101) % bgLandOceanMax + 1) : 0; } } @@ -189,13 +189,13 @@ public: } - virtual void GetInts(int a_MinX, int a_MinZ, int a_SizeX, int a_SizeZ, int * a_Values) override + virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { // Get the coords for the lower generator: - int lowerMinX = a_MinX >> 1; - int lowerMinZ = a_MinZ >> 1; - int lowerSizeX = a_SizeX / 2 + 2; - int lowerSizeZ = a_SizeZ / 2 + 2; + size_t lowerMinX = a_MinX >> 1; + size_t lowerMinZ = a_MinZ >> 1; + size_t lowerSizeX = a_SizeX / 2 + 2; + size_t lowerSizeZ = a_SizeZ / 2 + 2; ASSERT(lowerSizeX * lowerSizeZ <= m_BufferSize); ASSERT(lowerSizeX > 0); ASSERT(lowerSizeZ > 0); @@ -203,22 +203,22 @@ public: // Generate the underlying data with half the resolution: int lowerData[m_BufferSize]; m_UnderlyingGen->GetInts(lowerMinX, lowerMinZ, lowerSizeX, lowerSizeZ, lowerData); - const int lowStepX = (lowerSizeX - 1) * 2; + const size_t lowStepX = (lowerSizeX - 1) * 2; int cache[m_BufferSize]; // Discreet-interpolate the values into twice the size: - for (int z = 0; z < lowerSizeZ - 1; ++z) + for (size_t z = 0; z < lowerSizeZ - 1; ++z) { - int idx = (z * 2) * lowStepX; + size_t idx = (z * 2) * lowStepX; int PrevZ0 = lowerData[z * lowerSizeX]; int PrevZ1 = lowerData[(z + 1) * lowerSizeX]; - for (int x = 0; x < lowerSizeX - 1; ++x) + for (size_t x = 0; x < lowerSizeX - 1; ++x) { int ValX1Z0 = lowerData[x + 1 + z * lowerSizeX]; int ValX1Z1 = lowerData[x + 1 + (z + 1) * lowerSizeX]; - int RndX = (x + lowerMinX) * 2; - int RndZ = (z + lowerMinZ) * 2; + int RndX = static_cast(x + lowerMinX) * 2; + int RndZ = static_cast(z + lowerMinZ) * 2; cache[idx] = PrevZ0; cache[idx + lowStepX] = super::chooseRandomOne(RndX, RndZ + 1, PrevZ0, PrevZ1); cache[idx + 1] = super::chooseRandomOne(RndX, RndZ - 1, PrevZ0, ValX1Z0); @@ -230,7 +230,7 @@ public: } // Copy from Cache into a_Values; take into account the even / odd offsets in a_Min: - for (int z = 0; z < a_SizeZ; ++z) + for (size_t z = 0; z < a_SizeZ; ++z) { memcpy(a_Values + z * a_SizeX, cache + (z + (a_MinZ & 1)) * lowStepX + (a_MinX & 1), a_SizeX * sizeof(int)); } @@ -259,21 +259,21 @@ public: } - virtual void GetInts(int a_MinX, int a_MinZ, int a_SizeX, int a_SizeZ, int * a_Values) override + virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { // Generate the underlying values: - int lowerSizeX = a_SizeX + 2; - int lowerSizeZ = a_SizeZ + 2; + size_t lowerSizeX = a_SizeX + 2; + size_t lowerSizeZ = a_SizeZ + 2; ASSERT(lowerSizeX * lowerSizeZ <= m_BufferSize); int lowerData[m_BufferSize]; m_Underlying->GetInts(a_MinX - 1, a_MinZ - 1, lowerSizeX, lowerSizeZ, lowerData); // Smooth - for each square check if the surroundings are the same, if so, expand them diagonally. // Also get rid of single-pixel irregularities (A-B-A): - for (int z = 0; z < a_SizeZ; z++) + for (size_t z = 0; z < a_SizeZ; z++) { - int NoiseZ = a_MinZ + z; - for (int x = 0; x < a_SizeX; x++) + size_t NoiseZ = a_MinZ + z; + for (size_t x = 0; x < a_SizeX; x++) { int val = lowerData[x + 1 + (z + 1) * lowerSizeX]; int above = lowerData[x + 1 + z * lowerSizeX]; @@ -283,7 +283,7 @@ public: if ((left == right) && (above == below)) { - if (((super::m_Noise.IntNoise2DInt(a_MinX + x, NoiseZ) / 7) % 2) == 0) + if (((super::m_Noise.IntNoise2DInt(static_cast(a_MinX + x), static_cast(NoiseZ)) / 7) % 2) == 0) { val = left; } @@ -331,21 +331,21 @@ public: } - virtual void GetInts(int a_MinX, int a_MinZ, int a_SizeX, int a_SizeZ, int * a_Values) override + virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { // Generate the underlying values: - int lowerSizeX = a_SizeX + 1; - int lowerSizeZ = a_SizeZ + 1; + size_t lowerSizeX = a_SizeX + 1; + size_t lowerSizeZ = a_SizeZ + 1; ASSERT(lowerSizeX * lowerSizeZ <= m_BufferSize); int lowerData[m_BufferSize]; m_Underlying->GetInts(a_MinX, a_MinZ, lowerSizeX, lowerSizeZ, lowerData); // Average - add all 4 "neighbors" and divide by 4: - for (int z = 0; z < a_SizeZ; z++) + for (size_t z = 0; z < a_SizeZ; z++) { - for (int x = 0; x < a_SizeX; x++) + for (size_t x = 0; x < a_SizeX; x++) { - int idxLower = x + lowerSizeX * z; + size_t idxLower = x + lowerSizeX * z; a_Values[x + a_SizeX * z] = ( lowerData[idxLower] + lowerData[idxLower + 1] + lowerData[idxLower + lowerSizeX] + lowerData[idxLower + lowerSizeX + 1] @@ -375,24 +375,24 @@ public: } - virtual void GetInts(int a_MinX, int a_MinZ, int a_SizeX, int a_SizeZ, int * a_Values) override + virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { // Generate the underlying values: - int lowerSizeX = a_SizeX + 4; - int lowerSizeZ = a_SizeZ + 4; + size_t lowerSizeX = a_SizeX + 4; + size_t lowerSizeZ = a_SizeZ + 4; ASSERT(lowerSizeX * lowerSizeZ <= m_BufferSize); int lowerData[m_BufferSize]; m_Underlying->GetInts(a_MinX - 1, a_MinZ - 1, lowerSizeX, lowerSizeZ, lowerData); // Calculate the weighted average of all 16 "neighbors": - for (int z = 0; z < a_SizeZ; z++) + for (size_t z = 0; z < a_SizeZ; z++) { - for (int x = 0; x < a_SizeX; x++) + for (size_t x = 0; x < a_SizeX; x++) { - int idxLower1 = x + lowerSizeX * z; - int idxLower2 = idxLower1 + lowerSizeX; - int idxLower3 = idxLower1 + 2 * lowerSizeX; - int idxLower4 = idxLower1 + 3 * lowerSizeX; + size_t idxLower1 = x + lowerSizeX * z; + size_t idxLower2 = idxLower1 + lowerSizeX; + size_t idxLower3 = idxLower1 + 2 * lowerSizeX; + size_t idxLower4 = idxLower1 + 3 * lowerSizeX; a_Values[x + a_SizeX * z] = ( 1 * lowerData[idxLower1] + 2 * lowerData[idxLower1 + 1] + 2 * lowerData[idxLower1 + 2] + 1 * lowerData[idxLower1 + 3] + 2 * lowerData[idxLower2] + 32 * lowerData[idxLower2 + 1] + 32 * lowerData[idxLower2 + 2] + 2 * lowerData[idxLower2 + 3] + @@ -425,23 +425,23 @@ public: } - virtual void GetInts(int a_MinX, int a_MinZ, int a_SizeX, int a_SizeZ, int * a_Values) override + virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { // Generate the underlying values: - int lowerSizeX = a_SizeX + 3; - int lowerSizeZ = a_SizeZ + 3; + size_t lowerSizeX = a_SizeX + 3; + size_t lowerSizeZ = a_SizeZ + 3; ASSERT(lowerSizeX * lowerSizeZ <= m_BufferSize); int lowerData[m_BufferSize]; m_Underlying->GetInts(a_MinX, a_MinZ, lowerSizeX, lowerSizeZ, lowerData); // Calculate the weighted average the neighbors: - for (int z = 0; z < a_SizeZ; z++) + for (size_t z = 0; z < a_SizeZ; z++) { - for (int x = 0; x < a_SizeX; x++) + for (size_t x = 0; x < a_SizeX; x++) { - int idxLower1 = x + lowerSizeX * z; - int idxLower2 = idxLower1 + lowerSizeX; - int idxLower3 = idxLower1 + 2 * lowerSizeX; + size_t idxLower1 = x + lowerSizeX * z; + size_t idxLower2 = idxLower1 + lowerSizeX; + size_t idxLower3 = idxLower1 + 2 * lowerSizeX; a_Values[x + a_SizeX * z] = ( WeightDiagonal * lowerData[idxLower1] + WeightCardinal * lowerData[idxLower1 + 1] + WeightDiagonal * lowerData[idxLower1 + 2] + WeightCardinal * lowerData[idxLower2] + WeightCenter * lowerData[idxLower2 + 1] + WeightCardinal * lowerData[idxLower2 + 2] + @@ -476,20 +476,20 @@ public: } - virtual void GetInts(int a_MinX, int a_MinZ, int a_SizeX, int a_SizeZ, int * a_Values) override + virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { // Generate the underlying values: m_Underlying->GetInts(a_MinX, a_MinZ, a_SizeX, a_SizeZ, a_Values); // Replace random values: - for (int z = 0; z < a_SizeZ; z++) + for (size_t z = 0; z < a_SizeZ; z++) { - int BaseZ = a_MinZ + z; - for (int x = 0; x < a_SizeX; x++) + size_t BaseZ = a_MinZ + z; + for (size_t x = 0; x < a_SizeX; x++) { - if (((super::m_Noise.IntNoise2DInt(BaseZ, a_MinX + x) / 13) % 101) < m_ChancePct) + if (((super::m_Noise.IntNoise2DInt(static_cast(BaseZ), static_cast(a_MinX + x)) / 13) % 101) < m_ChancePct) { - a_Values[x + a_SizeX * z] = m_Min + (super::m_Noise.IntNoise2DInt(a_MinX + x, BaseZ) / 7) % m_Range; + a_Values[x + a_SizeX * z] = m_Min + (super::m_Noise.IntNoise2DInt(static_cast(a_MinX + x), static_cast(BaseZ)) / 7) % m_Range; } } // for x } // for z @@ -522,18 +522,18 @@ public: } - virtual void GetInts(int a_MinX, int a_MinZ, int a_SizeX, int a_SizeZ, int * a_Values) override + virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { // Generate the underlying values: m_Underlying->GetInts(a_MinX, a_MinZ, a_SizeX, a_SizeZ, a_Values); // Add the random values: - for (int z = 0; z < a_SizeZ; z++) + for (size_t z = 0; z < a_SizeZ; z++) { - int NoiseZ = a_MinZ + z; - for (int x = 0; x < a_SizeX; x++) + size_t NoiseZ = a_MinZ + z; + for (size_t x = 0; x < a_SizeX; x++) { - int noiseVal = ((super::m_Noise.IntNoise2DInt(a_MinX + x, NoiseZ) / 7) % m_Range) - m_HalfRange; + int noiseVal = ((super::m_Noise.IntNoise2DInt(static_cast(a_MinX + x), static_cast(NoiseZ)) / 7) % m_Range) - m_HalfRange; a_Values[x + z * a_SizeX] += noiseVal; } } @@ -564,23 +564,23 @@ public: } - virtual void GetInts(int a_MinX, int a_MinZ, int a_SizeX, int a_SizeZ, int * a_Values) override + virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { // Generate the underlying values: - int lowerSizeX = a_SizeX + 2; - int lowerSizeZ = a_SizeZ + 2; + size_t lowerSizeX = a_SizeX + 2; + size_t lowerSizeZ = a_SizeZ + 2; ASSERT(lowerSizeX * lowerSizeZ <= m_BufferSize); int lowerData[m_BufferSize]; m_Underlying->GetInts(a_MinX - 1, a_MinZ - 1, lowerSizeX, lowerSizeZ, lowerData); // Average random values: - for (int z = 0; z < a_SizeZ; z++) + for (size_t z = 0; z < a_SizeZ; z++) { - int NoiseZ = a_MinZ + z; - for (int x = 0; x < a_SizeX; x++) + size_t NoiseZ = a_MinZ + z; + for (size_t x = 0; x < a_SizeX; x++) { - int idxLower = x + 1 + lowerSizeX * (z + 1); - if (((super::m_Noise.IntNoise2DInt(a_MinX + x, NoiseZ) / 7) % 100) > m_AvgChancePct) + size_t idxLower = x + 1 + lowerSizeX * (z + 1); + if (((super::m_Noise.IntNoise2DInt(static_cast(a_MinX + x), static_cast(NoiseZ)) / 7) % 100) > m_AvgChancePct) { // Average the 4 neighbors: a_Values[x + z * a_SizeX] = ( @@ -621,28 +621,28 @@ public: } - virtual void GetInts(int a_MinX, int a_MinZ, int a_SizeX, int a_SizeZ, int * a_Values) override + virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { // Generate the underlying values: - int lowerSizeX = a_SizeX + 2; - int lowerSizeZ = a_SizeZ + 2; + size_t lowerSizeX = a_SizeX + 2; + size_t lowerSizeZ = a_SizeZ + 2; ASSERT(lowerSizeX * lowerSizeZ <= m_BufferSize); int lowerData[m_BufferSize]; m_Underlying->GetInts(a_MinX - 1, a_MinZ - 1, lowerSizeX, lowerSizeZ, lowerData); // Average random values: - for (int z = 0; z < a_SizeZ; z++) + for (size_t z = 0; z < a_SizeZ; z++) { - int NoiseZ = a_MinZ + z; - for (int x = 0; x < a_SizeX; x++) + size_t NoiseZ = a_MinZ + z; + for (size_t x = 0; x < a_SizeX; x++) { - int idxLower = x + 1 + lowerSizeX * (z + 1); - if (((super::m_Noise.IntNoise2DInt(a_MinX + x, NoiseZ) / 7) % 100) > m_AvgChancePct) + size_t idxLower = x + 1 + lowerSizeX * (z + 1); + if (((super::m_Noise.IntNoise2DInt(static_cast(a_MinX + x), static_cast(NoiseZ)) / 7) % 100) > m_AvgChancePct) { // Chose a value in between the min and max neighbor: int min = std::min(std::min(lowerData[idxLower - 1], lowerData[idxLower + 1]), std::min(lowerData[idxLower - lowerSizeX], lowerData[idxLower + lowerSizeX])); int max = std::max(std::max(lowerData[idxLower - 1], lowerData[idxLower + 1]), std::max(lowerData[idxLower - lowerSizeX], lowerData[idxLower + lowerSizeX])); - a_Values[x + z * a_SizeX] = min + ((super::m_Noise.IntNoise2DInt(a_MinX + x, NoiseZ + 10) / 7) % (max - min + 1)); + a_Values[x + z * a_SizeX] = min + ((super::m_Noise.IntNoise2DInt(static_cast(a_MinX + x), static_cast(NoiseZ + 10)) / 7) % (max - min + 1)); } else { @@ -675,7 +675,7 @@ public: } - virtual void GetInts(int a_MinX, int a_MinZ, int a_SizeX, int a_SizeZ, int * a_Values) override + virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { // Map for biome -> its beach: static const int ToBeach[] = @@ -723,16 +723,16 @@ public: }; // Generate the underlying values: - int lowerSizeX = a_SizeX + 2; - int lowerSizeZ = a_SizeZ + 2; + size_t lowerSizeX = a_SizeX + 2; + size_t lowerSizeZ = a_SizeZ + 2; ASSERT(lowerSizeX * lowerSizeZ <= m_BufferSize); int lowerValues[m_BufferSize]; m_Underlying->GetInts(a_MinX - 1, a_MinZ - 1, lowerSizeX, lowerSizeZ, lowerValues); // Add beaches between ocean and biomes: - for (int z = 0; z < a_SizeZ; z++) + for (size_t z = 0; z < a_SizeZ; z++) { - for (int x = 0; x < a_SizeX; x++) + for (size_t x = 0; x < a_SizeX; x++) { int val = lowerValues[x + 1 + (z + 1) * lowerSizeX]; int above = lowerValues[x + 1 + z * lowerSizeX]; @@ -779,16 +779,16 @@ public: } - virtual void GetInts(int a_MinX, int a_MinZ, int a_SizeX, int a_SizeZ, int * a_Values) override + virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { m_Underlying->GetInts(a_MinX, a_MinZ, a_SizeX, a_SizeZ, a_Values); - for (int z = 0; z < a_SizeZ; z++) + for (size_t z = 0; z < a_SizeZ; z++) { - for (int x = 0; x < a_SizeX; x++) + for (size_t x = 0; x < a_SizeX; x++) { if (a_Values[x + z * a_SizeX] == bgOcean) { - int rnd = super::m_Noise.IntNoise2DInt(a_MinX + x, a_MinZ + z) / 7; + int rnd = super::m_Noise.IntNoise2DInt(static_cast(a_MinX + x), static_cast(a_MinZ + z)) / 7; if (rnd % 1000 < m_Chance) { a_Values[x + z * a_SizeX] = (rnd / 1003) % bgLandOceanMax; @@ -822,19 +822,19 @@ public: } - virtual void GetInts(int a_MinX, int a_MinZ, int a_SizeX, int a_SizeZ, int * a_Values) + virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) { // Generate the underlying biome groups: - int lowerSizeX = a_SizeX + 2; - int lowerSizeZ = a_SizeZ + 2; + size_t lowerSizeX = a_SizeX + 2; + size_t lowerSizeZ = a_SizeZ + 2; ASSERT(lowerSizeX * lowerSizeZ <= m_BufferSize); int lowerValues[m_BufferSize]; m_Underlying->GetInts(a_MinX, a_MinZ, lowerSizeX, lowerSizeZ, lowerValues); // Change the biomes on incompatible edges into an edge biome: - for (int z = 0; z < a_SizeZ; z++) + for (size_t z = 0; z < a_SizeZ; z++) { - for (int x = 0; x < a_SizeX; x++) + for (size_t x = 0; x < a_SizeX; x++) { int val = lowerValues[x + 1 + (z + 1) * lowerSizeX]; int Above = lowerValues[x + 1 + z * lowerSizeX]; @@ -920,7 +920,7 @@ public: } - virtual void GetInts(int a_MinX, int a_MinZ, int a_SizeX, int a_SizeZ, int * a_Values) override + virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { // Define the per-biome-group biomes: static const int oceanBiomes[] = @@ -998,16 +998,16 @@ public: // Overwrite each biome group with a random biome from that group: // Take care of the bgfRare flag - for (int z = 0; z < a_SizeZ; z++) + for (size_t z = 0; z < a_SizeZ; z++) { - int IdxZ = z * a_SizeX; - for (int x = 0; x < a_SizeX; x++) + size_t IdxZ = z * a_SizeX; + for (size_t x = 0; x < a_SizeX; x++) { int val = a_Values[x + IdxZ]; const cBiomesInGroups & Biomes = (val > bgfRare) ? rareBiomesInGroups[(val & (bgfRare - 1)) % ARRAYCOUNT(rareBiomesInGroups)] : - biomesInGroups[val % ARRAYCOUNT(biomesInGroups)]; - int rnd = (super::m_Noise.IntNoise2DInt(x + a_MinX, z + a_MinZ) / 7); + biomesInGroups[static_cast(val) % ARRAYCOUNT(biomesInGroups)]; + int rnd = (super::m_Noise.IntNoise2DInt(static_cast(x + a_MinX), static_cast(z + a_MinZ)) / 7); a_Values[x + IdxZ] = Biomes.Biomes[rnd % Biomes.Count]; } } @@ -1050,21 +1050,21 @@ public: } - virtual void GetInts(int a_MinX, int a_MinZ, int a_SizeX, int a_SizeZ, int * a_Values) override + virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { // Generate the underlying values: m_Underlying->GetInts(a_MinX, a_MinZ, a_SizeX, a_SizeZ, a_Values); // Replace some of the values: - for (int z = 0; z < a_SizeZ; z++) + for (size_t z = 0; z < a_SizeZ; z++) { - int idxZ = z * a_SizeX; - for (int x = 0; x < a_SizeX; x++) + size_t idxZ = z * a_SizeX; + for (size_t x = 0; x < a_SizeX; x++) { - int idx = x + idxZ; + size_t idx = x + idxZ; if (a_Values[idx] == m_From) { - int rnd = super::m_Noise.IntNoise2DInt(x + a_MinX, z + a_MinZ) / 7; + int rnd = super::m_Noise.IntNoise2DInt(static_cast(x + a_MinX), static_cast(z + a_MinZ)) / 7; if (rnd % 1000 < m_Chance) { a_Values[idx] = m_To; @@ -1109,7 +1109,7 @@ public: } - virtual void GetInts(int a_MinX, int a_MinZ, int a_SizeX, int a_SizeZ, int * a_Values) override + virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { // Generate the underlying data: ASSERT(a_SizeX * a_SizeZ <= m_BufferSize); @@ -1118,12 +1118,12 @@ public: m_Rivers->GetInts(a_MinX, a_MinZ, a_SizeX, a_SizeZ, riverData); // Mix the values: - for (int z = 0; z < a_SizeZ; z++) + for (size_t z = 0; z < a_SizeZ; z++) { - int idxZ = z * a_SizeX; - for (int x = 0; x < a_SizeX; x++) + size_t idxZ = z * a_SizeX; + for (size_t x = 0; x < a_SizeX; x++) { - int idx = x + idxZ; + size_t idx = x + idxZ; if (IsBiomeOcean(a_Values[idx])) { // Oceans are kept without any changes @@ -1173,19 +1173,19 @@ public: } - virtual void GetInts(int a_MinX, int a_MinZ, int a_SizeX, int a_SizeZ, int * a_Values) override + virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { // Generate the underlying data: - int lowerSizeX = a_SizeX + 2; - int lowerSizeZ = a_SizeZ + 2; + size_t lowerSizeX = a_SizeX + 2; + size_t lowerSizeZ = a_SizeZ + 2; ASSERT(lowerSizeX * lowerSizeZ <= m_BufferSize); int lowerValues[m_BufferSize]; m_Underlying->GetInts(a_MinX - 1, a_MinZ - 1, lowerSizeX, lowerSizeZ, lowerValues); // Detect the edges: - for (int z = 0; z < a_SizeZ; z++) + for (size_t z = 0; z < a_SizeZ; z++) { - for (int x = 0; x < a_SizeX; x++) + for (size_t x = 0; x < a_SizeX; x++) { int Above = lowerValues[x + 1 + z * lowerSizeX]; int Below = lowerValues[x + 1 + (z + 2) * lowerSizeX]; @@ -1231,19 +1231,19 @@ public: } - virtual void GetInts(int a_MinX, int a_MinZ, int a_SizeX, int a_SizeZ, int * a_Values) override + virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { // Generate the underlying data: - int lowerSizeX = a_SizeX + 2; - int lowerSizeZ = a_SizeZ + 2; + size_t lowerSizeX = a_SizeX + 2; + size_t lowerSizeZ = a_SizeZ + 2; ASSERT(lowerSizeX * lowerSizeZ <= m_BufferSize); int lowerValues[m_BufferSize]; m_Underlying->GetInts(a_MinX - 1, a_MinZ - 1, lowerSizeX, lowerSizeZ, lowerValues); // Add the mushroom islands: - for (int z = 0; z < a_SizeZ; z++) + for (size_t z = 0; z < a_SizeZ; z++) { - for (int x = 0; x < a_SizeX; x++) + for (size_t x = 0; x < a_SizeX; x++) { int val = lowerValues[x + 1 + (z + 1) * lowerSizeX]; if (!IsBiomeOcean(val)) @@ -1278,7 +1278,7 @@ public: // If at least 3 ocean neighbors and the chance is right, change: if ( (NumOceanNeighbors >= 3) && - ((super::m_Noise.IntNoise2DInt(x + a_MinX, z + a_MinZ) / 7) % 1000 < m_Chance) + ((super::m_Noise.IntNoise2DInt(static_cast(x + a_MinX), static_cast(z + a_MinZ)) / 7) % 1000 < m_Chance) ) { a_Values[x + z * a_SizeX] = m_ToValue; @@ -1321,17 +1321,17 @@ public: } - virtual void GetInts(int a_MinX, int a_MinZ, int a_SizeX, int a_SizeZ, int * a_Values) override + virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { // Generate the underlying data: m_Underlying->GetInts(a_MinX, a_MinZ, a_SizeX, a_SizeZ, a_Values); // Change random pixels to bgOcean: - for (int z = 0; z < a_SizeZ; z++) + for (size_t z = 0; z < a_SizeZ; z++) { - for (int x = 0; x < a_SizeX; x++) + for (size_t x = 0; x < a_SizeX; x++) { - int rnd = super::m_Noise.IntNoise2DInt(x + a_MinX, z + a_MinZ) / 7; + int rnd = super::m_Noise.IntNoise2DInt(static_cast(x + a_MinX), static_cast(z + a_MinZ)) / 7; if (rnd % 1000 < m_Chance) { a_Values[x + z * a_SizeX] = m_ToValue; @@ -1370,20 +1370,20 @@ public: } - virtual void GetInts(int a_MinX, int a_MinZ, int a_SizeX, int a_SizeZ, int * a_Values) override + virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { // Generate the underlying data: m_Underlying->GetInts(a_MinX, a_MinZ, a_SizeX, a_SizeZ, a_Values); // Change some of the biome groups into rare biome groups: - for (int z = 0; z < a_SizeZ; z++) + for (size_t z = 0; z < a_SizeZ; z++) { - for (int x = 0; x < a_SizeX; x++) + for (size_t x = 0; x < a_SizeX; x++) { - int rnd = super::m_Noise.IntNoise2DInt(x + a_MinX, z + a_MinZ) / 7; + int rnd = super::m_Noise.IntNoise2DInt(static_cast(x + a_MinX), static_cast(z + a_MinZ)) / 7; if (rnd % 1000 < m_Chance) { - int idx = x + a_SizeX * z; + size_t idx = x + a_SizeX * z; a_Values[idx] = a_Values[idx] | bgfRare; } } @@ -1418,7 +1418,7 @@ public: } - virtual void GetInts(int a_MinX, int a_MinZ, int a_SizeX, int a_SizeZ, int * a_Values) override + virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { // Generate the base biomes and the alterations: m_BaseBiomes->GetInts(a_MinX, a_MinZ, a_SizeX, a_SizeZ, a_Values); @@ -1426,8 +1426,8 @@ public: m_Alterations->GetInts(a_MinX, a_MinZ, a_SizeX, a_SizeZ, alterations); // Change the biomes into their alternate versions: - int len = a_SizeX * a_SizeZ; - for (int idx = 0; idx < len; ++idx) + size_t len = a_SizeX * a_SizeZ; + for (size_t idx = 0; idx < len; ++idx) { if (alterations[idx] == 0) { @@ -1482,19 +1482,19 @@ public: } - virtual void GetInts(int a_MinX, int a_MinZ, int a_SizeX, int a_SizeZ, int * a_Values) override + virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { // Generate the underlying biomes: - int lowerSizeX = a_SizeX + 2; - int lowerSizeZ = a_SizeZ + 2; + size_t lowerSizeX = a_SizeX + 2; + size_t lowerSizeZ = a_SizeZ + 2; ASSERT(lowerSizeX * lowerSizeZ <= m_BufferSize); int lowerValues[m_BufferSize]; m_Underlying->GetInts(a_MinX - 1, a_MinZ - 1, lowerSizeX, lowerSizeZ, lowerValues); // Convert incompatible edges into neutral biomes: - for (int z = 0; z < a_SizeZ; z++) + for (size_t z = 0; z < a_SizeZ; z++) { - for (int x = 0; x < a_SizeX; x++) + for (size_t x = 0; x < a_SizeX; x++) { int biome = lowerValues[x + 1 + (z + 1) * lowerSizeX]; int above = lowerValues[x + 1 + z * lowerSizeX]; @@ -1642,7 +1642,7 @@ public: } - virtual void GetInts(int a_MinX, int a_MinZ, int a_SizeX, int a_SizeZ, int * a_Values) override + virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { // Generate the underlying biomes and the alterations: m_Underlying->GetInts(a_MinX, a_MinZ, a_SizeX, a_SizeZ, a_Values); @@ -1650,8 +1650,8 @@ public: m_Alteration->GetInts(a_MinX, a_MinZ, a_SizeX, a_SizeZ, alterations); // Wherever alterations are nonzero, change into alternate biome, if available: - int len = a_SizeX * a_SizeZ; - for (int idx = 0; idx < len; ++idx) + size_t len = a_SizeX * a_SizeZ; + for (size_t idx = 0; idx < len; ++idx) { if (alterations[idx] == 0) { diff --git a/src/HTTPServer/HTTPFormParser.cpp b/src/HTTPServer/HTTPFormParser.cpp index 72872078b..77f98e43b 100644 --- a/src/HTTPServer/HTTPFormParser.cpp +++ b/src/HTTPServer/HTTPFormParser.cpp @@ -90,11 +90,6 @@ void cHTTPFormParser::Parse(const char * a_Data, size_t a_Size) m_MultipartParser->Parse(a_Data, a_Size); break; } - default: - { - ASSERT(!"Unhandled form kind"); - break; - } } } @@ -113,7 +108,7 @@ bool cHTTPFormParser::Finish(void) ParseFormUrlEncoded(); break; } - default: + case fpkMultipart: { // Nothing needed for other formats break; diff --git a/src/HTTPServer/HTTPServer.cpp b/src/HTTPServer/HTTPServer.cpp index 71f974a97..2eb8bf1ff 100644 --- a/src/HTTPServer/HTTPServer.cpp +++ b/src/HTTPServer/HTTPServer.cpp @@ -112,7 +112,9 @@ class cDebugCallbacks : // TODO } -} g_DebugCallbacks; +}; + +static cDebugCallbacks g_DebugCallbacks; diff --git a/src/Noise/Noise.cpp b/src/Noise/Noise.cpp index d11c47bc2..703ec3d30 100644 --- a/src/Noise/Noise.cpp +++ b/src/Noise/Noise.cpp @@ -112,22 +112,22 @@ public: //////////////////////////////////////////////////////////////////////////////// // Globals: -void Debug3DNoise(const NOISE_DATATYPE * a_Noise, int a_SizeX, int a_SizeY, int a_SizeZ, const AString & a_FileNameBase, NOISE_DATATYPE a_Coeff) +void Debug3DNoise(const NOISE_DATATYPE * a_Noise, size_t a_SizeX, size_t a_SizeY, size_t a_SizeZ, const AString & a_FileNameBase, NOISE_DATATYPE a_Coeff) { const int BUF_SIZE = 512; ASSERT(a_SizeX <= BUF_SIZE); // Just stretch it, if needed // Save in XY cuts: cFile f1; - if (f1.Open(Printf("%s_XY (%d).grab", a_FileNameBase.c_str(), a_SizeX), cFile::fmWrite)) + if (f1.Open(Printf("%s_XY (" SIZE_T_FMT ").grab", a_FileNameBase.c_str(), a_SizeX), cFile::fmWrite)) { - for (int z = 0; z < a_SizeZ; z++) + for (size_t z = 0; z < a_SizeZ; z++) { - for (int y = 0; y < a_SizeY; y++) + for (size_t y = 0; y < a_SizeY; y++) { - int idx = y * a_SizeX + z * a_SizeX * a_SizeY; + size_t idx = y * a_SizeX + z * a_SizeX * a_SizeY; unsigned char buf[BUF_SIZE]; - for (int x = 0; x < a_SizeX; x++) + for (size_t x = 0; x < a_SizeX; x++) { buf[x] = static_cast(Clamp((int)(128 + a_Coeff * a_Noise[idx++]), 0, 255)); } @@ -140,15 +140,15 @@ void Debug3DNoise(const NOISE_DATATYPE * a_Noise, int a_SizeX, int a_SizeY, int } // if (XY file open) cFile f2; - if (f2.Open(Printf("%s_XZ (%d).grab", a_FileNameBase.c_str(), a_SizeX), cFile::fmWrite)) + if (f2.Open(Printf("%s_XZ (" SIZE_T_FMT ").grab", a_FileNameBase.c_str(), a_SizeX), cFile::fmWrite)) { - for (int y = 0; y < a_SizeY; y++) + for (size_t y = 0; y < a_SizeY; y++) { - for (int z = 0; z < a_SizeZ; z++) + for (size_t z = 0; z < a_SizeZ; z++) { - int idx = y * a_SizeX + z * a_SizeX * a_SizeY; + size_t idx = y * a_SizeX + z * a_SizeX * a_SizeY; unsigned char buf[BUF_SIZE]; - for (int x = 0; x < a_SizeX; x++) + for (size_t x = 0; x < a_SizeX; x++) { buf[x] = static_cast(Clamp((int)(128 + a_Coeff * a_Noise[idx++]), 0, 255)); } @@ -165,19 +165,19 @@ void Debug3DNoise(const NOISE_DATATYPE * a_Noise, int a_SizeX, int a_SizeY, int -void Debug2DNoise(const NOISE_DATATYPE * a_Noise, int a_SizeX, int a_SizeY, const AString & a_FileNameBase, NOISE_DATATYPE a_Coeff) +void Debug2DNoise(const NOISE_DATATYPE * a_Noise, size_t a_SizeX, size_t a_SizeY, const AString & a_FileNameBase, NOISE_DATATYPE a_Coeff) { const int BUF_SIZE = 512; ASSERT(a_SizeX <= BUF_SIZE); // Just stretch it, if needed cFile f1; - if (f1.Open(Printf("%s (%d).grab", a_FileNameBase.c_str(), a_SizeX), cFile::fmWrite)) + if (f1.Open(Printf("%s (" SIZE_T_FMT ").grab", a_FileNameBase.c_str(), a_SizeX), cFile::fmWrite)) { - for (int y = 0; y < a_SizeY; y++) + for (size_t y = 0; y < a_SizeY; y++) { - int idx = y * a_SizeX; + size_t idx = y * a_SizeX; unsigned char buf[BUF_SIZE]; - for (int x = 0; x < a_SizeX; x++) + for (size_t x = 0; x < a_SizeX; x++) { buf[x] = static_cast(Clamp((int)(128 + a_Coeff * a_Noise[idx++]), 0, 255)); } diff --git a/src/Noise/Noise.h b/src/Noise/Noise.h index 323194bfd..5df32d3dc 100644 --- a/src/Noise/Noise.h +++ b/src/Noise/Noise.h @@ -288,11 +288,11 @@ NOISE_DATATYPE cNoise::LinearInterpolate(NOISE_DATATYPE a_A, NOISE_DATATYPE a_B, /** Exports the noise array into a file. a_Coeff specifies the value that each array value is multiplied by before being converted into a byte. */ -extern void Debug2DNoise(const NOISE_DATATYPE * a_Array, int a_SizeX, int a_SizeY, const AString & a_FileNameBase, NOISE_DATATYPE a_Coeff = 32); +extern void Debug2DNoise(const NOISE_DATATYPE * a_Array, size_t a_SizeX, size_t a_SizeY, const AString & a_FileNameBase, NOISE_DATATYPE a_Coeff = 32); /** Exports the noise array into a set of files, ordered by XY and XZ. a_Coeff specifies the value that each array value is multiplied by before being converted into a byte. */ -extern void Debug3DNoise(const NOISE_DATATYPE * a_Array, int a_SizeX, int a_SizeY, int a_SizeZ, const AString & a_FileNameBase, NOISE_DATATYPE a_Coeff = 32); +extern void Debug3DNoise(const NOISE_DATATYPE * a_Array, size_t a_SizeX, size_t a_SizeY, size_t a_SizeZ, const AString & a_FileNameBase, NOISE_DATATYPE a_Coeff = 32); diff --git a/src/OSSupport/File.cpp b/src/OSSupport/File.cpp index 43105b230..53f7c4afe 100644 --- a/src/OSSupport/File.cpp +++ b/src/OSSupport/File.cpp @@ -201,7 +201,7 @@ int cFile::Seek (int iPosition) -int cFile::Tell (void) const +ssize_t cFile::Tell (void) const { ASSERT(IsOpen()); @@ -210,14 +210,14 @@ int cFile::Tell (void) const return -1; } - return (int)ftell(m_File); + return ftell(m_File); } -int cFile::GetSize(void) const +ssize_t cFile::GetSize(void) const { ASSERT(IsOpen()); @@ -226,7 +226,7 @@ int cFile::GetSize(void) const return -1; } - int CurPos = Tell(); + ssize_t CurPos = Tell(); if (CurPos < 0) { return -1; @@ -235,7 +235,7 @@ int cFile::GetSize(void) const { return -1; } - int res = Tell(); + ssize_t res = Tell(); if (fseek(m_File, (long)CurPos, SEEK_SET) != 0) { return -1; @@ -256,7 +256,19 @@ int cFile::ReadRestOfFile(AString & a_Contents) return -1; } - size_t DataSize = GetSize() - Tell(); + ssize_t TotalSize = GetSize(); + if (TotalSize < 0) + { + return -1; + } + + ssize_t Position = Tell(); + if (Position < 0) + { + return -1; + } + + auto DataSize = static_cast(TotalSize - Position); // HACK: This depends on the internal knowledge that AString's data() function returns the internal buffer directly a_Contents.assign(DataSize, '\0'); @@ -349,7 +361,7 @@ bool cFile::IsFile(const AString & a_Path) -int cFile::GetSize(const AString & a_FileName) +ssize_t cFile::GetSize(const AString & a_FileName) { struct stat st; if (stat(a_FileName.c_str(), &st) == 0) diff --git a/src/OSSupport/File.h b/src/OSSupport/File.h index 1b5e71a17..e92da4354 100644 --- a/src/OSSupport/File.h +++ b/src/OSSupport/File.h @@ -90,10 +90,10 @@ public: int Seek (int iPosition); /** Returns the current position (bytes from file start) or -1 for failure; asserts if not open */ - int Tell (void) const; + ssize_t Tell (void) const; /** Returns the size of file, in bytes, or -1 for failure; asserts if not open */ - int GetSize(void) const; + ssize_t GetSize(void) const; /** Reads the file from current position till EOF into an AString; returns the number of bytes read or -1 for error */ int ReadRestOfFile(AString & a_Contents); @@ -119,7 +119,7 @@ public: static bool IsFile(const AString & a_Path); /** Returns the size of the file, or a negative number on error */ - static int GetSize(const AString & a_FileName); + static ssize_t GetSize(const AString & a_FileName); /** Creates a new folder with the specified name. Returns true if successful. Path may be relative or absolute */ static bool CreateFolder(const AString & a_FolderPath); diff --git a/src/Protocol/Packetizer.h b/src/Protocol/Packetizer.h index 7f5e9c2c3..efed9c7a9 100644 --- a/src/Protocol/Packetizer.h +++ b/src/Protocol/Packetizer.h @@ -58,7 +58,7 @@ public: } - inline void WriteBEUInt16(short a_Value) + inline void WriteBEUInt16(UInt16 a_Value) { VERIFY(m_Out.WriteBEUInt16(a_Value)); } diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 799c021f3..0540ae9e1 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1023,8 +1023,8 @@ void cProtocol172::SendExperience (void) cPacketizer Pkt(*this, 0x1f); // Experience Packet cPlayer * Player = m_Client->GetPlayer(); Pkt.WriteBEFloat(Player->GetXpPercentage()); - Pkt.WriteBEInt16(static_cast(std::max(Player->GetXpLevel(), std::numeric_limits::max()))); - Pkt.WriteBEInt16(static_cast(std::max(Player->GetCurrentXp(), std::numeric_limits::max()))); + Pkt.WriteBEInt16(static_cast(std::max(Player->GetXpLevel(), std::numeric_limits::max()))); + Pkt.WriteBEInt16(static_cast(std::max(Player->GetCurrentXp(), std::numeric_limits::max()))); } diff --git a/src/StringUtils.h b/src/StringUtils.h index b5fc58a2d..8f67d8031 100644 --- a/src/StringUtils.h +++ b/src/StringUtils.h @@ -158,7 +158,7 @@ bool StringToInteger(const AString & a_str, T & a_Num) return false; } result *= 10; - T digit = a_str[i] - '0'; + T digit = static_cast(a_str[i] - '0'); if (std::numeric_limits::max() - digit < result) { return false; @@ -179,7 +179,7 @@ bool StringToInteger(const AString & a_str, T & a_Num) return false; } result *= 10; - T digit = a_str[i] - '0'; + T digit = static_cast(a_str[i] - '0'); if (std::numeric_limits::min() + digit > result) { return false; diff --git a/src/World.h b/src/World.h index 6c0548ae6..d29a89e65 100644 --- a/src/World.h +++ b/src/World.h @@ -216,7 +216,7 @@ public: // Broadcast respective packets to all clients of the chunk where the event is taking place // (Please keep these alpha-sorted) void BroadcastAttachEntity (const cEntity & a_Entity, const cEntity * a_Vehicle); - void BroadcastBlockAction (int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType, const cClientHandle * a_Exclude = nullptr); // tolua_export + void BroadcastBlockAction (int a_BlockX, int a_BlockY, int a_BlockZ, Byte a_Byte1, Byte a_Byte2, BLOCKTYPE a_BlockType, const cClientHandle * a_Exclude = nullptr); // tolua_export void BroadcastBlockBreakAnimation(UInt32 a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage, const cClientHandle * a_Exclude = nullptr); void BroadcastBlockEntity (int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude = nullptr); ///< If there is a block entity at the specified coods, sends it to all clients except a_Exclude -- cgit v1.2.3 From fa4fb75e03c6241370588de2ed62270e1043b312 Mon Sep 17 00:00:00 2001 From: tycho Date: Tue, 19 May 2015 12:28:31 +0100 Subject: Fixed compile and a few more warnings --- src/Blocks/BlockLever.h | 14 +++++++------- src/Blocks/BlockQuartz.h | 2 +- src/Blocks/BlockRail.h | 7 ++++++- src/Blocks/BlockSideways.h | 2 +- src/Blocks/BlockTorch.h | 2 +- src/Blocks/BlockTrapdoor.h | 4 +++- src/Blocks/BlockTripwireHook.h | 8 +++++++- src/Generating/CompoGenBiomal.cpp | 7 ++++++- src/World.cpp | 2 +- 9 files changed, 33 insertions(+), 15 deletions(-) diff --git a/src/Blocks/BlockLever.h b/src/Blocks/BlockLever.h index 2da138e5f..5792d280b 100644 --- a/src/Blocks/BlockLever.h +++ b/src/Blocks/BlockLever.h @@ -59,13 +59,13 @@ public: // Determine lever direction: switch (a_Dir) { - case BLOCK_FACE_YP: return 0x6; - case BLOCK_FACE_XP: return 0x1; - case BLOCK_FACE_XM: return 0x2; - case BLOCK_FACE_ZP: return 0x3; - case BLOCK_FACE_ZM: return 0x4; - case BLOCK_FACE_YM: return 0x0; - default: return 0x6; + case BLOCK_FACE_YP: return 0x6; + case BLOCK_FACE_XP: return 0x1; + case BLOCK_FACE_XM: return 0x2; + case BLOCK_FACE_ZP: return 0x3; + case BLOCK_FACE_ZM: return 0x4; + case BLOCK_FACE_YM: return 0x0; + case BLOCK_FACE_NONE: return 0x6; } } diff --git a/src/Blocks/BlockQuartz.h b/src/Blocks/BlockQuartz.h index edc4fb9c5..6f5c23902 100644 --- a/src/Blocks/BlockQuartz.h +++ b/src/Blocks/BlockQuartz.h @@ -58,7 +58,7 @@ public: return 0x3; // East or west } - default: + case BLOCK_FACE_NONE: { ASSERT(!"Unhandled block face!"); return a_QuartzMeta; // No idea, give a special meta (all sides the same) diff --git a/src/Blocks/BlockRail.h b/src/Blocks/BlockRail.h index a2e27a351..eecd07006 100644 --- a/src/Blocks/BlockRail.h +++ b/src/Blocks/BlockRail.h @@ -487,7 +487,12 @@ public: } break; } - default: break; + case BLOCK_FACE_NONE: + case BLOCK_FACE_YM: + case BLOCK_FACE_YP: + { + break; + } } return true; } diff --git a/src/Blocks/BlockSideways.h b/src/Blocks/BlockSideways.h index 4b1e38d6d..74b05e33c 100644 --- a/src/Blocks/BlockSideways.h +++ b/src/Blocks/BlockSideways.h @@ -58,7 +58,7 @@ public: return a_Meta | 0x4; // East or west } - default: + case BLOCK_FACE_NONE: { ASSERT(!"Unhandled block face!"); return a_Meta | 0xC; // No idea, give a special meta diff --git a/src/Blocks/BlockTorch.h b/src/Blocks/BlockTorch.h index d63df94cf..aaf50d23d 100644 --- a/src/Blocks/BlockTorch.h +++ b/src/Blocks/BlockTorch.h @@ -59,7 +59,7 @@ public: case BLOCK_FACE_WEST: return E_META_TORCH_WEST; case BLOCK_FACE_NORTH: return E_META_TORCH_NORTH; case BLOCK_FACE_SOUTH: return E_META_TORCH_SOUTH; - default: + case BLOCK_FACE_NONE: { ASSERT(!"Unhandled torch direction!"); break; diff --git a/src/Blocks/BlockTrapdoor.h b/src/Blocks/BlockTrapdoor.h index dbb0b5a5b..2841e3e08 100644 --- a/src/Blocks/BlockTrapdoor.h +++ b/src/Blocks/BlockTrapdoor.h @@ -74,7 +74,9 @@ public: case BLOCK_FACE_ZM: return 0x0; case BLOCK_FACE_XP: return 0x3; case BLOCK_FACE_XM: return 0x2; - default: + case BLOCK_FACE_NONE: + case BLOCK_FACE_YM: + case BLOCK_FACE_YP: { ASSERT(!"Unhandled block face!"); return 0; diff --git a/src/Blocks/BlockTripwireHook.h b/src/Blocks/BlockTripwireHook.h index 88d389711..c7a96d393 100644 --- a/src/Blocks/BlockTripwireHook.h +++ b/src/Blocks/BlockTripwireHook.h @@ -37,7 +37,13 @@ public: case BLOCK_FACE_XP: return 0x3; case BLOCK_FACE_ZM: return 0x2; case BLOCK_FACE_ZP: return 0x0; - default: ASSERT(!"Unhandled tripwire hook direction!"); return 0x0; + case BLOCK_FACE_NONE: + case BLOCK_FACE_YM: + case BLOCK_FACE_YP: + { + ASSERT(!"Unhandled tripwire hook direction!"); + return 0x0; + } } } diff --git a/src/Generating/CompoGenBiomal.cpp b/src/Generating/CompoGenBiomal.cpp index 1385bd523..60f7e7520 100644 --- a/src/Generating/CompoGenBiomal.cpp +++ b/src/Generating/CompoGenBiomal.cpp @@ -414,7 +414,12 @@ protected: FillColumnPattern(a_ChunkDesc, a_RelX, a_RelZ, Pattern, a_ShapeColumn); return; } - default: + case biInvalidBiome: + case biHell: + case biSky: + case biNumBiomes: + case biVariant: + case biNumVariantBiomes: { ASSERT(!"Unhandled biome"); return; diff --git a/src/World.cpp b/src/World.cpp index e93d6bb26..5f9eb2569 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -2071,7 +2071,7 @@ void cWorld::BroadcastAttachEntity(const cEntity & a_Entity, const cEntity * a_V -void cWorld::BroadcastBlockAction(int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType, const cClientHandle * a_Exclude) +void cWorld::BroadcastBlockAction(int a_BlockX, int a_BlockY, int a_BlockZ, Byte a_Byte1, Byte a_Byte2, BLOCKTYPE a_BlockType, const cClientHandle * a_Exclude) { m_ChunkMap->BroadcastBlockAction(a_BlockX, a_BlockY, a_BlockZ, a_Byte1, a_Byte2, a_BlockType, a_Exclude); } -- cgit v1.2.3 From 6cccd2aabbb02fbdc59d55aefd6fd0010f901140 Mon Sep 17 00:00:00 2001 From: tycho Date: Tue, 19 May 2015 13:33:34 +0100 Subject: Properly fix cFile Warnings --- src/OSSupport/File.cpp | 14 +++++++------- src/OSSupport/File.h | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/OSSupport/File.cpp b/src/OSSupport/File.cpp index 53f7c4afe..ed0dda681 100644 --- a/src/OSSupport/File.cpp +++ b/src/OSSupport/File.cpp @@ -180,7 +180,7 @@ int cFile::Write(const void * iBuffer, size_t iNumBytes) -int cFile::Seek (int iPosition) +long cFile::Seek (int iPosition) { ASSERT(IsOpen()); @@ -193,7 +193,7 @@ int cFile::Seek (int iPosition) { return -1; } - return (int)ftell(m_File); + return ftell(m_File); } @@ -201,7 +201,7 @@ int cFile::Seek (int iPosition) -ssize_t cFile::Tell (void) const +long cFile::Tell (void) const { ASSERT(IsOpen()); @@ -217,7 +217,7 @@ ssize_t cFile::Tell (void) const -ssize_t cFile::GetSize(void) const +long cFile::GetSize(void) const { ASSERT(IsOpen()); @@ -226,7 +226,7 @@ ssize_t cFile::GetSize(void) const return -1; } - ssize_t CurPos = Tell(); + long CurPos = Tell(); if (CurPos < 0) { return -1; @@ -235,7 +235,7 @@ ssize_t cFile::GetSize(void) const { return -1; } - ssize_t res = Tell(); + long res = Tell(); if (fseek(m_File, (long)CurPos, SEEK_SET) != 0) { return -1; @@ -361,7 +361,7 @@ bool cFile::IsFile(const AString & a_Path) -ssize_t cFile::GetSize(const AString & a_FileName) +long cFile::GetSize(const AString & a_FileName) { struct stat st; if (stat(a_FileName.c_str(), &st) == 0) diff --git a/src/OSSupport/File.h b/src/OSSupport/File.h index e92da4354..6281d1494 100644 --- a/src/OSSupport/File.h +++ b/src/OSSupport/File.h @@ -87,13 +87,13 @@ public: int Write(const void * iBuffer, size_t iNumBytes); /** Seeks to iPosition bytes from file start, returns old position or -1 for failure; asserts if not open */ - int Seek (int iPosition); + long Seek (int iPosition); /** Returns the current position (bytes from file start) or -1 for failure; asserts if not open */ - ssize_t Tell (void) const; + long Tell (void) const; /** Returns the size of file, in bytes, or -1 for failure; asserts if not open */ - ssize_t GetSize(void) const; + long GetSize(void) const; /** Reads the file from current position till EOF into an AString; returns the number of bytes read or -1 for error */ int ReadRestOfFile(AString & a_Contents); @@ -119,7 +119,7 @@ public: static bool IsFile(const AString & a_Path); /** Returns the size of the file, or a negative number on error */ - static ssize_t GetSize(const AString & a_FileName); + static long GetSize(const AString & a_FileName); /** Creates a new folder with the specified name. Returns true if successful. Path may be relative or absolute */ static bool CreateFolder(const AString & a_FolderPath); -- cgit v1.2.3 From 03c75943ead4d7fe12a07bbdea18b87f85879b0f Mon Sep 17 00:00:00 2001 From: tycho Date: Tue, 19 May 2015 13:34:52 +0100 Subject: More fixed warnings --- src/Generating/HeiGen.cpp | 5 ++++- src/Generating/MineShafts.cpp | 12 ++++++------ src/Generating/Noise3DGenerator.cpp | 7 +++++-- src/Generating/PieceGenerator.cpp | 12 +++++++++--- src/Generating/Ravines.cpp | 16 ++++++++-------- src/Generating/RoughRavines.cpp | 16 ++++++++-------- 6 files changed, 40 insertions(+), 28 deletions(-) diff --git a/src/Generating/HeiGen.cpp b/src/Generating/HeiGen.cpp index e44885135..6aa52c4a5 100644 --- a/src/Generating/HeiGen.cpp +++ b/src/Generating/HeiGen.cpp @@ -801,7 +801,10 @@ protected: case biTaiga: a_Min = 63; a_Max = 75; break; case biTaigaHills: a_Min = 63; a_Max = 90; break; case biTaigaM: a_Min = 63; a_Max = 80; break; - default: + case biInvalidBiome: + case biNumBiomes: + case biVariant: + case biNumVariantBiomes: { ASSERT(!"Unknown biome"); a_Min = 10; diff --git a/src/Generating/MineShafts.cpp b/src/Generating/MineShafts.cpp index 61f29b762..1482234f0 100644 --- a/src/Generating/MineShafts.cpp +++ b/src/Generating/MineShafts.cpp @@ -564,14 +564,14 @@ cMineShaft * cMineShaftCorridor::CreateAndFit( void cMineShaftCorridor::AppendBranches(int a_RecursionLevel, cNoise & a_Noise) { - int rnd = a_Noise.IntNoise3DInt(m_BoundingBox.p1.x, m_BoundingBox.p1.y + a_RecursionLevel, m_BoundingBox.p1.z) / 7; + int Outerrnd = a_Noise.IntNoise3DInt(m_BoundingBox.p1.x, m_BoundingBox.p1.y + a_RecursionLevel, m_BoundingBox.p1.z) / 7; // Prefer the same height, but allow for up to one block height displacement: - int Height = m_BoundingBox.p1.y + ((rnd % 4) + ((rnd >> 3) % 3)) / 2; + int OuterHeight = m_BoundingBox.p1.y + ((Outerrnd % 4) + ((Outerrnd >> 3) % 3)) / 2; switch (m_Direction) { case dirXM: { - m_ParentSystem.AppendBranch(m_BoundingBox.p1.x - 1, Height, m_BoundingBox.p1.z + 1, dirXM, a_Noise, a_RecursionLevel); + m_ParentSystem.AppendBranch(m_BoundingBox.p1.x - 1, OuterHeight, m_BoundingBox.p1.z + 1, dirXM, a_Noise, a_RecursionLevel); for (int i = m_NumSegments; i >= 0; i--) { int rnd = a_Noise.IntNoise3DInt(m_BoundingBox.p1.x + i + 10, m_BoundingBox.p1.y + a_RecursionLevel, m_BoundingBox.p1.z) / 11; @@ -586,7 +586,7 @@ void cMineShaftCorridor::AppendBranches(int a_RecursionLevel, cNoise & a_Noise) case dirXP: { - m_ParentSystem.AppendBranch(m_BoundingBox.p2.x + 1, Height, m_BoundingBox.p1.z + 1, dirXP, a_Noise, a_RecursionLevel); + m_ParentSystem.AppendBranch(m_BoundingBox.p2.x + 1, OuterHeight, m_BoundingBox.p1.z + 1, dirXP, a_Noise, a_RecursionLevel); for (int i = m_NumSegments; i >= 0; i--) { int rnd = a_Noise.IntNoise3DInt(m_BoundingBox.p1.x + i + 10, m_BoundingBox.p1.y + a_RecursionLevel, m_BoundingBox.p1.z) / 11; @@ -601,7 +601,7 @@ void cMineShaftCorridor::AppendBranches(int a_RecursionLevel, cNoise & a_Noise) case dirZM: { - m_ParentSystem.AppendBranch(m_BoundingBox.p1.x + 1, Height, m_BoundingBox.p1.z - 1, dirZM, a_Noise, a_RecursionLevel); + m_ParentSystem.AppendBranch(m_BoundingBox.p1.x + 1, OuterHeight, m_BoundingBox.p1.z - 1, dirZM, a_Noise, a_RecursionLevel); for (int i = m_NumSegments; i >= 0; i--) { int rnd = a_Noise.IntNoise3DInt(m_BoundingBox.p1.x + i + 10, m_BoundingBox.p1.y + a_RecursionLevel, m_BoundingBox.p1.z) / 11; @@ -616,7 +616,7 @@ void cMineShaftCorridor::AppendBranches(int a_RecursionLevel, cNoise & a_Noise) case dirZP: { - m_ParentSystem.AppendBranch(m_BoundingBox.p1.x + 1, Height, m_BoundingBox.p2.z + 1, dirZP, a_Noise, a_RecursionLevel); + m_ParentSystem.AppendBranch(m_BoundingBox.p1.x + 1, OuterHeight, m_BoundingBox.p2.z + 1, dirZP, a_Noise, a_RecursionLevel); for (int i = m_NumSegments; i >= 0; i--) { int rnd = a_Noise.IntNoise3DInt(m_BoundingBox.p1.x + i + 10, m_BoundingBox.p1.y + a_RecursionLevel, m_BoundingBox.p1.z) / 11; diff --git a/src/Generating/Noise3DGenerator.cpp b/src/Generating/Noise3DGenerator.cpp index 63e88c2a8..8163746f8 100644 --- a/src/Generating/Noise3DGenerator.cpp +++ b/src/Generating/Noise3DGenerator.cpp @@ -305,7 +305,7 @@ void cNoise3DGenerator::UpdateHeightmap(cChunkDesc & a_ChunkDesc) { for (int x = 0; x < cChunkDef::Width; x++) { - for (int y = cChunkDef::Height - 1; y > 0; y--) + for (HEIGHTTYPE y = cChunkDef::Height - 1; y > 0; y--) { if (a_ChunkDesc.GetBlockType(x, y, z) != E_BLOCK_AIR) { @@ -790,7 +790,10 @@ void cBiomalNoise3DComposable::GetBiomeParams(EMCSBiome a_Biome, NOISE_DATATYPE case biTaiga: a_HeightAmp = 0.1f; a_MidPoint = 64; break; case biTaigaM: a_HeightAmp = 0.1f; a_MidPoint = 70; break; case biTaigaHills: a_HeightAmp = 0.075f; a_MidPoint = 68; break; - default: + case biInvalidBiome: + case biNumBiomes: + case biVariant: + case biNumVariantBiomes: { // Make a crazy terrain so that it stands out a_HeightAmp = 0.001f; diff --git a/src/Generating/PieceGenerator.cpp b/src/Generating/PieceGenerator.cpp index 97aa646fc..b58a5394d 100644 --- a/src/Generating/PieceGenerator.cpp +++ b/src/Generating/PieceGenerator.cpp @@ -385,7 +385,7 @@ cPlacedPiece * cPieceGenerator::PlaceStartingPiece(int a_BlockX, int a_BlockY, i else { // All pieces returned zero weight, but we need one to start. Choose with equal chance: - StartingPiece = StartingPieces[rnd % StartingPieces.size()]; + StartingPiece = StartingPieces[static_cast(rnd) % StartingPieces.size()]; } rnd = rnd >> 16; @@ -561,7 +561,10 @@ void cPieceGenerator::DebugConnectorPool(const cPieceGenerator::cFreeConnectors { printf(" Connector pool: " SIZE_T_FMT " items\n", a_ConnectorPool.size() - a_NumProcessed); size_t idx = 0; - for (cPieceGenerator::cFreeConnectors::const_iterator itr = a_ConnectorPool.begin() + a_NumProcessed, end = a_ConnectorPool.end(); itr != end; ++itr, ++idx) + + typedef cPieceGenerator::cFreeConnectors::difference_type difType; + + for (auto itr = a_ConnectorPool.cbegin() + static_cast(a_NumProcessed), end = a_ConnectorPool.cend(); itr != end; ++itr, ++idx) { printf(" " SIZE_T_FMT ": {%d, %d, %d}, type %d, direction %s, depth %d\n", idx, @@ -672,7 +675,10 @@ void cBFSPieceGenerator::PlacePieces(int a_BlockX, int a_BlockY, int a_BlockZ, i NumProcessed++; if (NumProcessed > 1000) { - ConnectorPool.erase(ConnectorPool.begin(), ConnectorPool.begin() + NumProcessed); + + typedef cPieceGenerator::cFreeConnectors::difference_type difType; + + ConnectorPool.erase(ConnectorPool.begin(), ConnectorPool.begin() + static_cast(NumProcessed)); NumProcessed = 0; } } diff --git a/src/Generating/Ravines.cpp b/src/Generating/Ravines.cpp index 9f8f69139..8c6316273 100644 --- a/src/Generating/Ravines.cpp +++ b/src/Generating/Ravines.cpp @@ -135,17 +135,17 @@ void cStructGenRavines::cRavine::GenerateBaseDefPoints(int a_BlockX, int a_Block // Get the base angle in which the ravine "axis" goes: float Angle = (float)(((float)((a_Noise.IntNoise3DInt(20 * a_BlockX, 70 * a_BlockZ, 6000) / 9) % 16384)) / 16384.0 * M_PI); - float xc = sin(Angle); - float zc = cos(Angle); + float xc = sinf(Angle); + float zc = cosf(Angle); // Calculate the definition points and radii: int MaxRadius = (int)(sqrt(12.0 + ((a_Noise.IntNoise2DInt(61 * a_BlockX, 97 * a_BlockZ) / 13) % a_Size) / 16)); int Top = 32 + ((a_Noise.IntNoise2DInt(13 * a_BlockX, 17 * a_BlockZ) / 23) % 32); int Bottom = 5 + ((a_Noise.IntNoise2DInt(17 * a_BlockX, 29 * a_BlockZ) / 13) % 32); int Mid = (Top + Bottom) / 2; - int PointX = CenterX - (int)(xc * a_Size / 2); - int PointZ = CenterZ - (int)(zc * a_Size / 2); - m_Points.push_back(cRavDefPoint(PointX, PointZ, 0, (Mid + Top) / 2, (Mid + Bottom) / 2)); + int DefinitionPointX = CenterX - (int)(xc * a_Size / 2); + int DefinitionPointZ = CenterZ - (int)(zc * a_Size / 2); + m_Points.push_back(cRavDefPoint(DefinitionPointX, DefinitionPointZ, 0, (Mid + Top) / 2, (Mid + Bottom) / 2)); for (int i = 1; i < NUM_RAVINE_POINTS - 1; i++) { int LineX = CenterX + (int)(xc * a_Size * (i - NUM_RAVINE_POINTS / 2) / NUM_RAVINE_POINTS); @@ -160,9 +160,9 @@ void cStructGenRavines::cRavine::GenerateBaseDefPoints(int a_BlockX, int a_Block int ThisBottom = Bottom + ((a_Noise.IntNoise3DInt(19 * a_BlockX, 7 * a_BlockZ, i * 31) / 13) % 8) - 4; m_Points.push_back(cRavDefPoint(PointX, PointZ, Radius, ThisTop, ThisBottom)); } // for i - m_Points[] - PointX = CenterX + (int)(xc * a_Size / 2); - PointZ = CenterZ + (int)(zc * a_Size / 2); - m_Points.push_back(cRavDefPoint(PointX, PointZ, 0, Mid, Mid)); + DefinitionPointX = CenterX + (int)(xc * a_Size / 2); + DefinitionPointZ = CenterZ + (int)(zc * a_Size / 2); + m_Points.push_back(cRavDefPoint(DefinitionPointX, DefinitionPointZ, 0, Mid, Mid)); } diff --git a/src/Generating/RoughRavines.cpp b/src/Generating/RoughRavines.cpp index 2ee3704b3..c0397ee26 100644 --- a/src/Generating/RoughRavines.cpp +++ b/src/Generating/RoughRavines.cpp @@ -21,7 +21,7 @@ class cRoughRavine : public: cRoughRavine( - int a_Seed, int a_Size, + int a_Seed, size_t a_Size, float a_CenterWidth, float a_Roughness, float a_FloorHeightEdge1, float a_FloorHeightEdge2, float a_FloorHeightCenter, float a_CeilingHeightEdge1, float a_CeilingHeightEdge2, float a_CeilingHeightCenter, @@ -33,14 +33,14 @@ public: m_Roughness(a_Roughness) { // Create the basic structure - 2 lines meeting at the centerpoint: - int Max = 2 * a_Size; - int Half = a_Size; // m_DefPoints[Half] will be the centerpoint + size_t Max = 2 * a_Size; + size_t Half = a_Size; // m_DefPoints[Half] will be the centerpoint m_DefPoints.resize(Max + 1); int rnd = m_Noise.IntNoise2DInt(a_OriginX, a_OriginZ) / 7; float Len = (float)a_Size; float Angle = (float)rnd; // Angle is in radians, will be wrapped in the "sin" and "cos" operations - float OfsX = sin(Angle) * Len; - float OfsZ = cos(Angle) * Len; + float OfsX = sinf(Angle) * Len; + float OfsZ = cosf(Angle) * Len; m_DefPoints[0].Set (a_OriginX - OfsX, a_OriginZ - OfsZ, 1, a_CeilingHeightEdge1, a_FloorHeightEdge1); m_DefPoints[Half].Set((float)a_OriginX, (float)a_OriginZ, a_CenterWidth, a_CeilingHeightCenter, a_FloorHeightCenter); m_DefPoints[Max].Set (a_OriginX + OfsX, a_OriginZ + OfsZ, 1, a_CeilingHeightEdge2, a_FloorHeightEdge2); @@ -90,7 +90,7 @@ protected: /** Recursively subdivides the line between the points of the specified index. Sets the midpoint to the center of the line plus or minus a random offset, then calls itself for each half of the new line. */ - void SubdivideLine(int a_Idx1, int a_Idx2) + void SubdivideLine(size_t a_Idx1, size_t a_Idx2) { // Calculate the midpoint: const sRavineDefPoint & p1 = m_DefPoints[a_Idx1]; @@ -114,7 +114,7 @@ protected: MidX -= dz * m_Roughness; MidZ += dx * m_Roughness; } - int MidIdx = (a_Idx1 + a_Idx2) / 2; + size_t MidIdx = (a_Idx1 + a_Idx2) / 2; m_DefPoints[MidIdx].Set(MidX, MidZ, MidR, MidT, MidB); // Recurse the two halves, if they are worth recursing: @@ -275,7 +275,7 @@ cRoughRavines::cRoughRavines( cGridStructGen::cStructurePtr cRoughRavines::CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) { // Pick a random value for each of the ravine's parameters: - int Size = m_MinSize + (m_Noise.IntNoise2DInt(a_GridX, a_GridZ) / 7) % (m_MaxSize - m_MinSize); // Random int from m_MinSize to m_MaxSize + size_t Size = static_cast(m_MinSize + (m_Noise.IntNoise2DInt(a_GridX, a_GridZ) / 7) % (m_MaxSize - m_MinSize)); // Random int from m_MinSize to m_MaxSize float CenterWidth = m_Noise.IntNoise2DInRange(a_GridX + 10, a_GridZ, m_MinCenterWidth, m_MaxCenterWidth); float Roughness = m_Noise.IntNoise2DInRange(a_GridX + 20, a_GridZ, m_MinRoughness, m_MaxRoughness); float FloorHeightEdge1 = m_Noise.IntNoise2DInRange(a_GridX + 30, a_GridZ, m_MinFloorHeightEdge, m_MaxFloorHeightEdge); -- cgit v1.2.3 From 050a014106a57bcdcda6401090da201db15d7b87 Mon Sep 17 00:00:00 2001 From: tycho Date: Tue, 19 May 2015 14:02:02 +0100 Subject: Finish fixing windows --- src/OSSupport/File.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OSSupport/File.cpp b/src/OSSupport/File.cpp index ed0dda681..6327b3505 100644 --- a/src/OSSupport/File.cpp +++ b/src/OSSupport/File.cpp @@ -256,13 +256,13 @@ int cFile::ReadRestOfFile(AString & a_Contents) return -1; } - ssize_t TotalSize = GetSize(); + long TotalSize = GetSize(); if (TotalSize < 0) { return -1; } - ssize_t Position = Tell(); + long Position = Tell(); if (Position < 0) { return -1; -- cgit v1.2.3 From 2bb25b8afab365da8a8f3db15d742b1ec12c2903 Mon Sep 17 00:00:00 2001 From: tycho Date: Tue, 19 May 2015 15:21:29 +0100 Subject: Fixed some more warnings --- src/Generating/StructGen.cpp | 28 ++++++++++----------- src/Generating/Trees.cpp | 40 +++++++++++++++--------------- src/Generating/VillageGen.cpp | 4 +-- src/PolarSSL++/BlockingSslClientSocket.cpp | 2 +- 4 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/Generating/StructGen.cpp b/src/Generating/StructGen.cpp index 7572cdcbf..fd911e7dc 100644 --- a/src/Generating/StructGen.cpp +++ b/src/Generating/StructGen.cpp @@ -72,7 +72,7 @@ void cStructGenTrees::GenFinish(cChunkDesc & a_ChunkDesc) { for (int z = 0; z < cChunkDef::Width; z++) { - for (int y = cChunkDef::Height - 1; y >= 0; y--) + for (HEIGHTTYPE y = cChunkDef::Height - 1; y >= 0; y--) { if (a_ChunkDesc.GetBlockType(x, y, z) != E_BLOCK_AIR) { @@ -304,14 +304,14 @@ void cStructGenOreNests::GenerateOre(int a_ChunkX, int a_ChunkZ, BLOCKTYPE a_Ore for (int i = 0; i < a_NumNests; i++) { - int rnd = m_Noise.IntNoise3DInt(a_ChunkX + i, a_Seq, a_ChunkZ + 64 * i) / 8; - int BaseX = rnd % cChunkDef::Width; - rnd /= cChunkDef::Width; - int BaseZ = rnd % cChunkDef::Width; - rnd /= cChunkDef::Width; - int BaseY = rnd % a_MaxHeight; - rnd /= a_MaxHeight; - int NestSize = a_NestSize + (rnd % (a_NestSize / 4)); // The actual nest size may be up to 1 / 4 larger + int Nestrnd = m_Noise.IntNoise3DInt(a_ChunkX + i, a_Seq, a_ChunkZ + 64 * i) / 8; + int BaseX = Nestrnd % cChunkDef::Width; + Nestrnd /= cChunkDef::Width; + int BaseZ = Nestrnd % cChunkDef::Width; + Nestrnd /= cChunkDef::Width; + int BaseY = Nestrnd % a_MaxHeight; + Nestrnd /= a_MaxHeight; + int NestSize = a_NestSize + (Nestrnd % (a_NestSize / 4)); // The actual nest size may be up to 1 / 4 larger int Num = 0; while (Num < NestSize) { @@ -436,14 +436,14 @@ void cStructGenLakes::CreateLakeImage(int a_ChunkX, int a_ChunkZ, int a_MaxLakeH BLOCKTYPE * BlockTypes = a_Lake.GetBlockTypes(); for (int i = 0; i < NumBubbles; i++) { - int Rnd = m_Noise.IntNoise3DInt(a_ChunkX, i, a_ChunkZ) / 13; - const int BubbleR = 2 + (Rnd & 0x03); // 2 .. 5 + int BubbleRnd = m_Noise.IntNoise3DInt(a_ChunkX, i, a_ChunkZ) / 13; + const int BubbleR = 2 + (BubbleRnd & 0x03); // 2 .. 5 const int Range = 16 - 2 * BubbleR; - const int BubbleX = BubbleR + (Rnd % Range); + const int BubbleX = BubbleR + (BubbleRnd % Range); Rnd >>= 4; - const int BubbleY = 4 + (Rnd & 0x01); // 4 .. 5 + const int BubbleY = 4 + (BubbleRnd & 0x01); // 4 .. 5 Rnd >>= 1; - const int BubbleZ = BubbleR + (Rnd % Range); + const int BubbleZ = BubbleR + (BubbleRnd % Range); const int HalfR = BubbleR / 2; // 1 .. 2 const int RSquared = BubbleR * BubbleR; for (int y = -HalfR; y <= HalfR; y++) diff --git a/src/Generating/Trees.cpp b/src/Generating/Trees.cpp index 72fe5f819..014fdf1f2 100644 --- a/src/Generating/Trees.cpp +++ b/src/Generating/Trees.cpp @@ -321,12 +321,12 @@ void GetSmallAppleTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a int Random = a_Noise.IntNoise3DInt(a_BlockX + 64 * a_Seq, a_BlockY, a_BlockZ) >> 3; - int Heights[] = {1, 2, 2, 3} ; - int Height = 1 + Heights[Random & 3]; + HEIGHTTYPE Heights[] = {1, 2, 2, 3} ; + HEIGHTTYPE Height = 1 + Heights[Random & 3]; Random >>= 2; // Pre-alloc so that we don't realloc too often later: - a_LogBlocks.reserve(Height + 5); + a_LogBlocks.reserve(static_cast(Height + 5)); a_OtherBlocks.reserve(ARRAYCOUNT(BigO2) * 2 + ARRAYCOUNT(BigO1) + ARRAYCOUNT(Corners) * 3 + 3 + 5); // Trunk: @@ -396,8 +396,8 @@ void GetLargeAppleTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a for (int i = 4; i < Height; i++) { // Get a direction for the trunk to go to. - Vector3d BranchStartDirection = AvailableDirections[a_Noise.IntNoise3DInt(a_BlockX, a_BlockY + i, a_BlockZ) % ARRAYCOUNT(AvailableDirections)]; - Vector3d BranchDirection = AvailableDirections[a_Noise.IntNoise3DInt(a_BlockX, a_BlockY / i, a_BlockZ) % ARRAYCOUNT(AvailableDirections)] / 3; + Vector3d BranchStartDirection = AvailableDirections[static_cast(a_Noise.IntNoise3DInt(a_BlockX, a_BlockY + i, a_BlockZ)) % ARRAYCOUNT(AvailableDirections)]; + Vector3d BranchDirection = AvailableDirections[static_cast(a_Noise.IntNoise3DInt(a_BlockX, a_BlockY / i, a_BlockZ)) % ARRAYCOUNT(AvailableDirections)] / 3; int BranchLength = 2 + a_Noise.IntNoise3DInt(a_BlockX * a_Seq, a_BlockY * a_Seq, a_BlockZ * a_Seq) % 3; GetLargeAppleTreeBranch(a_BlockX, a_BlockY + i, a_BlockZ, BranchLength, BranchStartDirection, BranchDirection, a_BlockY + Height, a_Noise, a_LogBlocks); @@ -476,10 +476,10 @@ NIBBLETYPE GetLogMetaFromDirection(NIBBLETYPE a_BlockMeta, Vector3d a_Direction) void GetBirchTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks) { - int Height = 5 + (a_Noise.IntNoise3DInt(a_BlockX + 64 * a_Seq, a_BlockY, a_BlockZ) % 3); + HEIGHTTYPE Height = 5 + (a_Noise.IntNoise3DInt(a_BlockX + 64 * a_Seq, a_BlockY, a_BlockZ) % 3); // Prealloc, so that we don't realloc too often later: - a_LogBlocks.reserve(Height); + a_LogBlocks.reserve(static_cast(Height)); a_OtherBlocks.reserve(80); // The entire trunk, out of logs: @@ -650,10 +650,10 @@ void GetDarkoakTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_No void GetTallBirchTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks) { - int Height = 9 + (a_Noise.IntNoise3DInt(a_BlockX + 64 * a_Seq, a_BlockY, a_BlockZ) % 3); + HEIGHTTYPE Height = 9 + (a_Noise.IntNoise3DInt(a_BlockX + 64 * a_Seq, a_BlockY, a_BlockZ) % 3); // Prealloc, so that we don't realloc too often later: - a_LogBlocks.reserve(Height); + a_LogBlocks.reserve(static_cast(Height)); a_OtherBlocks.reserve(80); // The entire trunk, out of logs: @@ -713,12 +713,12 @@ void GetSpruceTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noi // (each of the mod8 remainders has a very different chance of occurrence) - that's why we divide by 8 int MyRandom = a_Noise.IntNoise3DInt(a_BlockX + 32 * a_Seq, a_BlockY + 32 * a_Seq, a_BlockZ) / 8; - static const int sHeights[] = {1, 2, 2, 3}; - int Height = sHeights[MyRandom & 3]; + static const HEIGHTTYPE sHeights[] = {1, 2, 2, 3}; + HEIGHTTYPE Height = sHeights[MyRandom & 3]; MyRandom >>= 2; // Prealloc, so that we don't realloc too often later: - a_LogBlocks.reserve(Height); + a_LogBlocks.reserve(static_cast(Height)); a_OtherBlocks.reserve(180); // Clear trunk blocks: @@ -816,8 +816,8 @@ void GetPineTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise } // Pre-allocate the vector: - a_LogBlocks.reserve(TrunkHeight); - a_OtherBlocks.reserve(NumLeavesLayers * 25); + a_LogBlocks.reserve(static_cast(TrunkHeight)); + a_OtherBlocks.reserve(static_cast(NumLeavesLayers * 25)); // The entire trunk, out of logs: for (int i = TrunkHeight; i >= 0; --i) @@ -866,8 +866,8 @@ void GetSwampTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Nois int Height = 3 + (a_Noise.IntNoise3DInt(a_BlockX + 32 * a_Seq, a_BlockY, a_BlockZ + 32 * a_Seq) / 8) % 3; - a_LogBlocks.reserve(Height); - a_OtherBlocks.reserve(2 * ARRAYCOUNT(BigO2) + 2 * ARRAYCOUNT(BigO3) + Height * ARRAYCOUNT(Vines) + 20); + a_LogBlocks.reserve(static_cast(Height)); + a_OtherBlocks.reserve(2 * ARRAYCOUNT(BigO2) + 2 * ARRAYCOUNT(BigO3) + static_cast(Height) * ARRAYCOUNT(Vines) + 20); for (int i = 0; i < Height; i++) { @@ -952,8 +952,8 @@ void GetLargeJungleTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & int Height = 24 + (a_Noise.IntNoise3DInt(a_BlockX + 32 * a_Seq, a_BlockY, a_BlockZ + 32 * a_Seq) / 11) % 24; - a_LogBlocks.reserve(Height * 4); - a_OtherBlocks.reserve(2 * ARRAYCOUNT(BigO4) + ARRAYCOUNT(BigO3) + Height * ARRAYCOUNT(Vines) + 50); + a_LogBlocks.reserve(static_cast(Height) * 4); + a_OtherBlocks.reserve(2 * ARRAYCOUNT(BigO4) + ARRAYCOUNT(BigO3) + static_cast(Height) * ARRAYCOUNT(Vines) + 50); for (int i = 0; i < Height; i++) { @@ -999,12 +999,12 @@ void GetSmallJungleTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & int Height = 7 + (a_Noise.IntNoise3DInt(a_BlockX + 5 * a_Seq, a_BlockY, a_BlockZ + 5 * a_Seq) / 5) % 3; - a_LogBlocks.reserve(Height); + a_LogBlocks.reserve(static_cast(Height)); a_OtherBlocks.reserve( 2 * ARRAYCOUNT(BigO3) + // O3 layer, 2x 2 * ARRAYCOUNT(BigO2) + // O2 layer, 2x ARRAYCOUNT(BigO1) + 1 + // Plus on the top - Height * ARRAYCOUNT(Vines) + // Vines + static_cast(Height) * ARRAYCOUNT(Vines) + // Vines 50 // some safety ); diff --git a/src/Generating/VillageGen.cpp b/src/Generating/VillageGen.cpp index a3f8caa46..8f0bc13ef 100644 --- a/src/Generating/VillageGen.cpp +++ b/src/Generating/VillageGen.cpp @@ -389,8 +389,8 @@ cGridStructGen::cStructurePtr cVillageGen::CreateStructure(int a_GridX, int a_Gr BLOCKTYPE RoadBlock = E_BLOCK_GRAVEL; BLOCKTYPE WaterRoadBlock = E_BLOCK_PLANKS; int rnd = m_Noise.IntNoise2DInt(a_OriginX, a_OriginZ) / 11; - cVillagePiecePool * PlainsVillage = g_PlainsVillagePools[rnd % ARRAYCOUNT(g_PlainsVillagePools)]; - cVillagePiecePool * DesertVillage = g_DesertVillagePools[rnd % ARRAYCOUNT(g_DesertVillagePools)]; + cVillagePiecePool * PlainsVillage = g_PlainsVillagePools[static_cast(rnd) % ARRAYCOUNT(g_PlainsVillagePools)]; + cVillagePiecePool * DesertVillage = g_DesertVillagePools[static_cast(rnd) % ARRAYCOUNT(g_DesertVillagePools)]; for (size_t i = 0; i < ARRAYCOUNT(Biomes); i++) { switch (Biomes[i]) diff --git a/src/PolarSSL++/BlockingSslClientSocket.cpp b/src/PolarSSL++/BlockingSslClientSocket.cpp index 821125b31..6a418dd7c 100644 --- a/src/PolarSSL++/BlockingSslClientSocket.cpp +++ b/src/PolarSSL++/BlockingSslClientSocket.cpp @@ -200,7 +200,7 @@ bool cBlockingSslClientSocket::Send(const void * a_Data, size_t a_NumBytes) else { Data += res; - NumBytes -= res; + NumBytes -= static_cast(res); if (NumBytes == 0) { return true; -- cgit v1.2.3 From 480052c058f3a8ebc70f024933ba5deb6baf0b08 Mon Sep 17 00:00:00 2001 From: tycho Date: Tue, 19 May 2015 15:25:18 +0100 Subject: Added LuaState support for all integral types All so added error handling for out of range values --- .gitignore | 1 + src/Bindings/BindingsProcessor.lua | 12 ++++---- src/Bindings/LuaState.cpp | 51 ++++++++++++-------------------- src/Bindings/LuaState.h | 52 ++++++++++++++++++++++++--------- src/Bindings/ManualBindings.cpp | 4 +-- src/Bindings/ManualBindings.h | 2 +- src/Bindings/ManualBindings_Network.cpp | 7 ++--- src/Bindings/ManualBindings_World.cpp | 2 +- src/Bindings/PluginLua.cpp | 10 ------- 9 files changed, 72 insertions(+), 69 deletions(-) diff --git a/.gitignore b/.gitignore index 8dc90910c..97b2e93d5 100644 --- a/.gitignore +++ b/.gitignore @@ -75,6 +75,7 @@ src/MCServer lib/tolua++/tolua src/Bindings/Bindings.* src/Bindings/BindingDependencies.txt +src/Bindings/LuaState_Call.inc MCServer.dir/ src/AllFiles.lst diff --git a/src/Bindings/BindingsProcessor.lua b/src/Bindings/BindingsProcessor.lua index f86be6c6d..fba992082 100644 --- a/src/Bindings/BindingsProcessor.lua +++ b/src/Bindings/BindingsProcessor.lua @@ -101,7 +101,7 @@ local function OutputLuaStateHelpers(a_Package) f:write("void Push(" .. item.name .. " * a_Value);\n") end for _, item in ipairs(types) do - f:write("void GetStackValue(int a_StackPos, Ptr" .. item.lname .. " & a_ReturnedVal);\n") + f:write("bool GetStackValue(int a_StackPos, Ptr" .. item.lname .. " & a_ReturnedVal);\n") end f:write("\n\n\n\n\n") f:close() @@ -125,15 +125,17 @@ local function OutputLuaStateHelpers(a_Package) end end for _, item in ipairs(types) do - f:write("void cLuaState::GetStackValue(int a_StackPos, Ptr" .. item.lname .. " & a_ReturnedVal)\n{\n\tASSERT(IsValid());\n") + f:write("bool cLuaState::GetStackValue(int a_StackPos, Ptr" .. item.lname .. " & a_ReturnedVal)\n{\n\tASSERT(IsValid());\n") f:write("\tif (lua_isnil(m_LuaState, a_StackPos))\n\t{\n") - f:write("\t a_ReturnedVal = nullptr;\n") - f:write("\t return;\n\t}\n") + f:write("\t\ta_ReturnedVal = nullptr;\n") + f:write("\t\treturn false;\n\t}\n") f:write("\ttolua_Error err;\n") f:write("\tif (tolua_isusertype(m_LuaState, a_StackPos, \"" .. item.name .. "\", false, &err))\n") f:write("\t{\n") - f:write("\t a_ReturnedVal = *(reinterpret_cast<" .. item.name .. " **>(lua_touserdata(m_LuaState, a_StackPos)));\n") + f:write("\t\ta_ReturnedVal = *(reinterpret_cast<" .. item.name .. " **>(lua_touserdata(m_LuaState, a_StackPos)));\n") + f:write("\t\treturn true;\n"); f:write("\t}\n") + f:write("\treturn false;\n") f:write("}\n\n\n\n\n\n") end f:close() diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index 08c7e19d7..232432a99 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -701,108 +701,95 @@ void cLuaState::PushUserType(void * a_Object, const char * a_Type) -void cLuaState::GetStackValue(int a_StackPos, AString & a_Value) +bool cLuaState::GetStackValue(int a_StackPos, AString & a_Value) { size_t len = 0; const char * data = lua_tolstring(m_LuaState, a_StackPos, &len); if (data != nullptr) { a_Value.assign(data, len); + return true; } + return false; } -void cLuaState::GetStackValue(int a_StackPos, BLOCKTYPE & a_ReturnedVal) -{ - if (lua_isnumber(m_LuaState, a_StackPos)) - { - a_ReturnedVal = static_cast(tolua_tonumber(m_LuaState, a_StackPos, a_ReturnedVal)); - } -} - - - - - -void cLuaState::GetStackValue(int a_StackPos, bool & a_ReturnedVal) +bool cLuaState::GetStackValue(int a_StackPos, bool & a_ReturnedVal) { a_ReturnedVal = (tolua_toboolean(m_LuaState, a_StackPos, a_ReturnedVal ? 1 : 0) > 0); + return true; } -void cLuaState::GetStackValue(int a_StackPos, cPluginManager::CommandResult & a_Result) +bool cLuaState::GetStackValue(int a_StackPos, cPluginManager::CommandResult & a_Result) { if (lua_isnumber(m_LuaState, a_StackPos)) { a_Result = static_cast(static_cast((tolua_tonumber(m_LuaState, a_StackPos, a_Result)))); + return true; } + return false; } -void cLuaState::GetStackValue(int a_StackPos, cRef & a_Ref) +bool cLuaState::GetStackValue(int a_StackPos, cRef & a_Ref) { a_Ref.RefStack(*this, a_StackPos); + return true; } -void cLuaState::GetStackValue(int a_StackPos, double & a_ReturnedVal) +bool cLuaState::GetStackValue(int a_StackPos, double & a_ReturnedVal) { if (lua_isnumber(m_LuaState, a_StackPos)) { a_ReturnedVal = tolua_tonumber(m_LuaState, a_StackPos, a_ReturnedVal); + return true; } + return false; } -void cLuaState::GetStackValue(int a_StackPos, float & a_ReturnedVal) +bool cLuaState::GetStackValue(int a_StackPos, float & a_ReturnedVal) { if (lua_isnumber(m_LuaState, a_StackPos)) { a_ReturnedVal = static_cast(tolua_tonumber(m_LuaState, a_StackPos, a_ReturnedVal)); + return true; } + return false; } -void cLuaState::GetStackValue(int a_StackPos, eWeather & a_ReturnedVal) +bool cLuaState::GetStackValue(int a_StackPos, eWeather & a_ReturnedVal) { if (!lua_isnumber(m_LuaState, a_StackPos)) { - return; + return false; } a_ReturnedVal = static_cast(Clamp( static_cast(tolua_tonumber(m_LuaState, a_StackPos, a_ReturnedVal)), static_cast(wSunny), static_cast(wThunderstorm)) ); -} - - - - - -void cLuaState::GetStackValue(int a_StackPos, int & a_ReturnedVal) -{ - if (lua_isnumber(m_LuaState, a_StackPos)) - { - a_ReturnedVal = static_cast(tolua_tonumber(m_LuaState, a_StackPos, a_ReturnedVal)); - } + return true; } diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index 5b4ec3ae4..bbd0294ef 100644 --- a/src/Bindings/LuaState.h +++ b/src/Bindings/LuaState.h @@ -187,16 +187,37 @@ public: void Push(cLuaUDPEndpoint * a_UDPEndpoint); // GetStackValue() retrieves the value at a_StackPos, if it is a valid type. If not, a_Value is unchanged. + // Returns whether value was changed // Enum values are clamped to their allowed range. - void GetStackValue(int a_StackPos, AString & a_Value); - void GetStackValue(int a_StackPos, BLOCKTYPE & a_Value); - void GetStackValue(int a_StackPos, bool & a_Value); - void GetStackValue(int a_StackPos, cPluginManager::CommandResult & a_Result); - void GetStackValue(int a_StackPos, cRef & a_Ref); - void GetStackValue(int a_StackPos, double & a_Value); - void GetStackValue(int a_StackPos, eWeather & a_Value); - void GetStackValue(int a_StackPos, float & a_ReturnedVal); - void GetStackValue(int a_StackPos, int & a_Value); + bool GetStackValue(int a_StackPos, AString & a_Value); + bool GetStackValue(int a_StackPos, bool & a_Value); + bool GetStackValue(int a_StackPos, cPluginManager::CommandResult & a_Result); + bool GetStackValue(int a_StackPos, cRef & a_Ref); + bool GetStackValue(int a_StackPos, double & a_Value); + bool GetStackValue(int a_StackPos, eWeather & a_Value); + bool GetStackValue(int a_StackPos, float & a_ReturnedVal); + + // template to catch all of the various c++ integral types without overload conflicts + template + bool GetStackValue(int a_StackPos, T & a_ReturnedVal, typename std::enable_if::value>::type * unused = nullptr) + { + UNUSED(unused); + if (lua_isnumber(m_LuaState, a_StackPos)) + { + lua_Number Val = tolua_tonumber(m_LuaState, a_StackPos, a_ReturnedVal); + if (Val > std::numeric_limits::max()) + { + return false; + } + if (Val < std::numeric_limits::min()) + { + return false; + } + a_ReturnedVal = static_cast(Val); + return true; + } + return false; + } // Include the auto-generated Push and GetStackValue() functions: #include "LuaState_Declaration.inc" @@ -218,10 +239,13 @@ public: /** Retrieves a list of values from the Lua stack, starting at the specified index. */ template - inline void GetStackValues(int a_StartStackPos, T & a_Ret, Args &&... args) + inline bool GetStackValues(int a_StartStackPos, T & a_Ret, Args &&... args) { - GetStackValue(a_StartStackPos, a_Ret); - GetStackValues(a_StartStackPos + 1, args...); + if (!GetStackValue(a_StartStackPos, a_Ret)) + { + return false; + } + return GetStackValues(a_StartStackPos + 1, args...); } /** Returns true if the specified parameters on the stack are of the specified usertable type; also logs warning if not. Used for static functions */ @@ -349,9 +373,9 @@ protected: /** Variadic template terminator: If there are no more values to get, bail out. This function is not available in the public API, because it's an error to request no values directly; only internal functions can do that. If you get a compile error saying this function is not accessible, check your calling code, you aren't reading any stack values. */ - void GetStackValues(int a_StartingStackPos) + bool GetStackValues(int a_StartingStackPos) { - // Do nothing + return true; } /** Pushes the function of the specified name onto the stack. diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index ff904d74a..bce1891e2 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -158,7 +158,7 @@ static int tolua_UncompressStringZLIB(lua_State * tolua_S) // Get the params: AString ToUncompress; - int UncompressedSize; + size_t UncompressedSize; S.GetStackValues(1, ToUncompress, UncompressedSize); // Compress the string: @@ -1801,7 +1801,7 @@ static int tolua_cMojangAPI_GetUUIDsFromPlayerNames(lua_State * L) // Convert the input table into AStringVector: AStringVector PlayerNames; int NumNames = luaL_getn(L, 2); - PlayerNames.reserve(NumNames); + PlayerNames.reserve(static_cast(NumNames)); for (int i = 1; i <= NumNames; i++) { lua_rawgeti(L, 2, i); diff --git a/src/Bindings/ManualBindings.h b/src/Bindings/ManualBindings.h index e7a576588..83b960058 100644 --- a/src/Bindings/ManualBindings.h +++ b/src/Bindings/ManualBindings.h @@ -199,7 +199,7 @@ public: // Get parameters: Ty1 * Self = nullptr; - int ItemID; + UInt32 ItemID; cLuaState::cRef FnRef; L.GetStackValues(1, Self, ItemID, FnRef); if (Self == nullptr) diff --git a/src/Bindings/ManualBindings_Network.cpp b/src/Bindings/ManualBindings_Network.cpp index df97d60b3..7d6ff95a7 100644 --- a/src/Bindings/ManualBindings_Network.cpp +++ b/src/Bindings/ManualBindings_Network.cpp @@ -101,13 +101,12 @@ static int tolua_cNetwork_CreateUDPEndpoint(lua_State * L) } // Read the params: - int Port; - S.GetStackValues(2, Port); + UInt16 Port; // Check validity: - if ((Port < 0) || (Port > 65535)) + if (S.GetStackValues(2, Port)) { - LOGWARNING("cNetwork:CreateUDPEndpoint() called with invalid port (%d), failing the request.", Port); + LOGWARNING("cNetwork:CreateUDPEndpoint() called with invalid port, failing the request."); S.Push(false); return 1; } diff --git a/src/Bindings/ManualBindings_World.cpp b/src/Bindings/ManualBindings_World.cpp index 3ee5ca498..cda1518d2 100644 --- a/src/Bindings/ManualBindings_World.cpp +++ b/src/Bindings/ManualBindings_World.cpp @@ -50,7 +50,7 @@ static int tolua_cWorld_BroadcastParticleEffect(lua_State * tolua_S) std::array data; for (int i = 0; (i < 2) && L.IsParamNumber(11 + i); i++) { - L.GetStackValue(11 + i, data[i]); + L.GetStackValue(11 + i, data[static_cast(i)]); } World->GetBroadcaster().BroadcastParticleEffect(Name, Vector3f(PosX, PosY, PosZ), Vector3f(OffX, OffY, OffZ), ParticleData, ParticleAmmount, ExcludeClient); diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp index a8be26f71..83466ab84 100644 --- a/src/Bindings/PluginLua.cpp +++ b/src/Bindings/PluginLua.cpp @@ -629,11 +629,6 @@ bool cPluginLua::OnExploded(cWorld & a_World, double a_ExplosionSize, bool a_Can case esWitherSkullBlue: m_LuaState.Call((int)(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, a_SourceData, cLuaState::Return, res); break; case esWitherBirth: m_LuaState.Call((int)(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, a_SourceData, cLuaState::Return, res); break; case esPlugin: m_LuaState.Call((int)(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, a_SourceData, cLuaState::Return, res); break; - default: - { - ASSERT(!"Unhandled ExplosionSource"); - return false; - } } if (res) { @@ -670,11 +665,6 @@ bool cPluginLua::OnExploding(cWorld & a_World, double & a_ExplosionSize, bool & case esWitherSkullBlue: m_LuaState.Call((int)(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, a_SourceData, cLuaState::Return, res, a_CanCauseFire, a_ExplosionSize); break; case esWitherBirth: m_LuaState.Call((int)(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, a_SourceData, cLuaState::Return, res, a_CanCauseFire, a_ExplosionSize); break; case esPlugin: m_LuaState.Call((int)(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, a_SourceData, cLuaState::Return, res, a_CanCauseFire, a_ExplosionSize); break; - default: - { - ASSERT(!"Unhandled ExplosionSource"); - return false; - } } if (res) { -- cgit v1.2.3 From 77f1f58c0a7eb55001b375f1945690ed5c1e87a2 Mon Sep 17 00:00:00 2001 From: tycho Date: Tue, 19 May 2015 19:32:10 +0100 Subject: Make -Werror disabling file only Ad fix a load of warnings --- SetFlags.cmake | 34 ++++++++++++++++++++---------- src/AllocationPool.h | 6 +++--- src/Bindings/CMakeLists.txt | 4 ++++ src/BlockEntities/CMakeLists.txt | 5 +++++ src/BlockEntities/MobSpawnerEntity.cpp | 4 ++-- src/Blocks/CMakeLists.txt | 1 + src/CMakeLists.txt | 25 ++++++++++++++++++++++ src/Chunk.cpp | 4 ++-- src/ChunkSender.cpp | 4 ---- src/CompositeChat.cpp | 4 ++++ src/Enchantments.cpp | 10 ++++----- src/Enchantments.h | 8 +++---- src/Entities/ArrowEntity.cpp | 4 ++-- src/Entities/CMakeLists.txt | 7 ++++++ src/Entities/Entity.cpp | 2 +- src/Entities/HangingEntity.h | 4 +++- src/Entities/Minecart.cpp | 5 ----- src/Entities/Pawn.cpp | 2 +- src/Entities/ProjectileEntity.cpp | 1 + src/Entities/ThrownEnderPearlEntity.cpp | 4 ++-- src/Generating/CMakeLists.txt | 14 ++++++++++++ src/HTTPServer/CMakeLists.txt | 5 +++++ src/IniFile.cpp | 2 +- src/Inventory.cpp | 2 +- src/Items/CMakeLists.txt | 4 ++++ src/Map.cpp | 6 +++--- src/MapManager.cpp | 2 +- src/MapManager.h | 2 +- src/MobCensus.cpp | 3 ++- src/Mobs/Blaze.cpp | 2 +- src/Mobs/CMakeLists.txt | 4 ++++ src/Mobs/CaveSpider.cpp | 2 +- src/Mobs/Chicken.cpp | 2 +- src/Mobs/Cow.cpp | 2 +- src/Mobs/Creeper.cpp | 2 +- src/Mobs/Enderman.cpp | 2 +- src/Mobs/Ghast.cpp | 2 +- src/Mobs/Guardian.cpp | 2 +- src/Mobs/Horse.cpp | 2 +- src/Mobs/Monster.cpp | 8 +++---- src/Mobs/Monster.h | 6 +++--- src/Mobs/Mooshroom.cpp | 2 +- src/Mobs/Path.h | 2 +- src/Mobs/Pig.cpp | 2 +- src/Mobs/Rabbit.cpp | 2 +- src/Mobs/Sheep.cpp | 6 +++--- src/Mobs/Skeleton.cpp | 2 +- src/Mobs/Slime.cpp | 2 +- src/Mobs/Spider.cpp | 2 +- src/Mobs/Squid.cpp | 2 +- src/Mobs/Witch.cpp | 2 +- src/Mobs/Zombie.cpp | 2 +- src/Mobs/ZombiePigman.cpp | 2 +- src/Protocol/CMakeLists.txt | 5 +++++ src/Simulator/CMakeLists.txt | 7 ++++++ src/Simulator/VanillaFluidSimulator.cpp | 2 +- src/Tracer.cpp | 2 +- src/UI/CMakeLists.txt | 5 +++++ src/WorldStorage/CMakeLists.txt | 8 +++++++ src/WorldStorage/EnchantmentSerializer.cpp | 6 +++--- src/WorldStorage/FastNBT.cpp | 6 +++--- src/WorldStorage/FireworksSerializer.cpp | 2 +- src/WorldStorage/MapSerializer.cpp | 12 +++++------ 63 files changed, 201 insertions(+), 96 deletions(-) diff --git a/SetFlags.cmake b/SetFlags.cmake index 0d1bd99b3..b26796522 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -16,8 +16,8 @@ macro (add_flags_lnk FLAGS) endmacro() macro(add_flags_cxx FLAGS) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAGS}") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAGS}") + #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAGS}") + #set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAGS}") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAGS}") set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FLAGS}") set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_COVERAGE} ${FLAGS}") @@ -235,7 +235,7 @@ macro(set_exe_flags) string(REPLACE "-w" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") string(REPLACE "-w" "" CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_COVERAGE}") string(REPLACE "-w" "" CMAKE_C_FLAGS_COVERAGE "${CMAKE_C_FLAGS_COVERAGE}") - add_flags_cxx("-Wall -Wextra -Wno-unused-parameter -Wno-error=switch") + add_flags_cxx("-Wall -Wextra -Wno-unused-parameter") # we support non-IEEE 754 fpus so can make no guarentees about error add_flags_cxx("-ffast-math") @@ -248,16 +248,10 @@ macro(set_exe_flags) # clang does not provide the __extern_always_inline macro and a part of libm depends on this when using fast-math add_flags_cxx("-D__extern_always_inline=inline") add_flags_cxx("-Werror -Weverything -Wno-c++98-compat-pedantic -Wno-string-conversion") - add_flags_cxx("-Wno-exit-time-destructors -Wno-padded") - add_flags_cxx("-Wno-error=sign-conversion -Wno-error=conversion -Wno-error=deprecated") - add_flags_cxx("-Wno-error=missing-prototypes") - add_flags_cxx("-Wno-error=shadow -Wno-error=old-style-cast -Wno-error=global-constructors") - add_flags_cxx("-Wno-error=float-equal") - add_flags_cxx("-Wno-weak-vtables -Wno-switch-enum") + add_flags_cxx("-Wno-exit-time-destructors -Wno-padded -Wno-weak-vtables") if ("${CLANG_VERSION}" VERSION_GREATER 3.0) # flags that are not present in 3.0 - add_flags_cxx("-Wno-error=covered-switch-default -Wno-error=missing-variable-declarations") - add_flags_cxx("-Wno-implicit-fallthrough -Wno-error=extra-semi") + add_flags_cxx("-Wno-implicit-fallthrough") endif() if ("${CLANG_VERSION}" VERSION_GREATER 3.1) # flags introduced in 3.2 @@ -267,3 +261,21 @@ macro(set_exe_flags) endif() endmacro() + +# if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") +# foreach(FILENAME ${ARGN}) +# message("downgrade_warnings for ${FILENAME}") +# set_source_files_properties(${FILENAME} PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=conversion") +# set_source_files_properties(${FILENAME} PROPERTIES COMPILE_FLAGS "-Wno-error=missing-prototypes -Wno-error=deprecated") +# set_source_files_properties(${FILENAME} PROPERTIES COMPILE_FLAGS "-Wno-error=shadow -Wno-error=old-style-cast -Wno-error=switch-enum -Wno-error=switch") +# set_source_files_properties(${FILENAME} PROPERTIES COMPILE_FLAGS "-Wno-error=float-equal -Wno-error=global-constructors") + +# if ("${CLANG_VERSION}" VERSION_GREATER 3.0) +# # flags that are not present in 3.0 +# set_source_files_properties(${FILENAME} PROPERTIES COMPILE_FLAGS "-Wno-error=covered-switch-default ") +# set_source_files_properties(${FILENAME} PROPERTIES COMPILE_FLAGS "-Wno-implicit-fallthrough -Wno-error=extra-semi") +# set_source_files_properties(${FILENAME} PROPERTIES COMPILE_FLAGS "-Wno-error=missing-variable-declarations") +# endif() +# endforeach() +# endif() + diff --git a/src/AllocationPool.h b/src/AllocationPool.h index 7c358cc84..e82f9807e 100644 --- a/src/AllocationPool.h +++ b/src/AllocationPool.h @@ -39,8 +39,8 @@ class cListAllocationPool : public cAllocationPool { public: - cListAllocationPool(std::auto_ptr::cStarvationCallbacks> a_Callbacks) : - m_Callbacks(a_Callbacks) + cListAllocationPool(std::unique_ptr::cStarvationCallbacks> a_Callbacks) : + m_Callbacks(std::move(a_Callbacks)) { for (size_t i = 0; i < NumElementsInReserve; i++) { @@ -105,7 +105,7 @@ class cListAllocationPool : public cAllocationPool private: std::list m_FreeList; - std::auto_ptr::cStarvationCallbacks> m_Callbacks; + std::unique_ptr::cStarvationCallbacks> m_Callbacks; }; diff --git a/src/Bindings/CMakeLists.txt b/src/Bindings/CMakeLists.txt index 133c2224d..e1ded8446 100644 --- a/src/Bindings/CMakeLists.txt +++ b/src/Bindings/CMakeLists.txt @@ -145,6 +145,10 @@ set_source_files_properties(${BINDING_OUTPUTS} PROPERTIES GENERATED TRUE) set_source_files_properties(${CMAKE_SOURCE_DIR}/src/Bindings/Bindings.cpp PROPERTIES COMPILE_FLAGS -Wno-error) +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set_source_files_properties(LuaWindow.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum") +endif() + if(NOT MSVC) add_library(Bindings ${SRCS} ${HDRS}) diff --git a/src/BlockEntities/CMakeLists.txt b/src/BlockEntities/CMakeLists.txt index 5f4af288d..b0bfca5e4 100644 --- a/src/BlockEntities/CMakeLists.txt +++ b/src/BlockEntities/CMakeLists.txt @@ -41,6 +41,11 @@ SET (HDRS NoteEntity.h SignEntity.h) +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set_source_files_properties(BeaconEntity.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion -Wno-error=switch-enum") + set_source_files_properties(NoteEntity.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion -Wno-error=sign-conversion") +endif() + if(NOT MSVC) add_library(BlockEntities ${SRCS} ${HDRS}) endif() diff --git a/src/BlockEntities/MobSpawnerEntity.cpp b/src/BlockEntities/MobSpawnerEntity.cpp index 764d7af84..f8222822c 100644 --- a/src/BlockEntities/MobSpawnerEntity.cpp +++ b/src/BlockEntities/MobSpawnerEntity.cpp @@ -246,9 +246,9 @@ int cMobSpawnerEntity::GetNearbyMonsterNum(eMonsterType a_EntityType) class cCallback : public cChunkDataCallback { public: - cCallback(Vector3d a_SpawnerPos, eMonsterType a_EntityType, int & a_NumEntities) : + cCallback(Vector3d a_SpawnerPos, eMonsterType a_CallbackEntityType, int & a_NumEntities) : m_SpawnerPos(a_SpawnerPos), - m_EntityType(a_EntityType), + m_EntityType(a_CallbackEntityType), m_NumEntities(a_NumEntities) { } diff --git a/src/Blocks/CMakeLists.txt b/src/Blocks/CMakeLists.txt index ed3e321d4..d7ea6258f 100644 --- a/src/Blocks/CMakeLists.txt +++ b/src/Blocks/CMakeLists.txt @@ -95,6 +95,7 @@ SET (HDRS MetaRotator.h WorldInterface.h) + if(NOT MSVC) add_library(Blocks ${SRCS} ${HDRS}) endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 25de24c91..bcf634fd7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -151,6 +151,31 @@ include_directories (SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/../lib/TCLAP/include") configure_file("BuildInfo.h.cmake" "${CMAKE_CURRENT_SOURCE_DIR}/BuildInfo.h") +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set_source_files_properties(BiomeDef.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum") + set_source_files_properties(BlockArea.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion") + set_source_files_properties(BlockID.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors") + set_source_files_properties(ByteBuffer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion") + set_source_files_properties(ChunkData.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion") + set_source_files_properties(ChunkMap.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=shadow -Wno-error=sign-conversion") + set_source_files_properties(ClientHandle.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion -Wno-error=sign-conversion -Wno-error=global-constructors") + set_source_files_properties(IniFile.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion") + set_source_files_properties(Inventory.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion") + set_source_files_properties(Item.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion") + set_source_files_properties(ItemGrid.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion") + set_source_files_properties(LightingThread.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion -Wno-error=sign-conversion") + set_source_files_properties(Map.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion") + set_source_files_properties(MobProximityCounter.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=float-equal") + set_source_files_properties(MobSpawner.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum") + set_source_files_properties(RCONServer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion") + set_source_files_properties(Root.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=shadow") + set_source_files_properties(Statistics.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors") + set_source_files_properties(StringUtils.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion") + set_source_files_properties(Tracer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion") + set_source_files_properties(World.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion") + set_source_files_properties(main.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=missing-variable-declarations -Wno-error=missing-prototypes") +endif() + if (NOT MSVC) # Bindings need to reference other folders, so they are done here instead # lib dependencies are not included diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 7d5f54373..7af669163 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -714,8 +714,8 @@ void cChunk::MoveEntityToNewChunk(cEntity * a_Entity) cEntity * m_Entity; public: - cMover(cEntity * a_Entity) : - m_Entity(a_Entity) + cMover(cEntity * a_CallbackEntity) : + m_Entity(a_CallbackEntity) {} } Mover(a_Entity); diff --git a/src/ChunkSender.cpp b/src/ChunkSender.cpp index 83d82884e..917ab198b 100644 --- a/src/ChunkSender.cpp +++ b/src/ChunkSender.cpp @@ -125,10 +125,6 @@ void cChunkSender::QueueSendChunkTo(int a_ChunkX, int a_ChunkZ, eChunkPriority a m_SendChunksHighPriority.push_back(Chunk); break; } - default: - { - ASSERT(!"Unknown chunk priority!"); - } } } m_evtQueue.Set(); diff --git a/src/CompositeChat.cpp b/src/CompositeChat.cpp index d1eb0b852..c6b89324c 100644 --- a/src/CompositeChat.cpp +++ b/src/CompositeChat.cpp @@ -345,6 +345,10 @@ AString cCompositeChat::ExtractText(void) const Msg.append(((cUrlPart *)(*itr))->m_Url); break; } + case ptShowAchievement: + { + break; + } } // switch (PartType) } // for itr - m_Parts[] return Msg; diff --git a/src/Enchantments.cpp b/src/Enchantments.cpp index 5ed18de6b..17c77dd93 100644 --- a/src/Enchantments.cpp +++ b/src/Enchantments.cpp @@ -69,8 +69,8 @@ void cEnchantments::AddFromString(const AString & a_StringSpec) LOG("%s: Failed to parse enchantment \"%s\", skipping.", __FUNCTION__, Split[0].c_str()); continue; } - int lvl = atoi(Split[1].c_str()); - if ((lvl == 0) && (Split[1] != "0")) + unsigned int lvl; + if (!StringToInteger(Split[1], lvl)) { // Level failed to parse LOG("%s: Failed to parse enchantment level \"%s\", skipping.", __FUNCTION__, Split[1].c_str()); @@ -108,7 +108,7 @@ AString cEnchantments::ToString(void) const -int cEnchantments::GetLevel(int a_EnchantmentID) const +unsigned int cEnchantments::GetLevel(int a_EnchantmentID) const { // Return the level for the specified enchantment; 0 if not stored cMap::const_iterator itr = m_Enchantments.find(a_EnchantmentID); @@ -125,7 +125,7 @@ int cEnchantments::GetLevel(int a_EnchantmentID) const -void cEnchantments::SetLevel(int a_EnchantmentID, int a_Level) +void cEnchantments::SetLevel(int a_EnchantmentID, unsigned int a_Level) { // Sets the level for the specified enchantment, adding it if not stored before or removing it if level <= 0 if (a_Level == 0) @@ -908,7 +908,7 @@ void cEnchantments::AddItemEnchantmentWeights(cWeightedEnchantments & a_Enchantm -void cEnchantments::AddEnchantmentWeightToVector(cWeightedEnchantments & a_Enchantments, int a_Weight, int a_EnchantmentID, int a_EnchantmentLevel) +void cEnchantments::AddEnchantmentWeightToVector(cWeightedEnchantments & a_Enchantments, int a_Weight, int a_EnchantmentID, unsigned int a_EnchantmentLevel) { cWeightedEnchantment weightedenchantment; weightedenchantment.m_Weight = a_Weight; diff --git a/src/Enchantments.h b/src/Enchantments.h index 9d3f342d4..8c08e7a93 100644 --- a/src/Enchantments.h +++ b/src/Enchantments.h @@ -92,10 +92,10 @@ public: AString ToString(void) const; /** Returns the level for the specified enchantment; 0 if not stored */ - int GetLevel(int a_EnchantmentID) const; + unsigned int GetLevel(int a_EnchantmentID) const; /** Sets the level for the specified enchantment, adding it if not stored before or removing it if level <= 0 */ - void SetLevel(int a_EnchantmentID, int a_Level); + void SetLevel(int a_EnchantmentID, unsigned int a_Level); /** Removes all enchantments */ void Clear(void); @@ -115,7 +115,7 @@ public: static void AddItemEnchantmentWeights(cWeightedEnchantments & a_Enchantments, short a_ItemType, int a_EnchantmentLevel); /** Add a enchantment with weight to the vector */ - static void AddEnchantmentWeightToVector(cWeightedEnchantments & a_Enchantments, int a_Weight, int a_EnchantmentID, int a_EnchantmentLevel); + static void AddEnchantmentWeightToVector(cWeightedEnchantments & a_Enchantments, int a_Weight, int a_EnchantmentID, unsigned int a_EnchantmentLevel); /** Remove the entire enchantment (with weight) from the vector */ static void RemoveEnchantmentWeightFromVector(cWeightedEnchantments & a_Enchantments, int a_EnchantmentID); @@ -145,7 +145,7 @@ public: protected: /** Maps enchantment ID -> enchantment level */ - typedef std::map cMap; + typedef std::map cMap; /** Currently stored enchantments */ cMap m_Enchantments; diff --git a/src/Entities/ArrowEntity.cpp b/src/Entities/ArrowEntity.cpp index 32952100c..0618ac2fc 100644 --- a/src/Entities/ArrowEntity.cpp +++ b/src/Entities/ArrowEntity.cpp @@ -108,7 +108,7 @@ void cArrowEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) Damage += m_World->GetTickRandomNumber(Damage / 2 + 2); } - int PowerLevel = m_CreatorData.m_Enchantments.GetLevel(cEnchantments::enchPower); + unsigned int PowerLevel = m_CreatorData.m_Enchantments.GetLevel(cEnchantments::enchPower); if (PowerLevel > 0) { int ExtraDamage = (int)ceil(0.25 * (PowerLevel + 1)); @@ -116,7 +116,7 @@ void cArrowEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) } int KnockbackAmount = 1; - int PunchLevel = m_CreatorData.m_Enchantments.GetLevel(cEnchantments::enchPunch); + unsigned int PunchLevel = m_CreatorData.m_Enchantments.GetLevel(cEnchantments::enchPunch); if (PunchLevel > 0) { Vector3d LookVector = GetLookVector(); diff --git a/src/Entities/CMakeLists.txt b/src/Entities/CMakeLists.txt index 5d10e1680..44257665e 100644 --- a/src/Entities/CMakeLists.txt +++ b/src/Entities/CMakeLists.txt @@ -60,6 +60,13 @@ SET (HDRS ThrownSnowballEntity.h WitherSkullEntity.h) +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set_source_files_properties(Entity.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=global-constructors -Wno-error=switch-enum") + set_source_files_properties(EntityEffect.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum") + set_source_files_properties(Floater.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion") + set_source_files_properties(Player.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=switch-enum -Wno-error=conversion") +endif() + if(NOT MSVC) add_library(Entities ${SRCS} ${HDRS}) diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index bc2b3e93e..941c4196c 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -396,7 +396,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) } } - int ThornsLevel = 0; + unsigned int ThornsLevel = 0; const cItem ArmorItems[] = { GetEquippedHelmet(), GetEquippedChestplate(), GetEquippedLeggings(), GetEquippedBoots() }; for (size_t i = 0; i < ARRAYCOUNT(ArmorItems); i++) { diff --git a/src/Entities/HangingEntity.h b/src/Entities/HangingEntity.h index 9d783006c..4d70cd1a0 100644 --- a/src/Entities/HangingEntity.h +++ b/src/Entities/HangingEntity.h @@ -89,7 +89,9 @@ protected: case BLOCK_FACE_ZM: Dir = 2; break; case BLOCK_FACE_XM: Dir = 1; break; case BLOCK_FACE_XP: Dir = 3; break; - default: + case BLOCK_FACE_YP: + case BLOCK_FACE_YM: + case BLOCK_FACE_NONE: { // Uncomment when entities are initialised with their real data, instead of dummy values: // LOGINFO("Invalid facing (%d) in a cHangingEntity, adjusting to BLOCK_FACE_XP.", a_BlockFace); diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index b80759d24..3adc63129 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -1051,11 +1051,6 @@ bool cMinecart::DoTakeDamage(TakeDamageInfo & TDI) Drops.push_back(cItem(E_ITEM_MINECART_WITH_HOPPER, 1, 0)); break; } - default: - { - ASSERT(!"Unhandled minecart type when spawning pickup!"); - return true; - } } m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ()); diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp index fcb686e28..9fdd7026b 100644 --- a/src/Entities/Pawn.cpp +++ b/src/Entities/Pawn.cpp @@ -78,7 +78,7 @@ void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, int a_Duration, s a_Duration = (int)(a_Duration * a_DistanceModifier); m_EntityEffects[a_EffectType] = cEntityEffect::CreateEntityEffect(a_EffectType, a_Duration, a_Intensity, a_DistanceModifier); - m_World->BroadcastEntityEffect(*this, a_EffectType, a_Intensity, a_Duration); + m_World->BroadcastEntityEffect(*this, a_EffectType, a_Intensity, static_cast(a_Duration)); m_EntityEffects[a_EffectType]->OnActivate(*this); } diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index 05b7669cd..1f00533db 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -281,6 +281,7 @@ cProjectileEntity * cProjectileEntity::Create(eKind a_Kind, cEntity * a_Creator, return new cFireworkEntity(a_Creator, a_X, a_Y, a_Z, *a_Item); } + case pkFishingFloat: break; } LOGWARNING("%s: Unknown projectile kind: %d", __FUNCTION__, a_Kind); diff --git a/src/Entities/ThrownEnderPearlEntity.cpp b/src/Entities/ThrownEnderPearlEntity.cpp index f01cdc18c..12d826042 100644 --- a/src/Entities/ThrownEnderPearlEntity.cpp +++ b/src/Entities/ThrownEnderPearlEntity.cpp @@ -77,9 +77,9 @@ void cThrownEnderPearlEntity::TeleportCreator(const Vector3d & a_HitPos) class cProjectileCreatorCallbackForPlayers : public cPlayerListCallback { public: - cProjectileCreatorCallbackForPlayers(cEntity * a_Attacker, Vector3i a_HitPos) : + cProjectileCreatorCallbackForPlayers(cEntity * a_Attacker, Vector3i a_CallbackHitPos) : m_Attacker(a_Attacker), - m_HitPos(a_HitPos) + m_HitPos(a_CallbackHitPos) { } diff --git a/src/Generating/CMakeLists.txt b/src/Generating/CMakeLists.txt index a28510d40..42c9d14e0 100644 --- a/src/Generating/CMakeLists.txt +++ b/src/Generating/CMakeLists.txt @@ -72,6 +72,20 @@ SET (HDRS VillageGen.h ) +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set_source_files_properties(CompoGenBiomal.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors") + set_source_files_properties(BioGen.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum") + set_source_files_properties(ComposableGenerator.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum") + set_source_files_properties(FinishGen.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum -Wno-error=switch") + set_source_files_properties(NetherFortGen.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors") + set_source_files_properties(RainbowRoadsGen.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors") + set_source_files_properties(RoughRavines.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=float-equal") + set_source_files_properties(StructGen.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum -Wno-error=switch") + set_source_files_properties(TestRailsGen.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors") + set_source_files_properties(UnderwaterBaseGen.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors -Wno-error=switch-enum") + set_source_files_properties(VillageGen.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors -Wno-error=switch-enum") +endif() + if(NOT MSVC) add_library(Generating ${SRCS} ${HDRS}) diff --git a/src/HTTPServer/CMakeLists.txt b/src/HTTPServer/CMakeLists.txt index b0efc810d..f6ef96d20 100644 --- a/src/HTTPServer/CMakeLists.txt +++ b/src/HTTPServer/CMakeLists.txt @@ -24,6 +24,11 @@ SET (HDRS NameValueParser.h SslHTTPConnection.h) +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set_source_files_properties(HTTPServer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors") + set_source_files_properties(HTTPConnection.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum") +endif() + if(NOT MSVC) add_library(HTTPServer ${SRCS} ${HDRS}) endif() diff --git a/src/IniFile.cpp b/src/IniFile.cpp index cd98cce57..b0b3d15ec 100644 --- a/src/IniFile.cpp +++ b/src/IniFile.cpp @@ -859,7 +859,7 @@ AString cIniFile::CheckCase(const AString & s) const size_t len = res.length(); for (size_t i = 0; i < len; i++) { - res[i] = tolower(res[i]); + res[i] = static_cast(tolower(res[i])); } return res; } diff --git a/src/Inventory.cpp b/src/Inventory.cpp index c595da5b0..079743e90 100644 --- a/src/Inventory.cpp +++ b/src/Inventory.cpp @@ -117,7 +117,7 @@ int cInventory::AddItem(const cItem & a_Item, bool a_AllowNewStacks, bool a_tryT } res += m_HotbarSlots.AddItem(ToAdd, a_AllowNewStacks, a_tryToFillEquippedFirst ? m_EquippedSlotNum : -1); - ToAdd.m_ItemCount = a_Item.m_ItemCount - res; + ToAdd.m_ItemCount = a_Item.m_ItemCount - static_cast(res); if (ToAdd.m_ItemCount == 0) { return res; diff --git a/src/Items/CMakeLists.txt b/src/Items/CMakeLists.txt index c50ddb372..46ff3b4a0 100644 --- a/src/Items/CMakeLists.txt +++ b/src/Items/CMakeLists.txt @@ -56,6 +56,10 @@ SET (HDRS ItemThrowable.h ) +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set_source_files_properties(ItemHandler.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=conversion -Wno-error=switch-enum") +endif() + if(NOT MSVC) add_library(Items ${SRCS} ${HDRS}) endif() diff --git a/src/Map.cpp b/src/Map.cpp index 5f296a5b2..48d7fb0ca 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -224,7 +224,7 @@ bool cMap::UpdatePixel(unsigned int a_X, unsigned int a_Z) return false; } - unsigned int PixelWidth = m_Map->GetPixelWidth(); + unsigned int CallbackPixelWidth = m_Map->GetPixelWidth(); if (m_Map->GetDimension() == dimNether) { @@ -237,9 +237,9 @@ bool cMap::UpdatePixel(unsigned int a_X, unsigned int a_Z) ColorCountMap ColorCounts; // Count surface blocks - for (unsigned int X = m_RelX; X < m_RelX + PixelWidth; ++X) + for (unsigned int X = m_RelX; X < m_RelX + CallbackPixelWidth; ++X) { - for (unsigned int Z = m_RelZ; Z < m_RelZ + PixelWidth; ++Z) + for (unsigned int Z = m_RelZ; Z < m_RelZ + CallbackPixelWidth; ++Z) { // unsigned int WaterDepth = 0; diff --git a/src/MapManager.cpp b/src/MapManager.cpp index fc67bd901..0965544cc 100644 --- a/src/MapManager.cpp +++ b/src/MapManager.cpp @@ -76,7 +76,7 @@ cMap * cMapManager::GetMapData(unsigned int a_ID) -cMap * cMapManager::CreateMap(int a_CenterX, int a_CenterY, int a_Scale) +cMap * cMapManager::CreateMap(int a_CenterX, int a_CenterY, unsigned int a_Scale) { cCSLock Lock(m_CS); diff --git a/src/MapManager.h b/src/MapManager.h index 1059773c3..cacc6d816 100644 --- a/src/MapManager.h +++ b/src/MapManager.h @@ -36,7 +36,7 @@ public: cMap * GetMapData(unsigned int a_ID); /** Creates a new map. Returns nullptr on error */ - cMap * CreateMap(int a_CenterX, int a_CenterY, int a_Scale = 3); + cMap * CreateMap(int a_CenterX, int a_CenterY, unsigned int a_Scale = 3); /** Calls the callback for the map with the specified ID. Returns true if the map was found and the callback called, false if map not found. diff --git a/src/MobCensus.cpp b/src/MobCensus.cpp index 1a69d8370..22c838c6b 100644 --- a/src/MobCensus.cpp +++ b/src/MobCensus.cpp @@ -41,7 +41,8 @@ int cMobCensus::GetCapMultiplier(cMonster::eFamily a_MobFamily) case cMonster::mfPassive: return 11; case cMonster::mfAmbient: return 16; case cMonster::mfWater: return 5; - default: + case cMonster::mfNoSpawn: + case cMonster::mfUnhandled: { ASSERT(!"Unhandled mob family"); return -1; diff --git a/src/Mobs/Blaze.cpp b/src/Mobs/Blaze.cpp index d4ad24166..731da6b18 100644 --- a/src/Mobs/Blaze.cpp +++ b/src/Mobs/Blaze.cpp @@ -23,7 +23,7 @@ void cBlaze::GetDrops(cItems & a_Drops, cEntity * a_Killer) { if ((a_Killer != nullptr) && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) { - int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + unsigned int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_BLAZE_ROD); } } diff --git a/src/Mobs/CMakeLists.txt b/src/Mobs/CMakeLists.txt index ffbcdf3ea..bd8fa76b1 100644 --- a/src/Mobs/CMakeLists.txt +++ b/src/Mobs/CMakeLists.txt @@ -80,6 +80,10 @@ SET (HDRS Zombie.h ZombiePigman.h) +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set_source_files_properties(Monster.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=conversion -Wno-error=switch -Wno-error=switch-enum -Wno-error=float-equal") +endif() + if(NOT MSVC) add_library(Mobs ${SRCS} ${HDRS}) endif() diff --git a/src/Mobs/CaveSpider.cpp b/src/Mobs/CaveSpider.cpp index fa530db82..8000f3f68 100644 --- a/src/Mobs/CaveSpider.cpp +++ b/src/Mobs/CaveSpider.cpp @@ -44,7 +44,7 @@ void cCaveSpider::Attack(std::chrono::milliseconds a_Dt) void cCaveSpider::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = 0; + unsigned int LootingLevel = 0; if (a_Killer != nullptr) { LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); diff --git a/src/Mobs/Chicken.cpp b/src/Mobs/Chicken.cpp index b2b21d4ae..a52d1a2da 100644 --- a/src/Mobs/Chicken.cpp +++ b/src/Mobs/Chicken.cpp @@ -48,7 +48,7 @@ void cChicken::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) void cChicken::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = 0; + unsigned int LootingLevel = 0; if (a_Killer != nullptr) { LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); diff --git a/src/Mobs/Cow.cpp b/src/Mobs/Cow.cpp index 7dc6f3f37..a45010201 100644 --- a/src/Mobs/Cow.cpp +++ b/src/Mobs/Cow.cpp @@ -21,7 +21,7 @@ cCow::cCow(void) : void cCow::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = 0; + unsigned int LootingLevel = 0; if (a_Killer != nullptr) { LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); diff --git a/src/Mobs/Creeper.cpp b/src/Mobs/Creeper.cpp index 41796402f..6968bed17 100644 --- a/src/Mobs/Creeper.cpp +++ b/src/Mobs/Creeper.cpp @@ -60,7 +60,7 @@ void cCreeper::GetDrops(cItems & a_Drops, cEntity * a_Killer) return; } - int LootingLevel = 0; + unsigned int LootingLevel = 0; if (a_Killer != nullptr) { LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); diff --git a/src/Mobs/Enderman.cpp b/src/Mobs/Enderman.cpp index 42c33884a..10cec9751 100644 --- a/src/Mobs/Enderman.cpp +++ b/src/Mobs/Enderman.cpp @@ -91,7 +91,7 @@ cEnderman::cEnderman(void) : void cEnderman::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = 0; + unsigned int LootingLevel = 0; if (a_Killer != nullptr) { LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); diff --git a/src/Mobs/Ghast.cpp b/src/Mobs/Ghast.cpp index d17047ab7..15bbe484b 100644 --- a/src/Mobs/Ghast.cpp +++ b/src/Mobs/Ghast.cpp @@ -19,7 +19,7 @@ cGhast::cGhast(void) : void cGhast::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = 0; + unsigned int LootingLevel = 0; if (a_Killer != nullptr) { LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); diff --git a/src/Mobs/Guardian.cpp b/src/Mobs/Guardian.cpp index 5eb30785b..a81667445 100644 --- a/src/Mobs/Guardian.cpp +++ b/src/Mobs/Guardian.cpp @@ -21,7 +21,7 @@ cGuardian::cGuardian(void) : void cGuardian::GetDrops(cItems & a_Drops, cEntity * a_Killer) { // Drops 0-3 Ink Sacs - int LootingLevel = 0; + unsigned int LootingLevel = 0; if (a_Killer != nullptr) { LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); diff --git a/src/Mobs/Horse.cpp b/src/Mobs/Horse.cpp index 5b4c78bfc..e33cc1b9d 100644 --- a/src/Mobs/Horse.cpp +++ b/src/Mobs/Horse.cpp @@ -140,7 +140,7 @@ void cHorse::OnRightClicked(cPlayer & a_Player) void cHorse::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = 0; + unsigned int LootingLevel = 0; if (a_Killer != nullptr) { LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 2b00f6959..619e20855 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -1137,10 +1137,10 @@ void cMonster::AddRandomUncommonDropItem(cItems & a_Drops, float a_Chance, short -void cMonster::AddRandomRareDropItem(cItems & a_Drops, cItems & a_Items, short a_LootingLevel) +void cMonster::AddRandomRareDropItem(cItems & a_Drops, cItems & a_Items, unsigned int a_LootingLevel) { MTRand r1; - int Count = r1.randInt() % 200; + unsigned int Count = r1.randInt() % 200; if (Count < (5 + a_LootingLevel)) { int Rare = r1.randInt() % a_Items.Size(); @@ -1152,7 +1152,7 @@ void cMonster::AddRandomRareDropItem(cItems & a_Drops, cItems & a_Items, short a -void cMonster::AddRandomArmorDropItem(cItems & a_Drops, short a_LootingLevel) +void cMonster::AddRandomArmorDropItem(cItems & a_Drops, unsigned int a_LootingLevel) { MTRand r1; if (r1.randInt() % 200 < ((m_DropChanceHelmet * 200) + (a_LootingLevel * 2))) @@ -1192,7 +1192,7 @@ void cMonster::AddRandomArmorDropItem(cItems & a_Drops, short a_LootingLevel) -void cMonster::AddRandomWeaponDropItem(cItems & a_Drops, short a_LootingLevel) +void cMonster::AddRandomWeaponDropItem(cItems & a_Drops, unsigned int a_LootingLevel) { MTRand r1; if (r1.randInt() % 200 < ((m_DropChanceWeapon * 200) + (a_LootingLevel * 2))) diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index c4043b0e5..50bc02558 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -274,13 +274,13 @@ protected: void AddRandomUncommonDropItem(cItems & a_Drops, float a_Chance, short a_Item, short a_ItemHealth = 0); /** Adds one rare item out of the list of rare items a_Items modified by the looting level a_LootingLevel(I-III or custom) to the itemdrop a_Drops*/ - void AddRandomRareDropItem(cItems & a_Drops, cItems & a_Items, short a_LootingLevel); + void AddRandomRareDropItem(cItems & a_Drops, cItems & a_Items, unsigned int a_LootingLevel); /** Adds armor that is equipped with the chance saved in m_DropChance[...] (this will be greter than 1 if piccked up or 0.085 + (0.01 per LootingLevel) if born with) to the drop*/ - void AddRandomArmorDropItem(cItems & a_Drops, short a_LootingLevel); + void AddRandomArmorDropItem(cItems & a_Drops, unsigned int a_LootingLevel); /** Adds weapon that is equipped with the chance saved in m_DropChance[...] (this will be greter than 1 if piccked up or 0.085 + (0.01 per LootingLevel) if born with) to the drop*/ - void AddRandomWeaponDropItem(cItems & a_Drops, short a_LootingLevel); + void AddRandomWeaponDropItem(cItems & a_Drops, unsigned int a_LootingLevel); } ; // tolua_export diff --git a/src/Mobs/Mooshroom.cpp b/src/Mobs/Mooshroom.cpp index ec533cfca..3b2fbad57 100644 --- a/src/Mobs/Mooshroom.cpp +++ b/src/Mobs/Mooshroom.cpp @@ -24,7 +24,7 @@ cMooshroom::cMooshroom(void) : void cMooshroom::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = 0; + unsigned int LootingLevel = 0; if (a_Killer != nullptr) { LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); diff --git a/src/Mobs/Path.h b/src/Mobs/Path.h index 7a4182f17..31002fe7f 100644 --- a/src/Mobs/Path.h +++ b/src/Mobs/Path.h @@ -99,7 +99,7 @@ public: return m_PathPoints[m_PathPoints.size() - 1 - a_index]; } /** Returns the total number of points this path has. */ - inline int GetPointCount() + inline size_t GetPointCount() { if (m_Status != ePathFinderStatus::PATH_FOUND) { diff --git a/src/Mobs/Pig.cpp b/src/Mobs/Pig.cpp index 56d6abfd5..efa779ac2 100644 --- a/src/Mobs/Pig.cpp +++ b/src/Mobs/Pig.cpp @@ -21,7 +21,7 @@ cPig::cPig(void) : void cPig::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = 0; + unsigned int LootingLevel = 0; if (a_Killer != nullptr) { LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); diff --git a/src/Mobs/Rabbit.cpp b/src/Mobs/Rabbit.cpp index cf49d2744..c7f3d58f0 100644 --- a/src/Mobs/Rabbit.cpp +++ b/src/Mobs/Rabbit.cpp @@ -20,7 +20,7 @@ cRabbit::cRabbit(void) : void cRabbit::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = 0; + unsigned int LootingLevel = 0; if (a_Killer != nullptr) { LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); diff --git a/src/Mobs/Sheep.cpp b/src/Mobs/Sheep.cpp index ec24f167e..dcfef8135 100644 --- a/src/Mobs/Sheep.cpp +++ b/src/Mobs/Sheep.cpp @@ -37,10 +37,10 @@ void cSheep::GetDrops(cItems & a_Drops, cEntity * a_Killer) { if (!m_IsSheared) { - a_Drops.push_back(cItem(E_BLOCK_WOOL, 1, m_WoolColor)); + a_Drops.push_back(cItem(E_BLOCK_WOOL, 1, static_cast(m_WoolColor))); } - int LootingLevel = 0; + unsigned int LootingLevel = 0; if (a_Killer != nullptr) { LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); @@ -65,7 +65,7 @@ void cSheep::OnRightClicked(cPlayer & a_Player) cItems Drops; int NumDrops = m_World->GetTickRandomNumber(2) + 1; - Drops.push_back(cItem(E_BLOCK_WOOL, NumDrops, m_WoolColor)); + Drops.push_back(cItem(E_BLOCK_WOOL, static_cast(NumDrops), static_cast(m_WoolColor))); m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ(), 10); m_World->BroadcastSoundEffect("mob.sheep.shear", GetPosX(), GetPosY(), GetPosZ(), 1.0f, 1.0f); } diff --git a/src/Mobs/Skeleton.cpp b/src/Mobs/Skeleton.cpp index f99404669..9a99a107c 100644 --- a/src/Mobs/Skeleton.cpp +++ b/src/Mobs/Skeleton.cpp @@ -22,7 +22,7 @@ cSkeleton::cSkeleton(bool IsWither) : void cSkeleton::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = 0; + unsigned int LootingLevel = 0; if (a_Killer != nullptr) { LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); diff --git a/src/Mobs/Slime.cpp b/src/Mobs/Slime.cpp index 7fc4821d8..4988d1082 100644 --- a/src/Mobs/Slime.cpp +++ b/src/Mobs/Slime.cpp @@ -29,7 +29,7 @@ cSlime::cSlime(int a_Size) : void cSlime::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = 0; + unsigned int LootingLevel = 0; if (a_Killer != nullptr) { LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); diff --git a/src/Mobs/Spider.cpp b/src/Mobs/Spider.cpp index deb263c41..184a1d912 100644 --- a/src/Mobs/Spider.cpp +++ b/src/Mobs/Spider.cpp @@ -18,7 +18,7 @@ cSpider::cSpider(void) : void cSpider::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = 0; + unsigned int LootingLevel = 0; if (a_Killer != nullptr) { LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); diff --git a/src/Mobs/Squid.cpp b/src/Mobs/Squid.cpp index 3c508b65f..9affcd6e1 100644 --- a/src/Mobs/Squid.cpp +++ b/src/Mobs/Squid.cpp @@ -21,7 +21,7 @@ cSquid::cSquid(void) : void cSquid::GetDrops(cItems & a_Drops, cEntity * a_Killer) { // Drops 0-3 Ink Sacs - int LootingLevel = 0; + unsigned int LootingLevel = 0; if (a_Killer != nullptr) { LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); diff --git a/src/Mobs/Witch.cpp b/src/Mobs/Witch.cpp index a3cadbaa0..1f672b4f7 100644 --- a/src/Mobs/Witch.cpp +++ b/src/Mobs/Witch.cpp @@ -19,7 +19,7 @@ cWitch::cWitch(void) : void cWitch::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = 0; + unsigned int LootingLevel = 0; if (a_Killer != nullptr) { LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); diff --git a/src/Mobs/Zombie.cpp b/src/Mobs/Zombie.cpp index fa4ac855d..a5b44e6c0 100644 --- a/src/Mobs/Zombie.cpp +++ b/src/Mobs/Zombie.cpp @@ -23,7 +23,7 @@ cZombie::cZombie(bool a_IsVillagerZombie) : void cZombie::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = 0; + unsigned int LootingLevel = 0; if (a_Killer != nullptr) { LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); diff --git a/src/Mobs/ZombiePigman.cpp b/src/Mobs/ZombiePigman.cpp index 8b415b0af..96d587287 100644 --- a/src/Mobs/ZombiePigman.cpp +++ b/src/Mobs/ZombiePigman.cpp @@ -18,7 +18,7 @@ cZombiePigman::cZombiePigman(void) : void cZombiePigman::GetDrops(cItems & a_Drops, cEntity * a_Killer) { - int LootingLevel = 0; + unsigned int LootingLevel = 0; if (a_Killer != nullptr) { LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); diff --git a/src/Protocol/CMakeLists.txt b/src/Protocol/CMakeLists.txt index c3a45ca47..f6aa6fca5 100644 --- a/src/Protocol/CMakeLists.txt +++ b/src/Protocol/CMakeLists.txt @@ -25,6 +25,11 @@ SET (HDRS ProtocolRecognizer.h ) +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set_source_files_properties(Protocol18x.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=conversion -Wno-error=switch-enum -Wno-error=switch") + set_source_files_properties(Protocol17x.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum") +endif() + if (NOT MSVC) add_library(Protocol ${SRCS} ${HDRS}) endif() diff --git a/src/Simulator/CMakeLists.txt b/src/Simulator/CMakeLists.txt index 5aa406717..8e1344ff0 100644 --- a/src/Simulator/CMakeLists.txt +++ b/src/Simulator/CMakeLists.txt @@ -31,6 +31,13 @@ SET (HDRS VanillaFluidSimulator.h VaporizeFluidSimulator.h) + +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set_source_files_properties(FireSimulator.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion") + set_source_files_properties(FluidSimulator.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=shadow") + set_source_files_properties(IncrementalRedstoneSimulator.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion") +endif() + if(NOT MSVC) add_library(Simulator ${SRCS} ${HDRS}) endif() diff --git a/src/Simulator/VanillaFluidSimulator.cpp b/src/Simulator/VanillaFluidSimulator.cpp index 6df75eebb..f6fe1e9ec 100644 --- a/src/Simulator/VanillaFluidSimulator.cpp +++ b/src/Simulator/VanillaFluidSimulator.cpp @@ -105,7 +105,7 @@ int cVanillaFluidSimulator::CalculateFlowCost(cChunk * a_Chunk, int a_RelX, int if (IsPassableForFluid(BlockType) || IsBlockLiquid(BlockType)) { // Path found, exit - return a_Iteration; + return static_cast(a_Iteration); } // 5 blocks away, bail out diff --git a/src/Tracer.cpp b/src/Tracer.cpp index 5fdaff15d..b54a50798 100644 --- a/src/Tracer.cpp +++ b/src/Tracer.cpp @@ -277,7 +277,7 @@ bool cTracer::Trace(const Vector3f & a_Start, const Vector3f & a_Direction, int // return 1 = hit, other is not hit -int LinesCross(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3) +static int LinesCross(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3) { // float linx, liny; diff --git a/src/UI/CMakeLists.txt b/src/UI/CMakeLists.txt index ef4afc40a..e01a09bb8 100644 --- a/src/UI/CMakeLists.txt +++ b/src/UI/CMakeLists.txt @@ -34,6 +34,11 @@ SET (HDRS MinecartWithChestWindow.h WindowOwner.h) +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set_source_files_properties(SlotArea.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion -Wno-error=switch-enum -Wno-error=sign-conversion") + set_source_files_properties(Window.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion -Wno-error=switch-enum -Wno-error=sign-conversion") +endif() + if(NOT MSVC) add_library(UI ${SRCS} ${HDRS}) endif() diff --git a/src/WorldStorage/CMakeLists.txt b/src/WorldStorage/CMakeLists.txt index 59193db2a..b511fc412 100644 --- a/src/WorldStorage/CMakeLists.txt +++ b/src/WorldStorage/CMakeLists.txt @@ -28,6 +28,14 @@ SET (HDRS WSSAnvil.h WorldStorage.h) +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set_source_files_properties(FastNBT.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion") + set_source_files_properties(FireworksSerializer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum") + set_source_files_properties(NBTChunkSerializer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum -Wno-error=sign-conversion -Wno-error=conversion") + set_source_files_properties(SchematicFileSerializer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=shadow -Wno-error=conversion") + set_source_files_properties(WSSAnvil.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=shorten-64-to-32 -Wno-error=switch -Wno-error=switch-enum -Wno-error=conversion") +endif() + if(NOT MSVC) add_library(WorldStorage ${SRCS} ${HDRS}) diff --git a/src/WorldStorage/EnchantmentSerializer.cpp b/src/WorldStorage/EnchantmentSerializer.cpp index a6e562956..b28e16b1d 100644 --- a/src/WorldStorage/EnchantmentSerializer.cpp +++ b/src/WorldStorage/EnchantmentSerializer.cpp @@ -14,8 +14,8 @@ void EnchantmentSerializer::WriteToNBTCompound(const cEnchantments & a_Enchantme for (cEnchantments::cMap::const_iterator itr = a_Enchantments.m_Enchantments.begin(), end = a_Enchantments.m_Enchantments.end(); itr != end; ++itr) { a_Writer.BeginCompound(""); - a_Writer.AddShort("id", itr->first); - a_Writer.AddShort("lvl", itr->second); + a_Writer.AddShort("id", static_cast(itr->first)); + a_Writer.AddShort("lvl", static_cast(itr->second)); a_Writer.EndCompound(); } // for itr - m_Enchantments[] a_Writer.EndList(); @@ -82,7 +82,7 @@ void EnchantmentSerializer::ParseFromNBT(cEnchantments & a_Enchantments, const c } // Store the enchantment: - a_Enchantments.m_Enchantments[id] = lvl; + a_Enchantments.m_Enchantments[id] = static_cast(lvl); } // for tag - children of the ench list tag } diff --git a/src/WorldStorage/FastNBT.cpp b/src/WorldStorage/FastNBT.cpp index 033a07601..f77197914 100644 --- a/src/WorldStorage/FastNBT.cpp +++ b/src/WorldStorage/FastNBT.cpp @@ -257,7 +257,7 @@ bool cParsedNBT::ReadTag(void) return true; } - default: + case TAG_Min: { ASSERT(!"Unhandled NBT tag type"); return false; @@ -503,7 +503,7 @@ void cFastNBTWriter::AddString(const AString & a_Name, const AString & a_Value) void cFastNBTWriter::AddByteArray(const AString & a_Name, const char * a_Value, size_t a_NumElements) { TagCommon(a_Name, TAG_ByteArray); - u_long len = htonl(static_cast(a_NumElements)); + u_int len = htonl(static_cast(a_NumElements)); m_Result.append(reinterpret_cast(&len), 4); m_Result.append(a_Value, a_NumElements); } @@ -515,7 +515,7 @@ void cFastNBTWriter::AddByteArray(const AString & a_Name, const char * a_Value, void cFastNBTWriter::AddIntArray(const AString & a_Name, const int * a_Value, size_t a_NumElements) { TagCommon(a_Name, TAG_IntArray); - u_long len = htonl(static_cast(a_NumElements)); + u_int len = htonl(static_cast(a_NumElements)); size_t cap = m_Result.capacity(); size_t size = m_Result.length(); if ((cap - size) < (4 + a_NumElements * 4)) diff --git a/src/WorldStorage/FireworksSerializer.cpp b/src/WorldStorage/FireworksSerializer.cpp index 91a5b8b63..0398f4da8 100644 --- a/src/WorldStorage/FireworksSerializer.cpp +++ b/src/WorldStorage/FireworksSerializer.cpp @@ -14,7 +14,7 @@ void cFireworkItem::WriteToNBTCompound(const cFireworkItem & a_FireworkItem, cFa case E_ITEM_FIREWORK_ROCKET: { a_Writer.BeginCompound("Fireworks"); - a_Writer.AddByte("Flight", a_FireworkItem.m_FlightTimeInTicks / 20); + a_Writer.AddByte("Flight", static_cast(a_FireworkItem.m_FlightTimeInTicks / 20)); a_Writer.BeginList("Explosions", TAG_Compound); a_Writer.BeginCompound(""); a_Writer.AddByte("Flicker", a_FireworkItem.m_HasFlicker); diff --git a/src/WorldStorage/MapSerializer.cpp b/src/WorldStorage/MapSerializer.cpp index da7b9d929..d4925dcab 100644 --- a/src/WorldStorage/MapSerializer.cpp +++ b/src/WorldStorage/MapSerializer.cpp @@ -102,11 +102,11 @@ void cMapSerializer::SaveMapToNBT(cFastNBTWriter & a_Writer) { a_Writer.BeginCompound("data"); - a_Writer.AddByte("scale", m_Map->GetScale()); - a_Writer.AddByte("dimension", (int) m_Map->GetDimension()); + a_Writer.AddByte("scale", static_cast(m_Map->GetScale())); + a_Writer.AddByte("dimension", static_cast(m_Map->GetDimension())); - a_Writer.AddShort("width", m_Map->GetWidth()); - a_Writer.AddShort("height", m_Map->GetHeight()); + a_Writer.AddShort("width", static_cast(m_Map->GetWidth())); + a_Writer.AddShort("height", static_cast(m_Map->GetHeight())); a_Writer.AddInt("xCenter", m_Map->GetCenterX()); a_Writer.AddInt("zCenter", m_Map->GetCenterZ()); @@ -235,7 +235,7 @@ bool cIDCountSerializer::Load(void) int CurrLine = NBT.FindChildByName(0, "map"); if (CurrLine >= 0) { - m_MapCount = (int)NBT.GetShort(CurrLine) + 1; + m_MapCount = static_cast(NBT.GetShort(CurrLine) + 1); } else { @@ -255,7 +255,7 @@ bool cIDCountSerializer::Save(void) if (m_MapCount > 0) { - Writer.AddShort("map", m_MapCount - 1); + Writer.AddShort("map", static_cast(m_MapCount - 1)); } Writer.Finish(); -- cgit v1.2.3 From 7f35671b21140331dcf93368340191cd0bce8cee Mon Sep 17 00:00:00 2001 From: tycho Date: Tue, 19 May 2015 19:53:16 +0100 Subject: Fix tests --- tests/ChunkData/CMakeLists.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/ChunkData/CMakeLists.txt b/tests/ChunkData/CMakeLists.txt index 381e11cc2..4079b7d93 100644 --- a/tests/ChunkData/CMakeLists.txt +++ b/tests/ChunkData/CMakeLists.txt @@ -4,6 +4,13 @@ enable_testing() include_directories(${CMAKE_SOURCE_DIR}/src/) + +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set_source_files_properties(${CMAKE_SOURCE_DIR}/src/ChunkData.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion") + set_source_files_properties(${CMAKE_SOURCE_DIR}/src/StringUtils.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion") +endif() + + add_definitions(-DTEST_GLOBALS=1) add_library(ChunkBuffer ${CMAKE_SOURCE_DIR}/src/ChunkData.cpp ${CMAKE_SOURCE_DIR}/src/StringUtils.cpp) -- cgit v1.2.3 From e512b7bf8e78b0450a542107e0182ff52169e59a Mon Sep 17 00:00:00 2001 From: Blitz Rakete Date: Thu, 21 May 2015 19:03:51 +0200 Subject: Fixes #2059 --- src/Items/ItemBucket.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Items/ItemBucket.h b/src/Items/ItemBucket.h index 015720415..45b4030a3 100644 --- a/src/Items/ItemBucket.h +++ b/src/Items/ItemBucket.h @@ -80,6 +80,13 @@ public: return false; } + // Check to see if destination block is too far away + // Reach Distance Multiplayer = 5 Blocks + if ((BlockPos.x - a_Player->GetPosX() > 5) || (BlockPos.z - a_Player->GetPosZ() > 5)) + { + return false; + } + // Remove water / lava block (unless plugins disagree) if (!a_Player->PlaceBlock(BlockPos.x, BlockPos.y, BlockPos.z, E_BLOCK_AIR, 0)) { @@ -126,6 +133,13 @@ public: { return false; } + + // Check to see if destination block is too far away + // Reach Distance Multiplayer = 5 Blocks + if ((BlockPos.x - a_Player->GetPosX() > 5) || (BlockPos.z - a_Player->GetPosZ() > 5)) + { + return false; + } if (a_Player->GetGameMode() != gmCreative) { -- cgit v1.2.3 From 7a5c1d30f8f8aaa7ea55463c42fe36e1dda0c6b6 Mon Sep 17 00:00:00 2001 From: tycho Date: Sat, 23 May 2015 11:53:49 +0100 Subject: Added pthread as a link flag. --- SetFlags.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SetFlags.cmake b/SetFlags.cmake index b26796522..54b40aabb 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -80,8 +80,9 @@ macro(set_flags) else() # Let gcc / clang know that we're compiling a multi-threaded app: - if (UNIX) + if (${UNIX}) add_flags_cxx("-pthread") + add_flags_lnk("-pthread") endif() if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") -- cgit v1.2.3 From 62c99145d0775bb41d210917e064cf257de41df1 Mon Sep 17 00:00:00 2001 From: tycho Date: Sat, 23 May 2015 12:27:55 +0100 Subject: Disable warnings in MCADefrag, ProtoProxy and tests --- Tools/MCADefrag/CMakeLists.txt | 5 +++-- Tools/ProtoProxy/CMakeLists.txt | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Tools/MCADefrag/CMakeLists.txt b/Tools/MCADefrag/CMakeLists.txt index 700310edc..a4096791d 100644 --- a/Tools/MCADefrag/CMakeLists.txt +++ b/Tools/MCADefrag/CMakeLists.txt @@ -11,8 +11,9 @@ set_flags() set_lib_flags() enable_profile() - - +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + add_flags_cxx("-Wno-error=sign-conversion -Wno-error=conversion -Wno-error=shorten-64-to-32") +endif() # Set include paths to the used libraries: include_directories("../../lib") diff --git a/Tools/ProtoProxy/CMakeLists.txt b/Tools/ProtoProxy/CMakeLists.txt index ce64db38d..1c48d7d93 100644 --- a/Tools/ProtoProxy/CMakeLists.txt +++ b/Tools/ProtoProxy/CMakeLists.txt @@ -14,7 +14,9 @@ include_directories("../../lib") include_directories("../../lib/polarssl/include") include_directories("../../src") - +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + add_flags_cxx("-Wno-error=conversion") +endif() function(flatten_files arg1) set(res "") -- cgit v1.2.3 From a5624debcb15f5edadeb598d86b4b8ee738d03bd Mon Sep 17 00:00:00 2001 From: tycho Date: Sat, 23 May 2015 12:59:41 +0100 Subject: Fix tests --- src/Generating/CMakeLists.txt | 2 ++ src/OSSupport/CMakeLists.txt | 4 ++++ tests/Network/CMakeLists.txt | 5 +++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Generating/CMakeLists.txt b/src/Generating/CMakeLists.txt index 42c9d14e0..8167b8ec7 100644 --- a/src/Generating/CMakeLists.txt +++ b/src/Generating/CMakeLists.txt @@ -78,6 +78,8 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") set_source_files_properties(ComposableGenerator.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum") set_source_files_properties(FinishGen.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum -Wno-error=switch") set_source_files_properties(NetherFortGen.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors") + set_source_files_properties(PieceGenerator.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors") + set_source_files_properties(Prefab.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors") set_source_files_properties(RainbowRoadsGen.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors") set_source_files_properties(RoughRavines.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=float-equal") set_source_files_properties(StructGen.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum -Wno-error=switch") diff --git a/src/OSSupport/CMakeLists.txt b/src/OSSupport/CMakeLists.txt index 0d3c9a63e..981c4c5b0 100644 --- a/src/OSSupport/CMakeLists.txt +++ b/src/OSSupport/CMakeLists.txt @@ -41,6 +41,10 @@ SET (HDRS UDPEndpointImpl.h ) +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + add_flags_cxx("-Wno-error=global-constructors") +endif() + if(NOT MSVC) add_library(OSSupport ${SRCS} ${HDRS}) diff --git a/tests/Network/CMakeLists.txt b/tests/Network/CMakeLists.txt index c0af50e2c..7412b16ad 100644 --- a/tests/Network/CMakeLists.txt +++ b/tests/Network/CMakeLists.txt @@ -41,8 +41,9 @@ if (MSVC) target_link_libraries(Network ws2_32.lib) endif() - - +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + add_flags_cxx("-Wno-error=conversion") +endif() # Define individual tests: -- cgit v1.2.3 From febc8529b1f555d29157ea94cbba9602de971845 Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Sat, 23 May 2015 19:31:33 +0100 Subject: Fix gamemode not changing properly. Should fix #604 --- src/Entities/Player.cpp | 135 +++++++++++++++++++------------------- src/Entities/Player.h | 167 ++++++++++++++++++++++++------------------------ 2 files changed, 154 insertions(+), 148 deletions(-) diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index b5a48d9bf..e3e3fac4f 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -94,7 +94,7 @@ cPlayer::cPlayer(cClientHandlePtr a_Client, const AString & a_PlayerName) : SetMaxHealth(MAX_HEALTH); m_Health = MAX_HEALTH; - + m_LastPlayerListTime = std::chrono::steady_clock::now(); m_PlayerName = a_PlayerName; @@ -106,7 +106,7 @@ cPlayer::cPlayer(cClientHandlePtr a_Client, const AString & a_PlayerName) : SetPosY(World->GetSpawnY()); SetPosZ(World->GetSpawnZ()); SetBedPos(Vector3i(static_cast(World->GetSpawnX()), static_cast(World->GetSpawnY()), static_cast(World->GetSpawnZ()))); - + LOGD("Player \"%s\" is connecting for the first time, spawning at default world spawn {%.2f, %.2f, %.2f}", a_PlayerName.c_str(), GetPosX(), GetPosY(), GetPosZ() ); @@ -135,7 +135,7 @@ cPlayer::cPlayer(cClientHandlePtr a_Client, const AString & a_PlayerName) : m_IsFlying = true; m_bVisible = false; } - + cRoot::Get()->GetServer()->PlayerCreated(this); } @@ -152,17 +152,17 @@ cPlayer::~cPlayer(void) } LOGD("Deleting cPlayer \"%s\" at %p, ID %d", GetName().c_str(), this, GetUniqueID()); - + // Notify the server that the player is being destroyed cRoot::Get()->GetServer()->PlayerDestroying(this); SaveToDisk(); m_ClientHandle = nullptr; - + delete m_InventoryWindow; m_InventoryWindow = nullptr; - + LOGD("Player %p deleted", this); } @@ -208,7 +208,7 @@ void cPlayer::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) m_ClientHandle = nullptr; return; } - + if (!m_ClientHandle->IsPlaying()) { // We're not yet in the game, ignore everything @@ -217,21 +217,21 @@ void cPlayer::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) } m_Stats.AddValue(statMinutesPlayed, 1); - + if (!a_Chunk.IsValid()) { // This may happen if the cPlayer is created before the chunks have the chance of being loaded / generated (#83) return; } - + super::Tick(a_Dt, a_Chunk); - + // Handle charging the bow: if (m_IsChargingBow) { m_BowCharge += 1; } - + // Handle updating experience if (m_bDirtyExperience) { @@ -243,7 +243,7 @@ void cPlayer::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { // Apply food exhaustion from movement: ApplyFoodExhaustionFromMovement(); - + if (cRoot::Get()->GetPluginManager()->CallHookPlayerMoving(*this, m_LastPos, GetPosition())) { CanMove = false; @@ -264,10 +264,10 @@ void cPlayer::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { FinishEating(); } - + HandleFood(); } - + if (m_IsFishing) { HandleFloater(); @@ -467,7 +467,7 @@ void cPlayer::SetTouchGround(bool a_bTouchGround) { return; } - + m_bTouchGround = a_bTouchGround; if (!m_bTouchGround) @@ -516,7 +516,7 @@ void cPlayer::SetTouchGround(bool a_bTouchGround) { // cPlayer makes sure damage isn't applied in creative, no need to check here TakeDamage(dtFalling, nullptr, Damage, Damage, 0); - + // Fall particles GetWorld()->BroadcastSoundParticleEffect(2006, POSX_TOINT, static_cast(GetPosY()) - 1, POSZ_TOINT, Damage /* Used as particle effect speed modifier */); } @@ -548,7 +548,7 @@ void cPlayer::SetFoodLevel(int a_FoodLevel) m_FoodSaturationLevel = 5.0; return; } - + m_FoodLevel = FoodLevel; SendHealth(); } @@ -616,7 +616,7 @@ void cPlayer::StartEating(void) { // Set the timer: m_EatingFinishTick = m_World->GetWorldAge() + EATING_TICKS; - + // Send the packets: m_World->BroadcastEntityAnimation(*this, 3); m_World->BroadcastEntityMetadata(*this); @@ -630,7 +630,7 @@ void cPlayer::FinishEating(void) { // Reset the timer: m_EatingFinishTick = -1; - + // Send the packets: m_ClientHandle->SendEntityStatus(*this, esPlayerEatingAccepted); m_World->BroadcastEntityMetadata(*this); @@ -764,7 +764,7 @@ void cPlayer::SetSprintingMaxSpeed(double a_Speed) void cPlayer::SetFlyingMaxSpeed(double a_Speed) { m_FlyingMaxSpeed = a_Speed; - + // Update the flying speed, always: m_ClientHandle->SendPlayerAbilities(); } @@ -776,7 +776,7 @@ void cPlayer::SetFlyingMaxSpeed(double a_Speed) void cPlayer::SetCrouch(bool a_IsCrouched) { // Set the crouch status, broadcast to all visible players - + if (a_IsCrouched == m_IsCrouched) { // No change @@ -797,7 +797,7 @@ void cPlayer::SetSprint(bool a_IsSprinting) // No change return; } - + m_IsSprinting = a_IsSprinting; m_ClientHandle->SendPlayerMaxSpeed(); } @@ -883,7 +883,7 @@ bool cPlayer::DoTakeDamage(TakeDamageInfo & a_TDI) } } } - + if (super::DoTakeDamage(a_TDI)) { // Any kind of damage adds food exhaustion @@ -1012,7 +1012,7 @@ void cPlayer::Respawn(void) m_Health = GetMaxHealth(); SetInvulnerableTicks(20); - + // Reset food level: m_FoodLevel = MAX_FOOD_LEVEL; m_FoodSaturationLevel = 5.0; @@ -1024,7 +1024,7 @@ void cPlayer::Respawn(void) // ToDo: send score to client? How? m_ClientHandle->SendRespawn(GetWorld()->GetDimension(), true); - + // Extinguish the fire: StopBurning(); @@ -1158,7 +1158,7 @@ void cPlayer::CloseWindow(bool a_CanRefuse) m_CurrentWindow = m_InventoryWindow; return; } - + if (m_CurrentWindow->ClosedByPlayer(*this, a_CanRefuse) || !a_CanRefuse) { // Close accepted, go back to inventory window (the default): @@ -1196,30 +1196,17 @@ void cPlayer::SetGameMode(eGameMode a_GameMode) LOGWARNING("%s: Setting invalid gamemode: %d", GetName().c_str(), a_GameMode); return; } - + if (m_GameMode == a_GameMode) { // Gamemode already set return; } - + m_GameMode = a_GameMode; m_ClientHandle->SendGameMode(a_GameMode); - if (!(IsGameModeCreative() || IsGameModeSpectator())) - { - SetFlying(false); - SetCanFly(false); - } - - if (IsGameModeSpectator() && IsVisible()) - { - SetVisible(false); - } - else if (!IsVisible()) - { - SetVisible(true); - } + SetCapabilities(); m_World->BroadcastPlayerListUpdateGameMode(*this); } @@ -1231,6 +1218,30 @@ void cPlayer::SetGameMode(eGameMode a_GameMode) void cPlayer::LoginSetGameMode( eGameMode a_GameMode) { m_GameMode = a_GameMode; + + SetCapabilities(); +} + + + + + +void cPlayer::SetCapabilities() +{ + if (!IsGameModeCreative() || IsGameModeSpectator()) + { + SetFlying(false); + SetCanFly(false); + } + + if (IsGameModeSpectator()) + { + SetVisible(false); + } + else + { + SetVisible(true); + } } @@ -1322,12 +1333,12 @@ void cPlayer::SendRotation(double a_YawDegrees, double a_PitchDegrees) Vector3d cPlayer::GetThrowStartPos(void) const { Vector3d res = GetEyePosition(); - + // Adjust the position to be just outside the player's bounding box: res.x += 0.16 * cos(GetPitch()); res.y += -0.1; res.z += 0.16 * sin(GetPitch()); - + return res; } @@ -1339,9 +1350,9 @@ Vector3d cPlayer::GetThrowSpeed(double a_SpeedCoeff) const { Vector3d res = GetLookVector(); res.Normalize(); - + // TODO: Add a slight random change (+-0.0075 in each direction) - + return res * a_SpeedCoeff; } @@ -1386,13 +1397,13 @@ void cPlayer::MoveTo( const Vector3d & a_NewPos) } return; } - + // TODO: should do some checks to see if player is not moving through terrain // TODO: Official server refuses position packets too far away from each other, kicking "hacked" clients; we should, too Vector3d DeltaPos = a_NewPos - GetPosition(); UpdateMovementStats(DeltaPos); - + SetPosition( a_NewPos); SetStance(a_NewPos.y + 1.62); } @@ -1427,7 +1438,7 @@ bool cPlayer::HasPermission(const AString & a_Permission) // Empty permission request is always granted return true; } - + AStringVector Split = StringSplit(a_Permission, "."); // Iterate over all restrictions; if any matches, then return failure: @@ -1599,7 +1610,7 @@ void cPlayer::TossItems(const cItems & a_Items) { return; } - + m_Stats.AddValue(statItemsDropped, (StatValue)a_Items.Size()); double vX = 0, vY = 0, vZ = 0; @@ -1621,7 +1632,7 @@ bool cPlayer::DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn) // Don't move to same world return false; } - + // Ask the plugins if the player is allowed to changing the world if (cRoot::Get()->GetPluginManager()->CallHookEntityChangingWorld(*this, *a_World)) { @@ -1658,7 +1669,7 @@ bool cPlayer::DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn) // Broadcast the player into the new world. a_World->BroadcastSpawnEntity(*this); - + // Player changed the world, call the hook cRoot::Get()->GetPluginManager()->CallHookEntityChangedWorld(*this, *OldWorld); @@ -1678,7 +1689,7 @@ bool cPlayer::LoadFromDisk(cWorldPtr & a_World) { return true; } - + // Load from the offline UUID file, if allowed: AString OfflineUUID = cClientHandle::GenerateOfflineUUID(GetName()); const char * OfflineUsage = " (unused)"; @@ -1690,7 +1701,7 @@ bool cPlayer::LoadFromDisk(cWorldPtr & a_World) return true; } } - + // Load from the old-style name-based file, if allowed: if (cRoot::Get()->GetServer()->ShouldLoadNamedPlayerData()) { @@ -1705,7 +1716,7 @@ bool cPlayer::LoadFromDisk(cWorldPtr & a_World) return true; } } - + // None of the files loaded successfully LOG("Player data file not found for %s (%s, offline %s%s), will be reset to defaults.", GetName().c_str(), m_UUID.c_str(), OfflineUUID.c_str(), OfflineUsage @@ -1782,7 +1793,7 @@ bool cPlayer::LoadFromFile(const AString & a_FileName, cWorldPtr & a_World) { m_CanFly = true; } - + m_Inventory.LoadFromJson(root["inventory"]); cEnderChestEntity::LoadFromJson(root["enderchestinventory"], m_EnderChestContents); @@ -1801,11 +1812,11 @@ bool cPlayer::LoadFromFile(const AString & a_FileName, cWorldPtr & a_World) // We use the default world name (like bukkit) because stats are shared between dimensions / worlds. cStatSerializer StatSerializer(cRoot::Get()->GetDefaultWorld()->GetName(), GetName(), &m_Stats); StatSerializer.Load(); - + LOGD("Player %s was read from file \"%s\", spawning at {%.2f, %.2f, %.2f} in world \"%s\"", GetName().c_str(), a_FileName.c_str(), GetPosX(), GetPosY(), GetPosZ(), a_World->GetName().c_str() ); - + return true; } @@ -2161,7 +2172,7 @@ void cPlayer::ApplyFoodExhaustionFromMovement() { return; } - + // Calculate the distance travelled, update the last pos: Vector3d Movement(GetPosition() - m_LastPos); Movement.y = 0; // Only take XZ movement into account @@ -2364,7 +2375,7 @@ AString cPlayer::GetUUIDFileName(const AString & a_UUID) { AString UUID = cMojangAPI::MakeUUIDDashed(a_UUID); ASSERT(UUID.length() == 36); - + AString res("players/"); res.append(UUID, 0, 2); res.push_back('/'); @@ -2372,7 +2383,3 @@ AString cPlayer::GetUUIDFileName(const AString & a_UUID) res.append(".json"); return res; } - - - - diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 579eb8748..a84fdd0c7 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -26,42 +26,42 @@ class cPlayer : public cPawn { typedef cPawn super; - + public: static const int MAX_HEALTH; - + static const int MAX_FOOD_LEVEL; - + /** Number of ticks it takes to eat an item */ static const int EATING_TICKS; - + // tolua_end - + CLASS_PROTODEF(cPlayer) - + cPlayer(cClientHandlePtr a_Client, const AString & a_PlayerName); - + virtual ~cPlayer(); virtual void SpawnOn(cClientHandle & a_Client) override; - + virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; virtual void HandlePhysics(std::chrono::milliseconds a_Dt, cChunk &) override { UNUSED(a_Dt); } /** Returns the curently equipped weapon; empty item if none */ virtual cItem GetEquippedWeapon(void) const override { return m_Inventory.GetEquippedItem(); } - + /** Returns the currently equipped helmet; empty item if none */ virtual cItem GetEquippedHelmet(void) const override { return m_Inventory.GetEquippedHelmet(); } - + /** Returns the currently equipped chestplate; empty item if none */ virtual cItem GetEquippedChestplate(void) const override { return m_Inventory.GetEquippedChestplate(); } /** Returns the currently equipped leggings; empty item if none */ virtual cItem GetEquippedLeggings(void) const override { return m_Inventory.GetEquippedLeggings(); } - + /** Returns the currently equipped boots; empty item if none */ virtual cItem GetEquippedBoots(void) const override { return m_Inventory.GetEquippedBoots(); } @@ -104,16 +104,16 @@ public: static int CalcLevelFromXp(int a_CurrentXp); // tolua_end - + /** Starts charging the equipped bow */ void StartChargingBow(void); - + /** Finishes charging the current bow. Returns the number of ticks for which the bow has been charged */ int FinishChargingBow(void); - + /** Cancels the current bow charging */ void CancelChargingBow(void); - + /** Returns true if the player is currently charging the bow */ bool IsChargingBow(void) const { return m_IsChargingBow; } @@ -128,7 +128,7 @@ public: /** Gets the contents of the player's associated enderchest */ cItemGrid & GetEnderChestContents(void) { return m_EnderChestContents; } - + inline const cItem & GetEquippedItem(void) const { return GetInventory().GetEquippedItem(); } // tolua_export /** Returns whether the player is climbing (ladders, vines etc.) */ @@ -137,43 +137,49 @@ public: virtual void TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ) override; // tolua_begin - + /** Sends the "look" packet to the player, forcing them to set their rotation to the specified values. a_YawDegrees is clipped to range [-180, +180), a_PitchDegrees is clipped to range [-180, +180) but the client only uses [-90, +90] */ void SendRotation(double a_YawDegrees, double a_PitchDegrees); - + /** Returns the position where projectiles thrown by this player should start, player eye position + adjustment */ Vector3d GetThrowStartPos(void) const; - + /** Returns the initial speed vector of a throw, with a 3D length of a_SpeedCoeff. */ Vector3d GetThrowSpeed(double a_SpeedCoeff) const; - + /** Returns the current gamemode. Partly OBSOLETE, you should use IsGameModeXXX() functions wherever applicable */ eGameMode GetGameMode(void) const { return m_GameMode; } - + /** Returns the current effective gamemode (inherited gamemode is resolved before returning) */ eGameMode GetEffectiveGameMode(void) const { return (m_GameMode == gmNotSet) ? m_World->GetGameMode() : m_GameMode; } - + /** Sets the gamemode for the player. The gamemode may be gmNotSet, in that case the player inherits the world's gamemode. Updates the gamemode on the client (sends the packet) */ void SetGameMode(eGameMode a_GameMode); + // Sets the current gamemode, doesn't check validity, doesn't send update packets to client + void LoginSetGameMode(eGameMode a_GameMode); + + // Updates player's capabilities - flying, visibility, etc. from their gamemode. + void SetCapabilities(); + /** Returns true if the player is in Creative mode, either explicitly, or by inheriting from current world */ bool IsGameModeCreative(void) const; - + /** Returns true if the player is in Survival mode, either explicitly, or by inheriting from current world */ bool IsGameModeSurvival(void) const; - + /** Returns true if the player is in Adventure mode, either explicitly, or by inheriting from current world */ bool IsGameModeAdventure(void) const; - + /** Returns true if the player is in Spectator mode, either explicitly, or by inheriting from current world */ bool IsGameModeSpectator(void) const; - + AString GetIP(void) const { return m_IP; } // tolua_export /** Returns the associated team, nullptr if none */ @@ -195,11 +201,8 @@ public: If the achievement has been already awarded to the player, this method will just increment the stat counter. Returns the _new_ stat value. (0 = Could not award achievement) */ unsigned int AwardAchievement(const eStatistic a_Ach); - + void SetIP(const AString & a_IP); - - // Sets the current gamemode, doesn't check validity, doesn't send update packets to client - void LoginSetGameMode(eGameMode a_GameMode); /** Forces the player to move in the given direction. @deprecated Use SetSpeed instead. */ @@ -210,15 +213,15 @@ public: cWindow * GetWindow(void) { return m_CurrentWindow; } // tolua_export const cWindow * GetWindow(void) const { return m_CurrentWindow; } - + /** Opens the specified window; closes the current one first using CloseWindow() */ void OpenWindow(cWindow * a_Window); // Exported in ManualBindings.cpp - + // tolua_begin - + /** Closes the current window, resets current window to m_InventoryWindow. A plugin may refuse the closing if a_CanRefuse is true */ void CloseWindow(bool a_CanRefuse = true); - + /** Closes the current window if it matches the specified ID, resets current window to m_InventoryWindow */ void CloseWindowIfID(char a_WindowID, bool a_CanRefuse = true); @@ -243,7 +246,7 @@ public: const AString & GetName(void) const { return m_PlayerName; } void SetName(const AString & a_Name) { m_PlayerName = a_Name; } - + // tolua_end bool HasPermission(const AString & a_Permission); // tolua_export @@ -260,7 +263,7 @@ public: const AStringVector & GetRestrictions(void) const { return m_Restrictions; } // Exported in ManualBindings.cpp // tolua_begin - + /** Returns the full color code to use for this player, based on their rank. The returned value either is empty, or includes the cChatColor::Delimiter. */ AString GetColor(void) const; @@ -279,15 +282,15 @@ public: /** Heals the player by the specified amount of HPs (positive only); sends health update */ virtual void Heal(int a_Health) override; - + int GetFoodLevel (void) const { return m_FoodLevel; } double GetFoodSaturationLevel (void) const { return m_FoodSaturationLevel; } int GetFoodTickTimer (void) const { return m_FoodTickTimer; } double GetFoodExhaustionLevel (void) const { return m_FoodExhaustionLevel; } - + /** Returns true if the player is satiated, i. e. their foodlevel is at the max and they cannot eat anymore */ bool IsSatiated(void) const { return (m_FoodLevel >= MAX_FOOD_LEVEL); } - + void SetFoodLevel (int a_FoodLevel); void SetFoodSaturationLevel (double a_FoodSaturationLevel); void SetFoodTickTimer (int a_FoodTickTimer); @@ -298,10 +301,10 @@ public: /** Adds the specified exhaustion to m_FoodExhaustion. Expects only positive values. */ void AddFoodExhaustion(double a_Exhaustion); - + /** Returns true if the player is currently in the process of eating the currently equipped item */ bool IsEating(void) const { return (m_EatingFinishTick >= 0); } - + /** Returns true if the player is currently flying. */ bool IsFlying(void) const { return m_IsFlying; } @@ -329,16 +332,16 @@ public: GetWorld()->BroadcastEntityAnimation(*this, 2); } } - + /** Starts eating the currently equipped item. Resets the eating timer and sends the proper animation packet */ void StartEating(void); - + /** Finishes eating the currently equipped item. Consumes the item, updates health and broadcasts the packets */ void FinishEating(void); - + /** Aborts the current eating operation */ void AbortEating(void); - + virtual void KilledBy(TakeDamageInfo & a_TDI) override; virtual void Killed(cEntity * a_Victim) override; @@ -356,69 +359,69 @@ public: bool SaveToDisk(void); typedef cWorld * cWorldPtr; - + /** Loads the player data from the disk file Sets a_World to the world where the player will spawn, based on the stored world name or the default world by calling LoadFromFile() Returns true on success, false on failure */ bool LoadFromDisk(cWorldPtr & a_World); - + /** Loads the player data from the specified file Sets a_World to the world where the player will spawn, based on the stored world name or the default world Returns true on success, false on failure */ bool LoadFromFile(const AString & a_FileName, cWorldPtr & a_World); - + const AString & GetLoadedWorldName() { return m_LoadedWorldName; } void UseEquippedItem(int a_Amount = 1); - + void SendHealth(void); void SendExperience(void); - + /** In UI windows, get the item that the player is dragging */ cItem & GetDraggingItem(void) {return m_DraggingItem; } - + // In UI windows, when inventory-painting: /** Clears the list of slots that are being inventory-painted. To be used by cWindow only */ void ClearInventoryPaintSlots(void); - + /** Adds a slot to the list for inventory painting. To be used by cWindow only */ void AddInventoryPaintSlot(int a_SlotNum); - + /** Returns the list of slots currently stored for inventory painting. To be used by cWindow only */ const cSlotNums & GetInventoryPaintSlots(void) const; - + // tolua_begin - + /** Returns the current relative maximum speed (takes current sprinting / flying state into account) */ double GetMaxSpeed(void) const; - + /** Gets the normal relative maximum speed */ double GetNormalMaxSpeed(void) const { return m_NormalMaxSpeed; } - + /** Gets the sprinting relative maximum speed */ double GetSprintingMaxSpeed(void) const { return m_SprintingMaxSpeed; } - + /** Gets the flying relative maximum speed */ double GetFlyingMaxSpeed(void) const { return m_FlyingMaxSpeed; } - + /** Sets the normal relative maximum speed. Sends the update to player, if needed. */ void SetNormalMaxSpeed(double a_Speed); - + /** Sets the sprinting relative maximum speed. Sends the update to player, if needed. */ void SetSprintingMaxSpeed(double a_Speed); - + /** Sets the flying relative maximum speed. Sends the update to player, if needed. */ void SetFlyingMaxSpeed(double a_Speed); - + /** Sets the crouch status, broadcasts to all visible players */ void SetCrouch(bool a_IsCrouched); - + /** Starts or stops sprinting, sends the max speed update to the client, if needed */ void SetSprint(bool a_IsSprinting); - + /** Flags the player as flying */ void SetFlying(bool a_IsFlying); @@ -442,17 +445,17 @@ public: /** Sets the player's bed (home) position */ void SetBedPos(const Vector3i & a_Pos) { m_LastBedPos = a_Pos; } - + // tolua_end /** Update movement-related statistics. */ void UpdateMovementStats(const Vector3d & a_DeltaPos); - + // tolua_begin /** Returns wheter the player can fly or not. */ virtual bool CanFly(void) const { return m_CanFly; } - + /** Returns the UUID (short format) that has been read from the client, or empty string if not available. */ const AString & GetUUID(void) const { return m_UUID; } @@ -492,7 +495,7 @@ public: /** Called by cClientHandle when the client is being destroyed. The player removes its m_ClientHandle ownership so that the ClientHandle gets deleted. */ void RemoveClientHandle(void); - + protected: typedef std::vector > AStringVectorVector; @@ -535,16 +538,16 @@ protected: // Food-related variables: /** Represents the food bar, one point equals half a "drumstick" */ int m_FoodLevel; - + /** "Overcharge" for the m_FoodLevel; is depleted before m_FoodLevel */ double m_FoodSaturationLevel; - + /** Count-up to the healing or damaging action, based on m_FoodLevel */ int m_FoodTickTimer; - + /** A "buffer" which adds up hunger before it is substracted from m_FoodSaturationLevel or m_FoodLevel. Each action adds a little */ double m_FoodExhaustionLevel; - + float m_LastJumpHeight; float m_LastGroundHeight; bool m_bTouchGround; @@ -564,31 +567,31 @@ protected: eGameMode m_GameMode; AString m_IP; - + /** The item being dragged by the cursor while in a UI window */ cItem m_DraggingItem; std::chrono::steady_clock::time_point m_LastPlayerListTime; cClientHandlePtr m_ClientHandle; - + cSlotNums m_InventoryPaintSlots; - + /** Max speed, relative to the game default. 1 means regular speed, 2 means twice as fast, 0.5 means half-speed. Default value is 1. */ double m_NormalMaxSpeed; - + /** Max speed, relative to the game default max speed, when sprinting. 1 means regular speed, 2 means twice as fast, 0.5 means half-speed. Default value is 1.3. */ double m_SprintingMaxSpeed; - + /** Max speed, relative to the game default flying max speed, when flying. 1 means regular speed, 2 means twice as fast, 0.5 means half-speed. Default value is 1. */ double m_FlyingMaxSpeed; - + bool m_IsCrouched; bool m_IsSprinting; bool m_IsFlying; @@ -629,7 +632,7 @@ protected: Will not apply food penalties if found to be true; will set to false after processing */ bool m_bIsTeleporting; - + /** The short UUID (no dashes) of the player, as read from the ClientHandle. If no ClientHandle is given, the UUID is initialized to empty. */ AString m_UUID; @@ -649,7 +652,7 @@ protected: /** Stops players from burning in creative mode */ virtual void TickBurning(cChunk & a_Chunk) override; - + /** Called in each tick to handle food-related processing */ void HandleFood(void); @@ -666,7 +669,3 @@ protected: This can be used both for online and offline UUIDs. */ AString GetUUIDFileName(const AString & a_UUID); } ; // tolua_export - - - - -- cgit v1.2.3 From 7021547e99e1e169aff1ff0fada6f7e1e5349bcf Mon Sep 17 00:00:00 2001 From: SafwatHalaby Date: Sat, 23 May 2015 17:41:29 +0300 Subject: Pathfinder - Bounding boxes and some tweaks --- src/Mobs/Monster.cpp | 6 +-- src/Mobs/Path.cpp | 117 +++++++++++++++++++++++++++++++++++++++++++-------- src/Mobs/Path.h | 17 +++++--- 3 files changed, 114 insertions(+), 26 deletions(-) diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index f5d961096..1da4124ed 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -169,7 +169,7 @@ bool cMonster::TickPathFinding(cChunk & a_Chunk) m_NoPathToTarget = false; m_NoMoreWayPoints = false; m_PathFinderDestination = m_FinalDestination; - m_Path = new cPath(a_Chunk, GetPosition().Floor(), m_PathFinderDestination.Floor(), 20); + m_Path = new cPath(a_Chunk, GetPosition(), m_PathFinderDestination, 20, GetWidth(), GetHeight()); } switch (m_Path->Step(a_Chunk)) @@ -183,7 +183,7 @@ bool cMonster::TickPathFinding(cChunk & a_Chunk) case ePathFinderStatus::PATH_NOT_FOUND: { - ResetPathFinding(); // Try to calculate a path again. + StopMovingToPosition(); // Try to calculate a path again. // Note that the next time may succeed, e.g. if a player breaks a barrier. break; } @@ -203,7 +203,7 @@ bool cMonster::TickPathFinding(cChunk & a_Chunk) { if ((m_Path->IsFirstPoint() || ReachedNextWaypoint())) { - m_NextWayPointPosition = Vector3d(0.5, 0, 0.5) + m_Path->GetNextPoint(); + m_NextWayPointPosition = m_Path->GetNextPoint(); m_GiveUpCounter = 40; // Give up after 40 ticks (2 seconds) if failed to reach m_NextWayPointPosition. } } diff --git a/src/Mobs/Path.cpp b/src/Mobs/Path.cpp index eba29be7e..6f3d43305 100644 --- a/src/Mobs/Path.cpp +++ b/src/Mobs/Path.cpp @@ -6,6 +6,7 @@ #include "Path.h" #include "../Chunk.h" +#define JUMP_G_COST 20 #define DISTANCE_MANHATTAN 0 // 1: More speed, a bit less accuracy 0: Max accuracy, less speed. #define HEURISTICS_ONLY 0 // 1: Much more speed, much less accurate. @@ -31,12 +32,11 @@ bool compareHeuristics::operator()(cPathCell * & a_Cell1, cPathCell * & a_Cell2) /* cPath implementation */ cPath::cPath( cChunk & a_Chunk, - const Vector3i & a_StartingPoint, const Vector3i & a_EndingPoint, int a_MaxSteps, + const Vector3d & a_StartingPoint, const Vector3d & a_EndingPoint, int a_MaxSteps, double a_BoundingBoxWidth, double a_BoundingBoxHeight, int a_MaxUp, int a_MaxDown ) : - m_Destination(a_EndingPoint.Floor()), - m_Source(a_StartingPoint.Floor()), + m_CurrentPoint(0), // GetNextPoint increments this to 1, but that's fine, since the first cell is always a_StartingPoint m_Chunk(&a_Chunk), m_BadChunkFound(false) @@ -44,6 +44,21 @@ cPath::cPath( // TODO: if src not walkable OR dest not walkable, then abort. // Borrow a new "isWalkable" from ProcessIfWalkable, make ProcessIfWalkable also call isWalkable + a_BoundingBoxWidth = 1; // Until we improve physics, if ever. + + m_BoundingBoxWidth = ceil(a_BoundingBoxWidth); + m_BoundingBoxHeight = ceil(a_BoundingBoxHeight); + m_HalfWidth = a_BoundingBoxWidth / 2; + + int HalfWidthInt = a_BoundingBoxWidth / 2; + m_Source.x = floor(a_StartingPoint.x - HalfWidthInt); + m_Source.y = floor(a_StartingPoint.y); + m_Source.z = floor(a_StartingPoint.z - HalfWidthInt); + + m_Destination.x = floor(a_EndingPoint.x - HalfWidthInt); + m_Destination.y = floor(a_EndingPoint.y); + m_Destination.z = floor(a_EndingPoint.z - HalfWidthInt); + if (GetCell(m_Source)->m_IsSolid || GetCell(m_Destination)->m_IsSolid) { m_Status = ePathFinderStatus::PATH_NOT_FOUND; @@ -148,7 +163,7 @@ bool cPath::IsSolid(const Vector3i & a_Location) } if (BlockType == E_BLOCK_STATIONARY_WATER) { - GetCell(a_Location + Vector3i(0, -1, 0))->m_IsSolid = true; // Mobs will always think that the fence is 2 blocks high and therefore won't jump over. + GetCell(a_Location + Vector3i(0, -1, 0))->m_IsSolid = true; } return cBlockInfo::IsSolid(BlockType); @@ -179,7 +194,7 @@ bool cPath::Step_Internal() // Calculation not finished yet. // Check if we have a new NearestPoint. - + // TODO I don't like this that much, there should be a smarter way. if ((m_Destination - CurrentCell->m_Location).Length() < 5) { if (m_Rand.NextInt(4) == 0) @@ -193,21 +208,43 @@ bool cPath::Step_Internal() } // process a currentCell by inspecting all neighbors. - // Check North, South, East, West on all 3 different heights. - int i; - for (i = -1; i <= 1; ++i) + + // Check North, South, East, West on our height. + ProcessIfWalkable(CurrentCell->m_Location + Vector3i(1, 0, 0), CurrentCell, 10); + ProcessIfWalkable(CurrentCell->m_Location + Vector3i(-1, 0, 0), CurrentCell, 10); + ProcessIfWalkable(CurrentCell->m_Location + Vector3i(0, 0, 1), CurrentCell, 10); + ProcessIfWalkable(CurrentCell->m_Location + Vector3i(0, 0, -1), CurrentCell, 10); + + // Check diagonals on XY plane. + for (int x = -1; x <= 1; x += 2) { - ProcessIfWalkable(CurrentCell->m_Location + Vector3i(1, i, 0), CurrentCell, 10); - ProcessIfWalkable(CurrentCell->m_Location + Vector3i(-1, i, 0), CurrentCell, 10); - ProcessIfWalkable(CurrentCell->m_Location + Vector3i(0, i, 1), CurrentCell, 10); - ProcessIfWalkable(CurrentCell->m_Location + Vector3i(0, i, -1), CurrentCell, 10); + if (GetCell(CurrentCell->m_Location + Vector3i(x, 0, 0))->m_IsSolid) // If there's a solid our east / west. + { + ProcessIfWalkable(CurrentCell->m_Location + Vector3i(x, 1, 0), CurrentCell, JUMP_G_COST); // Check east / west-up. + } + else + { + ProcessIfWalkable(CurrentCell->m_Location + Vector3i(x, -1, 0), CurrentCell, 14); // Else check east / west-down. + } } - // Check diagonals on mob's height only. - int x, z; - for (x = -1; x <= 1; x += 2) + // Check diagonals on the YZ plane. + for (int z = -1; z <= 1; z += 2) { - for (z = -1; z <= 1; z += 2) + if (GetCell(CurrentCell->m_Location + Vector3i(0, 0, z))->m_IsSolid) // If there's a solid our east / west. + { + ProcessIfWalkable(CurrentCell->m_Location + Vector3i(0, 1, z), CurrentCell, JUMP_G_COST); // Check east / west-up. + } + else + { + ProcessIfWalkable(CurrentCell->m_Location + Vector3i(0, -1, z), CurrentCell, 14); // Else check east / west-down. + } + } + + // Check diagonals on the XZ plane. (Normal diagonals, this plane is special because of gravity, etc) + for (int x = -1; x <= 1; x += 2) + { + for (int z = -1; z <= 1; z += 2) { // This condition prevents diagonal corner cutting. if (!GetCell(CurrentCell->m_Location + Vector3i(x, 0, 0))->m_IsSolid && !GetCell(CurrentCell->m_Location + Vector3i(0, 0, z))->m_IsSolid) @@ -320,7 +357,53 @@ si::setBlock((Ret)->m_Location.x, (Ret)->m_Location.y, (Ret)->m_Location.z, debu void cPath::ProcessIfWalkable(const Vector3i & a_Location, cPathCell * a_Parent, int a_Cost) { cPathCell * cell = GetCell(a_Location); - if (!cell->m_IsSolid && GetCell(a_Location + Vector3i(0, -1, 0))->m_IsSolid && !GetCell(a_Location + Vector3i(0, 1, 0))->m_IsSolid) + int x, y, z; + + // Make sure we fit in the position. + for (y = 0; y < m_BoundingBoxHeight; ++y) + { + for (x = 0; x < m_BoundingBoxWidth; ++x) + { + for (z = 0; z < m_BoundingBoxWidth; ++z) + { + if (GetCell(a_Location + Vector3i(x, y, z))->m_IsSolid) + { + return; + } + } + } + } + + /*y =-1; + for (x = 0; x < m_BoundingBoxWidth; ++x) + { + for (z = 0; z < m_BoundingBoxWidth; ++z) + { + if (!GetCell(a_Location + Vector3i(x, y, z))->m_IsSolid) + { + return; + } + } + } + ProcessCell(cell, a_Parent, a_Cost);*/ + + // Make sure there's at least 1 piece of solid below us. + + bool GroundFlag = false; + y =-1; + for (x = 0; x < m_BoundingBoxWidth; ++x) + { + for (z = 0; z < m_BoundingBoxWidth; ++z) + { + if (GetCell(a_Location + Vector3i(x, y, z))->m_IsSolid) + { + GroundFlag = true; + break; + } + } + } + + if (GroundFlag) { ProcessCell(cell, a_Parent, a_Cost); } diff --git a/src/Mobs/Path.h b/src/Mobs/Path.h index b296bbdf5..3b9c0400e 100644 --- a/src/Mobs/Path.h +++ b/src/Mobs/Path.h @@ -68,8 +68,8 @@ public: @param a_MaxSteps The maximum steps before giving up. */ cPath( cChunk & a_Chunk, - const Vector3i & a_StartingPoint, const Vector3i & a_EndingPoint, int a_MaxSteps, - double a_BoundingBoxWidth = 1, double a_BoundingBoxHeight = 2, + const Vector3d & a_StartingPoint, const Vector3d & a_EndingPoint, int a_MaxSteps, + double a_BoundingBoxWidth, double a_BoundingBoxHeight, int a_MaxUp = 1, int a_MaxDown = 1 ); @@ -89,10 +89,11 @@ public: /* Point retrieval functions, inlined for performance. */ /** Returns the next point in the path. */ - inline Vector3i GetNextPoint() + inline Vector3d GetNextPoint() { ASSERT(m_Status == ePathFinderStatus::PATH_FOUND); - return m_PathPoints[m_PathPoints.size() - 1 - (++m_CurrentPoint)]; + Vector3i Point = m_PathPoints[m_PathPoints.size() - 1 - (++m_CurrentPoint)]; + return Vector3d(Point.x + m_HalfWidth, Point.y, Point.z + m_HalfWidth); } /** Checks whether this is the last point or not. Never call getnextPoint when this is true. */ inline bool IsLastPoint() @@ -106,11 +107,12 @@ public: return (m_CurrentPoint == 0); } /** Get the point at a_index. Remark: Internally, the indexes are reversed. */ - inline Vector3i GetPoint(size_t a_index) + inline Vector3d GetPoint(size_t a_index) { ASSERT(m_Status == ePathFinderStatus::PATH_FOUND); ASSERT(a_index < m_PathPoints.size()); - return m_PathPoints[m_PathPoints.size() - 1 - a_index]; + Vector3i Point = m_PathPoints[m_PathPoints.size() - 1 - a_index]; + return Vector3d(Point.x + m_HalfWidth, Point.y, Point.z + m_HalfWidth); } /** Returns the total number of points this path has. */ inline int GetPointCount() @@ -161,6 +163,9 @@ private: std::unordered_map m_Map; Vector3i m_Destination; Vector3i m_Source; + int m_BoundingBoxWidth; + int m_BoundingBoxHeight; + double m_HalfWidth; int m_StepsLeft; cPathCell * m_NearestPointToTarget; cFastRandom m_Rand; -- cgit v1.2.3 From 45012b72e7af975421fb40f9aa8ff5b9ffc30f5a Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Sun, 24 May 2015 07:28:17 +0100 Subject: Wolves don't spawn in rivers. --- src/Generating/FinishGen.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index e96d959f9..c988224e6 100644 --- a/src/Generating/FinishGen.cpp +++ b/src/Generating/FinishGen.cpp @@ -1259,7 +1259,7 @@ bool cFinishGenPassiveMobs::TrySpawnAnimals(cChunkDesc & a_ChunkDesc, int a_RelX } if ( (BlockUnderFeet != E_BLOCK_GRASS) && - ((AnimalToSpawn == mtRabbit) || (AnimalToSpawn == mtCow) || (AnimalToSpawn == mtSheep) || (AnimalToSpawn == mtChicken) || (AnimalToSpawn == mtPig)) + ((AnimalToSpawn == mtWolf) || (AnimalToSpawn == mtRabbit) || (AnimalToSpawn == mtCow) || (AnimalToSpawn == mtSheep) || (AnimalToSpawn == mtChicken) || (AnimalToSpawn == mtPig)) ) { return false; -- cgit v1.2.3 From 885ebab7e62a8850a38815ce9b5e3fb1e8bcce0a Mon Sep 17 00:00:00 2001 From: Lukas Pioch Date: Sun, 24 May 2015 10:02:44 +0200 Subject: Fixed item name --- MCServer/items.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCServer/items.ini b/MCServer/items.ini index daf366654..5eb04619c 100644 --- a/MCServer/items.ini +++ b/MCServer/items.ini @@ -815,7 +815,7 @@ rawrabbit=411 cookedrabbit=412 rabbitstew=413 rabbitsoup=413 -rabbitsfood=414 +rabbitsfoot=414 rabbithide=415 armorstand=416 ironhorsearmor=417 -- cgit v1.2.3 From 1f18a0c8af31a0f2278d2ffec5905ba71bf161fd Mon Sep 17 00:00:00 2001 From: Lukas Pioch Date: Sun, 24 May 2015 10:11:51 +0200 Subject: Add Seadragon91 to contributors --- CONTRIBUTORS | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 9cc7f19fc..6f1d7878f 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -24,6 +24,7 @@ p-mcgowan rs2k SafwatHalaby (Safwat Halaby) SamJBarney +Seadragon91 (Lukas Pioch) Sofapriester SphinxC0re STR_Warrior -- cgit v1.2.3 From ae55723c3c8b564d96288c0b06b5de5ec9c1010c Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Sun, 24 May 2015 09:28:28 +0100 Subject: Update CONTRIBUTORS --- CONTRIBUTORS | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 6f1d7878f..1e73fb699 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -27,7 +27,7 @@ SamJBarney Seadragon91 (Lukas Pioch) Sofapriester SphinxC0re -STR_Warrior +NiLSPACE (formerly STR_Warrior) structinf (xdot) Sxw1212 Taugeshtu @@ -36,7 +36,7 @@ tonibm19 UltraCoderRU WebFreak001 worktycho -xoft +xoft (Mattes Dolak/madmaxoft on GH) Yeeeeezus (Donated AlchemistVillage prefabs) Please add yourself to this list if you contribute to MCServer. -- cgit v1.2.3 From 9a6fb60c8501da201cc5d2b45c1d1fad8de8af6c Mon Sep 17 00:00:00 2001 From: SafwatHalaby Date: Sun, 24 May 2015 12:30:22 +0300 Subject: Easy compile script --- README.md | 6 +- compile.sh | 199 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 204 insertions(+), 1 deletion(-) create mode 100755 compile.sh diff --git a/README.md b/README.md index 43ec942d5..8731b0896 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,11 @@ For Windows, you just need to download a file and extract it: - [Windows 32 bit](http://builds.cuberite.org/job/MCServer%20Windows%20x86/lastSuccessfulBuild/artifact/Install/MCServer.zip) - [Windows 64 bit](http://builds.cuberite.org/job/MCServer%20Windows%20x64/lastSuccessfulBuild/artifact/Install/MCServer.zip) -For other operating systems you need to download and compile yourself. There is also an archive of binary builds on the buildserver: http://builds.cuberite.org +For other operating systems you need to download and compile yourself. This can be done either manually, or with this automatic script: + + bash -c "$(wget -O - https://raw.githubusercontent.com/mc-server/MCServer/master/compile.sh)" + +There is also an archive of binary builds on the buildserver: http://builds.cuberite.org Compiling the server yourself has other benefits: you may get better performance performance (1.5-3x as fast) and it supports more operating systems. See the [COMPILING.md](https://github.com/mc-server/MCServer/blob/master/COMPILING.md) file for more details. diff --git a/compile.sh b/compile.sh new file mode 100755 index 000000000..329d79d81 --- /dev/null +++ b/compile.sh @@ -0,0 +1,199 @@ +#|| goto :windows_detected + +# Do we already have a repo? +if [[ -d .git && -f easyinstall.sh && -f MakeLuaAPI.cmd ]]; then # A good enough indicator that we're in the MCServer git repo. +cd ../ +echo "MCServer repository detected. This should make the process faster, especially if you compiled before." +fi + +# Error functions. +function error +{ + echo + echo "-----------------" + echo "Script aborted, reason:" + echo $1 + exit -1 +} + +function missingDepsExit +{ + echo + echo "Please install the dependencies, then come back." + echo + exit -2 +} + + +# Echo: Greetings. +echo +echo "Hello, this script will download and compile Cuberite/MCServer." +echo "On subsequent runs, it will update your MCServer." +echo "The compilation and download will occur in the current directory." +echo "If you're updating, you should run /MCServer/compile.sh" +echo "Compiling from source takes time, but it usually generates better executables." +echo "If you prefer ready-to-use binaries or if you want more info, please visit:" +echo "http://cuberite.org/" +echo "http://mc-server.org/" + +MISSING_PROGRAMS="" + +# Compiler check. +GCC_EXISTS=0 +CLANG_EXISTS=0 +g++ --help > /dev/null 2> /dev/null && GCC_EXISTS=1 +clang --help > /dev/null 2> /dev/null && CLANG_EXISTS=1 +if [[ $GCC_EXISTS == 0 && $CLANG_EXISTS == 0 ]]; then +MISSING_PROGRAMS="gcc g++" +fi + +# Depdendency check. +while read program; do +$program --help > /dev/null 2> /dev/null || MISSING_PROGRAMS="$MISSING_PROGRAMS $program" +done <<"EOF" +git +make +cmake +EOF +if [[ $MISSING_PROGRAMS != "" ]]; then + echo + echo "-----------------" + echo "You have missing compilation dependencies:" + echo $MISSING_PROGRAMS + echo + + # apt-get guide. + apt-get --help > /dev/null 2> /dev/null && \ + echo "You can install the missing depndencies via:" && \ + echo -n "sudo apt-get install " && echo $MISSING_PROGRAMS && missingDepsExit + + # yum guide. + yum --help > /dev/null 2> /dev/null && \ + echo "You can install the missing depndencies via:" && \ + echo -n "sudo yum install " && echo $MISSING_PROGRAMS && missingDepsExit + + # rpm guide. + rpm --help > /dev/null 2> /dev/null && \ + echo "You can install the missing depndencies via:" && \ + echo -n "sudo rpm -i " && echo $MISSING_PROGRAMS && missingDepsExit + + # pacman guide. + pacman --help > /dev/null 2> /dev/null && \ + echo "You can install the missing depndencies via:" && \ + echo -n "sudo pacman -S " && echo $MISSING_PROGRAMS && missingDepsExit + + missingDepsExit +fi + +exit +# Echo: Branch choice. +echo +echo "You can choose between 2 branches:" +echo "* (S)Stable: (Coming soon) Choose the stable branch if you want the most reliable server." +echo " As of now, Stable is not yet available, please use testing instead." +echo +echo "* (T)Testing: The testing branch is less stable," +echo " but using it and finding and reporting bugs helps us a lot!" +echo +echo "* (D)Dev: The least stable of the three. (Master branch)" +echo " Choose the development branch if you are feeling adventurous and" +echo " want to try new, bleeding edge features." +echo + + +# Input: Branch choice. +echo -n "Choose the branch (s/t/d): " +read BRANCH +if [[ ($BRANCH == "s") || ($BRANCH == "S" ) ]]; then + #BRANCH="stable" + error "We don't have a stable branch yet, please use testing, sorry." +elif [[ ($BRANCH == "t") || ($BRANCH == "T" ) ]]; then + BRANCH="testing" +elif [[ ($BRANCH == "d") || ($BRANCH == "D" ) ]]; then + BRANCH="master" +else + error "Unrecognized user input." +fi + +# Echo: Compile mode choice. +echo +echo "Choose compile mode:" +echo "* (N)Normal: Compiles normally." +echo +echo "* (D)Debug: Compiles in debug mode. Makes your console and crashes much more verbose." +echo " But it costs performance." +echo +echo "Note that the script will connect to the internet in order to fetch code after this step." +echo "It will then compile your program." +echo + +# Input: Compile mode choice. +echo -n "Choose compile mode: (n/d): " +read BUILDTYPE +if [[ ($BUILDTYPE == "d") || ($BUILDTYPE == "D") ]]; then + BUILDTYPE="Debug" +elif [[ ($BUILDTYPE == "n") || ($BUILDTYPE == "N") ]]; then + BUILDTYPE="Release" +else + error "Unrecognized user input." +fi + + +# Echo: Downloading began. +echo +echo " --- Downloading MCServer's source code from the $BRANCH branch..." + + +# Git: Clone. +if [ ! -d MCServer ]; then + echo " --- Looks like your first run, cloning the whole code..." + git clone https://github.com/mc-server/MCServer.git +fi + + +# Git: Fetch. +pushd MCServer +echo " --- Updating the $BRANCH branch..." +git fetch origin $BRANCH || error "git fetch failed" +git checkout $BRANCH || error "git checkout failed" +git merge origin/$BRANCH || error "git merge failed" + + +# Git: Submodules. +echo " --- Updating submodules..." +git submodule init +git submodule update + + +# Cmake. +echo " --- Running cmake..." +popd +if [ ! -d build-mcserver ]; then mkdir build-mcserver; fi +pushd build-mcserver +cmake ../MCServer/ -DCMAKE_BUILD_TYPE=$BUILDTYPE || error "cmake failed" + + +# Make. +echo " --- Compiling..." +make -j`nproc` || error "Compiling failed" +echo + + +# Echo: Compilation complete. +popd +pushd MCServer/MCServer +echo +echo "-----------------" +echo "Compilation done!" +echo +echo "Cuberite awaits you at:" +echo "`pwd`/MCServer" +echo +echo "Enjoy :)" +popd +exit 0 + +:windows_detected +echo "This script is not available for Windows yet, sorry." +echo "You can still download the Windows binaries from: http://mc-server.org" + -- cgit v1.2.3 From dae9e5792a4f030ae9e748548a16a89790fbd311 Mon Sep 17 00:00:00 2001 From: tycho Date: Sun, 24 May 2015 12:56:56 +0100 Subject: Made -Weverything an error. --- SetFlags.cmake | 2 +- src/Bindings/CMakeLists.txt | 5 +++++ src/Bindings/LuaChunkStay.cpp | 6 ++--- src/Bindings/LuaState.h | 2 +- src/BiomeDef.cpp | 4 ++-- src/BlockArea.cpp | 8 +++---- src/BlockArea.h | 2 +- src/BlockEntities/BeaconEntity.cpp | 6 ++--- src/BlockEntities/MobSpawnerEntity.cpp | 13 +++++++---- src/BlockEntities/NoteEntity.cpp | 9 ++++++-- src/BlockID.cpp | 38 ++++++++++++++++++-------------- src/BlockInfo.cpp | 2 +- src/Blocks/BlockBed.h | 2 +- src/Blocks/BlockDoor.h | 6 ++--- src/Blocks/BlockSlab.h | 4 ++-- src/Blocks/CMakeLists.txt | 4 ++++ src/CMakeLists.txt | 25 ++++++++++++--------- src/ChunkSender.cpp | 2 +- src/CompositeChat.cpp | 10 ++++----- src/CraftingRecipes.cpp | 4 ++-- src/Entities/CMakeLists.txt | 9 ++++---- src/Entities/EnderCrystal.cpp | 2 +- src/Entities/Entity.h | 4 ++-- src/Entities/ExpOrb.cpp | 4 ++-- src/Entities/FallingBlock.cpp | 2 +- src/Entities/FireChargeEntity.cpp | 10 ++++----- src/Entities/FireChargeEntity.h | 2 +- src/Entities/GhastFireballEntity.cpp | 8 +++---- src/Entities/GhastFireballEntity.h | 2 +- src/Entities/ItemFrame.cpp | 6 ++--- src/Entities/Minecart.cpp | 12 +++++----- src/Entities/Painting.cpp | 2 +- src/Entities/Pawn.cpp | 2 +- src/Entities/Pickup.cpp | 6 ++--- src/Entities/ProjectileEntity.cpp | 6 ++--- src/Entities/SplashPotionEntity.cpp | 11 ++++++--- src/Entities/ThrownSnowballEntity.cpp | 2 +- src/FurnaceRecipe.cpp | 6 ++--- src/Generating/CMakeLists.txt | 20 ++++++++++++----- src/Generating/ChunkDesc.h | 4 ++-- src/Generating/DungeonRoomsFinisher.cpp | 4 ++-- src/Generating/FinishGen.cpp | 14 ++++++------ src/Generating/GridStructGen.cpp | 4 ++-- src/Generating/MineShafts.cpp | 8 +++---- src/Generating/NetherFortGen.cpp | 4 ++-- src/Generating/POCPieceGenerator.cpp | 4 ++-- src/Generating/PieceGenerator.cpp | 4 ++-- src/Generating/Prefab.cpp | 10 ++++----- src/Generating/PrefabPiecePool.cpp | 6 ++--- src/Generating/RainbowRoadsGen.cpp | 2 +- src/Generating/TestRailsGen.cpp | 2 +- src/Generating/Trees.cpp | 4 ++-- src/Generating/UnderwaterBaseGen.cpp | 2 +- src/Generating/VillageGen.cpp | 8 +++---- src/HTTPServer/CMakeLists.txt | 2 +- src/HTTPServer/HTTPConnection.cpp | 2 +- src/HTTPServer/SslHTTPConnection.cpp | 2 +- src/IniFile.cpp | 2 +- src/IniFile.h | 4 ++-- src/ItemGrid.cpp | 2 +- src/Items/CMakeLists.txt | 2 +- src/Items/ItemBow.h | 11 +++++++-- src/Items/ItemBucket.h | 2 +- src/LightingThread.cpp | 6 ++--- src/LineBlockTracer.cpp | 12 +++++----- src/LoggerListeners.cpp | 6 ++++- src/MapManager.cpp | 4 ++-- src/Matrix4.h | 8 +++---- src/MobCensus.cpp | 2 +- src/MobFamilyCollecter.cpp | 2 +- src/MobSpawner.cpp | 2 +- src/Mobs/AggressiveMonster.cpp | 8 +++---- src/Mobs/CMakeLists.txt | 4 +++- src/Mobs/CaveSpider.cpp | 2 +- src/Mobs/Creeper.cpp | 4 ++-- src/Mobs/Enderman.cpp | 2 +- src/Mobs/Guardian.cpp | 6 ++--- src/Mobs/Horse.cpp | 8 +++---- src/Mobs/PassiveAggressiveMonster.cpp | 2 +- src/Mobs/PassiveMonster.cpp | 2 +- src/Mobs/Path.h | 8 +++---- src/Mobs/Squid.cpp | 6 ++--- src/Mobs/Wolf.cpp | 4 ++-- src/MonsterConfig.cpp | 4 ++-- src/Noise/CMakeLists.txt | 4 ++++ src/Noise/Noise.h | 11 ++++----- src/OSSupport/CMakeLists.txt | 2 +- src/OSSupport/GZipFile.h | 2 +- src/PolarSSL++/BufferedSslContext.cpp | 6 ++--- src/PolarSSL++/CMakeLists.txt | 4 ++++ src/PolarSSL++/CryptoKey.cpp | 12 +++++----- src/PolarSSL++/CtrDrbgContext.cpp | 2 +- src/PolarSSL++/SslContext.cpp | 4 ++-- src/PolarSSL++/SslContext.h | 4 ++-- src/PolarSSL++/X509Cert.cpp | 2 +- src/Protocol/CMakeLists.txt | 8 +++++-- src/Scoreboard.cpp | 10 ++++----- src/Simulator/CMakeLists.txt | 2 +- src/Simulator/DelayedFluidSimulator.cpp | 6 ++--- src/Simulator/FloodyFluidSimulator.cpp | 14 ++++++++++-- src/Simulator/SandSimulator.cpp | 10 ++++++--- src/Simulator/VaporizeFluidSimulator.cpp | 7 +++++- src/Statistics.cpp | 2 +- src/UI/CMakeLists.txt | 5 +++-- src/UI/EnchantingWindow.cpp | 6 ++--- src/UI/EnderChestWindow.cpp | 14 ++++++++++-- src/WebAdmin.cpp | 6 ++--- src/World.h | 2 +- src/WorldStorage/CMakeLists.txt | 14 +++++++----- src/WorldStorage/StatSerializer.cpp | 6 ++--- 110 files changed, 376 insertions(+), 270 deletions(-) diff --git a/SetFlags.cmake b/SetFlags.cmake index 2de86090d..c20a45133 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -248,7 +248,7 @@ macro(set_exe_flags) endif() # clang does not provide the __extern_always_inline macro and a part of libm depends on this when using fast-math add_flags_cxx("-D__extern_always_inline=inline") - add_flags_cxx("-Werror -Weverything -Wno-c++98-compat-pedantic -Wno-string-conversion") + add_flags_cxx("-Weverything -Werror -Wno-c++98-compat-pedantic -Wno-string-conversion") add_flags_cxx("-Wno-exit-time-destructors -Wno-padded -Wno-weak-vtables") if ("${CLANG_VERSION}" VERSION_GREATER 3.0) # flags that are not present in 3.0 diff --git a/src/Bindings/CMakeLists.txt b/src/Bindings/CMakeLists.txt index e1ded8446..b14576ea0 100644 --- a/src/Bindings/CMakeLists.txt +++ b/src/Bindings/CMakeLists.txt @@ -146,7 +146,12 @@ set_source_files_properties(${BINDING_OUTPUTS} PROPERTIES GENERATED TRUE) set_source_files_properties(${CMAKE_SOURCE_DIR}/src/Bindings/Bindings.cpp PROPERTIES COMPILE_FLAGS -Wno-error) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set_source_files_properties(DeprecatedBindings.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") + set_source_files_properties(LuaState.cpp COMPILE_FLAGS "-Wno-error=old-style-cast") set_source_files_properties(LuaWindow.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum") + set_source_files_properties(ManualBindings.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") + set_source_files_properties(ManualBindings_World.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") + set_source_files_properties(PluginLua.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") endif() if(NOT MSVC) diff --git a/src/Bindings/LuaChunkStay.cpp b/src/Bindings/LuaChunkStay.cpp index e50ffb75b..1afd09d11 100644 --- a/src/Bindings/LuaChunkStay.cpp +++ b/src/Bindings/LuaChunkStay.cpp @@ -41,7 +41,7 @@ bool cLuaChunkStay::AddChunks(int a_ChunkCoordTableStackPos) // Add each set of coords: int NumChunks = luaL_getn(L, a_ChunkCoordTableStackPos); - m_Chunks.reserve((size_t)NumChunks); + m_Chunks.reserve(static_cast(NumChunks)); for (int idx = 1; idx <= NumChunks; idx++) { // Push the idx-th element of the array onto stack top, check that it's a table: @@ -133,7 +133,7 @@ void cLuaChunkStay::OnChunkAvailable(int a_ChunkX, int a_ChunkZ) if (m_OnChunkAvailable.IsValid()) { cPluginLua::cOperation Op(m_Plugin); - Op().Call((int)m_OnChunkAvailable, a_ChunkX, a_ChunkZ); + Op().Call(static_cast(m_OnChunkAvailable), a_ChunkX, a_ChunkZ); } } @@ -147,7 +147,7 @@ bool cLuaChunkStay::OnAllChunksAvailable(void) { // Call the callback: cPluginLua::cOperation Op(m_Plugin); - Op().Call((int)m_OnAllChunksAvailable); + Op().Call(static_cast(m_OnAllChunksAvailable)); // Remove the callback references - they won't be needed anymore m_OnChunkAvailable.UnRef(); diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index bbd0294ef..8a3411d30 100644 --- a/src/Bindings/LuaState.h +++ b/src/Bindings/LuaState.h @@ -393,7 +393,7 @@ protected: */ bool PushFunction(const cRef & a_FnRef) { - return PushFunction((int)a_FnRef); + return PushFunction(static_cast(a_FnRef)); } /** Pushes a function that is stored in a referenced table by name diff --git a/src/BiomeDef.cpp b/src/BiomeDef.cpp index a2a06f10c..9dbdf05a2 100644 --- a/src/BiomeDef.cpp +++ b/src/BiomeDef.cpp @@ -98,11 +98,11 @@ EMCSBiome StringToBiome(const AString & a_BiomeString) { if ((res >= biFirstBiome) && (res < biNumBiomes)) { - return (EMCSBiome)res; + return static_cast(res); } else if ((res >= biFirstVariantBiome) && (res < biNumVariantBiomes)) { - return (EMCSBiome)res; + return static_cast(res); } // It was an invalid number return biInvalidBiome; diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp index 89cf18d4a..7982afc31 100644 --- a/src/BlockArea.cpp +++ b/src/BlockArea.cpp @@ -60,7 +60,7 @@ void InternalMergeBlocks( else { NIBBLETYPE FakeDestMeta = 0; - Combinator(a_DstTypes[DstIdx], a_SrcTypes[SrcIdx], FakeDestMeta, (NIBBLETYPE)0); + Combinator(a_DstTypes[DstIdx], a_SrcTypes[SrcIdx], FakeDestMeta, static_cast(0)); } ++DstIdx; ++SrcIdx; @@ -620,7 +620,7 @@ void cBlockArea::DumpToRawFile(const AString & a_FileName) f.Write(&SizeX, 4); f.Write(&SizeY, 4); f.Write(&SizeZ, 4); - unsigned char DataTypes = (unsigned char)GetDataTypes(); + unsigned char DataTypes = static_cast(GetDataTypes()); f.Write(&DataTypes, 1); size_t NumBlocks = GetBlockCount(); if (HasBlockTypes()) @@ -2157,7 +2157,7 @@ void cBlockArea::ExpandBlockTypes(int a_SubMinX, int a_AddMaxX, int a_SubMinY, i int NewSizeX = m_Size.x + a_SubMinX + a_AddMaxX; int NewSizeY = m_Size.y + a_SubMinY + a_AddMaxY; int NewSizeZ = m_Size.z + a_SubMinZ + a_AddMaxZ; - size_t BlockCount = (size_t)(NewSizeX * NewSizeY * NewSizeZ); + size_t BlockCount = static_cast(NewSizeX * NewSizeY * NewSizeZ); BLOCKTYPE * NewBlockTypes = new BLOCKTYPE[BlockCount]; memset(NewBlockTypes, 0, BlockCount * sizeof(BLOCKTYPE)); int OldIndex = 0; @@ -2187,7 +2187,7 @@ void cBlockArea::ExpandNibbles(NIBBLEARRAY & a_Array, int a_SubMinX, int a_AddMa int NewSizeX = m_Size.x + a_SubMinX + a_AddMaxX; int NewSizeY = m_Size.y + a_SubMinY + a_AddMaxY; int NewSizeZ = m_Size.z + a_SubMinZ + a_AddMaxZ; - size_t BlockCount = (size_t)(NewSizeX * NewSizeY * NewSizeZ); + size_t BlockCount = static_cast(NewSizeX * NewSizeY * NewSizeZ); NIBBLETYPE * NewNibbles = new NIBBLETYPE[BlockCount]; memset(NewNibbles, 0, BlockCount * sizeof(NIBBLETYPE)); int OldIndex = 0; diff --git a/src/BlockArea.h b/src/BlockArea.h index 856df542f..4b672029b 100644 --- a/src/BlockArea.h +++ b/src/BlockArea.h @@ -321,7 +321,7 @@ public: NIBBLETYPE * GetBlockMetas (void) const { return m_BlockMetas; } // NOTE: one byte per block! NIBBLETYPE * GetBlockLight (void) const { return m_BlockLight; } // NOTE: one byte per block! NIBBLETYPE * GetBlockSkyLight(void) const { return m_BlockSkyLight; } // NOTE: one byte per block! - size_t GetBlockCount(void) const { return (size_t)(m_Size.x * m_Size.y * m_Size.z); } + size_t GetBlockCount(void) const { return static_cast(m_Size.x * m_Size.y * m_Size.z); } int MakeIndex(int a_RelX, int a_RelY, int a_RelZ) const; protected: diff --git a/src/BlockEntities/BeaconEntity.cpp b/src/BlockEntities/BeaconEntity.cpp index fb3940ce9..a945c6ea9 100644 --- a/src/BlockEntities/BeaconEntity.cpp +++ b/src/BlockEntities/BeaconEntity.cpp @@ -77,7 +77,7 @@ bool cBeaconEntity::IsValidEffect(cEntityEffect::eType a_Effect, char a_BeaconLe default: { - LOGD("%s: Invalid beacon effect: %d", __FUNCTION__, (int)a_Effect); + LOGD("%s: Invalid beacon effect: %d", __FUNCTION__, static_cast(a_Effect)); return false; } } @@ -228,9 +228,9 @@ void cBeaconEntity::GiveEffects(void) virtual bool Item(cPlayer * a_Player) { Vector3d PlayerPosition = Vector3d(a_Player->GetPosition()); - if (PlayerPosition.y > (double)m_PosY) + if (PlayerPosition.y > static_cast(m_PosY)) { - PlayerPosition.y = (double)m_PosY; + PlayerPosition.y = static_cast(m_PosY); } // TODO: Vanilla minecraft uses an AABB check instead of a radius one diff --git a/src/BlockEntities/MobSpawnerEntity.cpp b/src/BlockEntities/MobSpawnerEntity.cpp index f8222822c..4746bdd1b 100644 --- a/src/BlockEntities/MobSpawnerEntity.cpp +++ b/src/BlockEntities/MobSpawnerEntity.cpp @@ -145,9 +145,9 @@ void cMobSpawnerEntity::SpawnEntity(void) break; } - int RelX = (int) (m_RelX + (double)(Random.NextFloat() - Random.NextFloat()) * 4.0); + int RelX = static_cast(m_RelX + static_cast(Random.NextFloat() - Random.NextFloat()) * 4.0); int RelY = m_RelY + Random.NextInt(3) - 1; - int RelZ = (int) (m_RelZ + (double)(Random.NextFloat() - Random.NextFloat()) * 4.0); + int RelZ = static_cast(m_RelZ + static_cast(Random.NextFloat() - Random.NextFloat()) * 4.0); cChunk * Chunk = a_Chunk->GetRelNeighborChunkAdjustCoords(RelX, RelZ); if ((Chunk == nullptr) || !Chunk->IsValid()) @@ -172,7 +172,12 @@ void cMobSpawnerEntity::SpawnEntity(void) if (Chunk->GetWorld()->SpawnMobFinalize(Monster) != cEntity::INVALID_ID) { EntitiesSpawned = true; - Chunk->BroadcastSoundParticleEffect(2004, (int)(PosX * 8.0), (int)(RelY * 8.0), (int)(PosZ * 8.0), 0); + Chunk->BroadcastSoundParticleEffect( + 2004, + static_cast(PosX * 8.0), + static_cast(RelY * 8.0), + static_cast(PosZ * 8.0), + 0); m_NearbyEntitiesNum++; } } @@ -260,7 +265,7 @@ int cMobSpawnerEntity::GetNearbyMonsterNum(eMonsterType a_EntityType) return; } - cMonster * Mob = (cMonster *)a_Entity; + cMonster * Mob = static_cast(a_Entity); if (Mob->GetMobType() != m_EntityType) { return; diff --git a/src/BlockEntities/NoteEntity.cpp b/src/BlockEntities/NoteEntity.cpp index a9af13c55..48ca15d1f 100644 --- a/src/BlockEntities/NoteEntity.cpp +++ b/src/BlockEntities/NoteEntity.cpp @@ -90,8 +90,13 @@ void cNoteEntity::MakeSound(void) m_World->BroadcastBlockAction(m_PosX, m_PosY, m_PosZ, instrument, m_Pitch, E_BLOCK_NOTE_BLOCK); // TODO: instead of calculating the power function over and over, make a precalculated table - there's only 24 pitches after all - float calcPitch = pow(2.0f, ((float)m_Pitch - 12.0f) / 12.0f); - m_World->BroadcastSoundEffect(sampleName, (double)m_PosX, (double)m_PosY, (double)m_PosZ, 3.0f, calcPitch); + float calcPitch = pow(2.0f, static_cast(m_Pitch - 12.0f) / 12.0f); + m_World->BroadcastSoundEffect( + sampleName, + static_cast(m_PosX), + static_cast(m_PosY), + static_cast(m_PosZ), + 3.0f, calcPitch); } diff --git a/src/BlockID.cpp b/src/BlockID.cpp index 7f0db3cfc..775d60a68 100644 --- a/src/BlockID.cpp +++ b/src/BlockID.cpp @@ -96,8 +96,7 @@ public: else { // Not a resolvable string, try pure numbers: "45:6", "45^6" etc. - a_Item.m_ItemType = (short)atoi(Split[0].c_str()); - if ((a_Item.m_ItemType == 0) && (Split[0] != "0")) + if (!StringToInteger(Split[0], a_Item.m_ItemType)) { // Parsing the number failed return false; @@ -111,9 +110,8 @@ public: a_Item.m_ItemCount = 1; return true; } - - a_Item.m_ItemDamage = (short)atoi(Split[1].c_str()); - if ((a_Item.m_ItemDamage == 0) && (Split[1] != "0")) + + if (!StringToInteger(Split[1], a_Item.m_ItemDamage)) { // Parsing the number failed return false; @@ -175,8 +173,16 @@ protected: { return; } - short ItemType = (short)atoi(Split[0].c_str()); - short ItemDamage = (Split.size() > 1) ? (short)atoi(Split[1].c_str()) : -1; + short ItemType; + if (!StringToInteger(Split[0], ItemType)) + { + ASSERT(!"Invalid item type"); + } + short ItemDamage = -1; + if (Split.size() > 1 && !StringToInteger(Split[1], ItemDamage)) + { + ASSERT(!"Invalid item damage"); + } m_Map[a_Name] = std::make_pair(ItemType, ItemDamage); } } ; @@ -288,11 +294,11 @@ AString ItemToFullString(const cItem & a_Item) eDimension StringToDimension(const AString & a_DimensionString) { // First try decoding as a number - int res = atoi(a_DimensionString.c_str()); - if ((res != 0) || (a_DimensionString == "0")) + int res; + if (!StringToInteger(a_DimensionString, res)) { // It was a valid number - return (eDimension)res; + return static_cast(res); } // Decode using a built-in map: @@ -350,7 +356,7 @@ AString DimensionToString(eDimension a_Dimension) } // for i - DimensionMap[] // Not found - LOGWARNING("Unknown dimension: \"%i\". Setting to Overworld", (int)a_Dimension); + LOGWARNING("Unknown dimension: \"%i\". Setting to Overworld", static_cast(a_Dimension)); return "Overworld"; } @@ -386,7 +392,7 @@ AString DamageTypeToString(eDamageType a_DamageType) // Unknown damage type: ASSERT(!"Unknown DamageType"); - return Printf("dtUnknown_%d", (int)a_DamageType); + return Printf("dtUnknown_%d", static_cast(a_DamageType)); } @@ -397,11 +403,11 @@ AString DamageTypeToString(eDamageType a_DamageType) eDamageType StringToDamageType(const AString & a_DamageTypeString) { // First try decoding as a number: - int res = atoi(a_DamageTypeString.c_str()); - if ((res != 0) || (a_DamageTypeString == "0")) + int res; + if (!StringToInteger(a_DamageTypeString, res)) { // It was a valid number - return (eDamageType)res; + return static_cast(res); } // Decode using a built-in map: @@ -462,7 +468,7 @@ eDamageType StringToDamageType(const AString & a_DamageTypeString) } // for i - DamageTypeMap[] // Not found: - return (eDamageType)-1; + return static_cast(-1); } diff --git a/src/BlockInfo.cpp b/src/BlockInfo.cpp index 3c5e8d7b7..04d214b01 100644 --- a/src/BlockInfo.cpp +++ b/src/BlockInfo.cpp @@ -19,7 +19,7 @@ void cBlockInfo::Initialize(cBlockInfoArray & a_Info) { if (a_Info[i].m_Handler == nullptr) { - a_Info[i].m_Handler = cBlockHandler::CreateBlockHandler((BLOCKTYPE) i); + a_Info[i].m_Handler = cBlockHandler::CreateBlockHandler(static_cast(i)); } } diff --git a/src/Blocks/BlockBed.h b/src/Blocks/BlockBed.h index 46f361686..57ffebfca 100644 --- a/src/Blocks/BlockBed.h +++ b/src/Blocks/BlockBed.h @@ -53,7 +53,7 @@ public: a_Rotation = (a_Rotation / 360) * 4; - return ((char)a_Rotation + 2) % 4; + return (static_cast(a_Rotation + 2)) % 4; } static Vector3i MetaDataToDirection(NIBBLETYPE a_MetaData) diff --git a/src/Blocks/BlockDoor.h b/src/Blocks/BlockDoor.h index 445383e7c..9332e6728 100644 --- a/src/Blocks/BlockDoor.h +++ b/src/Blocks/BlockDoor.h @@ -245,10 +245,10 @@ public: if (a_BlockX > 0) { NIBBLETYPE DownMeta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY - 1, a_BlockZ); - return (NIBBLETYPE) ((DownMeta & 0x07) | 0x08 | (Meta << 4)); + return static_cast((DownMeta & 0x07) | 0x08 | (Meta << 4)); } // This is the top part of the door at the bottommost layer of the world, there's no bottom: - return (NIBBLETYPE) (0x08 | (Meta << 4)); + return static_cast(0x08 | (Meta << 4)); } else { @@ -256,7 +256,7 @@ public: if (a_BlockY < cChunkDef::Height - 1) { NIBBLETYPE UpMeta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY + 1, a_BlockZ); - return (NIBBLETYPE) (Meta | (UpMeta << 4)); + return static_cast(Meta | (UpMeta << 4)); } // This is the bottom part of the door at the topmost layer of the world, there's no top: return Meta; diff --git a/src/Blocks/BlockSlab.h b/src/Blocks/BlockSlab.h index d762154df..9b3fad72e 100644 --- a/src/Blocks/BlockSlab.h +++ b/src/Blocks/BlockSlab.h @@ -41,7 +41,7 @@ public: ) override { a_BlockType = m_BlockType; - NIBBLETYPE Meta = (NIBBLETYPE) a_Player->GetEquippedItem().m_ItemDamage; + NIBBLETYPE Meta = static_cast(a_Player->GetEquippedItem().m_ItemDamage); // Set the correct metadata based on player equipped item (i.e. a_BlockMeta not initialised yet) switch (a_BlockFace) @@ -104,7 +104,7 @@ public: virtual void OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override { - if ((a_BlockFace == BLOCK_FACE_NONE) || (a_Player->GetEquippedItem().m_ItemType != (short)m_BlockType)) + if ((a_BlockFace == BLOCK_FACE_NONE) || (a_Player->GetEquippedItem().m_ItemType != static_cast(m_BlockType))) { return; } diff --git a/src/Blocks/CMakeLists.txt b/src/Blocks/CMakeLists.txt index d7ea6258f..d8affd9cf 100644 --- a/src/Blocks/CMakeLists.txt +++ b/src/Blocks/CMakeLists.txt @@ -95,6 +95,10 @@ SET (HDRS MetaRotator.h WorldInterface.h) +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set_source_files_properties(BlockHandler.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") + set_source_files_properties(BlockPiston.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") +endif() if(NOT MSVC) add_library(Blocks ${SRCS} ${HDRS}) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bcf634fd7..bf14136f2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -155,24 +155,29 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") set_source_files_properties(BiomeDef.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum") set_source_files_properties(BlockArea.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion") set_source_files_properties(BlockID.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors") - set_source_files_properties(ByteBuffer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion") - set_source_files_properties(ChunkData.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion") - set_source_files_properties(ChunkMap.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=shadow -Wno-error=sign-conversion") - set_source_files_properties(ClientHandle.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion -Wno-error=sign-conversion -Wno-error=global-constructors") - set_source_files_properties(IniFile.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion") + set_source_files_properties(ByteBuffer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=old-style-cast") + set_source_files_properties(Chunk.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") + set_source_files_properties(ChunkData.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=old-style-cast") + set_source_files_properties(ChunkMap.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=shadow -Wno-error=sign-conversion -Wno-error=old-style-cast") + set_source_files_properties(ClientHandle.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion -Wno-error=sign-conversion -Wno-error=global-constructors -Wno-error=old-style-cast") + set_source_files_properties(Enchantments.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") + set_source_files_properties(IniFile.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=old-style-cast") set_source_files_properties(Inventory.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion") - set_source_files_properties(Item.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion") + set_source_files_properties(Item.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion -Wno-error=old-style-cast") set_source_files_properties(ItemGrid.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion") set_source_files_properties(LightingThread.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion -Wno-error=sign-conversion") - set_source_files_properties(Map.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion") + set_source_files_properties(LinearInterpolation.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") + set_source_files_properties(Map.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion -Wno-error=old-style-cast") set_source_files_properties(MobProximityCounter.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=float-equal") set_source_files_properties(MobSpawner.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum") set_source_files_properties(RCONServer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion") - set_source_files_properties(Root.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=shadow") + set_source_files_properties(Root.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=shadow -Wno-error=old-style-cast") + set_source_files_properties(Server.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") set_source_files_properties(Statistics.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors") - set_source_files_properties(StringUtils.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion") + set_source_files_properties(StringCompression.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") + set_source_files_properties(StringUtils.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion -Wno-error=old-style-cast") set_source_files_properties(Tracer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion") - set_source_files_properties(World.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion") + set_source_files_properties(World.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=old-style-cast") set_source_files_properties(main.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=missing-variable-declarations -Wno-error=missing-prototypes") endif() diff --git a/src/ChunkSender.cpp b/src/ChunkSender.cpp index 917ab198b..70b2e9101 100644 --- a/src/ChunkSender.cpp +++ b/src/ChunkSender.cpp @@ -338,7 +338,7 @@ void cChunkSender::BiomeData(const cChunkDef::BiomeMap * a_BiomeMap) if ((*a_BiomeMap)[i] < 255) { // Normal MC biome, copy as-is: - m_BiomeMap[i] = (unsigned char)((*a_BiomeMap)[i]); + m_BiomeMap[i] = static_cast((*a_BiomeMap)[i]); } else { diff --git a/src/CompositeChat.cpp b/src/CompositeChat.cpp index c6b89324c..5d6c028ab 100644 --- a/src/CompositeChat.cpp +++ b/src/CompositeChat.cpp @@ -342,7 +342,7 @@ AString cCompositeChat::ExtractText(void) const } case ptUrl: { - Msg.append(((cUrlPart *)(*itr))->m_Url); + Msg.append((static_cast(*itr))->m_Url); break; } case ptShowAchievement: @@ -423,7 +423,7 @@ AString cCompositeChat::CreateJsonString(bool a_ShouldUseChatPrefixes) const case cCompositeChat::ptClientTranslated: { - const cCompositeChat::cClientTranslatedPart & p = (const cCompositeChat::cClientTranslatedPart &)**itr; + const cCompositeChat::cClientTranslatedPart & p = static_cast(**itr); Part["translate"] = p.m_Text; Json::Value With; for (AStringVector::const_iterator itrW = p.m_Parameters.begin(), endW = p.m_Parameters.end(); itrW != endW; ++itr) @@ -440,7 +440,7 @@ AString cCompositeChat::CreateJsonString(bool a_ShouldUseChatPrefixes) const case cCompositeChat::ptUrl: { - const cCompositeChat::cUrlPart & p = (const cCompositeChat::cUrlPart &)**itr; + const cCompositeChat::cUrlPart & p = static_cast(**itr); Part["text"] = p.m_Text; Json::Value Url; Url["action"] = "open_url"; @@ -453,7 +453,7 @@ AString cCompositeChat::CreateJsonString(bool a_ShouldUseChatPrefixes) const case cCompositeChat::ptSuggestCommand: case cCompositeChat::ptRunCommand: { - const cCompositeChat::cCommandPart & p = (const cCompositeChat::cCommandPart &)**itr; + const cCompositeChat::cCommandPart & p = static_cast(**itr); Part["text"] = p.m_Text; Json::Value Cmd; Cmd["action"] = (p.m_PartType == cCompositeChat::ptRunCommand) ? "run_command" : "suggest_command"; @@ -465,7 +465,7 @@ AString cCompositeChat::CreateJsonString(bool a_ShouldUseChatPrefixes) const case cCompositeChat::ptShowAchievement: { - const cCompositeChat::cShowAchievementPart & p = (const cCompositeChat::cShowAchievementPart &)**itr; + const cCompositeChat::cShowAchievementPart & p = static_cast(**itr); Part["translate"] = "chat.type.achievement"; Json::Value Ach; diff --git a/src/CraftingRecipes.cpp b/src/CraftingRecipes.cpp index 472044fa3..755b152b0 100644 --- a/src/CraftingRecipes.cpp +++ b/src/CraftingRecipes.cpp @@ -373,7 +373,7 @@ void cCraftingRecipes::AddRecipeLine(int a_LineNum, const AString & a_RecipeLine AStringVector Sides = StringSplit(RecipeLine, "="); if (Sides.size() != 2) { - LOGWARNING("crafting.txt: line %d: A single '=' was expected, got %d", a_LineNum, (int)Sides.size() - 1); + LOGWARNING("crafting.txt: line %d: A single '=' was expected, got " SIZE_T_FMT, a_LineNum, Sides.size() - 1); LOGINFO("Offending line: \"%s\"", a_RecipeLine.c_str()); return; } @@ -833,7 +833,7 @@ void cCraftingRecipes::HandleFireworks(const cItem * a_CraftingGrid, cCraftingRe case E_ITEM_DYE: { int GridID = (itr->x + a_OffsetX) + a_GridStride * (itr->y + a_OffsetY); - DyeColours.push_back(cFireworkItem::GetVanillaColourCodeFromDye((NIBBLETYPE)(a_CraftingGrid[GridID].m_ItemDamage & 0x0f))); + DyeColours.push_back(cFireworkItem::GetVanillaColourCodeFromDye(static_cast(a_CraftingGrid[GridID].m_ItemDamage & 0x0f))); break; } case E_ITEM_GUNPOWDER: break; diff --git a/src/Entities/CMakeLists.txt b/src/Entities/CMakeLists.txt index 44257665e..7261e85c0 100644 --- a/src/Entities/CMakeLists.txt +++ b/src/Entities/CMakeLists.txt @@ -61,10 +61,11 @@ SET (HDRS WitherSkullEntity.h) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - set_source_files_properties(Entity.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=global-constructors -Wno-error=switch-enum") - set_source_files_properties(EntityEffect.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum") - set_source_files_properties(Floater.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion") - set_source_files_properties(Player.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=switch-enum -Wno-error=conversion") + set_source_files_properties(ArrowEntity.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") + set_source_files_properties(Entity.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=global-constructors -Wno-error=switch-enum -Wno-error=old-style-cast") + set_source_files_properties(EntityEffect.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum -Wno-error=old-style-cast") + set_source_files_properties(Floater.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=old-style-cast") + set_source_files_properties(Player.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=switch-enum -Wno-error=conversion -Wno-error=old-style-cast") endif() if(NOT MSVC) diff --git a/src/Entities/EnderCrystal.cpp b/src/Entities/EnderCrystal.cpp index 7a911d4db..b71d70bdd 100644 --- a/src/Entities/EnderCrystal.cpp +++ b/src/Entities/EnderCrystal.cpp @@ -22,7 +22,7 @@ cEnderCrystal::cEnderCrystal(double a_X, double a_Y, double a_Z) void cEnderCrystal::SpawnOn(cClientHandle & a_ClientHandle) { - a_ClientHandle.SendSpawnObject(*this, 51, 0, (Byte)GetYaw(), (Byte)GetPitch()); + a_ClientHandle.SendSpawnObject(*this, 51, 0, static_cast(GetYaw()), static_cast(GetPitch())); } diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index fecbb9bf5..58d1287e7 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -205,8 +205,8 @@ public: double GetSpeedZ (void) const { return m_Speed.z; } double GetWidth (void) const { return m_Width; } - int GetChunkX(void) const {return (int)floor(m_Pos.x / cChunkDef::Width); } - int GetChunkZ(void) const {return (int)floor(m_Pos.z / cChunkDef::Width); } + int GetChunkX(void) const {return static_cast(floor(m_Pos.x / cChunkDef::Width)); } + int GetChunkZ(void) const {return static_cast(floor(m_Pos.z / cChunkDef::Width)); } void SetHeadYaw (double a_HeadYaw); void SetHeight (double a_Height); diff --git a/src/Entities/ExpOrb.cpp b/src/Entities/ExpOrb.cpp index db7f6f2c8..676370508 100644 --- a/src/Entities/ExpOrb.cpp +++ b/src/Entities/ExpOrb.cpp @@ -56,12 +56,12 @@ void cExpOrb::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) LOGD("Player %s picked up an ExpOrb. His reward is %i", a_ClosestPlayer->GetName().c_str(), m_Reward); a_ClosestPlayer->DeltaExperience(m_Reward); - m_World->BroadcastSoundEffect("random.orb", GetPosX(), GetPosY(), GetPosZ(), 0.5f, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); + m_World->BroadcastSoundEffect("random.orb", GetPosX(), GetPosY(), GetPosZ(), 0.5f, (0.75f + (static_cast((GetUniqueID() * 23) % 32)) / 64)); Destroy(); } a_Distance.Normalize(); - a_Distance *= ((float) (5.5 - Distance)); + a_Distance *= (static_cast(5.5 - Distance)); SetSpeedX( a_Distance.x); SetSpeedY( a_Distance.y); SetSpeedZ( a_Distance.z); diff --git a/src/Entities/FallingBlock.cpp b/src/Entities/FallingBlock.cpp index 4a165909a..bae13ea66 100644 --- a/src/Entities/FallingBlock.cpp +++ b/src/Entities/FallingBlock.cpp @@ -38,7 +38,7 @@ void cFallingBlock::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) // GetWorld()->BroadcastTeleportEntity(*this); // Test position int BlockX = POSX_TOINT; - int BlockY = (int)(GetPosY() - 0.5); + int BlockY = static_cast(GetPosY() - 0.5); int BlockZ = POSZ_TOINT; if (BlockY < 0) diff --git a/src/Entities/FireChargeEntity.cpp b/src/Entities/FireChargeEntity.cpp index f6c665156..10d83b8dd 100644 --- a/src/Entities/FireChargeEntity.cpp +++ b/src/Entities/FireChargeEntity.cpp @@ -19,11 +19,11 @@ cFireChargeEntity::cFireChargeEntity(cEntity * a_Creator, double a_X, double a_Y -void cFireChargeEntity::Explode(int a_BlockX, int a_BlockY, int a_BlockZ) +void cFireChargeEntity::Explode(Vector3i a_Block) { - if (m_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_AIR) + if (m_World->GetBlock(a_Block) == E_BLOCK_AIR) { - m_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_FIRE, 1); + m_World->SetBlock(a_Block.x, a_Block.y, a_Block.z, E_BLOCK_FIRE, 1); } } @@ -34,7 +34,7 @@ void cFireChargeEntity::Explode(int a_BlockX, int a_BlockY, int a_BlockZ) void cFireChargeEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) { Destroy(); - Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); + Explode(a_HitPos.Floor()); } @@ -44,7 +44,7 @@ void cFireChargeEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_ void cFireChargeEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) { Destroy(); - Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); + Explode(a_HitPos.Floor()); // TODO: Some entities are immune to hits a_EntityHit.StartBurning(5 * 20); // 5 seconds of burning diff --git a/src/Entities/FireChargeEntity.h b/src/Entities/FireChargeEntity.h index eb08f5324..25f04cb7c 100644 --- a/src/Entities/FireChargeEntity.h +++ b/src/Entities/FireChargeEntity.h @@ -32,7 +32,7 @@ public: protected: - void Explode(int a_BlockX, int a_BlockY, int a_BlockZ); + void Explode(Vector3i a_Block); // cProjectileEntity overrides: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; diff --git a/src/Entities/GhastFireballEntity.cpp b/src/Entities/GhastFireballEntity.cpp index c64fb2a17..1adfd1bc0 100644 --- a/src/Entities/GhastFireballEntity.cpp +++ b/src/Entities/GhastFireballEntity.cpp @@ -19,9 +19,9 @@ cGhastFireballEntity::cGhastFireballEntity(cEntity * a_Creator, double a_X, doub -void cGhastFireballEntity::Explode(int a_BlockX, int a_BlockY, int a_BlockZ) +void cGhastFireballEntity::Explode(Vector3i a_Block) { - m_World->DoExplosionAt(1, a_BlockX, a_BlockY, a_BlockZ, true, esGhastFireball, this); + m_World->DoExplosionAt(1, a_Block.x, a_Block.y, a_Block.z, true, esGhastFireball, this); } @@ -31,7 +31,7 @@ void cGhastFireballEntity::Explode(int a_BlockX, int a_BlockY, int a_BlockZ) void cGhastFireballEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) { Destroy(); - Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); + Explode(a_HitPos.Floor()); } @@ -41,5 +41,5 @@ void cGhastFireballEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace void cGhastFireballEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) { Destroy(); - Explode((int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z)); + Explode(a_HitPos.Floor()); } diff --git a/src/Entities/GhastFireballEntity.h b/src/Entities/GhastFireballEntity.h index bbce89d31..dc136dfc2 100644 --- a/src/Entities/GhastFireballEntity.h +++ b/src/Entities/GhastFireballEntity.h @@ -32,7 +32,7 @@ public: protected: - void Explode(int a_BlockX, int a_BlockY, int a_BlockZ); + void Explode(Vector3i a_Block); // cProjectileEntity overrides: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; diff --git a/src/Entities/ItemFrame.cpp b/src/Entities/ItemFrame.cpp index 4e6e38f1f..6317eba85 100644 --- a/src/Entities/ItemFrame.cpp +++ b/src/Entities/ItemFrame.cpp @@ -62,7 +62,7 @@ void cItemFrame::KilledBy(TakeDamageInfo & a_TDI) return; } - if ((a_TDI.Attacker != nullptr) && a_TDI.Attacker->IsPlayer() && !((cPlayer *)a_TDI.Attacker)->IsGameModeCreative()) + if ((a_TDI.Attacker != nullptr) && a_TDI.Attacker->IsPlayer() && !static_cast(a_TDI.Attacker)->IsGameModeCreative()) { cItems Item; Item.push_back(m_Item); @@ -83,7 +83,7 @@ void cItemFrame::KilledBy(TakeDamageInfo & a_TDI) void cItemFrame::GetDrops(cItems & a_Items, cEntity * a_Killer) { - if ((a_Killer != nullptr) && a_Killer->IsPlayer() && !((cPlayer *)a_Killer)->IsGameModeCreative()) + if ((a_Killer != nullptr) && a_Killer->IsPlayer() && !static_cast(a_Killer)->IsGameModeCreative()) { a_Items.push_back(cItem(E_ITEM_ITEM_FRAME)); } @@ -96,7 +96,7 @@ void cItemFrame::GetDrops(cItems & a_Items, cEntity * a_Killer) void cItemFrame::SpawnOn(cClientHandle & a_ClientHandle) { super::SpawnOn(a_ClientHandle); - a_ClientHandle.SendSpawnObject(*this, 71, GetProtocolFacing(), (Byte)GetYaw(), (Byte)GetPitch()); + a_ClientHandle.SendSpawnObject(*this, 71, GetProtocolFacing(), static_cast(GetYaw()), static_cast(GetPitch())); a_ClientHandle.SendEntityMetadata(*this); } diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index 3adc63129..7274a7a41 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -106,7 +106,7 @@ cMinecart::cMinecart(ePayload a_Payload, double a_X, double a_Y, double a_Z) : void cMinecart::SpawnOn(cClientHandle & a_ClientHandle) { - a_ClientHandle.SendSpawnVehicle(*this, 10, (char)m_Payload); // 10 = Minecarts + a_ClientHandle.SendSpawnVehicle(*this, 10, static_cast(m_Payload)); // 10 = Minecarts a_ClientHandle.SendEntityMetadata(*this); } @@ -725,11 +725,11 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta) { if (GetSpeedZ() > 0) { - BLOCKTYPE Block = m_World->GetBlock(POSX_TOINT, POSY_TOINT, (int)ceil(GetPosZ())); + BLOCKTYPE Block = m_World->GetBlock(POSX_TOINT, POSY_TOINT, static_cast(ceil(GetPosZ()))); if (!IsBlockRail(Block) && cBlockInfo::IsSolid(Block)) { // We could try to detect a block in front based purely on coordinates, but xoft made a bounding box system - why not use? :P - cBoundingBox bbBlock(Vector3d(POSX_TOINT, POSY_TOINT, (int)ceil(GetPosZ())), 0.5, 1); + cBoundingBox bbBlock(Vector3d(POSX_TOINT, POSY_TOINT, static_cast(ceil(GetPosZ()))), 0.5, 1); cBoundingBox bbMinecart(Vector3d(GetPosX(), floor(GetPosY()), GetPosZ()), GetWidth() / 2, GetHeight()); if (bbBlock.DoesIntersect(bbMinecart)) @@ -762,10 +762,10 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta) { if (GetSpeedX() > 0) { - BLOCKTYPE Block = m_World->GetBlock((int)ceil(GetPosX()), POSY_TOINT, POSZ_TOINT); + BLOCKTYPE Block = m_World->GetBlock(static_cast(ceil(GetPosX())), POSY_TOINT, POSZ_TOINT); if (!IsBlockRail(Block) && cBlockInfo::IsSolid(Block)) { - cBoundingBox bbBlock(Vector3d((int)ceil(GetPosX()), POSY_TOINT, POSZ_TOINT), 0.5, 1); + cBoundingBox bbBlock(Vector3d(static_cast(ceil(GetPosX())), POSY_TOINT, POSZ_TOINT), 0.5, 1); cBoundingBox bbMinecart(Vector3d(GetPosX(), floor(GetPosY()), GetPosZ()), GetWidth() / 2, GetHeight()); if (bbBlock.DoesIntersect(bbMinecart)) @@ -1003,7 +1003,7 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta) bool cMinecart::DoTakeDamage(TakeDamageInfo & TDI) { - if ((TDI.Attacker != nullptr) && TDI.Attacker->IsPlayer() && ((cPlayer *)TDI.Attacker)->IsGameModeCreative()) + if ((TDI.Attacker != nullptr) && TDI.Attacker->IsPlayer() && static_cast(TDI.Attacker)->IsGameModeCreative()) { Destroy(); TDI.FinalDamage = GetMaxHealth(); // Instant hit for creative diff --git a/src/Entities/Painting.cpp b/src/Entities/Painting.cpp index 02a8f6ed0..d73c2a245 100644 --- a/src/Entities/Painting.cpp +++ b/src/Entities/Painting.cpp @@ -33,7 +33,7 @@ void cPainting::SpawnOn(cClientHandle & a_Client) void cPainting::GetDrops(cItems & a_Items, cEntity * a_Killer) { - if ((a_Killer != nullptr) && a_Killer->IsPlayer() && !((cPlayer *)a_Killer)->IsGameModeCreative()) + if ((a_Killer != nullptr) && a_Killer->IsPlayer() && !static_cast(a_Killer)->IsGameModeCreative()) { a_Items.push_back(cItem(E_ITEM_PAINTING)); } diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp index 9fdd7026b..2cd0f2f0e 100644 --- a/src/Entities/Pawn.cpp +++ b/src/Entities/Pawn.cpp @@ -75,7 +75,7 @@ void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, int a_Duration, s { return; } - a_Duration = (int)(a_Duration * a_DistanceModifier); + a_Duration = static_cast(a_Duration * a_DistanceModifier); m_EntityEffects[a_EffectType] = cEntityEffect::CreateEntityEffect(a_EffectType, a_Duration, a_Intensity, a_DistanceModifier); m_World->BroadcastEntityEffect(*this, a_EffectType, a_Intensity, static_cast(a_Duration)); diff --git a/src/Entities/Pickup.cpp b/src/Entities/Pickup.cpp index f2f76dbf9..24736350e 100644 --- a/src/Entities/Pickup.cpp +++ b/src/Entities/Pickup.cpp @@ -38,7 +38,7 @@ public: Vector3d EntityPos = a_Entity->GetPosition(); double Distance = (EntityPos - m_Position).Length(); - cItem & Item = ((cPickup *)a_Entity)->GetItem(); + cItem & Item = static_cast(a_Entity)->GetItem(); if ((Distance < 1.2) && Item.IsEqual(m_Pickup->GetItem())) { short CombineCount = Item.m_ItemCount; @@ -52,7 +52,7 @@ public: return false; } - m_Pickup->GetItem().AddCount((char)CombineCount); + m_Pickup->GetItem().AddCount(static_cast(CombineCount)); Item.m_ItemCount -= CombineCount; if (Item.m_ItemCount <= 0) @@ -229,7 +229,7 @@ bool cPickup::CollectedBy(cPlayer & a_Dest) m_Item.m_ItemCount -= NumAdded; m_World->BroadcastCollectEntity(*this, a_Dest); // Also send the "pop" sound effect with a somewhat random pitch (fast-random using EntityID ;) - m_World->BroadcastSoundEffect("random.pop", GetPosX(), GetPosY(), GetPosZ(), 0.5, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); + m_World->BroadcastSoundEffect("random.pop", GetPosX(), GetPosY(), GetPosZ(), 0.5, (0.75f + (static_cast((GetUniqueID() * 23) % 32)) / 64)); if (m_Item.m_ItemCount <= 0) { // All of the pickup has been collected, schedule the pickup for destroying diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index 1f00533db..8e2e412dd 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -30,7 +30,7 @@ /// Converts an angle in radians into a byte representation used by the network protocol -#define ANGLE_TO_PROTO(X) (Byte)(X * 255 / 360) +#define ANGLE_TO_PROTO(X) static_cast(X * 255 / 360) @@ -222,7 +222,7 @@ cProjectileEntity::cProjectileEntity(eKind a_Kind, cEntity * a_Creator, double a m_ProjectileKind(a_Kind), m_CreatorData( ((a_Creator != nullptr) ? a_Creator->GetUniqueID() : cEntity::INVALID_ID), - ((a_Creator != nullptr) ? (a_Creator->IsPlayer() ? ((cPlayer *)a_Creator)->GetName() : "") : ""), + ((a_Creator != nullptr) ? (a_Creator->IsPlayer() ? static_cast(a_Creator)->GetName() : "") : ""), ((a_Creator != nullptr) ? a_Creator->GetEquippedWeapon().m_Enchantments : cEnchantments()) ), m_IsInGround(false) @@ -238,7 +238,7 @@ cProjectileEntity::cProjectileEntity(eKind a_Kind, cEntity * a_Creator, double a cProjectileEntity::cProjectileEntity(eKind a_Kind, cEntity * a_Creator, const Vector3d & a_Pos, const Vector3d & a_Speed, double a_Width, double a_Height) : super(etProjectile, a_Pos.x, a_Pos.y, a_Pos.z, a_Width, a_Height), m_ProjectileKind(a_Kind), - m_CreatorData(a_Creator->GetUniqueID(), a_Creator->IsPlayer() ? ((cPlayer *)a_Creator)->GetName() : "", a_Creator->GetEquippedWeapon().m_Enchantments), + m_CreatorData(a_Creator->GetUniqueID(), a_Creator->IsPlayer() ? static_cast(a_Creator)->GetName() : "", a_Creator->GetEquippedWeapon().m_Enchantments), m_IsInGround(false) { SetSpeed(a_Speed); diff --git a/src/Entities/SplashPotionEntity.cpp b/src/Entities/SplashPotionEntity.cpp index fd1a0179b..a79ba92b0 100644 --- a/src/Entities/SplashPotionEntity.cpp +++ b/src/Entities/SplashPotionEntity.cpp @@ -9,7 +9,7 @@ /// Converts an angle in radians into a byte representation used by the network protocol -#define ANGLE_TO_PROTO(X) (Byte)(X * 255 / 360) +#define ANGLE_TO_PROTO(X) static_cast(X * 255 / 360) //////////////////////////////////////////////////////////////////////////////// // cSplashPotionEntityCallback: @@ -51,7 +51,7 @@ public: double Reduction = -0.25 * SplashDistance + 1.0; Reduction = std::max(Reduction, 0.0); - ((cPawn *) a_Entity)->AddEntityEffect(m_EntityEffectType, m_EntityEffect.GetDuration(), m_EntityEffect.GetIntensity(), Reduction); + static_cast(a_Entity)->AddEntityEffect(m_EntityEffectType, m_EntityEffect.GetDuration(), m_EntityEffect.GetIntensity(), Reduction); return false; } @@ -116,7 +116,12 @@ void cSplashPotionEntity::Splash(const Vector3d & a_HitPos) cSplashPotionCallback Callback(a_HitPos, m_EntityEffectType, m_EntityEffect); m_World->ForEachEntity(Callback); - m_World->BroadcastSoundParticleEffect(2002, (int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z), m_PotionColor); + m_World->BroadcastSoundParticleEffect( + 2002, + static_cast(floor(a_HitPos.x)), + static_cast(floor(a_HitPos.y)), + static_cast(floor(a_HitPos.z)), + m_PotionColor); } diff --git a/src/Entities/ThrownSnowballEntity.cpp b/src/Entities/ThrownSnowballEntity.cpp index 24db1e7ee..b28205d44 100644 --- a/src/Entities/ThrownSnowballEntity.cpp +++ b/src/Entities/ThrownSnowballEntity.cpp @@ -32,7 +32,7 @@ void cThrownSnowballEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & int TotalDamage = 0; if (a_EntityHit.IsMob()) { - eMonsterType MobType = ((cMonster &) a_EntityHit).GetMobType(); + eMonsterType MobType = static_cast(a_EntityHit).GetMobType(); if (MobType == mtBlaze) { TotalDamage = 3; diff --git a/src/FurnaceRecipe.cpp b/src/FurnaceRecipe.cpp index ea952a852..e3be6b230 100644 --- a/src/FurnaceRecipe.cpp +++ b/src/FurnaceRecipe.cpp @@ -77,7 +77,7 @@ void cFurnaceRecipe::ReloadRecipes(void) size_t FirstCommentSymbol = ParsingLine.find('#'); if ((FirstCommentSymbol != AString::npos) && (FirstCommentSymbol != 0)) { - ParsingLine.erase(ParsingLine.begin() + (const long)FirstCommentSymbol, ParsingLine.end()); + ParsingLine.erase(ParsingLine.begin() + static_cast(FirstCommentSymbol), ParsingLine.end()); } switch (ParsingLine[0]) @@ -121,7 +121,7 @@ void cFurnaceRecipe::AddFuelFromLine(const AString & a_Line, unsigned int a_Line const AStringVector & Sides = StringSplit(Line, "="); if (Sides.size() != 2) { - LOGWARNING("furnace.txt: line %d: A single '=' was expected, got %d", a_LineNum, (int)Sides.size() - 1); + LOGWARNING("furnace.txt: line %d: A single '=' was expected, got " SIZE_T_FMT, a_LineNum, Sides.size() - 1); LOGINFO("Offending line: \"%s\"", a_Line.c_str()); return; } @@ -163,7 +163,7 @@ void cFurnaceRecipe::AddRecipeFromLine(const AString & a_Line, unsigned int a_Li const AStringVector & Sides = StringSplit(Line, "="); if (Sides.size() != 2) { - LOGWARNING("furnace.txt: line %d: A single '=' was expected, got %d", a_LineNum, (int)Sides.size() - 1); + LOGWARNING("furnace.txt: line %d: A single '=' was expected, got " SIZE_T_FMT, a_LineNum, Sides.size() - 1); LOGINFO("Offending line: \"%s\"", a_Line.c_str()); return; } diff --git a/src/Generating/CMakeLists.txt b/src/Generating/CMakeLists.txt index 8167b8ec7..ebba4cce8 100644 --- a/src/Generating/CMakeLists.txt +++ b/src/Generating/CMakeLists.txt @@ -73,17 +73,27 @@ SET (HDRS ) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - set_source_files_properties(CompoGenBiomal.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors") - set_source_files_properties(BioGen.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum") - set_source_files_properties(ComposableGenerator.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum") + set_source_files_properties(BioGen.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum -Wno-error=old-style-cast") + set_source_files_properties(Caves.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") + set_source_files_properties(ChunkGenerator.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") + set_source_files_properties(CompoGen.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") + set_source_files_properties(CompoGenBiomal.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors -Wno-error=old-style-cast") + set_source_files_properties(ComposableGenerator.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum -Wno-error=old-style-cast") + set_source_files_properties(DistortedHeightmap.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") + set_source_files_properties(EndGen.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") set_source_files_properties(FinishGen.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum -Wno-error=switch") + set_source_files_properties(HeiGen.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") set_source_files_properties(NetherFortGen.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors") + set_source_files_properties(Noise3DGenerator.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") set_source_files_properties(PieceGenerator.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors") set_source_files_properties(Prefab.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors") set_source_files_properties(RainbowRoadsGen.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors") - set_source_files_properties(RoughRavines.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=float-equal") - set_source_files_properties(StructGen.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum -Wno-error=switch") + set_source_files_properties(Ravines.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") + set_source_files_properties(RoughRavines.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=float-equal -Wno-error=old-style-cast") + set_source_files_properties(StructGen.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum -Wno-error=switch -Wno-error=old-style-cast") + set_source_files_properties(ShapeGen.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") set_source_files_properties(TestRailsGen.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors") + set_source_files_properties(TwoHeights.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") set_source_files_properties(UnderwaterBaseGen.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors -Wno-error=switch-enum") set_source_files_properties(VillageGen.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors -Wno-error=switch-enum") endif() diff --git a/src/Generating/ChunkDesc.h b/src/Generating/ChunkDesc.h index 8308aae41..672ed99c0 100644 --- a/src/Generating/ChunkDesc.h +++ b/src/Generating/ChunkDesc.h @@ -204,10 +204,10 @@ public: // Accessors used by cChunkGenerator::Generator descendants: inline cChunkDef::BiomeMap & GetBiomeMap (void) { return m_BiomeMap; } - inline cChunkDef::BlockTypes & GetBlockTypes (void) { return *((cChunkDef::BlockTypes *)m_BlockArea.GetBlockTypes()); } + inline cChunkDef::BlockTypes & GetBlockTypes (void) { return *(reinterpret_cast(m_BlockArea.GetBlockTypes())); } // CANNOT, different compression! // inline cChunkDef::BlockNibbles & GetBlockMetas (void) { return *((cChunkDef::BlockNibbles *)m_BlockArea.GetBlockMetas()); } - inline BlockNibbleBytes & GetBlockMetasUncompressed(void) { return *((BlockNibbleBytes *)m_BlockArea.GetBlockMetas()); } + inline BlockNibbleBytes & GetBlockMetasUncompressed(void) { return *(reinterpret_cast(m_BlockArea.GetBlockMetas())); } inline cChunkDef::HeightMap & GetHeightMap (void) { return m_HeightMap; } inline cEntityList & GetEntities (void) { return m_Entities; } inline cBlockEntityList & GetBlockEntities (void) { return m_BlockEntities; } diff --git a/src/Generating/DungeonRoomsFinisher.cpp b/src/Generating/DungeonRoomsFinisher.cpp index c4bf8839e..c62da7492 100644 --- a/src/Generating/DungeonRoomsFinisher.cpp +++ b/src/Generating/DungeonRoomsFinisher.cpp @@ -194,7 +194,7 @@ protected: { return; } - a_ChunkDesc.SetBlockTypeMeta(RelX, m_FloorHeight + 1, RelZ, E_BLOCK_CHEST, (NIBBLETYPE)a_Chest.y); + a_ChunkDesc.SetBlockTypeMeta(RelX, m_FloorHeight + 1, RelZ, E_BLOCK_CHEST, static_cast(a_Chest.y)); // Fill the chest with random loot static const cLootProbab LootProbab[] = @@ -217,7 +217,7 @@ protected: { cItem(E_ITEM_NAME_TAG), 1, 1, 10 }, } ; - cChestEntity * ChestEntity = (cChestEntity *)a_ChunkDesc.GetBlockEntity(RelX, m_FloorHeight + 1, RelZ); + cChestEntity * ChestEntity = static_cast(a_ChunkDesc.GetBlockEntity(RelX, m_FloorHeight + 1, RelZ)); ASSERT((ChestEntity != nullptr) && (ChestEntity->GetBlockType() == E_BLOCK_CHEST)); cNoise Noise(a_ChunkDesc.GetChunkX() ^ a_ChunkDesc.GetChunkZ()); int NumSlots = 3 + ((Noise.IntNoise3DInt(a_Chest.x, a_Chest.y, a_Chest.z) / 11) % 4); diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index e0349f012..1c48fdee4 100644 --- a/src/Generating/FinishGen.cpp +++ b/src/Generating/FinishGen.cpp @@ -69,7 +69,7 @@ void cFinishGenNetherClumpFoliage::GenFinish(cChunkDesc & a_ChunkDesc) } // Choose what block to use. - NOISE_DATATYPE BlockType = m_Noise.IntNoise3D((int) ChunkX, y, (int) ChunkZ); + NOISE_DATATYPE BlockType = m_Noise.IntNoise3D(static_cast(ChunkX), y, static_cast(ChunkZ)); if (BlockType < -0.7) { TryPlaceClump(a_ChunkDesc, PosX, y, PosZ, E_BLOCK_BROWN_MUSHROOM); @@ -507,7 +507,7 @@ void cFinishGenSprinkleFoliage::GenFinish(cChunkDesc & a_ChunkDesc) for (int z = 0; z < cChunkDef::Width; z++) { int BlockZ = a_ChunkDesc.GetChunkZ() * cChunkDef::Width + z; - const float zz = (float)BlockZ; + const float zz = static_cast(BlockZ); for (int x = 0; x < cChunkDef::Width; x++) { int BlockX = a_ChunkDesc.GetChunkX() * cChunkDef::Width + x; @@ -528,7 +528,7 @@ void cFinishGenSprinkleFoliage::GenFinish(cChunkDesc & a_ChunkDesc) continue; } - const float xx = (float)BlockX; + const float xx = static_cast(BlockX); float val1 = m_Noise.CubicNoise2D(xx * 0.1f, zz * 0.1f); float val2 = m_Noise.CubicNoise2D(xx * 0.01f, zz * 0.01f); switch (a_ChunkDesc.GetBlockType(x, Top, z)) @@ -563,7 +563,7 @@ void cFinishGenSprinkleFoliage::GenFinish(cChunkDesc & a_ChunkDesc) } else if ((val1 > 0.5) && (val2 < -0.5)) { - a_ChunkDesc.SetBlockTypeMeta(x, ++Top, z, E_BLOCK_PUMPKIN, (int)(val3 * 8) % 4); + a_ChunkDesc.SetBlockTypeMeta(x, ++Top, z, E_BLOCK_PUMPKIN, static_cast(val3 * 8) % 4); } break; } // case E_BLOCK_GRASS @@ -650,9 +650,9 @@ void cFinishGenSoulsandRims::GenFinish(cChunkDesc & a_ChunkDesc) continue; } - NOISE_DATATYPE NoiseX = ((NOISE_DATATYPE)(xx)) / 32; - NOISE_DATATYPE NoiseY = ((NOISE_DATATYPE)(zz)) / 32; - NOISE_DATATYPE CompBlock = m_Noise.CubicNoise3D(NoiseX, (float) (y) / 4, NoiseY); + NOISE_DATATYPE NoiseX = (static_cast(xx)) / 32; + NOISE_DATATYPE NoiseY = (static_cast(zz)) / 32; + NOISE_DATATYPE CompBlock = m_Noise.CubicNoise3D(NoiseX, static_cast(y) / 4, NoiseY); if (CompBlock < 0) { a_ChunkDesc.SetBlockType(x, y, z, E_BLOCK_SOULSAND); diff --git a/src/Generating/GridStructGen.cpp b/src/Generating/GridStructGen.cpp index 3c08c1a39..5adc60c4f 100644 --- a/src/Generating/GridStructGen.cpp +++ b/src/Generating/GridStructGen.cpp @@ -64,13 +64,13 @@ cGridStructGen::cGridStructGen( LOG("Grid Size cannot be zero, setting to 1"); m_GridSizeZ = 1; } - size_t NumStructuresPerQuery = (size_t)(((m_MaxStructureSizeX + m_MaxOffsetX) / m_GridSizeX + 1) * ((m_MaxStructureSizeZ + m_MaxOffsetZ) / m_GridSizeZ + 1)); + size_t NumStructuresPerQuery = static_cast(((m_MaxStructureSizeX + m_MaxOffsetX) / m_GridSizeX + 1) * ((m_MaxStructureSizeZ + m_MaxOffsetZ) / m_GridSizeZ + 1)); if (NumStructuresPerQuery > m_MaxCacheSize) { m_MaxCacheSize = NumStructuresPerQuery * 4; LOGINFO( "cGridStructGen: The cache size is too small (%u), increasing the cache size to %u to avoid inefficiency.", - (unsigned)a_MaxCacheSize, (unsigned)m_MaxCacheSize + static_cast(a_MaxCacheSize), static_cast(m_MaxCacheSize) ); } } diff --git a/src/Generating/MineShafts.cpp b/src/Generating/MineShafts.cpp index 1482234f0..88dade240 100644 --- a/src/Generating/MineShafts.cpp +++ b/src/Generating/MineShafts.cpp @@ -542,7 +542,7 @@ cMineShaft * cMineShaftCorridor::CreateAndFit( { cCuboid BoundingBox(a_PivotX, a_PivotY - 1, a_PivotZ); BoundingBox.p2.y += 3; - int rnd = a_Noise.IntNoise3DInt(a_PivotX, a_PivotY + (int)a_ParentSystem.m_MineShafts.size(), a_PivotZ) / 7; + int rnd = a_Noise.IntNoise3DInt(a_PivotX, a_PivotY + static_cast(a_ParentSystem.m_MineShafts.size()), a_PivotZ) / 7; int NumSegments = 2 + (rnd) % (MAX_SEGMENTS - 1); // 2 .. MAX_SEGMENTS switch (a_Direction) { @@ -795,7 +795,7 @@ void cMineShaftCorridor::PlaceChest(cChunkDesc & a_ChunkDesc) ) { a_ChunkDesc.SetBlockTypeMeta(x, m_BoundingBox.p1.y + 1, z, E_BLOCK_CHEST, Meta); - cChestEntity * ChestEntity = (cChestEntity *)a_ChunkDesc.GetBlockEntity(x, m_BoundingBox.p1.y + 1, z); + cChestEntity * ChestEntity = static_cast(a_ChunkDesc.GetBlockEntity(x, m_BoundingBox.p1.y + 1, z)); ASSERT((ChestEntity != nullptr) && (ChestEntity->GetBlockType() == E_BLOCK_CHEST)); cNoise Noise(a_ChunkDesc.GetChunkX() ^ a_ChunkDesc.GetChunkZ()); int NumSlots = 3 + ((Noise.IntNoise3DInt(x, m_BoundingBox.p1.y, z) / 11) % 4); @@ -985,7 +985,7 @@ cMineShaft * cMineShaftCrossing::CreateAndFit( ) { cCuboid BoundingBox(a_PivotX, a_PivotY - 1, a_PivotZ); - int rnd = a_Noise.IntNoise3DInt(a_PivotX, a_PivotY + (int)a_ParentSystem.m_MineShafts.size(), a_PivotZ) / 7; + int rnd = a_Noise.IntNoise3DInt(a_PivotX, a_PivotY + static_cast(a_ParentSystem.m_MineShafts.size()), a_PivotZ) / 7; BoundingBox.p2.y += 3; if ((rnd % 4) < 2) { @@ -1126,7 +1126,7 @@ cMineShaft * cMineShaftStaircase::CreateAndFit( cNoise & a_Noise ) { - int rnd = a_Noise.IntNoise3DInt(a_PivotX, a_PivotY + (int)a_ParentSystem.m_MineShafts.size(), a_PivotZ) / 7; + int rnd = a_Noise.IntNoise3DInt(a_PivotX, a_PivotY + static_cast(a_ParentSystem.m_MineShafts.size()), a_PivotZ) / 7; cCuboid Box; switch (a_Direction) { diff --git a/src/Generating/NetherFortGen.cpp b/src/Generating/NetherFortGen.cpp index f35555efd..d29ab8cd1 100644 --- a/src/Generating/NetherFortGen.cpp +++ b/src/Generating/NetherFortGen.cpp @@ -36,7 +36,7 @@ public: int BlockY = 64; // Generate pieces: - for (int i = 0; m_Pieces.size() < (size_t)(a_MaxDepth * a_MaxDepth / 8 + a_MaxDepth); i++) + for (int i = 0; m_Pieces.size() < static_cast(a_MaxDepth * a_MaxDepth / 8 + a_MaxDepth); i++) { cBFSPieceGenerator pg(cNetherFortGen::m_PiecePool, a_Seed + i); pg.PlacePieces(a_OriginX, BlockY, a_OriginZ, a_MaxDepth, m_Pieces); @@ -55,7 +55,7 @@ public: { for (cPlacedPieces::const_iterator itr = m_Pieces.begin(), end = m_Pieces.end(); itr != end; ++itr) { - const cPrefab & Prefab = (const cPrefab &)((*itr)->GetPiece()); + const cPrefab & Prefab = static_cast((*itr)->GetPiece()); Prefab.Draw(a_Chunk, *itr); } // for itr - m_PlacedPieces[] } diff --git a/src/Generating/POCPieceGenerator.cpp b/src/Generating/POCPieceGenerator.cpp index 6e7e74d7a..834e3887f 100644 --- a/src/Generating/POCPieceGenerator.cpp +++ b/src/Generating/POCPieceGenerator.cpp @@ -32,7 +32,7 @@ public: /** Imprints the piece in the specified chunk. Assumes they intersect. */ - void ImprintInChunk(cChunkDesc & a_ChunkDesc, const Vector3i & a_Pos, int a_NumCCWRotations) + void ImprintInChunk(cChunkDesc & a_ChunkDesc, const Vector3i & a_Pos, int a_NumCCWRotations) const { int BlockX = a_ChunkDesc.GetChunkX() * cChunkDef::Width; int BlockZ = a_ChunkDesc.GetChunkZ() * cChunkDef::Width; @@ -227,7 +227,7 @@ void cPOCPieceGenerator::GenFinish(cChunkDesc & a_ChunkDesc) continue; } - ((cPOCPiece &)(*itr)->GetPiece()).ImprintInChunk(a_ChunkDesc, Pos, (*itr)->GetNumCCWRotations()); + (static_cast((*itr)->GetPiece())).ImprintInChunk(a_ChunkDesc, Pos, (*itr)->GetNumCCWRotations()); } // for itr - m_Pieces[] a_ChunkDesc.UpdateHeightmap(); } diff --git a/src/Generating/PieceGenerator.cpp b/src/Generating/PieceGenerator.cpp index b58a5394d..14a9da39d 100644 --- a/src/Generating/PieceGenerator.cpp +++ b/src/Generating/PieceGenerator.cpp @@ -394,9 +394,9 @@ cPlacedPiece * cPieceGenerator::PlaceStartingPiece(int a_BlockX, int a_BlockY, i int NumRotations = 1; for (size_t i = 1; i < ARRAYCOUNT(Rotations); i++) { - if (StartingPiece->CanRotateCCW((int)i)) + if (StartingPiece->CanRotateCCW(static_cast(i))) { - Rotations[NumRotations] = (int)i; + Rotations[NumRotations] = static_cast(i); NumRotations += 1; } } diff --git a/src/Generating/Prefab.cpp b/src/Generating/Prefab.cpp index 761986690..1de0346bd 100644 --- a/src/Generating/Prefab.cpp +++ b/src/Generating/Prefab.cpp @@ -348,13 +348,13 @@ void cPrefab::ParseCharMap(CharMap & a_CharMapOut, const char * a_CharMapDef) LOGWARNING("Bad prefab CharMap definition line: \"%s\", skipping.", itr->c_str()); continue; } - unsigned char Src = (unsigned char)CharDef[0][0]; + unsigned char Src = static_cast(CharDef[0][0]); ASSERT(a_CharMapOut[Src].m_BlockMeta == 16); // This letter has not been assigned yet? - a_CharMapOut[Src].m_BlockType = (BLOCKTYPE)atoi(CharDef[1].c_str()); + a_CharMapOut[Src].m_BlockType = static_cast(atoi(CharDef[1].c_str())); NIBBLETYPE BlockMeta = 0; if ((NumElements >= 3) && !CharDef[2].empty()) { - BlockMeta = (NIBBLETYPE)atoi(CharDef[2].c_str()); + BlockMeta = static_cast(atoi(CharDef[2].c_str())); ASSERT((BlockMeta <= 15)); } a_CharMapOut[Src].m_BlockMeta = BlockMeta; @@ -372,7 +372,7 @@ void cPrefab::ParseBlockImage(const CharMap & a_CharMap, const char * a_BlockIma { for (int z = 0; z < m_Size.z; z++) { - const unsigned char * BlockImage = (const unsigned char *)a_BlockImage + y * m_Size.x * m_Size.z + z * m_Size.x; + const unsigned char * BlockImage = reinterpret_cast(a_BlockImage + y * m_Size.x * m_Size.z + z * m_Size.x); for (int x = 0; x < m_Size.x; x++) { const sBlockTypeDef & MappedValue = a_CharMap[BlockImage[x]]; @@ -424,7 +424,7 @@ void cPrefab::ParseConnectors(const char * a_ConnectorsDef) m_Connectors.push_back(cPiece::cConnector( atoi(Coords[0].c_str()), atoi(Coords[1].c_str()), atoi(Coords[2].c_str()), // Connector pos atoi(Defs[0].c_str()), // Connector type - (eBlockFace)BlockFace + static_cast(BlockFace) )); } // for itr - Lines[] } diff --git a/src/Generating/PrefabPiecePool.cpp b/src/Generating/PrefabPiecePool.cpp index 895555ef8..e4df8efa8 100644 --- a/src/Generating/PrefabPiecePool.cpp +++ b/src/Generating/PrefabPiecePool.cpp @@ -85,7 +85,7 @@ void cPrefabPiecePool::AddStartingPieceDefs(const cPrefab::sDef * a_StartingPiec void cPrefabPiecePool::AddToPerConnectorMap(cPrefab * a_Prefab) { - cPiece::cConnectors Connectors = ((const cPiece *)a_Prefab)->GetConnectors(); + cPiece::cConnectors Connectors = (static_cast(a_Prefab))->GetConnectors(); for (cPiece::cConnectors::const_iterator itr = Connectors.begin(), end = Connectors.end(); itr != end; ++itr) { m_PiecesByConnector[itr->m_Type].push_back(a_Prefab); @@ -122,7 +122,7 @@ cPieces cPrefabPiecePool::GetStartingPieces(void) int cPrefabPiecePool::GetPieceWeight(const cPlacedPiece & a_PlacedPiece, const cPiece::cConnector & a_ExistingConnector, const cPiece & a_NewPiece) { - return ((const cPrefab &)a_NewPiece).GetPieceWeight(a_PlacedPiece, a_ExistingConnector); + return (static_cast(a_NewPiece)).GetPieceWeight(a_PlacedPiece, a_ExistingConnector); } @@ -131,7 +131,7 @@ int cPrefabPiecePool::GetPieceWeight(const cPlacedPiece & a_PlacedPiece, const c int cPrefabPiecePool::GetStartingPieceWeight(const cPiece & a_NewPiece) { - return ((const cPrefab &)a_NewPiece).GetDefaultWeight(); + return (static_cast(a_NewPiece)).GetDefaultWeight(); } diff --git a/src/Generating/RainbowRoadsGen.cpp b/src/Generating/RainbowRoadsGen.cpp index fd4a81692..03400556a 100644 --- a/src/Generating/RainbowRoadsGen.cpp +++ b/src/Generating/RainbowRoadsGen.cpp @@ -76,7 +76,7 @@ protected: { for (cPlacedPieces::iterator itr = m_Pieces.begin(), end = m_Pieces.end(); itr != end; ++itr) { - cPrefab & Prefab = (cPrefab &)((*itr)->GetPiece()); + const cPrefab & Prefab = static_cast((*itr)->GetPiece()); Prefab.Draw(a_Chunk, *itr); } // for itr - m_PlacedPieces[] } diff --git a/src/Generating/TestRailsGen.cpp b/src/Generating/TestRailsGen.cpp index 8256b55a0..72317eb67 100644 --- a/src/Generating/TestRailsGen.cpp +++ b/src/Generating/TestRailsGen.cpp @@ -76,7 +76,7 @@ protected: { for (cPlacedPieces::iterator itr = m_Pieces.begin(), end = m_Pieces.end(); itr != end; ++itr) { - cPrefab & Prefab = (cPrefab &)((*itr)->GetPiece()); + const cPrefab & Prefab = static_cast((*itr)->GetPiece()); Prefab.Draw(a_Chunk, *itr); } // for itr - m_PlacedPieces[] } diff --git a/src/Generating/Trees.cpp b/src/Generating/Trees.cpp index 014fdf1f2..c8bbab12f 100644 --- a/src/Generating/Trees.cpp +++ b/src/Generating/Trees.cpp @@ -130,7 +130,7 @@ inline void PushSomeColumns(int a_BlockX, int a_Height, int a_BlockZ, int a_Colu { int x = a_BlockX + a_Coords[i].x; int z = a_BlockZ + a_Coords[i].z; - if (a_Noise.IntNoise3DInt(x + 64 * a_Seq, a_Height + (int)i, z + 64 * a_Seq) <= a_Chance) + if (a_Noise.IntNoise3DInt(x + 64 * a_Seq, a_Height + static_cast(i), z + 64 * a_Seq) <= a_Chance) { for (int j = 0; j < a_ColumnHeight; j++) { @@ -843,7 +843,7 @@ void GetPineTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise { break; } - ASSERT((size_t)LayerSize < ARRAYCOUNT(BigOs)); + ASSERT(static_cast(LayerSize) < ARRAYCOUNT(BigOs)); PushCoordBlocks(a_BlockX, h, a_BlockZ, a_OtherBlocks, BigOs[LayerSize].Coords, BigOs[LayerSize].Count, E_BLOCK_LEAVES, E_META_LEAVES_CONIFER); h--; } diff --git a/src/Generating/UnderwaterBaseGen.cpp b/src/Generating/UnderwaterBaseGen.cpp index dbc4aef1b..c5066ca1b 100644 --- a/src/Generating/UnderwaterBaseGen.cpp +++ b/src/Generating/UnderwaterBaseGen.cpp @@ -76,7 +76,7 @@ protected: { for (cPlacedPieces::iterator itr = m_Pieces.begin(), end = m_Pieces.end(); itr != end; ++itr) { - cPrefab & Prefab = (cPrefab &)((*itr)->GetPiece()); + const cPrefab & Prefab = static_cast((*itr)->GetPiece()); Prefab.Draw(a_Chunk, *itr); } // for itr - m_PlacedPieces[] } diff --git a/src/Generating/VillageGen.cpp b/src/Generating/VillageGen.cpp index c0f1d4c8f..488497ac1 100644 --- a/src/Generating/VillageGen.cpp +++ b/src/Generating/VillageGen.cpp @@ -93,7 +93,7 @@ public: return 0; } - return ((const cPrefab &)a_NewPiece).GetPieceWeight(a_PlacedPiece, a_ExistingConnector); + return static_cast(a_NewPiece).GetPieceWeight(a_PlacedPiece, a_ExistingConnector); } }; @@ -141,7 +141,7 @@ public: // If the central piece should be moved to ground, move it, and // check all of its dependents and move those that are strictly connector-driven based on its new Y coord: - if (((cPrefab &)m_Pieces[0]->GetPiece()).ShouldMoveToGround()) + if (static_cast(m_Pieces[0]->GetPiece()).ShouldMoveToGround()) { int OrigPosY = m_Pieces[0]->GetCoords().y; PlacePieceOnGround(*m_Pieces[0]); @@ -197,7 +197,7 @@ protected: m_HeightGen->GenHeightMap(a_Chunk.GetChunkX(), a_Chunk.GetChunkZ(), HeightMap); for (cPlacedPieces::iterator itr = m_Pieces.begin(), end = m_Pieces.end(); itr != end; ++itr) { - cPrefab & Prefab = (cPrefab &)((*itr)->GetPiece()); + const cPrefab & Prefab = static_cast((*itr)->GetPiece()); if ((*itr)->GetPiece().GetSize().y == 1) { // It's a road, special handling (change top terrain blocks to m_RoadBlock) @@ -319,7 +319,7 @@ protected: { if ( (a_PlacedPieces[i]->GetParent() == Pivot) && // It is a direct dependant of the pivot - !((const cPrefab &)a_PlacedPieces[i]->GetPiece()).ShouldMoveToGround() // It attaches strictly by connectors + !(static_cast(a_PlacedPieces[i]->GetPiece())).ShouldMoveToGround() // It attaches strictly by connectors ) { a_PlacedPieces[i]->MoveToGroundBy(a_HeightDifference); diff --git a/src/HTTPServer/CMakeLists.txt b/src/HTTPServer/CMakeLists.txt index f6ef96d20..ab3828aae 100644 --- a/src/HTTPServer/CMakeLists.txt +++ b/src/HTTPServer/CMakeLists.txt @@ -25,7 +25,7 @@ SET (HDRS SslHTTPConnection.h) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - set_source_files_properties(HTTPServer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors") + set_source_files_properties(HTTPServer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors -Wno-error=old-style-cast") set_source_files_properties(HTTPConnection.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum") endif() diff --git a/src/HTTPServer/HTTPConnection.cpp b/src/HTTPServer/HTTPConnection.cpp index a5c6afd18..c6a45e6ed 100644 --- a/src/HTTPServer/HTTPConnection.cpp +++ b/src/HTTPServer/HTTPConnection.cpp @@ -213,7 +213,7 @@ void cHTTPConnection::OnReceivedData(const char * a_Data, size_t a_Size) ASSERT(m_CurrentRequest != nullptr); if (m_CurrentRequestBodyRemaining > 0) { - size_t BytesToConsume = std::min(m_CurrentRequestBodyRemaining, (size_t)a_Size); + size_t BytesToConsume = std::min(m_CurrentRequestBodyRemaining, static_cast(a_Size)); m_HTTPServer.RequestBody(*this, *m_CurrentRequest, a_Data, BytesToConsume); m_CurrentRequestBodyRemaining -= BytesToConsume; } diff --git a/src/HTTPServer/SslHTTPConnection.cpp b/src/HTTPServer/SslHTTPConnection.cpp index f8dea0731..7239741da 100644 --- a/src/HTTPServer/SslHTTPConnection.cpp +++ b/src/HTTPServer/SslHTTPConnection.cpp @@ -55,7 +55,7 @@ void cSslHTTPConnection::OnReceivedData(const char * a_Data, size_t a_Size) int NumRead = m_Ssl.ReadPlain(Buffer, sizeof(Buffer)); if (NumRead > 0) { - super::OnReceivedData(Buffer, (size_t)NumRead); + super::OnReceivedData(Buffer, static_cast(NumRead)); } else if (NumRead == POLARSSL_ERR_NET_WANT_READ) { diff --git a/src/IniFile.cpp b/src/IniFile.cpp index b0b3d15ec..635af740d 100644 --- a/src/IniFile.cpp +++ b/src/IniFile.cpp @@ -243,7 +243,7 @@ int cIniFile::FindKey(const AString & a_KeyName) const { if (CheckCase(names[keyID]) == CaseKeyName) { - return (int)keyID; + return static_cast(keyID); } } return noID; diff --git a/src/IniFile.h b/src/IniFile.h index 2a4113fb4..a05e8f734 100644 --- a/src/IniFile.h +++ b/src/IniFile.h @@ -98,7 +98,7 @@ public: int FindValue(const int keyID, const AString & valuename) const; /// Returns number of keys currently in the ini - int GetNumKeys(void) const { return (int)keys.size(); } + int GetNumKeys(void) const { return static_cast(keys.size()); } /// Add a key name int AddKeyName(const AString & keyname) override; @@ -173,7 +173,7 @@ public: // Header comments are those comments before the first key. /// Returns the number of header comments - int GetNumHeaderComments(void) {return (int)comments.size();} + int GetNumHeaderComments(void) {return static_cast(comments.size());} /// Adds a header comment void AddHeaderComment(const AString & comment); diff --git a/src/ItemGrid.cpp b/src/ItemGrid.cpp index 06971a1ac..8433598f7 100644 --- a/src/ItemGrid.cpp +++ b/src/ItemGrid.cpp @@ -358,7 +358,7 @@ int cItemGrid::RemoveItem(const cItem & a_ItemStack) if (m_Slots[i].IsEqual(a_ItemStack)) { - int NumToRemove = std::min(NumLeft, (int)m_Slots[i].m_ItemCount); + int NumToRemove = std::min(NumLeft, static_cast(m_Slots[i].m_ItemCount)); NumLeft -= NumToRemove; m_Slots[i].m_ItemCount -= NumToRemove; diff --git a/src/Items/CMakeLists.txt b/src/Items/CMakeLists.txt index 46ff3b4a0..71f2d9ceb 100644 --- a/src/Items/CMakeLists.txt +++ b/src/Items/CMakeLists.txt @@ -57,7 +57,7 @@ SET (HDRS ) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - set_source_files_properties(ItemHandler.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=conversion -Wno-error=switch-enum") + set_source_files_properties(ItemHandler.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=conversion -Wno-error=old-style-cast -Wno-error=switch-enum") endif() if(NOT MSVC) diff --git a/src/Items/ItemBow.h b/src/Items/ItemBow.h index 5164ddf59..8bbaa3d8c 100644 --- a/src/Items/ItemBow.h +++ b/src/Items/ItemBow.h @@ -53,7 +53,7 @@ public: ASSERT(a_Player != nullptr); int BowCharge = a_Player->FinishChargingBow(); - double Force = (double)BowCharge / 20.0; + double Force = static_cast(BowCharge) / 20.0; Force = (Force * Force + 2.0 * Force) / 3.0; // This formula is used by the 1.6.2 client if (Force < 0.1) { @@ -80,7 +80,14 @@ public: Arrow = nullptr; return; } - a_Player->GetWorld()->BroadcastSoundEffect("random.bow", a_Player->GetPosX(), a_Player->GetPosY(), a_Player->GetPosZ(), 0.5, (float)Force); + a_Player->GetWorld()->BroadcastSoundEffect( + "random.bow", + a_Player->GetPosX(), + a_Player->GetPosY(), + a_Player->GetPosZ(), + 0.5, + static_cast(Force) + ); if (!a_Player->IsGameModeCreative()) { if (a_Player->GetEquippedItem().m_Enchantments.GetLevel(cEnchantments::enchInfinity) == 0) diff --git a/src/Items/ItemBucket.h b/src/Items/ItemBucket.h index 015720415..1dbdfd7bc 100644 --- a/src/Items/ItemBucket.h +++ b/src/Items/ItemBucket.h @@ -236,7 +236,7 @@ public: m_EntryFace = static_cast(a_CBEntryFace); if (!cFluidSimulator::CanWashAway(a_CBBlockType) && !IsBlockLiquid(a_CBBlockType)) { - AddFaceDirection(a_CBBlockX, a_CBBlockY, a_CBBlockZ, (eBlockFace)a_CBEntryFace); // Was an unwashawayable block, can't overwrite it! + AddFaceDirection(a_CBBlockX, a_CBBlockY, a_CBBlockZ, static_cast(a_CBEntryFace)); // Was an unwashawayable block, can't overwrite it! } m_Pos.Set(a_CBBlockX, a_CBBlockY, a_CBBlockZ); // (Block could be washed away, replace it) return true; // Abort tracing diff --git a/src/LightingThread.cpp b/src/LightingThread.cpp index effde03d0..266744a24 100644 --- a/src/LightingThread.cpp +++ b/src/LightingThread.cpp @@ -43,8 +43,8 @@ class cReader : { // Copy the entire heightmap, distribute it into the 3x3 chunk blob: typedef struct {HEIGHTTYPE m_Row[16]; } ROW; - ROW * InputRows = (ROW *)a_Heightmap; - ROW * OutputRows = (ROW *)m_HeightMap; + const ROW * InputRows = reinterpret_cast(a_Heightmap); + ROW * OutputRows = reinterpret_cast(m_HeightMap); int InputIdx = 0; int OutputIdx = m_ReadingChunkX + m_ReadingChunkZ * cChunkDef::Width * 3; for (int z = 0; z < cChunkDef::Width; z++) @@ -217,7 +217,7 @@ void cLightingThread::Execute(void) { continue; } - Item = (cLightingChunkStay *)m_Queue.front(); + Item = static_cast(m_Queue.front()); m_Queue.pop_front(); if (m_Queue.empty()) { diff --git a/src/LineBlockTracer.cpp b/src/LineBlockTracer.cpp index e43a79566..ee28bef88 100644 --- a/src/LineBlockTracer.cpp +++ b/src/LineBlockTracer.cpp @@ -96,17 +96,17 @@ bool cLineBlockTracer::Trace(double a_StartX, double a_StartY, double a_StartZ, m_Callbacks->OnIntoWorld(m_StartX, m_StartY, m_StartZ); } - m_CurrentX = (int)floor(m_StartX); - m_CurrentY = (int)floor(m_StartY); - m_CurrentZ = (int)floor(m_StartZ); + m_CurrentX = static_cast(floor(m_StartX)); + m_CurrentY = static_cast(floor(m_StartY)); + m_CurrentZ = static_cast(floor(m_StartZ)); m_DiffX = m_EndX - m_StartX; m_DiffY = m_EndY - m_StartY; m_DiffZ = m_EndZ - m_StartZ; // The actual trace is handled with ChunkMapCS locked by calling our Item() for the specified chunk - int BlockX = (int)floor(m_StartX); - int BlockZ = (int)floor(m_StartZ); + int BlockX = static_cast(floor(m_StartX)); + int BlockZ = static_cast(floor(m_StartZ)); int ChunkX, ChunkZ; cChunkDef::BlockToChunk(BlockX, BlockZ, ChunkX, ChunkZ); return m_World->DoWithChunk(ChunkX, ChunkZ, *this); @@ -120,7 +120,7 @@ void cLineBlockTracer::FixStartAboveWorld(void) { // We must set the start Y to less than cChunkDef::Height so that it is considered inside the world later on // Therefore we use an EPS-offset from the height, as small as reasonably possible. - const double Height = (double)cChunkDef::Height - 0.00001; + const double Height = static_cast(cChunkDef::Height) - 0.00001; CalcXZIntersection(Height, m_StartX, m_StartZ); m_StartY = Height; } diff --git a/src/LoggerListeners.cpp b/src/LoggerListeners.cpp index 5c7097956..cc2f883d8 100644 --- a/src/LoggerListeners.cpp +++ b/src/LoggerListeners.cpp @@ -3,6 +3,8 @@ #include "LoggerListeners.h" +#include + #if defined(_WIN32) #include // Needed for _isatty(), not available on Linux #include @@ -280,7 +282,9 @@ cFileListener::cFileListener(void) { cFile::CreateFolder(FILE_IO_PREFIX + AString("logs")); AString FileName; - FileName = Printf("%s%sLOG_%d.txt", FILE_IO_PREFIX, "logs/", (int)time(nullptr)); + auto time = std::chrono::system_clock::now(); + FileName = Printf("%s%sLOG_%d.txt", FILE_IO_PREFIX, "logs/", + std::chrono::duration_cast>(time.time_since_epoch()).count()); m_File.Open(FileName, cFile::fmAppend); } diff --git a/src/MapManager.cpp b/src/MapManager.cpp index 0965544cc..41b0d9e34 100644 --- a/src/MapManager.cpp +++ b/src/MapManager.cpp @@ -86,7 +86,7 @@ cMap * cMapManager::CreateMap(int a_CenterX, int a_CenterY, unsigned int a_Scale return nullptr; } - cMap Map((unsigned)m_MapData.size(), a_CenterX, a_CenterY, m_World, a_Scale); + cMap Map(static_cast(m_MapData.size()), a_CenterX, a_CenterY, m_World, a_Scale); m_MapData.push_back(Map); @@ -151,7 +151,7 @@ void cMapManager::SaveMapData(void) cIDCountSerializer IDSerializer(m_World->GetName()); - IDSerializer.SetMapCount((unsigned)m_MapData.size()); + IDSerializer.SetMapCount(static_cast(m_MapData.size())); if (!IDSerializer.Save()) { diff --git a/src/Matrix4.h b/src/Matrix4.h index 61ea60bfd..0558fa5f3 100644 --- a/src/Matrix4.h +++ b/src/Matrix4.h @@ -76,8 +76,8 @@ public: inline void RotateX(T a_RX) { - T sx = (T) sin(a_RX * M_PI / 180); - T cx = (T) cos(a_RX * M_PI / 180); + T sx = static_cast(sin(a_RX * M_PI / 180)); + T cx = static_cast(cos(a_RX * M_PI / 180)); Identity(); @@ -87,8 +87,8 @@ public: inline void RotateY(T a_RY) { - T sy = (T) sin(a_RY * M_PI / 180); - T cy = (T) cos(a_RY * M_PI / 180); + T sy = static_cast(sin(a_RY * M_PI / 180)); + T cy = static_cast(cos(a_RY * M_PI / 180)); Identity(); diff --git a/src/MobCensus.cpp b/src/MobCensus.cpp index 22c838c6b..ca960a2bc 100644 --- a/src/MobCensus.cpp +++ b/src/MobCensus.cpp @@ -65,7 +65,7 @@ void cMobCensus::CollectSpawnableChunk(cChunk & a_Chunk) int cMobCensus::GetNumChunks(void) { - return (int)m_EligibleForSpawnChunks.size(); + return static_cast(m_EligibleForSpawnChunks.size()); } diff --git a/src/MobFamilyCollecter.cpp b/src/MobFamilyCollecter.cpp index 6da330c83..c24ee48f5 100644 --- a/src/MobFamilyCollecter.cpp +++ b/src/MobFamilyCollecter.cpp @@ -18,7 +18,7 @@ void cMobFamilyCollecter::CollectMob(cMonster & a_Monster) int cMobFamilyCollecter::GetNumberOfCollectedMobs(cMonster::eFamily a_Family) { - return (int)m_Mobs[a_Family].size(); + return static_cast(m_Mobs[a_Family].size()); } diff --git a/src/MobSpawner.cpp b/src/MobSpawner.cpp index 468b0cfb2..27dc5a877 100644 --- a/src/MobSpawner.cpp +++ b/src/MobSpawner.cpp @@ -110,7 +110,7 @@ eMonsterType cMobSpawner::ChooseMobType(EMCSBiome a_Biome) if (allowedMobsSize > 0) { std::set::iterator itr = allowedMobs.begin(); - int iRandom = m_Random.NextInt((int)allowedMobsSize); + int iRandom = m_Random.NextInt(static_cast(allowedMobsSize)); for (int i = 0; i < iRandom; i++) { diff --git a/src/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp index 648599999..7eccf0265 100644 --- a/src/Mobs/AggressiveMonster.cpp +++ b/src/Mobs/AggressiveMonster.cpp @@ -30,7 +30,7 @@ void cAggressiveMonster::InStateChasing(std::chrono::milliseconds a_Dt) { if (m_Target->IsPlayer()) { - if (((cPlayer *)m_Target)->IsGameModeCreative()) + if (static_cast(m_Target)->IsGameModeCreative()) { m_EMState = IDLE; return; @@ -46,7 +46,7 @@ void cAggressiveMonster::InStateChasing(std::chrono::milliseconds a_Dt) void cAggressiveMonster::EventSeePlayer(cEntity * a_Entity) { - if (!((cPlayer *)a_Entity)->IsGameModeCreative()) + if (!static_cast(a_Entity)->IsGameModeCreative()) { super::EventSeePlayer(a_Entity); m_EMState = CHASING; @@ -110,12 +110,12 @@ void cAggressiveMonster::Attack(std::chrono::milliseconds a_Dt) bool cAggressiveMonster::IsMovingToTargetPosition() { // Difference between destination x and target x is negligible (to 10^-12 precision) - if (fabsf((float)m_FinalDestination.x - (float)m_Target->GetPosX()) < std::numeric_limits::epsilon()) + if (fabsf(static_cast(m_FinalDestination.x) - static_cast(m_Target->GetPosX())) < std::numeric_limits::epsilon()) { return false; } // Difference between destination z and target z is negligible (to 10^-12 precision) - else if (fabsf((float)m_FinalDestination.z - (float)m_Target->GetPosZ()) > std::numeric_limits::epsilon()) + else if (fabsf(static_cast(m_FinalDestination.z) - static_cast(m_Target->GetPosZ())) > std::numeric_limits::epsilon()) { return false; } diff --git a/src/Mobs/CMakeLists.txt b/src/Mobs/CMakeLists.txt index bd8fa76b1..e99494508 100644 --- a/src/Mobs/CMakeLists.txt +++ b/src/Mobs/CMakeLists.txt @@ -81,7 +81,9 @@ SET (HDRS ZombiePigman.h) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - set_source_files_properties(Monster.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=conversion -Wno-error=switch -Wno-error=switch-enum -Wno-error=float-equal") + set_source_files_properties(Monster.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=conversion -Wno-error=switch -Wno-error=switch-enum -Wno-error=float-equal -Wno-error=old-style-cast") + set_source_files_properties(SnowGolem.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") + set_source_files_properties(Villager.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") endif() if(NOT MSVC) diff --git a/src/Mobs/CaveSpider.cpp b/src/Mobs/CaveSpider.cpp index 8000f3f68..a8b40f52e 100644 --- a/src/Mobs/CaveSpider.cpp +++ b/src/Mobs/CaveSpider.cpp @@ -34,7 +34,7 @@ void cCaveSpider::Attack(std::chrono::milliseconds a_Dt) if (m_Target->IsPawn()) { // TODO: Easy = no poison, Medium = 7 seconds, Hard = 15 seconds - ((cPawn *) m_Target)->AddEntityEffect(cEntityEffect::effPoison, 7 * 20, 0); + static_cast(m_Target)->AddEntityEffect(cEntityEffect::effPoison, 7 * 20, 0); } } diff --git a/src/Mobs/Creeper.cpp b/src/Mobs/Creeper.cpp index 6968bed17..ef3245894 100644 --- a/src/Mobs/Creeper.cpp +++ b/src/Mobs/Creeper.cpp @@ -124,7 +124,7 @@ void cCreeper::Attack(std::chrono::milliseconds a_Dt) if (!m_bIsBlowing) { - m_World->BroadcastSoundEffect("game.tnt.primed", GetPosX(), GetPosY(), GetPosZ(), 1.f, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); + m_World->BroadcastSoundEffect("game.tnt.primed", GetPosX(), GetPosY(), GetPosZ(), 1.f, (0.75f + (static_cast((GetUniqueID() * 23) % 32)) / 64)); m_bIsBlowing = true; m_World->BroadcastEntityMetadata(*this); } @@ -142,7 +142,7 @@ void cCreeper::OnRightClicked(cPlayer & a_Player) { a_Player.UseEquippedItem(); } - m_World->BroadcastSoundEffect("game.tnt.primed", GetPosX(), GetPosY(), GetPosZ(), 1.f, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); + m_World->BroadcastSoundEffect("game.tnt.primed", GetPosX(), GetPosY(), GetPosZ(), 1.f, (0.75f + (static_cast((GetUniqueID() * 23) % 32)) / 64)); m_bIsBlowing = true; m_World->BroadcastEntityMetadata(*this); m_BurnedWithFlintAndSteel = true; diff --git a/src/Mobs/Enderman.cpp b/src/Mobs/Enderman.cpp index 10cec9751..30bf82067 100644 --- a/src/Mobs/Enderman.cpp +++ b/src/Mobs/Enderman.cpp @@ -55,7 +55,7 @@ public: } cTracer LineOfSight(a_Player->GetWorld()); - if (LineOfSight.Trace(m_EndermanPos, Direction, (int)Direction.Length())) + if (LineOfSight.Trace(m_EndermanPos, Direction, static_cast(Direction.Length()))) { // No direct line of sight return false; diff --git a/src/Mobs/Guardian.cpp b/src/Mobs/Guardian.cpp index a81667445..6efd4a42b 100644 --- a/src/Mobs/Guardian.cpp +++ b/src/Mobs/Guardian.cpp @@ -43,13 +43,13 @@ void cGuardian::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) Vector3d Pos = GetPosition(); // TODO: Not a real behavior, but cool :D - int RelY = (int)floor(Pos.y); + int RelY = static_cast(floor(Pos.y)); if ((RelY < 0) || (RelY >= cChunkDef::Height)) { return; } - int RelX = (int)floor(Pos.x) - a_Chunk.GetPosX() * cChunkDef::Width; - int RelZ = (int)floor(Pos.z) - a_Chunk.GetPosZ() * cChunkDef::Width; + int RelX = static_cast(floor(Pos.x)) - a_Chunk.GetPosX() * cChunkDef::Width; + int RelZ = static_cast(floor(Pos.z)) - a_Chunk.GetPosZ() * cChunkDef::Width; BLOCKTYPE BlockType; if (a_Chunk.UnboundedRelGetBlockType(RelX, RelY, RelZ, BlockType) && !IsBlockWater(BlockType) && !IsOnFire()) { diff --git a/src/Mobs/Horse.cpp b/src/Mobs/Horse.cpp index e33cc1b9d..4321fdc73 100644 --- a/src/Mobs/Horse.cpp +++ b/src/Mobs/Horse.cpp @@ -55,10 +55,10 @@ void cHorse::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { if (m_World->GetTickRandomNumber(50) == 25) { - m_World->BroadcastSoundParticleEffect(2000, (int)GetPosX(), (int)GetPosY(), (int)GetPosZ(), 0); - m_World->BroadcastSoundParticleEffect(2000, (int)GetPosX(), (int)GetPosY(), (int)GetPosZ(), 2); - m_World->BroadcastSoundParticleEffect(2000, (int)GetPosX(), (int)GetPosY(), (int)GetPosZ(), 6); - m_World->BroadcastSoundParticleEffect(2000, (int)GetPosX(), (int)GetPosY(), (int)GetPosZ(), 8); + m_World->BroadcastSoundParticleEffect(2000, static_cast(GetPosX()), static_cast(GetPosY()), static_cast(GetPosZ()), 0); + m_World->BroadcastSoundParticleEffect(2000, static_cast(GetPosX()), static_cast(GetPosY()), static_cast(GetPosZ()), 2); + m_World->BroadcastSoundParticleEffect(2000, static_cast(GetPosX()), static_cast(GetPosY()), static_cast(GetPosZ()), 6); + m_World->BroadcastSoundParticleEffect(2000, static_cast(GetPosX()), static_cast(GetPosY()), static_cast(GetPosZ()), 8); m_Attachee->Detach(); m_bIsRearing = true; diff --git a/src/Mobs/PassiveAggressiveMonster.cpp b/src/Mobs/PassiveAggressiveMonster.cpp index cb8650cb9..f5577f71f 100644 --- a/src/Mobs/PassiveAggressiveMonster.cpp +++ b/src/Mobs/PassiveAggressiveMonster.cpp @@ -28,7 +28,7 @@ bool cPassiveAggressiveMonster::DoTakeDamage(TakeDamageInfo & a_TDI) if ((m_Target != nullptr) && (m_Target->IsPlayer())) { - if (!((cPlayer *)m_Target)->IsGameModeCreative()) + if (!static_cast(m_Target)->IsGameModeCreative()) { m_EMState = CHASING; } diff --git a/src/Mobs/PassiveMonster.cpp b/src/Mobs/PassiveMonster.cpp index 012ca9949..c220a7128 100644 --- a/src/Mobs/PassiveMonster.cpp +++ b/src/Mobs/PassiveMonster.cpp @@ -48,7 +48,7 @@ void cPassiveMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { return; } - cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance); + cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), static_cast(m_SightDistance)); if (a_Closest_Player != nullptr) { if (a_Closest_Player->GetEquippedItem().IsEqual(FollowedItem)) diff --git a/src/Mobs/Path.h b/src/Mobs/Path.h index 71b42edc0..db74eaba2 100644 --- a/src/Mobs/Path.h +++ b/src/Mobs/Path.h @@ -128,13 +128,13 @@ public: { // Guaranteed to have no hash collisions for any 128x128x128 area. Suitable for pathfinding. int32_t t = 0; - t += (int8_t)a_Vector.x; + t += static_cast(a_Vector.x); t = t << 8; - t += (int8_t)a_Vector.y; + t += static_cast(a_Vector.y); t = t << 8; - t += (int8_t)a_Vector.z; + t += static_cast(a_Vector.z); t = t << 8; - return (size_t)t; + return static_cast(t); } }; private: diff --git a/src/Mobs/Squid.cpp b/src/Mobs/Squid.cpp index 9affcd6e1..7928f7dc8 100644 --- a/src/Mobs/Squid.cpp +++ b/src/Mobs/Squid.cpp @@ -41,13 +41,13 @@ void cSquid::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) Vector3d Pos = GetPosition(); // TODO: Not a real behavior, but cool :D - int RelY = (int)floor(Pos.y); + int RelY = static_cast(floor(Pos.y)); if ((RelY < 0) || (RelY >= cChunkDef::Height)) { return; } - int RelX = (int)floor(Pos.x) - a_Chunk.GetPosX() * cChunkDef::Width; - int RelZ = (int)floor(Pos.z) - a_Chunk.GetPosZ() * cChunkDef::Width; + int RelX = static_cast(floor(Pos.x)) - a_Chunk.GetPosX() * cChunkDef::Width; + int RelZ = static_cast(floor(Pos.z)) - a_Chunk.GetPosZ() * cChunkDef::Width; BLOCKTYPE BlockType; if (a_Chunk.UnboundedRelGetBlockType(RelX, RelY, RelZ, BlockType) && !IsBlockWater(BlockType) && !IsOnFire()) { diff --git a/src/Mobs/Wolf.cpp b/src/Mobs/Wolf.cpp index 3c2ec1520..61c28c467 100644 --- a/src/Mobs/Wolf.cpp +++ b/src/Mobs/Wolf.cpp @@ -50,7 +50,7 @@ void cWolf::Attack(std::chrono::milliseconds a_Dt) if ((m_Target != nullptr) && (m_Target->IsPlayer())) { - if (((cPlayer *)m_Target)->GetName() != m_OwnerName) + if (static_cast(m_Target)->GetName() != m_OwnerName) { super::Attack(a_Dt); } @@ -157,7 +157,7 @@ void cWolf::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) super::Tick(a_Dt, a_Chunk); } - cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance); + cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), static_cast(m_SightDistance)); if (a_Closest_Player != nullptr) { switch (a_Closest_Player->GetEquippedItem().m_ItemType) diff --git a/src/MonsterConfig.cpp b/src/MonsterConfig.cpp index ae2cbbc6b..278e67b93 100644 --- a/src/MonsterConfig.cpp +++ b/src/MonsterConfig.cpp @@ -64,7 +64,7 @@ void cMonsterConfig::Initialize() return; } - for (int i = (int)MonstersIniFile.GetNumKeys(); i >= 0; i--) + for (int i = static_cast(MonstersIniFile.GetNumKeys()); i >= 0; i--) { sAttributesStruct Attributes; AString Name = MonstersIniFile.GetKeyName(i); @@ -93,7 +93,7 @@ void cMonsterConfig::AssignAttributes(cMonster * a_Monster, const AString & a_Na a_Monster->SetAttackDamage (itr->m_AttackDamage); a_Monster->SetAttackRange (itr->m_AttackRange); a_Monster->SetSightDistance(itr->m_SightDistance); - a_Monster->SetAttackRate ((float)itr->m_AttackRate); + a_Monster->SetAttackRate (static_cast(itr->m_AttackRate)); a_Monster->SetMaxHealth (itr->m_MaxHealth); a_Monster->SetIsFireproof (itr->m_IsFireproof); return; diff --git a/src/Noise/CMakeLists.txt b/src/Noise/CMakeLists.txt index e1837500f..ab4cf031b 100644 --- a/src/Noise/CMakeLists.txt +++ b/src/Noise/CMakeLists.txt @@ -14,6 +14,10 @@ SET (HDRS RidgedNoise.h ) +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set_source_files_properties(Noise.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") +endif() + if(NOT MSVC) add_library(Noise ${SRCS} ${HDRS}) diff --git a/src/Noise/Noise.h b/src/Noise/Noise.h index 5df32d3dc..be3b282ac 100644 --- a/src/Noise/Noise.h +++ b/src/Noise/Noise.h @@ -185,7 +185,7 @@ typedef cOctavedNoise> cRidgedMultiNoise; NOISE_DATATYPE cNoise::IntNoise1D(int a_X) const { int x = ((a_X * m_Seed) << 13) ^ a_X; - return (1 - (NOISE_DATATYPE)((x * (x * x * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824); + return (1 - static_cast((x * (x * x * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824); // returns a float number in the range of [-1, 1] } @@ -197,7 +197,7 @@ NOISE_DATATYPE cNoise::IntNoise2D(int a_X, int a_Y) const { int n = a_X + a_Y * 57 + m_Seed * 57 * 57; n = (n << 13) ^ n; - return (1 - (NOISE_DATATYPE)((n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824); + return (1 - static_cast((n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824); // returns a float number in the range of [-1, 1] } @@ -209,7 +209,8 @@ NOISE_DATATYPE cNoise::IntNoise3D(int a_X, int a_Y, int a_Z) const { int n = a_X + a_Y * 57 + a_Z * 57 * 57 + m_Seed * 57 * 57 * 57; n = (n << 13) ^ n; - return ((NOISE_DATATYPE)1 - (NOISE_DATATYPE)((n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0f); + return (static_cast(1) - + static_cast((n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0f); // returns a float number in the range of [-1, 1] } @@ -265,8 +266,8 @@ NOISE_DATATYPE cNoise::CubicInterpolate(NOISE_DATATYPE a_A, NOISE_DATATYPE a_B, NOISE_DATATYPE cNoise::CosineInterpolate(NOISE_DATATYPE a_A, NOISE_DATATYPE a_B, NOISE_DATATYPE a_Pct) { - const NOISE_DATATYPE ft = a_Pct * (NOISE_DATATYPE)3.1415927; - const NOISE_DATATYPE f = (NOISE_DATATYPE)((NOISE_DATATYPE)(1 - cos(ft)) * (NOISE_DATATYPE)0.5); + const NOISE_DATATYPE ft = a_Pct * static_cast(3.1415927); + const NOISE_DATATYPE f = static_cast(static_cast(1 - cos(ft)) * static_cast(0.5)); return a_A * (1 - f) + a_B * f; } diff --git a/src/OSSupport/CMakeLists.txt b/src/OSSupport/CMakeLists.txt index 981c4c5b0..d1db0373d 100644 --- a/src/OSSupport/CMakeLists.txt +++ b/src/OSSupport/CMakeLists.txt @@ -42,7 +42,7 @@ SET (HDRS ) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - add_flags_cxx("-Wno-error=global-constructors") + add_flags_cxx("-Wno-error=global-constructors -Wno-error=old-style-cast") endif() if(NOT MSVC) diff --git a/src/OSSupport/GZipFile.h b/src/OSSupport/GZipFile.h index dfb4e8c31..286c98aff 100644 --- a/src/OSSupport/GZipFile.h +++ b/src/OSSupport/GZipFile.h @@ -37,7 +37,7 @@ public: int ReadRestOfFile(AString & a_Contents); /// Writes a_Contents into file, compressing it along the way. Returns true if successful. Multiple writes are supported. - bool Write(const AString & a_Contents) { return Write(a_Contents.data(), (int)(a_Contents.size())); } + bool Write(const AString & a_Contents) { return Write(a_Contents.data(), static_cast(a_Contents.size())); } bool Write(const char * a_Data, int a_Size); diff --git a/src/PolarSSL++/BufferedSslContext.cpp b/src/PolarSSL++/BufferedSslContext.cpp index 9f7caeb8a..c8d4736f7 100644 --- a/src/PolarSSL++/BufferedSslContext.cpp +++ b/src/PolarSSL++/BufferedSslContext.cpp @@ -66,7 +66,7 @@ int cBufferedSslContext::ReceiveEncrypted(unsigned char * a_Buffer, size_t a_Num return POLARSSL_ERR_NET_RECV_FAILED; } m_IncomingData.CommitRead(); - return (int)NumBytes; + return static_cast(NumBytes); } @@ -81,11 +81,11 @@ int cBufferedSslContext::SendEncrypted(const unsigned char * a_Buffer, size_t a_ { return POLARSSL_ERR_NET_WANT_WRITE; } - if (!m_OutgoingData.Write((const char *)a_Buffer, a_NumBytes)) + if (!m_OutgoingData.Write(reinterpret_cast(a_Buffer), a_NumBytes)) { return POLARSSL_ERR_NET_SEND_FAILED; } - return (int)a_NumBytes; + return static_cast(a_NumBytes); } diff --git a/src/PolarSSL++/CMakeLists.txt b/src/PolarSSL++/CMakeLists.txt index b11d16e33..fddb37501 100644 --- a/src/PolarSSL++/CMakeLists.txt +++ b/src/PolarSSL++/CMakeLists.txt @@ -33,6 +33,10 @@ set(HDRS X509Cert.h ) +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set_source_files_properties(RsaPrivateKey.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") +endif() + if(NOT MSVC) add_library(PolarSSL++ ${SRCS} ${HDRS}) diff --git a/src/PolarSSL++/CryptoKey.cpp b/src/PolarSSL++/CryptoKey.cpp index 9354ddf50..cc4eefdfe 100644 --- a/src/PolarSSL++/CryptoKey.cpp +++ b/src/PolarSSL++/CryptoKey.cpp @@ -77,7 +77,7 @@ int cCryptoKey::Decrypt(const Byte * a_EncryptedData, size_t a_EncryptedLength, { return res; } - return (int)DecryptedLen; + return static_cast(DecryptedLen); } @@ -97,7 +97,7 @@ int cCryptoKey::Encrypt(const Byte * a_PlainData, size_t a_PlainLength, Byte * a { return res; } - return (int)EncryptedLength; + return static_cast(EncryptedLength); } @@ -109,7 +109,7 @@ int cCryptoKey::ParsePublic(const void * a_Data, size_t a_NumBytes) { ASSERT(!IsValid()); // Cannot parse a second key - return pk_parse_public_key(&m_Pk, (const unsigned char *)a_Data, a_NumBytes); + return pk_parse_public_key(&m_Pk, reinterpret_cast(a_Data), a_NumBytes); } @@ -123,14 +123,14 @@ int cCryptoKey::ParsePrivate(const void * a_Data, size_t a_NumBytes, const AStri if (a_Password.empty()) { - return pk_parse_key(&m_Pk, (const unsigned char *)a_Data, a_NumBytes, nullptr, 0); + return pk_parse_key(&m_Pk, reinterpret_cast(a_Data), a_NumBytes, nullptr, 0); } else { return pk_parse_key( &m_Pk, - (const unsigned char *)a_Data, a_NumBytes, - (const unsigned char *)a_Password.c_str(), a_Password.size() + reinterpret_cast(a_Data), a_NumBytes, + reinterpret_cast(a_Password.c_str()), a_Password.size() ); } } diff --git a/src/PolarSSL++/CtrDrbgContext.cpp b/src/PolarSSL++/CtrDrbgContext.cpp index 86e6d1ca5..25c2987b1 100644 --- a/src/PolarSSL++/CtrDrbgContext.cpp +++ b/src/PolarSSL++/CtrDrbgContext.cpp @@ -39,7 +39,7 @@ int cCtrDrbgContext::Initialize(const void * a_Custom, size_t a_CustomSize) return 0; } - int res = ctr_drbg_init(&m_CtrDrbg, entropy_func, &(m_EntropyContext->m_Entropy), (const unsigned char *)a_Custom, a_CustomSize); + int res = ctr_drbg_init(&m_CtrDrbg, entropy_func, &(m_EntropyContext->m_Entropy), reinterpret_cast(a_Custom), a_CustomSize); m_IsValid = (res == 0); return res; } diff --git a/src/PolarSSL++/SslContext.cpp b/src/PolarSSL++/SslContext.cpp index 5ac4bc227..1409405bc 100644 --- a/src/PolarSSL++/SslContext.cpp +++ b/src/PolarSSL++/SslContext.cpp @@ -172,7 +172,7 @@ int cSslContext::WritePlain(const void * a_Data, size_t a_NumBytes) } } - return ssl_write(&m_Ssl, (const unsigned char *)a_Data, a_NumBytes); + return ssl_write(&m_Ssl, reinterpret_cast(a_Data), a_NumBytes); } @@ -191,7 +191,7 @@ int cSslContext::ReadPlain(void * a_Data, size_t a_MaxBytes) } } - return ssl_read(&m_Ssl, (unsigned char *)a_Data, a_MaxBytes); + return ssl_read(&m_Ssl, reinterpret_cast(a_Data), a_MaxBytes); } diff --git a/src/PolarSSL++/SslContext.h b/src/PolarSSL++/SslContext.h index 6b4f2c1e7..ce6a2e398 100644 --- a/src/PolarSSL++/SslContext.h +++ b/src/PolarSSL++/SslContext.h @@ -127,13 +127,13 @@ protected: /** The callback used by PolarSSL when it wants to read encrypted data. */ static int ReceiveEncrypted(void * a_This, unsigned char * a_Buffer, size_t a_NumBytes) { - return ((cSslContext *)a_This)->ReceiveEncrypted(a_Buffer, a_NumBytes); + return (static_cast(a_This))->ReceiveEncrypted(a_Buffer, a_NumBytes); } /** The callback used by PolarSSL when it wants to write encrypted data. */ static int SendEncrypted(void * a_This, const unsigned char * a_Buffer, size_t a_NumBytes) { - return ((cSslContext *)a_This)->SendEncrypted(a_Buffer, a_NumBytes); + return (static_cast(a_This))->SendEncrypted(a_Buffer, a_NumBytes); } #ifdef _DEBUG diff --git a/src/PolarSSL++/X509Cert.cpp b/src/PolarSSL++/X509Cert.cpp index ecf664855..ed65639a5 100644 --- a/src/PolarSSL++/X509Cert.cpp +++ b/src/PolarSSL++/X509Cert.cpp @@ -30,7 +30,7 @@ cX509Cert::~cX509Cert() int cX509Cert::Parse(const void * a_CertContents, size_t a_Size) { - return x509_crt_parse(&m_Cert, (const unsigned char *)a_CertContents, a_Size); + return x509_crt_parse(&m_Cert, reinterpret_cast(a_CertContents), a_Size); } diff --git a/src/Protocol/CMakeLists.txt b/src/Protocol/CMakeLists.txt index f6aa6fca5..fdc98b960 100644 --- a/src/Protocol/CMakeLists.txt +++ b/src/Protocol/CMakeLists.txt @@ -26,8 +26,12 @@ SET (HDRS ) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - set_source_files_properties(Protocol18x.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=conversion -Wno-error=switch-enum -Wno-error=switch") - set_source_files_properties(Protocol17x.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum") + set_source_files_properties(ChunkDataSerializer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") + set_source_files_properties(MojangAPI.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") + set_source_files_properties(Packetizer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") + set_source_files_properties(Protocol18x.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=conversion -Wno-error=switch-enum -Wno-error=switch -Wno-error=old-style-cast") + set_source_files_properties(Protocol17x.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum -Wno-error=old-style-cast") + set_source_files_properties(ProtocolRecognizer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") endif() if (NOT MSVC) diff --git a/src/Scoreboard.cpp b/src/Scoreboard.cpp index a4a4c3391..9f251ab94 100644 --- a/src/Scoreboard.cpp +++ b/src/Scoreboard.cpp @@ -276,7 +276,7 @@ size_t cTeam::GetNumPlayers(void) const cScoreboard::cScoreboard(cWorld * a_World) : m_World(a_World) { - for (int i = 0; i < (int) dsCount; ++i) + for (int i = 0; i < static_cast(dsCount); ++i) { m_Display[i] = nullptr; } @@ -323,11 +323,11 @@ bool cScoreboard::RemoveObjective(const AString & a_Name) ASSERT(m_World != nullptr); m_World->BroadcastScoreboardObjective(it->second.GetName(), it->second.GetDisplayName(), 1); - for (unsigned int i = 0; i < (unsigned int) dsCount; ++i) + for (unsigned int i = 0; i < static_cast(dsCount); ++i) { if (m_Display[i] == &it->second) { - SetDisplay(nullptr, (eDisplaySlot) i); + SetDisplay(nullptr, static_cast(i)); } } @@ -557,14 +557,14 @@ void cScoreboard::SendTo(cClientHandle & a_Client) it->second.SendTo(a_Client); } - for (int i = 0; i < (int) dsCount; ++i) + for (int i = 0; i < static_cast(dsCount); ++i) { // Avoid race conditions cObjective * Objective = m_Display[i]; if (Objective) { - a_Client.SendDisplayObjective(Objective->GetName(), (eDisplaySlot) i); + a_Client.SendDisplayObjective(Objective->GetName(), static_cast(i)); } } } diff --git a/src/Simulator/CMakeLists.txt b/src/Simulator/CMakeLists.txt index 8e1344ff0..5ac39bb0f 100644 --- a/src/Simulator/CMakeLists.txt +++ b/src/Simulator/CMakeLists.txt @@ -35,7 +35,7 @@ SET (HDRS if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") set_source_files_properties(FireSimulator.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion") set_source_files_properties(FluidSimulator.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=shadow") - set_source_files_properties(IncrementalRedstoneSimulator.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion") + set_source_files_properties(IncrementalRedstoneSimulator.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion -Wno-error=old-style-cast") endif() if(NOT MSVC) diff --git a/src/Simulator/DelayedFluidSimulator.cpp b/src/Simulator/DelayedFluidSimulator.cpp index 0973962b6..cbf70bf05 100644 --- a/src/Simulator/DelayedFluidSimulator.cpp +++ b/src/Simulator/DelayedFluidSimulator.cpp @@ -100,7 +100,7 @@ void cDelayedFluidSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, } void * ChunkDataRaw = (m_FluidBlock == E_BLOCK_WATER) ? a_Chunk->GetWaterSimulatorData() : a_Chunk->GetLavaSimulatorData(); - cDelayedFluidSimulatorChunkData * ChunkData = (cDelayedFluidSimulatorChunkData *)ChunkDataRaw; + cDelayedFluidSimulatorChunkData * ChunkData = static_cast(ChunkDataRaw); cDelayedFluidSimulatorChunkData::cSlot & Slot = ChunkData->m_Slots[m_AddSlotNum]; // Add, if not already present: @@ -133,7 +133,7 @@ void cDelayedFluidSimulator::Simulate(float a_Dt) void cDelayedFluidSimulator::SimulateChunk(std::chrono::milliseconds a_Dt, int a_ChunkX, int a_ChunkZ, cChunk * a_Chunk) { void * ChunkDataRaw = (m_FluidBlock == E_BLOCK_WATER) ? a_Chunk->GetWaterSimulatorData() : a_Chunk->GetLavaSimulatorData(); - cDelayedFluidSimulatorChunkData * ChunkData = (cDelayedFluidSimulatorChunkData *)ChunkDataRaw; + cDelayedFluidSimulatorChunkData * ChunkData = static_cast(ChunkDataRaw); cDelayedFluidSimulatorChunkData::cSlot & Slot = ChunkData->m_Slots[m_SimSlotNum]; // Simulate all the blocks in the scheduled slot: @@ -148,7 +148,7 @@ void cDelayedFluidSimulator::SimulateChunk(std::chrono::milliseconds a_Dt, int a { SimulateBlock(a_Chunk, itr->x, itr->y, itr->z); } - m_TotalBlocks -= (int)Blocks.size(); + m_TotalBlocks -= static_cast(Blocks.size()); Blocks.clear(); } } diff --git a/src/Simulator/FloodyFluidSimulator.cpp b/src/Simulator/FloodyFluidSimulator.cpp index a9481edb0..e7082d9ab 100644 --- a/src/Simulator/FloodyFluidSimulator.cpp +++ b/src/Simulator/FloodyFluidSimulator.cpp @@ -255,7 +255,12 @@ void cFloodyFluidSimulator::SpreadToNeighbor(cChunk * a_NearChunk, int a_RelX, i ); a_NearChunk->SetBlock(a_RelX, a_RelY, a_RelZ, NewBlock, 0); - a_NearChunk->BroadcastSoundEffect("random.fizz", (double)BlockX, (double)a_RelY, (double)BlockZ, 0.5f, 1.5f); + a_NearChunk->BroadcastSoundEffect( + "random.fizz", + static_cast(BlockX), + static_cast(a_RelY), + static_cast(BlockZ), + 0.5f, 1.5f); return; } } @@ -270,7 +275,12 @@ void cFloodyFluidSimulator::SpreadToNeighbor(cChunk * a_NearChunk, int a_RelX, i ); a_NearChunk->SetBlock(a_RelX, a_RelY, a_RelZ, NewBlock, 0); - a_NearChunk->BroadcastSoundEffect("random.fizz", (double)BlockX, (double)a_RelY, (double)BlockZ, 0.5f, 1.5f); + a_NearChunk->BroadcastSoundEffect( + "random.fizz", + static_cast(BlockX), + static_cast(a_RelY), + static_cast(BlockZ), + 0.5f, 1.5f); return; } } diff --git a/src/Simulator/SandSimulator.cpp b/src/Simulator/SandSimulator.cpp index 497f81999..e11bc714a 100644 --- a/src/Simulator/SandSimulator.cpp +++ b/src/Simulator/SandSimulator.cpp @@ -65,7 +65,7 @@ void cSandSimulator::SimulateChunk(std::chrono::milliseconds a_Dt, int a_ChunkX, a_Chunk->SetBlock(itr->x, itr->y, itr->z, E_BLOCK_AIR, 0); } } - m_TotalBlocks -= (int)ChunkData.size(); + m_TotalBlocks -= static_cast(ChunkData.size()); ChunkData.clear(); } @@ -265,8 +265,12 @@ void cSandSimulator::FinishFalling( // Create a pickup instead: cItems Pickups; - Pickups.Add((ENUM_ITEM_ID)a_FallingBlockType, 1, a_FallingBlockMeta); - a_World->SpawnItemPickups(Pickups, (double)a_BlockX + 0.5, (double)a_BlockY + 0.5, (double)a_BlockZ + 0.5); + Pickups.Add(static_cast(a_FallingBlockType), 1, a_FallingBlockMeta); + a_World->SpawnItemPickups( + Pickups, + static_cast(a_BlockX) + 0.5, + static_cast(a_BlockY) + 0.5, + static_cast(a_BlockZ) + 0.5); } diff --git a/src/Simulator/VaporizeFluidSimulator.cpp b/src/Simulator/VaporizeFluidSimulator.cpp index 119742346..7bca6c580 100644 --- a/src/Simulator/VaporizeFluidSimulator.cpp +++ b/src/Simulator/VaporizeFluidSimulator.cpp @@ -35,7 +35,12 @@ void cVaporizeFluidSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, ) { a_Chunk->SetBlock(RelX, a_BlockY, RelZ, E_BLOCK_AIR, 0); - a_Chunk->BroadcastSoundEffect("random.fizz", (double)a_BlockX, (double)a_BlockY, (double)a_BlockZ, 1.0f, 0.6f); + a_Chunk->BroadcastSoundEffect( + "random.fizz", + static_cast(a_BlockX), + static_cast(a_BlockY), + static_cast(a_BlockZ), + 1.0f, 0.6f); } } diff --git a/src/Statistics.cpp b/src/Statistics.cpp index e0c0dd925..fcaf3e7bc 100644 --- a/src/Statistics.cpp +++ b/src/Statistics.cpp @@ -185,7 +185,7 @@ StatValue cStatManager::AddValue(const eStatistic a_Stat, const StatValue a_Delt void cStatManager::Reset(void) { - for (unsigned int i = 0; i < (unsigned int)statCount; ++i) + for (unsigned int i = 0; i < static_cast(statCount); ++i) { m_MainStats[i] = 0; } diff --git a/src/UI/CMakeLists.txt b/src/UI/CMakeLists.txt index e01a09bb8..178498479 100644 --- a/src/UI/CMakeLists.txt +++ b/src/UI/CMakeLists.txt @@ -35,8 +35,9 @@ SET (HDRS WindowOwner.h) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - set_source_files_properties(SlotArea.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion -Wno-error=switch-enum -Wno-error=sign-conversion") - set_source_files_properties(Window.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion -Wno-error=switch-enum -Wno-error=sign-conversion") + set_source_files_properties(SlotArea.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion -Wno-error=switch-enum -Wno-error=sign-conversion -Wno-error=old-style-cast") + set_source_files_properties(Window.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion -Wno-error=switch-enum -Wno-error=sign-conversion -Wno-error=old-style-cast") + set_source_files_properties(ChestWindow.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") endif() if(NOT MSVC) diff --git a/src/UI/EnchantingWindow.cpp b/src/UI/EnchantingWindow.cpp index fe21ee83d..4c5bcbfd5 100644 --- a/src/UI/EnchantingWindow.cpp +++ b/src/UI/EnchantingWindow.cpp @@ -30,7 +30,7 @@ cEnchantingWindow::cEnchantingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) : void cEnchantingWindow::SetProperty(short a_Property, short a_Value, cPlayer & a_Player) { - if ((a_Property < 0) || ((size_t)a_Property >= ARRAYCOUNT(m_PropertyValue))) + if ((a_Property < 0) || (static_cast(a_Property) >= ARRAYCOUNT(m_PropertyValue))) { ASSERT(!"a_Property is invalid"); return; @@ -47,7 +47,7 @@ void cEnchantingWindow::SetProperty(short a_Property, short a_Value, cPlayer & a void cEnchantingWindow::SetProperty(short a_Property, short a_Value) { - if ((a_Property < 0) || ((size_t)a_Property >= ARRAYCOUNT(m_PropertyValue))) + if ((a_Property < 0) || (static_cast(a_Property) >= ARRAYCOUNT(m_PropertyValue))) { ASSERT(!"a_Property is invalid"); return; @@ -63,7 +63,7 @@ void cEnchantingWindow::SetProperty(short a_Property, short a_Value) short cEnchantingWindow::GetPropertyValue(short a_Property) { - if ((a_Property < 0) || ((size_t)a_Property >= ARRAYCOUNT(m_PropertyValue))) + if ((a_Property < 0) || (static_cast(a_Property) >= ARRAYCOUNT(m_PropertyValue))) { ASSERT(!"a_Property is invalid"); return 0; diff --git a/src/UI/EnderChestWindow.cpp b/src/UI/EnderChestWindow.cpp index a5484468f..9a4918aa4 100644 --- a/src/UI/EnderChestWindow.cpp +++ b/src/UI/EnderChestWindow.cpp @@ -24,7 +24,12 @@ cEnderChestWindow::cEnderChestWindow(cEnderChestEntity * a_EnderChest) : m_SlotAreas.push_back(new cSlotAreaHotBar(*this)); // Play the opening sound: - m_World->BroadcastSoundEffect("random.chestopen", (double)m_BlockX, (double)m_BlockY, (double)m_BlockZ, 1, 1); + m_World->BroadcastSoundEffect( + "random.chestopen", + static_cast(m_BlockX), + static_cast(m_BlockY), + static_cast(m_BlockZ), + 1, 1); // Send out the chest-open packet: m_World->BroadcastBlockAction(m_BlockX, m_BlockY, m_BlockZ, 1, 1, E_BLOCK_ENDER_CHEST); @@ -40,7 +45,12 @@ cEnderChestWindow::~cEnderChestWindow() m_World->BroadcastBlockAction(m_BlockX, m_BlockY, m_BlockZ, 1, 0, E_BLOCK_ENDER_CHEST); // Play the closing sound - m_World->BroadcastSoundEffect("random.chestclosed", (double)m_BlockX, (double)m_BlockY, (double)m_BlockZ, 1, 1); + m_World->BroadcastSoundEffect( + "random.chestclosed", + static_cast(m_BlockX), + static_cast(m_BlockY), + static_cast(m_BlockZ), + 1, 1); } diff --git a/src/WebAdmin.cpp b/src/WebAdmin.cpp index 1cb4463e1..1295d90f7 100644 --- a/src/WebAdmin.cpp +++ b/src/WebAdmin.cpp @@ -321,7 +321,7 @@ void cWebAdmin::HandleWebadminRequest(cHTTPConnection & a_Connection, cHTTPReque int MemUsageKiB = cRoot::GetPhysicalRAMUsage(); if (MemUsageKiB > 0) { - ReplaceString(Template, "{MEM}", Printf("%.02f", (double)MemUsageKiB / 1024)); + ReplaceString(Template, "{MEM}", Printf("%.02f", static_cast(MemUsageKiB) / 1024)); ReplaceString(Template, "{MEMKIB}", Printf("%d", MemUsageKiB)); } else @@ -648,7 +648,7 @@ void cWebAdmin::OnRequestBegun(cHTTPConnection & a_Connection, cHTTPRequest & a_ void cWebAdmin::OnRequestBody(cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, size_t a_Size) { UNUSED(a_Connection); - cRequestData * Data = (cRequestData *)(a_Request.GetUserData()); + cRequestData * Data = static_cast(a_Request.GetUserData()); if (Data == nullptr) { return; @@ -681,7 +681,7 @@ void cWebAdmin::OnRequestFinished(cHTTPConnection & a_Connection, cHTTPRequest & } // Delete any request data assigned to the request: - cRequestData * Data = (cRequestData *)(a_Request.GetUserData()); + cRequestData * Data = static_cast(a_Request.GetUserData()); delete Data; Data = nullptr; } diff --git a/src/World.h b/src/World.h index 8f3f07dc2..d1ca01989 100644 --- a/src/World.h +++ b/src/World.h @@ -817,7 +817,7 @@ public: UInt32 CreateProjectile(double a_PosX, double a_PosY, double a_PosZ, cProjectileEntity::eKind a_Kind, cEntity * a_Creator, const cItem * a_Item, const Vector3d * a_Speed = nullptr); // tolua_export /** Returns a random number from the m_TickRand in range [0 .. a_Range]. To be used only in the tick thread! */ - int GetTickRandomNumber(int a_Range) { return (int)(m_TickRand.randInt(a_Range)); } + int GetTickRandomNumber(int a_Range) { return static_cast(m_TickRand.randInt(a_Range)); } /** Appends all usernames starting with a_Text (case-insensitive) into Results */ void TabCompleteUserName(const AString & a_Text, AStringVector & a_Results); diff --git a/src/WorldStorage/CMakeLists.txt b/src/WorldStorage/CMakeLists.txt index b511fc412..a7b8e7bf9 100644 --- a/src/WorldStorage/CMakeLists.txt +++ b/src/WorldStorage/CMakeLists.txt @@ -29,11 +29,15 @@ SET (HDRS WorldStorage.h) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - set_source_files_properties(FastNBT.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion") - set_source_files_properties(FireworksSerializer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum") - set_source_files_properties(NBTChunkSerializer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum -Wno-error=sign-conversion -Wno-error=conversion") - set_source_files_properties(SchematicFileSerializer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=shadow -Wno-error=conversion") - set_source_files_properties(WSSAnvil.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=shorten-64-to-32 -Wno-error=switch -Wno-error=switch-enum -Wno-error=conversion") + set_source_files_properties(EnchantmentSerializer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") + set_source_files_properties(FastNBT.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=old-style-cast") + set_source_files_properties(FireworksSerializer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum -Wno-error=old-style-cast") + set_source_files_properties(MapSerializer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") + set_source_files_properties(NBTChunkSerializer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum -Wno-error=sign-conversion -Wno-error=conversion -Wno-error=old-style-cast") + set_source_files_properties(SchematicFileSerializer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=shadow -Wno-error=conversion -Wno-error=old-style-cast") + set_source_files_properties(ScoreboardSerializer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") + set_source_files_properties(WSSAnvil.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=shorten-64-to-32 -Wno-error=switch -Wno-error=switch-enum -Wno-error=conversion -Wno-error=old-style-cast") + set_source_files_properties(WorldStorage.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") endif() if(NOT MSVC) diff --git a/src/WorldStorage/StatSerializer.cpp b/src/WorldStorage/StatSerializer.cpp index 99a702c39..29f9b3cd6 100644 --- a/src/WorldStorage/StatSerializer.cpp +++ b/src/WorldStorage/StatSerializer.cpp @@ -79,13 +79,13 @@ bool cStatSerializer::Save(void) void cStatSerializer::SaveStatToJSON(Json::Value & a_Out) { - for (unsigned int i = 0; i < (unsigned int)statCount; ++i) + for (unsigned int i = 0; i < static_cast(statCount); ++i) { - StatValue Value = m_Manager->GetValue((eStatistic) i); + StatValue Value = m_Manager->GetValue(static_cast(i)); if (Value != 0) { - const AString & StatName = cStatInfo::GetName((eStatistic) i); + const AString & StatName = cStatInfo::GetName(static_cast(i)); a_Out[StatName] = Value; } -- cgit v1.2.3 From 7a8025eacd28388b70a180f0b3348b09c4f14cf0 Mon Sep 17 00:00:00 2001 From: tycho Date: Sun, 24 May 2015 13:24:34 +0100 Subject: Disable -Werror for warnings in tools. --- Tools/MCADefrag/CMakeLists.txt | 3 ++- Tools/ProtoProxy/CMakeLists.txt | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Tools/MCADefrag/CMakeLists.txt b/Tools/MCADefrag/CMakeLists.txt index a4096791d..17e332d8d 100644 --- a/Tools/MCADefrag/CMakeLists.txt +++ b/Tools/MCADefrag/CMakeLists.txt @@ -12,7 +12,8 @@ set_lib_flags() enable_profile() if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - add_flags_cxx("-Wno-error=sign-conversion -Wno-error=conversion -Wno-error=shorten-64-to-32") + add_flags_cxx("-Wno-error=sign-conversion -Wno-error=conversion -Wno-error=shorten-64-to-32 -Wno-error=keyword-macro") + add_flags_cxx("-Wno-error=old-style-cast") endif() # Set include paths to the used libraries: diff --git a/Tools/ProtoProxy/CMakeLists.txt b/Tools/ProtoProxy/CMakeLists.txt index 1c48d7d93..0d3ef3f3e 100644 --- a/Tools/ProtoProxy/CMakeLists.txt +++ b/Tools/ProtoProxy/CMakeLists.txt @@ -15,7 +15,8 @@ include_directories("../../lib/polarssl/include") include_directories("../../src") if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - add_flags_cxx("-Wno-error=conversion") + add_flags_cxx("-Wno-error=sign-conversion -Wno-error=conversion -Wno-error=shorten-64-to-32 -Wno-error=keyword-macro") + add_flags_cxx("-Wno-error=old-style-cast") endif() function(flatten_files arg1) -- cgit v1.2.3 From 10c9e66aad9a0d994c5c227f5dedec4af19db9b2 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 24 May 2015 13:37:36 +0100 Subject: Fixes #2041 --- src/UI/SlotArea.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index accd44b06..5b58b18b6 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -2154,10 +2154,10 @@ bool cSlotAreaArmor::CanPlaceArmorInSlot(int a_SlotNum, const cItem & a_Item) { switch (a_SlotNum) { - case 0: return ItemCategory::IsHelmet (a_Item.m_ItemType); + case 0: return (ItemCategory::IsHelmet(a_Item.m_ItemType) || (a_Item.m_ItemType == E_BLOCK_PUMPKIN)); case 1: return ItemCategory::IsChestPlate(a_Item.m_ItemType); - case 2: return ItemCategory::IsLeggings (a_Item.m_ItemType); - case 3: return ItemCategory::IsBoots (a_Item.m_ItemType); + case 2: return ItemCategory::IsLeggings(a_Item.m_ItemType); + case 3: return ItemCategory::IsBoots(a_Item.m_ItemType); } return false; } -- cgit v1.2.3 From 95b81b3ef1885f822907ae3f3999ef1cf543e105 Mon Sep 17 00:00:00 2001 From: tycho Date: Sun, 24 May 2015 14:16:05 +0100 Subject: Disable -Werror for warnings in tests. --- src/CMakeLists.txt | 4 +++- src/WorldStorage/CMakeLists.txt | 2 +- tests/ChunkData/CMakeLists.txt | 3 +-- tests/ChunkData/Coordinates.cpp | 12 +----------- tests/Network/CMakeLists.txt | 2 +- 5 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bf14136f2..dba6822c2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -155,11 +155,13 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") set_source_files_properties(BiomeDef.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum") set_source_files_properties(BlockArea.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion") set_source_files_properties(BlockID.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors") - set_source_files_properties(ByteBuffer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=old-style-cast") + set_source_files_properties(BoundingBox.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors -Wno-error=float-equal") + set_source_files_properties(ByteBuffer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=old-style-cast -Wno-error=global-constructors") set_source_files_properties(Chunk.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") set_source_files_properties(ChunkData.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=old-style-cast") set_source_files_properties(ChunkMap.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=shadow -Wno-error=sign-conversion -Wno-error=old-style-cast") set_source_files_properties(ClientHandle.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion -Wno-error=sign-conversion -Wno-error=global-constructors -Wno-error=old-style-cast") + set_source_files_properties(CompositeChat.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors -Wno-error=missing-variable-declarations") set_source_files_properties(Enchantments.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") set_source_files_properties(IniFile.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=old-style-cast") set_source_files_properties(Inventory.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion") diff --git a/src/WorldStorage/CMakeLists.txt b/src/WorldStorage/CMakeLists.txt index a7b8e7bf9..074958191 100644 --- a/src/WorldStorage/CMakeLists.txt +++ b/src/WorldStorage/CMakeLists.txt @@ -34,7 +34,7 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") set_source_files_properties(FireworksSerializer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum -Wno-error=old-style-cast") set_source_files_properties(MapSerializer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") set_source_files_properties(NBTChunkSerializer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum -Wno-error=sign-conversion -Wno-error=conversion -Wno-error=old-style-cast") - set_source_files_properties(SchematicFileSerializer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=shadow -Wno-error=conversion -Wno-error=old-style-cast") + set_source_files_properties(SchematicFileSerializer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=shadow -Wno-error=conversion -Wno-error=old-style-cast -Wno-error=global-constructors") set_source_files_properties(ScoreboardSerializer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") set_source_files_properties(WSSAnvil.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=shorten-64-to-32 -Wno-error=switch -Wno-error=switch-enum -Wno-error=conversion -Wno-error=old-style-cast") set_source_files_properties(WorldStorage.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") diff --git a/tests/ChunkData/CMakeLists.txt b/tests/ChunkData/CMakeLists.txt index 4079b7d93..bd2d6d9b4 100644 --- a/tests/ChunkData/CMakeLists.txt +++ b/tests/ChunkData/CMakeLists.txt @@ -3,9 +3,8 @@ cmake_minimum_required (VERSION 2.6) enable_testing() include_directories(${CMAKE_SOURCE_DIR}/src/) - - if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + add_flags_cxx("-Wno-error=old-style-cast") set_source_files_properties(${CMAKE_SOURCE_DIR}/src/ChunkData.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion") set_source_files_properties(${CMAKE_SOURCE_DIR}/src/StringUtils.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion") endif() diff --git a/tests/ChunkData/Coordinates.cpp b/tests/ChunkData/Coordinates.cpp index b3c66dde5..de6686243 100644 --- a/tests/ChunkData/Coordinates.cpp +++ b/tests/ChunkData/Coordinates.cpp @@ -8,7 +8,7 @@ int main(int argc, char** argv) { class cMockAllocationPool : public cAllocationPool - { + { virtual cChunkData::sChunkSection * Allocate() { return new cChunkData::sChunkSection(); @@ -138,17 +138,7 @@ int main(int argc, char** argv) cChunkData buffer(Pool); buffer.SetBlock(0, 0, 0, 0x42); cChunkData copy(Pool); - #if __cplusplus < 201103L - copy = buffer; - #else copy = std::move(buffer); - #endif - testassert(copy.GetBlock(0, 0, 0) == 0x42); - #if __cplusplus < 201103L - copy = copy; - #else - copy = std::move(copy); - #endif testassert(copy.GetBlock(0, 0, 0) == 0x42); } diff --git a/tests/Network/CMakeLists.txt b/tests/Network/CMakeLists.txt index 7412b16ad..9ba5801f4 100644 --- a/tests/Network/CMakeLists.txt +++ b/tests/Network/CMakeLists.txt @@ -42,7 +42,7 @@ if (MSVC) endif() if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - add_flags_cxx("-Wno-error=conversion") + add_flags_cxx("-Wno-error=conversion -Wno-error=old-style-cast -Wno-error=inconsistent-missing-override") endif() # Define individual tests: -- cgit v1.2.3 From 76a3165f09e729c07cc64b085ec320cbeb206d59 Mon Sep 17 00:00:00 2001 From: tycho Date: Sun, 24 May 2015 14:58:24 +0100 Subject: Fix comments --- src/Bindings/ManualBindings_Network.cpp | 2 +- src/Defines.h | 18 ++++-- src/Generating/BioGen.cpp | 4 +- src/Generating/ChunkDesc.h | 2 +- src/Generating/HeiGen.cpp | 2 +- src/Generating/ProtIntGen.h | 108 ++++++++++++++++---------------- 6 files changed, 73 insertions(+), 63 deletions(-) diff --git a/src/Bindings/ManualBindings_Network.cpp b/src/Bindings/ManualBindings_Network.cpp index 7d6ff95a7..b5fb5b046 100644 --- a/src/Bindings/ManualBindings_Network.cpp +++ b/src/Bindings/ManualBindings_Network.cpp @@ -104,7 +104,7 @@ static int tolua_cNetwork_CreateUDPEndpoint(lua_State * L) UInt16 Port; // Check validity: - if (S.GetStackValues(2, Port)) + if (!S.GetStackValues(2, Port)) { LOGWARNING("cNetwork:CreateUDPEndpoint() called with invalid port, failing the request."); S.Push(false); diff --git a/src/Defines.h b/src/Defines.h index 71288b430..67d29f7a9 100644 --- a/src/Defines.h +++ b/src/Defines.h @@ -241,7 +241,9 @@ inline eBlockFace MirrorBlockFaceY(eBlockFace a_BlockFace) case BLOCK_FACE_NONE: case BLOCK_FACE_YM: case BLOCK_FACE_YP: + { return a_BlockFace; + }; } } @@ -254,14 +256,20 @@ inline eBlockFace RotateBlockFaceCCW(eBlockFace a_BlockFace) { switch (a_BlockFace) { - case BLOCK_FACE_XM: return BLOCK_FACE_ZP; - case BLOCK_FACE_XP: return BLOCK_FACE_ZM; - case BLOCK_FACE_ZM: return BLOCK_FACE_XM; - case BLOCK_FACE_ZP: return BLOCK_FACE_XP; + case BLOCK_FACE_XM: + return BLOCK_FACE_ZP; + case BLOCK_FACE_XP: + return BLOCK_FACE_ZM; + case BLOCK_FACE_ZM: + return BLOCK_FACE_XM; + case BLOCK_FACE_ZP: + return BLOCK_FACE_XP; case BLOCK_FACE_NONE: case BLOCK_FACE_YM: case BLOCK_FACE_YP: + { return a_BlockFace; + } } } @@ -280,7 +288,9 @@ inline eBlockFace RotateBlockFaceCW(eBlockFace a_BlockFace) case BLOCK_FACE_NONE: case BLOCK_FACE_YM: case BLOCK_FACE_YP: + { return a_BlockFace; + }; } } diff --git a/src/Generating/BioGen.cpp b/src/Generating/BioGen.cpp index 2c6af27a4..eb9129c60 100644 --- a/src/Generating/BioGen.cpp +++ b/src/Generating/BioGen.cpp @@ -60,7 +60,7 @@ cBioGenCache::cBioGenCache(cBiomeGenPtr a_BioGenToCache, size_t a_CacheSize) : { for (size_t i = 0; i < m_CacheSize; i++) { - m_CacheOrder[i] = static_cast(i); + m_CacheOrder[i] = i; m_CacheData[i].m_ChunkX = 0x7fffffff; m_CacheData[i].m_ChunkZ = 0x7fffffff; } @@ -1121,7 +1121,7 @@ public: virtual void GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_Biomes) override { int vals[16 * 16]; - m_Gen->GetInts(static_cast(a_ChunkX * cChunkDef::Width), static_cast(a_ChunkZ * cChunkDef::Width), 16, 16, vals); + m_Gen->GetInts(a_ChunkX * cChunkDef::Width, a_ChunkZ * cChunkDef::Width, 16, 16, vals); for (int z = 0; z < cChunkDef::Width; z++) { for (int x = 0; x < cChunkDef::Width; x++) diff --git a/src/Generating/ChunkDesc.h b/src/Generating/ChunkDesc.h index 672ed99c0..1033242f8 100644 --- a/src/Generating/ChunkDesc.h +++ b/src/Generating/ChunkDesc.h @@ -66,7 +66,7 @@ public: // These operate on the heightmap, so they could get out of sync with the data // Use UpdateHeightmap() to re-calculate heightmap from the block data void SetHeight(int a_RelX, int a_RelZ, HEIGHTTYPE a_Height); - HEIGHTTYPE GetHeight(int a_RelX, int a_RelZ); + HEIGHTTYPE GetHeight(int a_RelX, int a_RelZ); // tolua_end diff --git a/src/Generating/HeiGen.cpp b/src/Generating/HeiGen.cpp index 6aa52c4a5..aa1c1893b 100644 --- a/src/Generating/HeiGen.cpp +++ b/src/Generating/HeiGen.cpp @@ -58,7 +58,7 @@ public: virtual void GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMap & a_HeightMap) override { int heights[cChunkDef::Width * cChunkDef::Width]; - m_Gen->GetInts(static_cast(a_ChunkX * cChunkDef::Width), static_cast(a_ChunkZ * cChunkDef::Width), static_cast(cChunkDef::Width), static_cast(cChunkDef::Width), heights); + m_Gen->GetInts(a_ChunkX * cChunkDef::Width, a_ChunkZ * cChunkDef::Width, static_cast(cChunkDef::Width), static_cast(cChunkDef::Width), heights); for (size_t i = 0; i < ARRAYCOUNT(heights); i++) { a_HeightMap[i] = static_cast(std::max(std::min(60 + heights[i], cChunkDef::Height - 60), 40)); diff --git a/src/Generating/ProtIntGen.h b/src/Generating/ProtIntGen.h index a7625731a..c0c7102d2 100644 --- a/src/Generating/ProtIntGen.h +++ b/src/Generating/ProtIntGen.h @@ -47,7 +47,7 @@ public: virtual ~cProtIntGen() {} /** Generates the array of specified size into a_Values, based on given min coords. */ - virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) = 0; + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) = 0; }; @@ -109,14 +109,14 @@ public: } - virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override { for (size_t z = 0; z < a_SizeZ; z++) { - size_t BaseZ = a_MinZ + z; + int BaseZ = a_MinZ + static_cast(z); for (size_t x = 0; x < a_SizeX; x++) { - a_Values[x + a_SizeX * z] = (super::m_Noise.IntNoise2DInt(static_cast(a_MinX + x), static_cast(BaseZ)) / 7) % m_Range; + a_Values[x + a_SizeX * z] = (super::m_Noise.IntNoise2DInt(a_MinX + static_cast(x), BaseZ) / 7) % m_Range; } } // for z } @@ -146,22 +146,22 @@ public: } - virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override { for (size_t z = 0; z < a_SizeZ; z++) { - size_t BaseZ = a_MinZ + z; + int BaseZ = a_MinZ + static_cast(z); for (size_t x = 0; x < a_SizeX; x++) { - int rnd = (super::m_Noise.IntNoise2DInt(static_cast(a_MinX + x), static_cast(BaseZ)) / 7); + int rnd = (super::m_Noise.IntNoise2DInt(a_MinX + static_cast(x), BaseZ) / 7); a_Values[x + a_SizeX * z] = ((rnd % 100) < m_Threshold) ? ((rnd / 101) % bgLandOceanMax + 1) : 0; } } // If the centerpoint of the world is within the area, set it to bgTemperate, always: - if ((a_MinX <= 0) && (a_MinZ <= 0) && (a_MinX + a_SizeX > 0) && (a_MinZ + a_SizeZ > 0)) + if ((a_MinX <= 0) && (a_MinZ <= 0) && (a_MinX + static_cast(a_SizeX) > 0) && (a_MinZ + static_cast(a_SizeZ) > 0)) { - a_Values[-a_MinX - a_MinZ * a_SizeX] = bgTemperate; + a_Values[static_cast(-a_MinX) - static_cast(a_MinZ) * a_SizeX] = bgTemperate; } } @@ -189,11 +189,11 @@ public: } - virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override { // Get the coords for the lower generator: - size_t lowerMinX = a_MinX >> 1; - size_t lowerMinZ = a_MinZ >> 1; + int lowerMinX = a_MinX >> 1; + int lowerMinZ = a_MinZ >> 1; size_t lowerSizeX = a_SizeX / 2 + 2; size_t lowerSizeZ = a_SizeZ / 2 + 2; ASSERT(lowerSizeX * lowerSizeZ <= m_BufferSize); @@ -217,8 +217,8 @@ public: { int ValX1Z0 = lowerData[x + 1 + z * lowerSizeX]; int ValX1Z1 = lowerData[x + 1 + (z + 1) * lowerSizeX]; - int RndX = static_cast(x + lowerMinX) * 2; - int RndZ = static_cast(z + lowerMinZ) * 2; + int RndX = (static_cast(x) + lowerMinX) * 2; + int RndZ = (static_cast(z) + lowerMinZ) * 2; cache[idx] = PrevZ0; cache[idx + lowStepX] = super::chooseRandomOne(RndX, RndZ + 1, PrevZ0, PrevZ1); cache[idx + 1] = super::chooseRandomOne(RndX, RndZ - 1, PrevZ0, ValX1Z0); @@ -259,7 +259,7 @@ public: } - virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override { // Generate the underlying values: size_t lowerSizeX = a_SizeX + 2; @@ -272,7 +272,7 @@ public: // Also get rid of single-pixel irregularities (A-B-A): for (size_t z = 0; z < a_SizeZ; z++) { - size_t NoiseZ = a_MinZ + z; + int NoiseZ = a_MinZ + static_cast(z); for (size_t x = 0; x < a_SizeX; x++) { int val = lowerData[x + 1 + (z + 1) * lowerSizeX]; @@ -283,7 +283,7 @@ public: if ((left == right) && (above == below)) { - if (((super::m_Noise.IntNoise2DInt(static_cast(a_MinX + x), static_cast(NoiseZ)) / 7) % 2) == 0) + if (((super::m_Noise.IntNoise2DInt(a_MinX + static_cast(x), NoiseZ) / 7) % 2) == 0) { val = left; } @@ -331,7 +331,7 @@ public: } - virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override { // Generate the underlying values: size_t lowerSizeX = a_SizeX + 1; @@ -375,7 +375,7 @@ public: } - virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override { // Generate the underlying values: size_t lowerSizeX = a_SizeX + 4; @@ -425,7 +425,7 @@ public: } - virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override { // Generate the underlying values: size_t lowerSizeX = a_SizeX + 3; @@ -476,7 +476,7 @@ public: } - virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override { // Generate the underlying values: m_Underlying->GetInts(a_MinX, a_MinZ, a_SizeX, a_SizeZ, a_Values); @@ -484,12 +484,12 @@ public: // Replace random values: for (size_t z = 0; z < a_SizeZ; z++) { - size_t BaseZ = a_MinZ + z; + int BaseZ = a_MinZ + static_cast(z); for (size_t x = 0; x < a_SizeX; x++) { - if (((super::m_Noise.IntNoise2DInt(static_cast(BaseZ), static_cast(a_MinX + x)) / 13) % 101) < m_ChancePct) + if (((super::m_Noise.IntNoise2DInt(BaseZ, a_MinX + static_cast(x)) / 13) % 101) < m_ChancePct) { - a_Values[x + a_SizeX * z] = m_Min + (super::m_Noise.IntNoise2DInt(static_cast(a_MinX + x), static_cast(BaseZ)) / 7) % m_Range; + a_Values[x + a_SizeX * z] = m_Min + (super::m_Noise.IntNoise2DInt(a_MinX + static_cast(x), BaseZ) / 7) % m_Range; } } // for x } // for z @@ -522,7 +522,7 @@ public: } - virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override { // Generate the underlying values: m_Underlying->GetInts(a_MinX, a_MinZ, a_SizeX, a_SizeZ, a_Values); @@ -530,10 +530,10 @@ public: // Add the random values: for (size_t z = 0; z < a_SizeZ; z++) { - size_t NoiseZ = a_MinZ + z; + int NoiseZ = a_MinZ + static_cast(z); for (size_t x = 0; x < a_SizeX; x++) { - int noiseVal = ((super::m_Noise.IntNoise2DInt(static_cast(a_MinX + x), static_cast(NoiseZ)) / 7) % m_Range) - m_HalfRange; + int noiseVal = ((super::m_Noise.IntNoise2DInt(a_MinX + static_cast(x), NoiseZ) / 7) % m_Range) - m_HalfRange; a_Values[x + z * a_SizeX] += noiseVal; } } @@ -564,7 +564,7 @@ public: } - virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override { // Generate the underlying values: size_t lowerSizeX = a_SizeX + 2; @@ -576,11 +576,11 @@ public: // Average random values: for (size_t z = 0; z < a_SizeZ; z++) { - size_t NoiseZ = a_MinZ + z; + int NoiseZ = a_MinZ + static_cast(z); for (size_t x = 0; x < a_SizeX; x++) { size_t idxLower = x + 1 + lowerSizeX * (z + 1); - if (((super::m_Noise.IntNoise2DInt(static_cast(a_MinX + x), static_cast(NoiseZ)) / 7) % 100) > m_AvgChancePct) + if (((super::m_Noise.IntNoise2DInt(a_MinX + static_cast(x), NoiseZ) / 7) % 100) > m_AvgChancePct) { // Average the 4 neighbors: a_Values[x + z * a_SizeX] = ( @@ -621,7 +621,7 @@ public: } - virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override { // Generate the underlying values: size_t lowerSizeX = a_SizeX + 2; @@ -633,16 +633,16 @@ public: // Average random values: for (size_t z = 0; z < a_SizeZ; z++) { - size_t NoiseZ = a_MinZ + z; + int NoiseZ = a_MinZ + static_cast(z); for (size_t x = 0; x < a_SizeX; x++) { size_t idxLower = x + 1 + lowerSizeX * (z + 1); - if (((super::m_Noise.IntNoise2DInt(static_cast(a_MinX + x), static_cast(NoiseZ)) / 7) % 100) > m_AvgChancePct) + if (((super::m_Noise.IntNoise2DInt(a_MinX + static_cast(x), NoiseZ) / 7) % 100) > m_AvgChancePct) { // Chose a value in between the min and max neighbor: int min = std::min(std::min(lowerData[idxLower - 1], lowerData[idxLower + 1]), std::min(lowerData[idxLower - lowerSizeX], lowerData[idxLower + lowerSizeX])); int max = std::max(std::max(lowerData[idxLower - 1], lowerData[idxLower + 1]), std::max(lowerData[idxLower - lowerSizeX], lowerData[idxLower + lowerSizeX])); - a_Values[x + z * a_SizeX] = min + ((super::m_Noise.IntNoise2DInt(static_cast(a_MinX + x), static_cast(NoiseZ + 10)) / 7) % (max - min + 1)); + a_Values[x + z * a_SizeX] = min + ((super::m_Noise.IntNoise2DInt(a_MinX + static_cast(x), NoiseZ + 10) / 7) % (max - min + 1)); } else { @@ -675,7 +675,7 @@ public: } - virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override { // Map for biome -> its beach: static const int ToBeach[] = @@ -779,7 +779,7 @@ public: } - virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override { m_Underlying->GetInts(a_MinX, a_MinZ, a_SizeX, a_SizeZ, a_Values); for (size_t z = 0; z < a_SizeZ; z++) @@ -788,7 +788,7 @@ public: { if (a_Values[x + z * a_SizeX] == bgOcean) { - int rnd = super::m_Noise.IntNoise2DInt(static_cast(a_MinX + x), static_cast(a_MinZ + z)) / 7; + int rnd = super::m_Noise.IntNoise2DInt(a_MinX + static_cast(x), a_MinZ + static_cast(z)) / 7; if (rnd % 1000 < m_Chance) { a_Values[x + z * a_SizeX] = (rnd / 1003) % bgLandOceanMax; @@ -822,7 +822,7 @@ public: } - virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) { // Generate the underlying biome groups: size_t lowerSizeX = a_SizeX + 2; @@ -920,7 +920,7 @@ public: } - virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override { // Define the per-biome-group biomes: static const int oceanBiomes[] = @@ -1007,7 +1007,7 @@ public: const cBiomesInGroups & Biomes = (val > bgfRare) ? rareBiomesInGroups[(val & (bgfRare - 1)) % ARRAYCOUNT(rareBiomesInGroups)] : biomesInGroups[static_cast(val) % ARRAYCOUNT(biomesInGroups)]; - int rnd = (super::m_Noise.IntNoise2DInt(static_cast(x + a_MinX), static_cast(z + a_MinZ)) / 7); + int rnd = (super::m_Noise.IntNoise2DInt(static_cast(x) + a_MinX, static_cast(z) + a_MinZ) / 7); a_Values[x + IdxZ] = Biomes.Biomes[rnd % Biomes.Count]; } } @@ -1050,7 +1050,7 @@ public: } - virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override { // Generate the underlying values: m_Underlying->GetInts(a_MinX, a_MinZ, a_SizeX, a_SizeZ, a_Values); @@ -1064,7 +1064,7 @@ public: size_t idx = x + idxZ; if (a_Values[idx] == m_From) { - int rnd = super::m_Noise.IntNoise2DInt(static_cast(x + a_MinX), static_cast(z + a_MinZ)) / 7; + int rnd = super::m_Noise.IntNoise2DInt(static_cast(x) + a_MinX, static_cast(z) + a_MinZ) / 7; if (rnd % 1000 < m_Chance) { a_Values[idx] = m_To; @@ -1109,7 +1109,7 @@ public: } - virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override { // Generate the underlying data: ASSERT(a_SizeX * a_SizeZ <= m_BufferSize); @@ -1136,7 +1136,7 @@ public: } // There's a river, change the output to a river or a frozen river, based on the original biome: - if (IsBiomeVeryCold((EMCSBiome)a_Values[idx])) + if (IsBiomeVeryCold(static_cast(a_Values[idx]))) { a_Values[idx] = biFrozenRiver; } @@ -1173,7 +1173,7 @@ public: } - virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override { // Generate the underlying data: size_t lowerSizeX = a_SizeX + 2; @@ -1231,7 +1231,7 @@ public: } - virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override { // Generate the underlying data: size_t lowerSizeX = a_SizeX + 2; @@ -1278,7 +1278,7 @@ public: // If at least 3 ocean neighbors and the chance is right, change: if ( (NumOceanNeighbors >= 3) && - ((super::m_Noise.IntNoise2DInt(static_cast(x + a_MinX), static_cast(z + a_MinZ)) / 7) % 1000 < m_Chance) + ((super::m_Noise.IntNoise2DInt(static_cast(x) + a_MinX, static_cast(z) + a_MinZ) / 7) % 1000 < m_Chance) ) { a_Values[x + z * a_SizeX] = m_ToValue; @@ -1321,7 +1321,7 @@ public: } - virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override { // Generate the underlying data: m_Underlying->GetInts(a_MinX, a_MinZ, a_SizeX, a_SizeZ, a_Values); @@ -1331,7 +1331,7 @@ public: { for (size_t x = 0; x < a_SizeX; x++) { - int rnd = super::m_Noise.IntNoise2DInt(static_cast(x + a_MinX), static_cast(z + a_MinZ)) / 7; + int rnd = super::m_Noise.IntNoise2DInt(static_cast(x) + a_MinX, static_cast(z) + a_MinZ) / 7; if (rnd % 1000 < m_Chance) { a_Values[x + z * a_SizeX] = m_ToValue; @@ -1370,7 +1370,7 @@ public: } - virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override { // Generate the underlying data: m_Underlying->GetInts(a_MinX, a_MinZ, a_SizeX, a_SizeZ, a_Values); @@ -1380,7 +1380,7 @@ public: { for (size_t x = 0; x < a_SizeX; x++) { - int rnd = super::m_Noise.IntNoise2DInt(static_cast(x + a_MinX), static_cast(z + a_MinZ)) / 7; + int rnd = super::m_Noise.IntNoise2DInt(static_cast(x) + a_MinX, static_cast(z) + a_MinZ) / 7; if (rnd % 1000 < m_Chance) { size_t idx = x + a_SizeX * z; @@ -1418,7 +1418,7 @@ public: } - virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override { // Generate the base biomes and the alterations: m_BaseBiomes->GetInts(a_MinX, a_MinZ, a_SizeX, a_SizeZ, a_Values); @@ -1482,7 +1482,7 @@ public: } - virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override { // Generate the underlying biomes: size_t lowerSizeX = a_SizeX + 2; @@ -1642,7 +1642,7 @@ public: } - virtual void GetInts(size_t a_MinX, size_t a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override { // Generate the underlying biomes and the alterations: m_Underlying->GetInts(a_MinX, a_MinZ, a_SizeX, a_SizeZ, a_Values); -- cgit v1.2.3 From 51b4584b425bbc9c96b4967b9391479768d3cb28 Mon Sep 17 00:00:00 2001 From: tycho Date: Sun, 24 May 2015 15:22:55 +0100 Subject: Fix clang 3.6 flags to only be used in clang 3.6 --- SetFlags.cmake | 24 ++++++++++++++---------- tests/Network/CMakeLists.txt | 5 ++++- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/SetFlags.cmake b/SetFlags.cmake index c20a45133..d824d054a 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -27,6 +27,16 @@ macro(add_flags_cxx FLAGS) endmacro() +#this is a hack because we can't use cmake 2.8.10 because of travis +macro(get_clang_version) + execute_process( + COMMAND "${CMAKE_CXX_COMPILER}" "--version" + OUTPUT_VARIABLE CLANG_VERSION_OUTPUT) + string(REGEX MATCH "version ([0-9]\\.[0-9])" x ${CLANG_VERSION_OUTPUT}) + set(CLANG_VERSION ${CMAKE_MATCH_1}) +endmacro() + + macro(set_flags) # Add coverage processing, if requested: if (NOT MSVC) @@ -113,6 +123,10 @@ macro(set_flags) add_flags_cxx("-march=native") endif() + if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + get_clang_version() + endif() + # Use static CRT in MSVC builds: if (MSVC) @@ -215,15 +229,6 @@ macro(enable_profile) endif() endmacro() -#this is a hack because we can't use cmake 2.8.10 because of travis -macro(get_clang_version) - execute_process( - COMMAND "${CMAKE_CXX_COMPILER}" "--version" - OUTPUT_VARIABLE CLANG_VERSION_OUTPUT) - string(REGEX MATCH "version ([0-9]\\.[0-9])" x ${CLANG_VERSION_OUTPUT}) - set(CLANG_VERSION ${CMAKE_MATCH_1}) -endmacro() - macro(set_exe_flags) # Remove disabling the maximum warning level: # clang does not like a command line that reads -Wall -Wextra -w -Wall -Wextra and does not output any warnings @@ -242,7 +247,6 @@ macro(set_exe_flags) add_flags_cxx("-ffast-math") if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - get_clang_version() if ("${CLANG_VERSION}" VERSION_LESS 3.0) message(FATAL_ERROR "MCServer requires clang version 3.0 or higher, version is ${CLANG_VERSION}") endif() diff --git a/tests/Network/CMakeLists.txt b/tests/Network/CMakeLists.txt index 9ba5801f4..f93ccad8e 100644 --- a/tests/Network/CMakeLists.txt +++ b/tests/Network/CMakeLists.txt @@ -42,7 +42,10 @@ if (MSVC) endif() if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - add_flags_cxx("-Wno-error=conversion -Wno-error=old-style-cast -Wno-error=inconsistent-missing-override") + add_flags_cxx("-Wno-error=conversion -Wno-error=old-style-cast") + if ("${CLANG_VERSION}" VERSION_GREATER 3.5) + add_flags_cxx("-Wno-error=inconsistent-missing-override") + endif() endif() # Define individual tests: -- cgit v1.2.3 From 5ab650e4bb712f14181fceaedec2a20dda136d54 Mon Sep 17 00:00:00 2001 From: tycho Date: Sun, 24 May 2015 15:25:52 +0100 Subject: Fix bearbins comments --- src/Defines.h | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/Defines.h b/src/Defines.h index 67d29f7a9..bbc69f79c 100644 --- a/src/Defines.h +++ b/src/Defines.h @@ -256,14 +256,10 @@ inline eBlockFace RotateBlockFaceCCW(eBlockFace a_BlockFace) { switch (a_BlockFace) { - case BLOCK_FACE_XM: - return BLOCK_FACE_ZP; - case BLOCK_FACE_XP: - return BLOCK_FACE_ZM; - case BLOCK_FACE_ZM: - return BLOCK_FACE_XM; - case BLOCK_FACE_ZP: - return BLOCK_FACE_XP; + case BLOCK_FACE_XM: return BLOCK_FACE_ZP; + case BLOCK_FACE_XP: return BLOCK_FACE_ZM; + case BLOCK_FACE_ZM: return BLOCK_FACE_XM; + case BLOCK_FACE_ZP: return BLOCK_FACE_XP; case BLOCK_FACE_NONE: case BLOCK_FACE_YM: case BLOCK_FACE_YP: @@ -298,12 +294,12 @@ inline eBlockFace ReverseBlockFace(eBlockFace a_BlockFace) { switch (a_BlockFace) { - case BLOCK_FACE_YP: return BLOCK_FACE_YM; - case BLOCK_FACE_XP: return BLOCK_FACE_XM; - case BLOCK_FACE_ZP: return BLOCK_FACE_ZM; - case BLOCK_FACE_YM: return BLOCK_FACE_YP; - case BLOCK_FACE_XM: return BLOCK_FACE_XP; - case BLOCK_FACE_ZM: return BLOCK_FACE_ZP; + case BLOCK_FACE_YP: return BLOCK_FACE_YM; + case BLOCK_FACE_XP: return BLOCK_FACE_XM; + case BLOCK_FACE_ZP: return BLOCK_FACE_ZM; + case BLOCK_FACE_YM: return BLOCK_FACE_YP; + case BLOCK_FACE_XM: return BLOCK_FACE_XP; + case BLOCK_FACE_ZM: return BLOCK_FACE_ZP; case BLOCK_FACE_NONE: return a_BlockFace; } } -- cgit v1.2.3 From ea43ae231818e7999eb6c218a65198b3438a440c Mon Sep 17 00:00:00 2001 From: Cengiz Can Date: Sat, 23 May 2015 15:45:05 +0300 Subject: Fix #2105 - Add gcc to CI compilers --- .travis.yml | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6dde5b62b..e39cdbc14 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,39 +1,27 @@ language: cpp -compiler: clang -before_install: -# - if [ "$TRAVIS_MCSERVER_BUILD_TYPE" == "COVERAGE" ]; then sudo pip install cpp_coveralls; fi +compiler: +- clang +- gcc - # g++4.8 +before_install: - sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test - sudo apt-get update -qq install: - # g++4.8 and clang - sudo apt-get install -qq g++-4.8 + - sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 90 + - sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 90 # lua, needed for style checking and possibly later on for bindings generation - sudo apt-get install -qq lua5.1 - - # g++4.8 - - if [ "$CXX" == "g++" ]; then export CXX="g++-4.8"; export CC="gcc-4.8"; fi -# Build MCServer script: ./CIbuild.sh -#after_success: -# - ./uploadCoverage.sh - env: - TRAVIS_MCSERVER_BUILD_TYPE=RELEASE MCSERVER_PATH=./MCServer - TRAVIS_MCSERVER_BUILD_TYPE=DEBUG MCSERVER_PATH=./MCServer_debug -#matrix: -# include: -# - compiler: gcc -# env: TRAVIS_MCSERVER_BUILD_TYPE=COVERAGE MCSERVER_PATH=./MCServer - -# Notification Settings notifications: email: on_success: change -- cgit v1.2.3 From c627016ea684d6d778499e05536da2217c0cff93 Mon Sep 17 00:00:00 2001 From: tycho Date: Sun, 24 May 2015 16:58:53 +0100 Subject: Fix other clang 3.6 commit --- Tools/MCADefrag/CMakeLists.txt | 5 ++++- Tools/ProtoProxy/CMakeLists.txt | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Tools/MCADefrag/CMakeLists.txt b/Tools/MCADefrag/CMakeLists.txt index 17e332d8d..9d600d3ec 100644 --- a/Tools/MCADefrag/CMakeLists.txt +++ b/Tools/MCADefrag/CMakeLists.txt @@ -12,8 +12,11 @@ set_lib_flags() enable_profile() if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - add_flags_cxx("-Wno-error=sign-conversion -Wno-error=conversion -Wno-error=shorten-64-to-32 -Wno-error=keyword-macro") + add_flags_cxx("-Wno-error=sign-conversion -Wno-error=conversion -Wno-error=shorten-64-to-32") add_flags_cxx("-Wno-error=old-style-cast") + if ("${CLANG_VERSION}" VERSION_GREATER 3.5) + add_flags_cxx("-Wno-error=keyword-macro") + endif() endif() # Set include paths to the used libraries: diff --git a/Tools/ProtoProxy/CMakeLists.txt b/Tools/ProtoProxy/CMakeLists.txt index 0d3ef3f3e..480e6fba8 100644 --- a/Tools/ProtoProxy/CMakeLists.txt +++ b/Tools/ProtoProxy/CMakeLists.txt @@ -15,8 +15,11 @@ include_directories("../../lib/polarssl/include") include_directories("../../src") if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - add_flags_cxx("-Wno-error=sign-conversion -Wno-error=conversion -Wno-error=shorten-64-to-32 -Wno-error=keyword-macro") + add_flags_cxx("-Wno-error=sign-conversion -Wno-error=conversion -Wno-error=shorten-64-to-32") add_flags_cxx("-Wno-error=old-style-cast") + if ("${CLANG_VERSION}" VERSION_GREATER 3.5) + add_flags_cxx("-Wno-error=keyword-macro") + endif() endif() function(flatten_files arg1) -- cgit v1.2.3 From d1c91223401f7d13d6f32471da36db77360678b6 Mon Sep 17 00:00:00 2001 From: tycho Date: Sun, 24 May 2015 17:47:15 +0100 Subject: Fix warnings in cPath --- src/Mobs/Path.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Mobs/Path.cpp b/src/Mobs/Path.cpp index 6f3d43305..4d04d9861 100644 --- a/src/Mobs/Path.cpp +++ b/src/Mobs/Path.cpp @@ -46,18 +46,18 @@ cPath::cPath( a_BoundingBoxWidth = 1; // Until we improve physics, if ever. - m_BoundingBoxWidth = ceil(a_BoundingBoxWidth); - m_BoundingBoxHeight = ceil(a_BoundingBoxHeight); + m_BoundingBoxWidth = static_cast(ceil(a_BoundingBoxWidth)); + m_BoundingBoxHeight = static_cast(ceil(a_BoundingBoxHeight)); m_HalfWidth = a_BoundingBoxWidth / 2; - int HalfWidthInt = a_BoundingBoxWidth / 2; - m_Source.x = floor(a_StartingPoint.x - HalfWidthInt); - m_Source.y = floor(a_StartingPoint.y); - m_Source.z = floor(a_StartingPoint.z - HalfWidthInt); + int HalfWidthInt = static_cast(a_BoundingBoxWidth / 2); + m_Source.x = static_cast(floor(a_StartingPoint.x - HalfWidthInt)); + m_Source.y = static_cast(floor(a_StartingPoint.y)); + m_Source.z = static_cast(floor(a_StartingPoint.z - HalfWidthInt)); - m_Destination.x = floor(a_EndingPoint.x - HalfWidthInt); - m_Destination.y = floor(a_EndingPoint.y); - m_Destination.z = floor(a_EndingPoint.z - HalfWidthInt); + m_Destination.x = static_cast(floor(a_EndingPoint.x - HalfWidthInt)); + m_Destination.y = static_cast(floor(a_EndingPoint.y)); + m_Destination.z = static_cast(floor(a_EndingPoint.z - HalfWidthInt)); if (GetCell(m_Source)->m_IsSolid || GetCell(m_Destination)->m_IsSolid) { -- cgit v1.2.3 From 5049fd0fbf2fe2e54d86d9d0f704d5daa301f819 Mon Sep 17 00:00:00 2001 From: linnemannr Date: Sun, 24 May 2015 20:07:31 -0600 Subject: Support building on FreeBSD SetFlags.cmake Add -lexecinfo to linker flags for FreeBSD to resolve backtrace() lib/sqlite/CMakeLists.txt Define _XOPEN_SOURCE to 600 instead of __POSIX_VISIBLE to 200112 for POSIX 1-2001 support. For POSIX standards, the _XOPEN_SOURCE define controls the eventual value of __POSIX_VISIBLE. _XOPEN_SOURCE is defined to 500 in sqlite.c if not already defined, which sets up _POSIX_C_SOURCE and __POSIX_VISIBLE to the 199506 for POSIX.1c lib/tolua++/CMakeLists.txt src/CMakeLists.txt Add /usr/local/lib to the library search path for FreeBSD builds src/OSSupport/Errors.cpp Correct the strerror_r() implementation determination to check whether _GNU_SOURCE is defined, not what it evaluates to --- SetFlags.cmake | 5 +++++ lib/sqlite/CMakeLists.txt | 2 +- lib/tolua++/CMakeLists.txt | 4 ++++ src/CMakeLists.txt | 5 +++++ src/OSSupport/Errors.cpp | 2 +- 5 files changed, 16 insertions(+), 2 deletions(-) diff --git a/SetFlags.cmake b/SetFlags.cmake index b05585f7d..92046b688 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -240,6 +240,11 @@ macro(set_exe_flags) # we support non-IEEE 754 fpus so can make no guarentees about error add_flags_cxx("-ffast-math") + if(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD") + # backtrace() and friends are in libexecinfo + add_flags_lnk("-lexecinfo") + endif() + if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") get_clang_version() if ("${CLANG_VERSION}" VERSION_LESS 3.0) diff --git a/lib/sqlite/CMakeLists.txt b/lib/sqlite/CMakeLists.txt index 993dac146..b9471c1f2 100644 --- a/lib/sqlite/CMakeLists.txt +++ b/lib/sqlite/CMakeLists.txt @@ -25,7 +25,7 @@ endif() # FreeBSD requires us to define this to get POSIX 2001 standard if (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD") - add_flags_cxx(-D__POSIX_VISIBLE=200112) + add_flags_cxx("-D_XOPEN_SOURCE=600") endif() add_library(sqlite ${SOURCE}) diff --git a/lib/tolua++/CMakeLists.txt b/lib/tolua++/CMakeLists.txt index 12054323b..02883397e 100644 --- a/lib/tolua++/CMakeLists.txt +++ b/lib/tolua++/CMakeLists.txt @@ -53,4 +53,8 @@ if(UNIX) target_link_libraries(tolua m ${DYNAMIC_LOADER}) endif() +if (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD") + add_flags_lnk(-L/usr/local/lib) +endif() + target_link_libraries(tolua tolualib lua) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 25de24c91..1b721100d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -332,4 +332,9 @@ endif () if (WIN32) target_link_libraries(${EXECUTABLE} expat tolualib ws2_32.lib Psapi.lib) endif() + +if (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD") + add_flags_lnk(-L/usr/local/lib) +endif() + target_link_libraries(${EXECUTABLE} luaexpat jsoncpp mbedtls zlib sqlite lua SQLiteCpp event_core event_extra) diff --git a/src/OSSupport/Errors.cpp b/src/OSSupport/Errors.cpp index a5361e1a6..407799495 100644 --- a/src/OSSupport/Errors.cpp +++ b/src/OSSupport/Errors.cpp @@ -22,7 +22,7 @@ AString GetOSErrorString( int a_ErrNo) // According to http://linux.die.net/man/3/strerror_r there are two versions of strerror_r(): - #if !defined(__APPLE__) && ( _GNU_SOURCE) && !defined(ANDROID_NDK) // GNU version of strerror_r() + #if !defined(__APPLE__) && defined( _GNU_SOURCE) && !defined(ANDROID_NDK) // GNU version of strerror_r() char * res = strerror_r( errno, buffer, ARRAYCOUNT(buffer)); if (res != nullptr) -- cgit v1.2.3 From c6d2d1d7153e69bd263af6cdbd52fbbebbb75a56 Mon Sep 17 00:00:00 2001 From: Mathias Date: Mon, 25 May 2015 20:23:02 +0300 Subject: Update CONTRIBUTORS --- CONTRIBUTORS | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 1e73fb699..4a6850a2f 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -18,6 +18,7 @@ Masy98 mborland mgueydan MikeHunsinger +missingchar (mathias-github) mtilden nesco p-mcgowan -- cgit v1.2.3 From 6735b0d5346ba17d282bb27ca00f92e6d963a516 Mon Sep 17 00:00:00 2001 From: worktycho Date: Mon, 25 May 2015 18:43:18 +0100 Subject: Only add default plugins if there are not any plugins Fixes #2082 --- src/Bindings/PluginManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp index 4dc3e20d3..5b6bec728 100644 --- a/src/Bindings/PluginManager.cpp +++ b/src/Bindings/PluginManager.cpp @@ -1935,7 +1935,7 @@ size_t cPluginManager::GetNumLoadedPlugins(void) const AStringVector cPluginManager::GetFoldersToLoad(cSettingsRepositoryInterface & a_Settings) { // Check if the Plugins section exists. - if (a_Settings.KeyExists("Plugins")) + if (!a_Settings.KeyExists("Plugins")) { InsertDefaultPlugins(a_Settings); } -- cgit v1.2.3 From c3b872ad933a720c94886e0d614154d10a781dd1 Mon Sep 17 00:00:00 2001 From: Lukas Pioch Date: Tue, 26 May 2015 05:36:46 +0200 Subject: Added method to get the uptime of the server in seconds. Implements #1650. --- MCServer/Plugins/APIDump/APIDesc.lua | 61 +++++++++++++++---------------- src/Root.cpp | 32 ++++++++--------- src/Root.h | 69 +++++++++++++++++++----------------- 3 files changed, 82 insertions(+), 80 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 2c26ccecc..4af01c0a4 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -29,7 +29,7 @@ g_APIDesc = { ConstantName = { Notes = "Notes about the constant" }, } , - + ConstantGroups = { GroupName1 = -- GroupName1 is used as the HTML anchor name @@ -270,7 +270,7 @@ g_APIDesc =

Special strategies

For each strategy, evaluate the table rows from top downwards, the first match wins.

- +

msDifference - changes all the blocks which are the same to air. Otherwise the source block gets placed.

@@ -282,8 +282,8 @@ g_APIDesc = B B Air The blocks are the same so we get air. - - + +

msLake - used for merging areas with lava and water lakes, in the appropriate generator.

@@ -363,7 +363,7 @@ g_APIDesc = A non-A A Differing blocks are kept from 'self' - +

msSimpleCompare - the blocks that are the same in both areas are replaced with air, all the differing blocks are replaced with stone. Meta is used in the comparison, too, two blocks of the @@ -535,7 +535,7 @@ g_APIDesc = function OnChunkGenerated(a_World, a_ChunkX, a_ChunkZ, a_ChunkDesc) -- Get the topmost block coord: local Height = a_ChunkDesc:GetHeight(0, 0); - + -- Create a sign there: a_ChunkDesc:SetBlockTypeMeta(0, Height + 1, 0, E_BLOCK_SIGN_POST, 0); local BlockEntity = a_ChunkDesc:GetBlockEntity(0, Height + 1, 0); @@ -666,7 +666,7 @@ end }, }, -- AdditionalInfo }, -- cCompositeChat - + cCraftingGrid = { Desc = [[ @@ -738,7 +738,7 @@ local Hash = cCryptoHash.sha1HexString("DataToHash")

Each cryptographic hash has two variants, one returns the hash as a raw binary string, the other returns the hash as a hex-encoded string twice as long as the binary string. ]], - + Functions = { md5 = { Params = "Data", Return = "string", Notes = "(STATIC) Calculates the md5 hash of the data, returns it as a raw (binary) string of 16 characters." }, @@ -747,7 +747,7 @@ local Hash = cCryptoHash.sha1HexString("DataToHash") sha1HexString = { Params = "Data", Return = "string", Notes = "(STATIC) Calculates the sha1 hash of the data, returns it as a hex-encoded string of 40 characters." }, }, }, -- cCryptoHash - + cEnchantments = { Desc = [[ @@ -1038,7 +1038,7 @@ cFile:Delete("/usr/bin/virus.exe"); }, Inherits = "cEntity", }, - + cIniFile = { Desc = [[ @@ -1073,7 +1073,7 @@ ValueName0=SomeOtherValue { constructor = { Params = "", Return = "cIniFile", Notes = "Creates a new empty cIniFile object." }, AddHeaderComment = { Params = "Comment", Return = "", Notes = "Adds a comment to be stored in the file header." }, - AddKeyComment = + AddKeyComment = { { Params = "KeyID, Comment", Return = "", Notes = "Adds a comment to be stored in the file under the specified key" }, { Params = "KeyName, Comment", Return = "", Notes = "Adds a comment to be stored in the file under the specified key" }, @@ -1117,12 +1117,12 @@ ValueName0=SomeOtherValue { Params = "KeyName", Return = "number", Notes = "Returns the number of comments under the specified key" }, }, GetNumKeys = { Params = "", Return = "number", Notes = "Returns the total number of keys. This is the range for the KeyID (0 .. GetNumKeys() - 1)" }, - GetNumValues = + GetNumValues = { { Params = "KeyID", Return = "number", Notes = "Returns the number of values stored under the specified key." }, { Params = "KeyName", Return = "number", Notes = "Returns the number of values stored under the specified key." }, }, - GetValue = + GetValue = { { Params = "KeyName, ValueName", Return = "string", Notes = "Returns the value of the specified name under the specified key. Returns an empty string if the value doesn't exist." }, { Params = "KeyID, ValueID", Return = "string", Notes = "Returns the value of the specified name under the specified key. Returns an empty string if the value doesn't exist." }, @@ -1130,7 +1130,7 @@ ValueName0=SomeOtherValue GetValueB = { Params = "KeyName, ValueName", Return = "bool", Notes = "Returns the value of the specified name under the specified key, as a bool. Returns false if the value doesn't exist." }, GetValueF = { Params = "KeyName, ValueName", Return = "number", Notes = "Returns the value of the specified name under the specified key, as a floating-point number. Returns zero if the value doesn't exist." }, GetValueI = { Params = "KeyName, ValueName", Return = "number", Notes = "Returns the value of the specified name under the specified key, as an integer. Returns zero if the value doesn't exist." }, - GetValueName = + GetValueName = { { Params = "KeyID, ValueID", Return = "string", Notes = "Returns the name of the specified value Inverse for FindValue()." }, { Params = "KeyName, ValueID", Return = "string", Notes = "Returns the name of the specified value Inverse for FindValue()." }, @@ -1141,7 +1141,7 @@ ValueName0=SomeOtherValue GetValueSetI = { Params = "KeyName, ValueName, Default", Return = "number", Notes = "Returns the value of the specified name under the specified key, as an integer. If the value doesn't exist, creates it with the specified default." }, HasValue = { Params = "KeyName, ValueName", Return = "bool", Notes = "Returns true if the specified value is present." }, ReadFile = { Params = "FileName, [AllowExampleFallback]", Return = "bool", Notes = "Reads the values from the specified file. Previous in-memory contents are lost. If the file cannot be opened, and AllowExample is true, another file, \"filename.example.ini\", is loaded and then saved as \"filename.ini\". Returns true if successful, false if not." }, - SetValue = + SetValue = { { Params = "KeyID, ValueID, NewValue", Return = "bool", Notes = "Overwrites the specified value with a new value. If the specified value doesn't exist, returns false (doesn't add)." }, { Params = "KeyName, ValueName, NewValue, [CreateIfNotExists]", Return = "bool", Notes = "Overwrites the specified value with a new value. If CreateIfNotExists is true (default) and the value doesn't exist, it is first created. Returns true if the value was successfully set, false if not (didn't exists, CreateIfNotExists false)." }, @@ -2061,6 +2061,7 @@ a_Player:OpenWindow(Window); GetPrimaryServerVersion = { Params = "", Return = "number", Notes = "Returns the servers primary server version." }, GetProtocolVersionTextFromInt = { Params = "Protocol Version", Return = "string", Notes = "Returns the Minecraft version from the given Protocol. If there is no version found, it returns 'Unknown protocol(Parameter)'" }, GetServer = { Params = "", Return = "{{cServer|cServer}}", Notes = "Returns the cServer object." }, + GetServerUpTime = { Params = "", Return = "number", Notes = "Returns the uptime of the server in seconds." }, GetTotalChunkCount = { Params = "", Return = "number", Notes = "Returns the amount of loaded chunks." }, GetVirtualRAMUsage = { Params = "", Return = "number", Notes = "Returns the amount of virtual RAM that the entire MCServer process is using, in KiB. Negative if the OS doesn't support this query." }, GetWebAdmin = { Params = "", Return = "{{cWebAdmin|cWebAdmin}}", Notes = "Returns the cWebAdmin object." }, @@ -2146,7 +2147,7 @@ end ShouldAuthenticate = { Params = "", Return = "bool", Notes = "Returns true iff the server is set to authenticate players (\"online mode\")." }, }, }, -- cServer - + cStringCompression = { Desc = [[ @@ -2157,7 +2158,7 @@ end local CompressedString = cStringCompression.CompressStringGZIP("DataToCompress") ]], - + Functions = { CompressStringGZIP = {Params = "string", Return = "string", Notes = "Compress a string using GZIP"}, @@ -2205,7 +2206,7 @@ local CompressedString = cStringCompression.CompressStringGZIP("DataToCompress") }, Inherits = "cEntity", }, - + cWebPlugin = { Desc = "", @@ -2361,7 +2362,7 @@ local CompressedString = cStringCompression.CompressStringGZIP("DataToCompress") GetGeneratorQueueLength = { Params = "", Return = "number", Notes = "Returns the number of chunks that are queued in the chunk generator." }, GetHeight = { Params = "BlockX, BlockZ", Return = "number", Notes = "Returns the maximum height of the particula block column in the world. If the chunk is not loaded, it waits for it to load / generate. WARNING: Do not use, Use TryGetHeight() instead for a non-waiting version, otherwise you run the risk of a deadlock!" }, GetIniFileName = { Params = "", Return = "string", Notes = "Returns the name of the world.ini file that the world uses to store the information." }, - GetLightingQueueLength = { Params = "", Return = "number", Notes = "Returns the number of chunks in the lighting thread's queue." }, + GetLightingQueueLength = { Params = "", Return = "number", Notes = "Returns the number of chunks in the lighting thread's queue." }, GetLinkedEndWorldName = { Params = "", Return = "string", Notes = "Returns the name of the end world this world is linked to." }, GetLinkedNetherWorldName = { Params = "", Return = "string", Notes = "Returns the name of the Netherworld linked to this world." }, GetLinkedOverworldName = { Params = "", Return = "string", Notes = "Returns the name of the world this world is linked to." }, @@ -2514,7 +2515,7 @@ World:ForEachEntity( if not(a_Entity:IsMob()) then return; end - + -- Get the cMonster out of cEntity, now that we know the entity represents one. local Monster = tolua.cast(a_Entity, "cMonster"); if (Monster:GetMobType() == mtSpider) then @@ -2565,7 +2566,7 @@ end } }, }, -- ItemCategory - + lxp = { Desc = [[ @@ -2635,7 +2636,7 @@ local Callbacks = { CharacterData = function(a_Parser, a_String) LOG(string.rep(" ", Depth) .. "* " .. a_String); end - + EndElement = function(a_Parser, a_ElementName) Depth = Depth - 1; LOG(string.rep(" ", Depth) .. "- " .. a_ElementName); @@ -2671,12 +2672,12 @@ Parser:close(); }, }, -- AdditionalInfo }, -- lxp - + sqlite3 = { Desc = [[ ]], - + Functions = { complete = { Params = "string", Return = "bool", Notes = "Returns true if the string sql comprises one or more complete SQL statements and false otherwise." }, @@ -2700,7 +2701,7 @@ myDB:close() version = { Return = "string", Notes = "Returns a string with SQLite version information, in the form 'x.y[.z]'." }, }, }, - + TakeDamageInfo = { Desc = [[ @@ -2994,7 +2995,7 @@ end "WriteHtmlHook", "WriteStats", }, - + IgnoreConstants = { "cChestEntity.__cBlockEntityWindowOwner__", @@ -3003,12 +3004,12 @@ end "cHopperEntity.__cBlockEntityWindowOwner__", "cLuaWindow.__cItemGrid__cListener__", }, - + IgnoreVariables = { "__.*__", -- tolua exports multiple inheritance this way } , - + ExtraPages = { -- No sorting is provided for these, they will be output in the same order as defined here @@ -3020,7 +3021,3 @@ end { FileName = "WebWorldThreads.html", Title = "Webserver vs World threads" }, } } ; - - - - diff --git a/src/Root.cpp b/src/Root.cpp index c3c880e73..b28e7c894 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -72,7 +72,7 @@ cRoot::~cRoot() void cRoot::InputThread(cRoot & a_Params) { cLogCommandOutputCallback Output; - + while (!cRoot::m_ShouldStop && !a_Params.m_bRestart && !m_TerminateEventRaised && std::cin.good()) { AString Command; @@ -105,12 +105,12 @@ void cRoot::Start(std::unique_ptr overridesRepo) HMENU hmenu = GetSystemMenu(hwnd, FALSE); EnableMenuItem(hmenu, SC_CLOSE, MF_GRAYED); // Disable close button when starting up; it causes problems with our CTRL-CLOSE handling #endif - + cLogger::cListener * consoleLogListener = MakeConsoleListener(); cLogger::cListener * fileLogListener = new cFileListener(); cLogger::GetInstance().AttachListener(consoleLogListener); cLogger::GetInstance().AttachListener(fileLogListener); - + LOG("--- Started Log ---\n"); #ifdef BUILD_ID @@ -162,30 +162,30 @@ void cRoot::Start(std::unique_ptr overridesRepo) m_RankManager->Initialize(*m_MojangAPI); m_CraftingRecipes = new cCraftingRecipes; m_FurnaceRecipe = new cFurnaceRecipe(); - + LOGD("Loading worlds..."); LoadWorlds(*settingsRepo); LOGD("Loading plugin manager..."); m_PluginManager = new cPluginManager(); m_PluginManager->ReloadPluginsNow(*settingsRepo); - + LOGD("Loading MonsterConfig..."); m_MonsterConfig = new cMonsterConfig; // This sets stuff in motion LOGD("Starting Authenticator..."); m_Authenticator.Start(*settingsRepo); - + LOGD("Starting worlds..."); StartWorlds(); - + if (settingsRepo->GetValueSetB("DeadlockDetect", "Enabled", true)) { LOGD("Starting deadlock detector..."); dd.Start(settingsRepo->GetValueSetI("DeadlockDetect", "IntervalSec", 20)); } - + settingsRepo->Flush(); LOGD("Finalising startup..."); @@ -207,6 +207,10 @@ void cRoot::Start(std::unique_ptr overridesRepo) #endif LOG("Startup complete, took %ldms!", static_cast(std::chrono::duration_cast(std::chrono::steady_clock::now() - BeginTime).count())); + + // Save the current time + m_StartTime = std::chrono::steady_clock::now(); + #ifdef _WIN32 EnableMenuItem(hmenu, SC_CLOSE, MF_ENABLED); // Re-enable close button #endif @@ -253,7 +257,7 @@ void cRoot::Start(std::unique_ptr overridesRepo) LOGD("Unloading worlds..."); UnloadWorlds(); - + LOGD("Stopping plugin manager..."); delete m_PluginManager; m_PluginManager = nullptr; @@ -264,9 +268,9 @@ void cRoot::Start(std::unique_ptr overridesRepo) LOG("Shutdown successful!"); } - + LOG("--- Stopped Log ---"); - + cLogger::GetInstance().DetachListener(consoleLogListener); delete consoleLogListener; cLogger::GetInstance().DetachListener(fileLogListener); @@ -299,7 +303,7 @@ void cRoot::LoadWorlds(cSettingsRepositoryInterface & a_Settings) { return; } - + bool FoundAdditionalWorlds = false; for (auto WorldNameValue : Worlds) { @@ -850,7 +854,3 @@ int cRoot::GetFurnaceFuelBurnTime(const cItem & a_Fuel) cFurnaceRecipe * FR = Get()->GetFurnaceRecipe(); return FR->GetBurnTime(a_Fuel); } - - - - diff --git a/src/Root.h b/src/Root.h index 2b30afaff..ab820427f 100644 --- a/src/Root.h +++ b/src/Root.h @@ -70,22 +70,31 @@ public: a_OverworldName should be set for non-overworld dimensions if one wishes that world to link back to an overworld via portals */ cWorld * CreateAndInitializeWorld(const AString & a_WorldName, eDimension a_Dimension = dimOverworld, const AString & a_OverworldName = ""); + + /** Returns the up time of the server in seconds */ + int GetServerUpTime(void) + { + return static_cast(std::chrono::duration_cast(std::chrono::steady_clock::now() - m_StartTime).count()); + } // tolua_end - + /// Calls the callback for each world; returns true if the callback didn't abort (return true) bool ForEachWorld(cWorldListCallback & a_Callback); // >> Exported in ManualBindings << - + /// Writes chunkstats, for each world and totals, to the output callback void LogChunkStats(cCommandOutputCallback & a_Output); - + cMonsterConfig * GetMonsterConfig(void) { return m_MonsterConfig; } cCraftingRecipes * GetCraftingRecipes(void) { return m_CraftingRecipes; } // tolua_export cFurnaceRecipe * GetFurnaceRecipe (void) { return m_FurnaceRecipe; } // Exported in ManualBindings.cpp with quite a different signature - + /// Returns the number of ticks for how long the item would fuel a furnace. Returns zero if not a fuel static int GetFurnaceFuelBurnTime(const cItem & a_Fuel); // tolua_export - + + /** The current time where the startup of the server has been completed */ + std::chrono::steady_clock::time_point m_StartTime; + cWebAdmin * GetWebAdmin (void) { return m_WebAdmin; } // tolua_export cPluginManager * GetPluginManager (void) { return m_PluginManager; } // tolua_export cAuthenticator & GetAuthenticator (void) { return m_Authenticator; } @@ -98,32 +107,32 @@ public: "stop" and "restart" commands have special handling. */ void QueueExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallback & a_Output); - + /** Queues a console command for execution through the cServer class. The command will be executed in the tick thread The command's output will be sent to console "stop" and "restart" commands have special handling. */ void QueueExecuteConsoleCommand(const AString & a_Cmd); // tolua_export - + /// Executes a console command through the cServer class; does special handling for "stop" and "restart". void ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallback & a_Output); - + /// Kicks the user, no matter in what world they are. Used from cAuthenticator void KickUser(int a_ClientID, const AString & a_Reason); - + /// Called by cAuthenticator to auth the specified user void AuthenticateUser(int a_ClientID, const AString & a_Name, const AString & a_UUID, const Json::Value & a_Properties); - + /// Executes commands queued in the command queue void TickCommands(void); /// Returns the number of chunks loaded int GetTotalChunkCount(void); // tolua_export - + /// Saves all chunks in all worlds void SaveAllChunks(void); // tolua_export - + /// Calls the callback for each player in all worlds bool ForEachPlayer(cPlayerListCallback & a_Callback); // >> EXPORTED IN MANUALBINDINGS << @@ -132,12 +141,12 @@ public: /** Finds the player over his uuid and calls the callback */ bool DoWithPlayerByUUID(const AString & a_PlayerUUID, cPlayerListCallback & a_Callback); // >> EXPORTED IN MANUALBINDINGS << - + /** Finds the player using it's complete username and calls the callback */ bool DoWithPlayer(const AString & a_PlayerName, cPlayerListCallback & a_Callback); - + // tolua_begin - + /// Sends a chat message to all connected clients (in all worlds) void BroadcastChat (const AString & a_Message, eMessageType a_ChatPrefix = mtCustom); void BroadcastChat (const cCompositeChat & a_Message); @@ -149,18 +158,18 @@ public: void BroadcastChatLeave (const AString & a_Message) { BroadcastChat(a_Message, mtLeave); } void BroadcastChatSuccess(const AString & a_Message) { BroadcastChat(a_Message, mtSuccess); } void BroadcastChatWarning(const AString & a_Message) { BroadcastChat(a_Message, mtWarning); } - + /// Returns the textual description of the protocol version: 49 -> "1.4.4". Provided specifically for Lua API static AString GetProtocolVersionTextFromInt(int a_ProtocolVersionNum); - + /// Returns the amount of virtual RAM used, in KiB. Returns a negative number on error static int GetVirtualRAMUsage(void); - + /// Returns the amount of virtual RAM used, in KiB. Returns a negative number on error static int GetPhysicalRAMUsage(void); - + // tolua_end - + private: class cCommand { @@ -170,17 +179,17 @@ private: m_Output(a_Output) { } - + AString m_Command; cCommandOutputCallback * m_Output; } ; - + typedef std::map WorldMap; typedef std::vector cCommandQueue; cWorld * m_pDefaultWorld; WorldMap m_WorldsByName; - + cCriticalSection m_CSPendingCommands; cCommandQueue m_PendingCommands; @@ -206,24 +215,20 @@ private: /// Loads the worlds from settings.ini, creates the worldmap void LoadWorlds(cSettingsRepositoryInterface & a_Settings); - + /// Starts each world's life void StartWorlds(void); - + /// Stops each world's threads, so that it's safe to unload them void StopWorlds(void); - + /// Unloads all worlds from memory void UnloadWorlds(void); - + /// Does the actual work of executing a command void DoExecuteConsoleCommand(const AString & a_Cmd); - + static cRoot * s_Root; static void InputThread(cRoot & a_Params); }; // tolua_export - - - - -- cgit v1.2.3 From 31b95afd79886a90f7629b0a7038d90790660e7d Mon Sep 17 00:00:00 2001 From: tycho Date: Mon, 25 May 2015 11:10:26 +0100 Subject: Fixed ClientHandle not getting properly removed from the world when socket is closed whilst the client is being added to the world Fixes #1969 --- src/ClientHandle.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 13972b0f5..765ccdee2 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -2957,13 +2957,20 @@ void cClientHandle::PacketError(UInt32 a_PacketType) void cClientHandle::SocketClosed(void) { // The socket has been closed for any reason - + if (!m_Username.empty()) // Ignore client pings { LOGD("Client %s @ %s disconnected", m_Username.c_str(), m_IPString.c_str()); cRoot::Get()->GetPluginManager()->CallHookDisconnect(*this, "Player disconnected"); } - + if (m_State < csDestroying) + { + cWorld * World = m_Player->GetWorld(); + if (World != nullptr) + { + World->RemovePlayer(m_Player, true); // Must be called before cPlayer::Destroy() as otherwise cChunk tries to delete the player, and then we do it again + } + } Destroy(); } -- cgit v1.2.3 From 142a5dd05eb1cfb2ca6c0a5cbf149d6060fe992b Mon Sep 17 00:00:00 2001 From: jammet Date: Tue, 26 May 2015 19:22:43 +0200 Subject: Corrected Cookie recipe You should get a batch of 8 cookies for 2 wheat and one cocoabean. --- MCServer/crafting.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCServer/crafting.txt b/MCServer/crafting.txt index e7d11ab92..daac9e098 100644 --- a/MCServer/crafting.txt +++ b/MCServer/crafting.txt @@ -322,7 +322,7 @@ MushroomStew = Bowl, * | BrownMushroom, * | RedMushroom, * Bread = Wheat, 1:1, 2:1, 3:1 Sugar = Sugarcane, * Cake = MilkBucket, 1:1, 2:1, 3:1 | Sugar, 1:2, 3:2 | Egg, 2:2 | Wheat, 1:3, 2:3, 3:3 -Cookie = Wheat, *, * | CocoaBeans, * +Cookie, 8 = Wheat, *, * | CocoaBeans, * GoldenApple = RedApple, 2:2 | GoldIngot, 1:1, 1:2, 1:3, 2:1, 2:3, 3:1, 3:2, 3:3 EnchantedGoldenApple = RedApple, 2:2 | GoldBlock, 1:1, 1:2, 1:3, 2:1, 2:3, 3:1, 3:2, 3:3 Melon = MelonSlice, 1:1, 1:2, 1:3, 2:1, 2:2, 2:3, 3:1, 3:2, 3:3 -- cgit v1.2.3 From 52fcbb5c654bd0b4a0b602f9b7bebed342030e7b Mon Sep 17 00:00:00 2001 From: SafwatHalaby Date: Wed, 27 May 2015 18:53:46 +0300 Subject: AI - Saner Livestock --- src/Mobs/Monster.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 1da4124ed..3fbee9a65 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -196,7 +196,15 @@ bool cMonster::TickPathFinding(cChunk & a_Chunk) { if (m_NoMoreWayPoints || (--m_GiveUpCounter == 0)) { - ResetPathFinding(); // Try to calculate a path again. + if (m_EMState == ATTACKING) + { + ResetPathFinding(); // Try to calculate a path again. + // This results in mobs hanging around an unreachable target (player). + } + else + { + StopMovingToPosition(); // Find a different place to go to. + } return false; } else if (!m_Path->IsLastPoint()) // Have we arrived at the next cell, as denoted by m_NextWayPointPosition? @@ -391,6 +399,7 @@ void cMonster::MoveToPosition(const Vector3d & a_Position) void cMonster::StopMovingToPosition() { m_IsFollowingPath = false; + ResetPathFinding(); } @@ -520,7 +529,7 @@ void cMonster::SetPitchAndYawFromDestination() double HeadRotation, HeadPitch; Distance.Normalize(); VectorToEuler(Distance.x, Distance.y, Distance.z, HeadRotation, HeadPitch); - if (std::abs(BodyRotation - HeadRotation) < 120) + if (std::abs(BodyRotation - HeadRotation) < 90) { SetHeadYaw(HeadRotation); SetPitch(-HeadPitch); -- cgit v1.2.3 From b936781f93f6d8d1421edc42444244850aa4fa18 Mon Sep 17 00:00:00 2001 From: SafwatHalaby Date: Thu, 28 May 2015 08:31:17 +0300 Subject: AI - Tweaked wolf speed and teleport threshold --- src/Mobs/Wolf.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Mobs/Wolf.cpp b/src/Mobs/Wolf.cpp index 3c2ec1520..af7de1579 100644 --- a/src/Mobs/Wolf.cpp +++ b/src/Mobs/Wolf.cpp @@ -20,6 +20,7 @@ cWolf::cWolf(void) : m_OwnerName(""), m_CollarColor(14) { + m_RelativeWalkSpeed = 2; } @@ -230,7 +231,7 @@ void cWolf::TickFollowPlayer() { // The player is present in the world, follow him: double Distance = (Callback.OwnerPos - GetPosition()).Length(); - if (Distance > 30) + if (Distance > 20) { Callback.OwnerPos.y = FindFirstNonAirBlockPosition(Callback.OwnerPos.x, Callback.OwnerPos.z); TeleportToCoords(Callback.OwnerPos.x, Callback.OwnerPos.y, Callback.OwnerPos.z); -- cgit v1.2.3 From b2fa71a32ac8bd86bda778a5d54fe2e7e471a1c0 Mon Sep 17 00:00:00 2001 From: tycho Date: Thu, 28 May 2015 12:29:26 +0100 Subject: Fix comments --- .gitignore | 1 - src/Bindings/CMakeLists.txt | 10 +++++----- src/BlockEntities/MobSpawnerEntity.cpp | 3 ++- src/BlockEntities/NoteEntity.cpp | 12 +++++++----- src/Entities/SplashPotionEntity.cpp | 11 ++++++----- src/Generating/ChunkDesc.cpp | 2 +- src/LineBlockTracer.cpp | 10 +++++----- src/LoggerListeners.cpp | 8 ++++++-- src/Mobs/Guardian.cpp | 6 +++--- src/Mobs/Horse.cpp | 8 ++++---- src/Mobs/Path.cpp | 18 +++++++++--------- src/Mobs/Squid.cpp | 6 +++--- src/Noise/Noise.h | 3 ++- src/PolarSSL++/SslContext.h | 4 ++-- src/Simulator/DelayedFluidSimulator.cpp | 4 ++-- src/Simulator/FloodyFluidSimulator.cpp | 8 ++++++-- src/Simulator/SandSimulator.cpp | 9 +++++---- src/Simulator/VaporizeFluidSimulator.cpp | 4 +++- src/UI/EnderChestWindow.cpp | 15 +++++++++------ src/WebAdmin.cpp | 4 ++-- 20 files changed, 82 insertions(+), 64 deletions(-) diff --git a/.gitignore b/.gitignore index 97b2e93d5..8dc90910c 100644 --- a/.gitignore +++ b/.gitignore @@ -75,7 +75,6 @@ src/MCServer lib/tolua++/tolua src/Bindings/Bindings.* src/Bindings/BindingDependencies.txt -src/Bindings/LuaState_Call.inc MCServer.dir/ src/AllFiles.lst diff --git a/src/Bindings/CMakeLists.txt b/src/Bindings/CMakeLists.txt index b14576ea0..0a069ad85 100644 --- a/src/Bindings/CMakeLists.txt +++ b/src/Bindings/CMakeLists.txt @@ -146,12 +146,12 @@ set_source_files_properties(${BINDING_OUTPUTS} PROPERTIES GENERATED TRUE) set_source_files_properties(${CMAKE_SOURCE_DIR}/src/Bindings/Bindings.cpp PROPERTIES COMPILE_FLAGS -Wno-error) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - set_source_files_properties(DeprecatedBindings.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") - set_source_files_properties(LuaState.cpp COMPILE_FLAGS "-Wno-error=old-style-cast") + set_source_files_properties(DeprecatedBindings.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") + set_source_files_properties(LuaState.cpp COMPILE_FLAGS "-Wno-error=old-style-cast") set_source_files_properties(LuaWindow.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum") - set_source_files_properties(ManualBindings.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") - set_source_files_properties(ManualBindings_World.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") - set_source_files_properties(PluginLua.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") + set_source_files_properties(ManualBindings.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") + set_source_files_properties(ManualBindings_World.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") + set_source_files_properties(PluginLua.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") endif() if(NOT MSVC) diff --git a/src/BlockEntities/MobSpawnerEntity.cpp b/src/BlockEntities/MobSpawnerEntity.cpp index 4746bdd1b..1a0ce5b22 100644 --- a/src/BlockEntities/MobSpawnerEntity.cpp +++ b/src/BlockEntities/MobSpawnerEntity.cpp @@ -177,7 +177,8 @@ void cMobSpawnerEntity::SpawnEntity(void) static_cast(PosX * 8.0), static_cast(RelY * 8.0), static_cast(PosZ * 8.0), - 0); + 0 + ); m_NearbyEntitiesNum++; } } diff --git a/src/BlockEntities/NoteEntity.cpp b/src/BlockEntities/NoteEntity.cpp index 48ca15d1f..29839bae1 100644 --- a/src/BlockEntities/NoteEntity.cpp +++ b/src/BlockEntities/NoteEntity.cpp @@ -92,11 +92,13 @@ void cNoteEntity::MakeSound(void) // TODO: instead of calculating the power function over and over, make a precalculated table - there's only 24 pitches after all float calcPitch = pow(2.0f, static_cast(m_Pitch - 12.0f) / 12.0f); m_World->BroadcastSoundEffect( - sampleName, - static_cast(m_PosX), - static_cast(m_PosY), - static_cast(m_PosZ), - 3.0f, calcPitch); + sampleName, + static_cast(m_PosX), + static_cast(m_PosY), + static_cast(m_PosZ), + 3.0f, + calcPitch + ); } diff --git a/src/Entities/SplashPotionEntity.cpp b/src/Entities/SplashPotionEntity.cpp index a79ba92b0..926fd1abe 100644 --- a/src/Entities/SplashPotionEntity.cpp +++ b/src/Entities/SplashPotionEntity.cpp @@ -117,11 +117,12 @@ void cSplashPotionEntity::Splash(const Vector3d & a_HitPos) m_World->ForEachEntity(Callback); m_World->BroadcastSoundParticleEffect( - 2002, - static_cast(floor(a_HitPos.x)), - static_cast(floor(a_HitPos.y)), - static_cast(floor(a_HitPos.z)), - m_PotionColor); + 2002, + FloorC(a_HitPos.x), + FloorC(a_HitPos.y), + FloorC(a_HitPos.z), + m_PotionColor + ); } diff --git a/src/Generating/ChunkDesc.cpp b/src/Generating/ChunkDesc.cpp index fe5182004..07855b1d0 100644 --- a/src/Generating/ChunkDesc.cpp +++ b/src/Generating/ChunkDesc.cpp @@ -158,7 +158,7 @@ void cChunkDesc::SetHeightFromShape(const Shape & a_Shape) { for (int x = 0; x < cChunkDef::Width; x++) { - for (unsigned char y = cChunkDef::Height - 1; y > 0; y--) + for (HEIGHTTYPE y = cChunkDef::Height - 1; y > 0; y--) { if (a_Shape[y + x * 256 + z * 16 * 256] != 0) { diff --git a/src/LineBlockTracer.cpp b/src/LineBlockTracer.cpp index ee28bef88..315e8d082 100644 --- a/src/LineBlockTracer.cpp +++ b/src/LineBlockTracer.cpp @@ -96,17 +96,17 @@ bool cLineBlockTracer::Trace(double a_StartX, double a_StartY, double a_StartZ, m_Callbacks->OnIntoWorld(m_StartX, m_StartY, m_StartZ); } - m_CurrentX = static_cast(floor(m_StartX)); - m_CurrentY = static_cast(floor(m_StartY)); - m_CurrentZ = static_cast(floor(m_StartZ)); + m_CurrentX = FloorC(m_StartX); + m_CurrentY = FloorC(m_StartY); + m_CurrentZ = FloorC(m_StartZ); m_DiffX = m_EndX - m_StartX; m_DiffY = m_EndY - m_StartY; m_DiffZ = m_EndZ - m_StartZ; // The actual trace is handled with ChunkMapCS locked by calling our Item() for the specified chunk - int BlockX = static_cast(floor(m_StartX)); - int BlockZ = static_cast(floor(m_StartZ)); + int BlockX = FloorC(m_StartX); + int BlockZ = FloorC(m_StartZ); int ChunkX, ChunkZ; cChunkDef::BlockToChunk(BlockX, BlockZ, ChunkX, ChunkZ); return m_World->DoWithChunk(ChunkX, ChunkZ, *this); diff --git a/src/LoggerListeners.cpp b/src/LoggerListeners.cpp index cc2f883d8..31b12af1e 100644 --- a/src/LoggerListeners.cpp +++ b/src/LoggerListeners.cpp @@ -283,8 +283,12 @@ cFileListener::cFileListener(void) cFile::CreateFolder(FILE_IO_PREFIX + AString("logs")); AString FileName; auto time = std::chrono::system_clock::now(); - FileName = Printf("%s%sLOG_%d.txt", FILE_IO_PREFIX, "logs/", - std::chrono::duration_cast>(time.time_since_epoch()).count()); + FileName = Printf( + "%s%sLOG_%d.txt", + FILE_IO_PREFIX, + "logs/", + std::chrono::duration_cast>(time.time_since_epoch()).count() + ); m_File.Open(FileName, cFile::fmAppend); } diff --git a/src/Mobs/Guardian.cpp b/src/Mobs/Guardian.cpp index 6efd4a42b..cfe7861a6 100644 --- a/src/Mobs/Guardian.cpp +++ b/src/Mobs/Guardian.cpp @@ -43,13 +43,13 @@ void cGuardian::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) Vector3d Pos = GetPosition(); // TODO: Not a real behavior, but cool :D - int RelY = static_cast(floor(Pos.y)); + int RelY = FloorC(Pos.y); if ((RelY < 0) || (RelY >= cChunkDef::Height)) { return; } - int RelX = static_cast(floor(Pos.x)) - a_Chunk.GetPosX() * cChunkDef::Width; - int RelZ = static_cast(floor(Pos.z)) - a_Chunk.GetPosZ() * cChunkDef::Width; + int RelX = FloorC(Pos.x) - a_Chunk.GetPosX() * cChunkDef::Width; + int RelZ = FloorC(Pos.z) - a_Chunk.GetPosZ() * cChunkDef::Width; BLOCKTYPE BlockType; if (a_Chunk.UnboundedRelGetBlockType(RelX, RelY, RelZ, BlockType) && !IsBlockWater(BlockType) && !IsOnFire()) { diff --git a/src/Mobs/Horse.cpp b/src/Mobs/Horse.cpp index 4321fdc73..ce3bd65eb 100644 --- a/src/Mobs/Horse.cpp +++ b/src/Mobs/Horse.cpp @@ -55,10 +55,10 @@ void cHorse::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { if (m_World->GetTickRandomNumber(50) == 25) { - m_World->BroadcastSoundParticleEffect(2000, static_cast(GetPosX()), static_cast(GetPosY()), static_cast(GetPosZ()), 0); - m_World->BroadcastSoundParticleEffect(2000, static_cast(GetPosX()), static_cast(GetPosY()), static_cast(GetPosZ()), 2); - m_World->BroadcastSoundParticleEffect(2000, static_cast(GetPosX()), static_cast(GetPosY()), static_cast(GetPosZ()), 6); - m_World->BroadcastSoundParticleEffect(2000, static_cast(GetPosX()), static_cast(GetPosY()), static_cast(GetPosZ()), 8); + m_World->BroadcastSoundParticleEffect(2000, FloorC(GetPosX()), FloorC(GetPosY()), FloorC(GetPosZ()), 0); + m_World->BroadcastSoundParticleEffect(2000, FloorC(GetPosX()), FloorC(GetPosY()), FloorC(GetPosZ()), 2); + m_World->BroadcastSoundParticleEffect(2000, FloorC(GetPosX()), FloorC(GetPosY()), FloorC(GetPosZ()), 6); + m_World->BroadcastSoundParticleEffect(2000, FloorC(GetPosX()), FloorC(GetPosY()), FloorC(GetPosZ()), 8); m_Attachee->Detach(); m_bIsRearing = true; diff --git a/src/Mobs/Path.cpp b/src/Mobs/Path.cpp index 4d04d9861..1848e144e 100644 --- a/src/Mobs/Path.cpp +++ b/src/Mobs/Path.cpp @@ -46,18 +46,18 @@ cPath::cPath( a_BoundingBoxWidth = 1; // Until we improve physics, if ever. - m_BoundingBoxWidth = static_cast(ceil(a_BoundingBoxWidth)); - m_BoundingBoxHeight = static_cast(ceil(a_BoundingBoxHeight)); + m_BoundingBoxWidth = CeilC(a_BoundingBoxWidth); + m_BoundingBoxHeight = CeilC(a_BoundingBoxHeight); m_HalfWidth = a_BoundingBoxWidth / 2; - int HalfWidthInt = static_cast(a_BoundingBoxWidth / 2); - m_Source.x = static_cast(floor(a_StartingPoint.x - HalfWidthInt)); - m_Source.y = static_cast(floor(a_StartingPoint.y)); - m_Source.z = static_cast(floor(a_StartingPoint.z - HalfWidthInt)); + int HalfWidthInt = FloorC(a_BoundingBoxWidth / 2); + m_Source.x = FloorC(a_StartingPoint.x - HalfWidthInt); + m_Source.y = FloorC(a_StartingPoint.y); + m_Source.z = FloorC(a_StartingPoint.z - HalfWidthInt); - m_Destination.x = static_cast(floor(a_EndingPoint.x - HalfWidthInt)); - m_Destination.y = static_cast(floor(a_EndingPoint.y)); - m_Destination.z = static_cast(floor(a_EndingPoint.z - HalfWidthInt)); + m_Destination.x = FloorC(a_EndingPoint.x - HalfWidthInt); + m_Destination.y = FloorC(a_EndingPoint.y); + m_Destination.z = FloorC(a_EndingPoint.z - HalfWidthInt); if (GetCell(m_Source)->m_IsSolid || GetCell(m_Destination)->m_IsSolid) { diff --git a/src/Mobs/Squid.cpp b/src/Mobs/Squid.cpp index 7928f7dc8..d148d65f3 100644 --- a/src/Mobs/Squid.cpp +++ b/src/Mobs/Squid.cpp @@ -41,13 +41,13 @@ void cSquid::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) Vector3d Pos = GetPosition(); // TODO: Not a real behavior, but cool :D - int RelY = static_cast(floor(Pos.y)); + int RelY = FloorC(Pos.y); if ((RelY < 0) || (RelY >= cChunkDef::Height)) { return; } - int RelX = static_cast(floor(Pos.x)) - a_Chunk.GetPosX() * cChunkDef::Width; - int RelZ = static_cast(floor(Pos.z)) - a_Chunk.GetPosZ() * cChunkDef::Width; + int RelX = FloorC(Pos.x) - a_Chunk.GetPosX() * cChunkDef::Width; + int RelZ = FloorC(Pos.z) - a_Chunk.GetPosZ() * cChunkDef::Width; BLOCKTYPE BlockType; if (a_Chunk.UnboundedRelGetBlockType(RelX, RelY, RelZ, BlockType) && !IsBlockWater(BlockType) && !IsOnFire()) { diff --git a/src/Noise/Noise.h b/src/Noise/Noise.h index be3b282ac..b08b96e24 100644 --- a/src/Noise/Noise.h +++ b/src/Noise/Noise.h @@ -210,7 +210,8 @@ NOISE_DATATYPE cNoise::IntNoise3D(int a_X, int a_Y, int a_Z) const int n = a_X + a_Y * 57 + a_Z * 57 * 57 + m_Seed * 57 * 57 * 57; n = (n << 13) ^ n; return (static_cast(1) - - static_cast((n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0f); + static_cast((n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0f + ); // returns a float number in the range of [-1, 1] } diff --git a/src/PolarSSL++/SslContext.h b/src/PolarSSL++/SslContext.h index ce6a2e398..408fc7c56 100644 --- a/src/PolarSSL++/SslContext.h +++ b/src/PolarSSL++/SslContext.h @@ -127,13 +127,13 @@ protected: /** The callback used by PolarSSL when it wants to read encrypted data. */ static int ReceiveEncrypted(void * a_This, unsigned char * a_Buffer, size_t a_NumBytes) { - return (static_cast(a_This))->ReceiveEncrypted(a_Buffer, a_NumBytes); + return (reinterpret_cast(a_This))->ReceiveEncrypted(a_Buffer, a_NumBytes); } /** The callback used by PolarSSL when it wants to write encrypted data. */ static int SendEncrypted(void * a_This, const unsigned char * a_Buffer, size_t a_NumBytes) { - return (static_cast(a_This))->SendEncrypted(a_Buffer, a_NumBytes); + return (reinterpret_cast(a_This))->SendEncrypted(a_Buffer, a_NumBytes); } #ifdef _DEBUG diff --git a/src/Simulator/DelayedFluidSimulator.cpp b/src/Simulator/DelayedFluidSimulator.cpp index cbf70bf05..e0da3ff61 100644 --- a/src/Simulator/DelayedFluidSimulator.cpp +++ b/src/Simulator/DelayedFluidSimulator.cpp @@ -99,7 +99,7 @@ void cDelayedFluidSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, return; } - void * ChunkDataRaw = (m_FluidBlock == E_BLOCK_WATER) ? a_Chunk->GetWaterSimulatorData() : a_Chunk->GetLavaSimulatorData(); + auto ChunkDataRaw = (m_FluidBlock == E_BLOCK_WATER) ? a_Chunk->GetWaterSimulatorData() : a_Chunk->GetLavaSimulatorData(); cDelayedFluidSimulatorChunkData * ChunkData = static_cast(ChunkDataRaw); cDelayedFluidSimulatorChunkData::cSlot & Slot = ChunkData->m_Slots[m_AddSlotNum]; @@ -132,7 +132,7 @@ void cDelayedFluidSimulator::Simulate(float a_Dt) void cDelayedFluidSimulator::SimulateChunk(std::chrono::milliseconds a_Dt, int a_ChunkX, int a_ChunkZ, cChunk * a_Chunk) { - void * ChunkDataRaw = (m_FluidBlock == E_BLOCK_WATER) ? a_Chunk->GetWaterSimulatorData() : a_Chunk->GetLavaSimulatorData(); + auto ChunkDataRaw = (m_FluidBlock == E_BLOCK_WATER) ? a_Chunk->GetWaterSimulatorData() : a_Chunk->GetLavaSimulatorData(); cDelayedFluidSimulatorChunkData * ChunkData = static_cast(ChunkDataRaw); cDelayedFluidSimulatorChunkData::cSlot & Slot = ChunkData->m_Slots[m_SimSlotNum]; diff --git a/src/Simulator/FloodyFluidSimulator.cpp b/src/Simulator/FloodyFluidSimulator.cpp index e7082d9ab..69c46f090 100644 --- a/src/Simulator/FloodyFluidSimulator.cpp +++ b/src/Simulator/FloodyFluidSimulator.cpp @@ -260,7 +260,9 @@ void cFloodyFluidSimulator::SpreadToNeighbor(cChunk * a_NearChunk, int a_RelX, i static_cast(BlockX), static_cast(a_RelY), static_cast(BlockZ), - 0.5f, 1.5f); + 0.5f, + 1.5f + ); return; } } @@ -280,7 +282,9 @@ void cFloodyFluidSimulator::SpreadToNeighbor(cChunk * a_NearChunk, int a_RelX, i static_cast(BlockX), static_cast(a_RelY), static_cast(BlockZ), - 0.5f, 1.5f); + 0.5f, + 1.5f + ); return; } } diff --git a/src/Simulator/SandSimulator.cpp b/src/Simulator/SandSimulator.cpp index e11bc714a..70dde8cc0 100644 --- a/src/Simulator/SandSimulator.cpp +++ b/src/Simulator/SandSimulator.cpp @@ -267,10 +267,11 @@ void cSandSimulator::FinishFalling( cItems Pickups; Pickups.Add(static_cast(a_FallingBlockType), 1, a_FallingBlockMeta); a_World->SpawnItemPickups( - Pickups, - static_cast(a_BlockX) + 0.5, - static_cast(a_BlockY) + 0.5, - static_cast(a_BlockZ) + 0.5); + Pickups, + static_cast(a_BlockX) + 0.5, + static_cast(a_BlockY) + 0.5, + static_cast(a_BlockZ) + 0.5 + ); } diff --git a/src/Simulator/VaporizeFluidSimulator.cpp b/src/Simulator/VaporizeFluidSimulator.cpp index 7bca6c580..d766b069f 100644 --- a/src/Simulator/VaporizeFluidSimulator.cpp +++ b/src/Simulator/VaporizeFluidSimulator.cpp @@ -40,7 +40,9 @@ void cVaporizeFluidSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, static_cast(a_BlockX), static_cast(a_BlockY), static_cast(a_BlockZ), - 1.0f, 0.6f); + 1.0f, + 0.6f + ); } } diff --git a/src/UI/EnderChestWindow.cpp b/src/UI/EnderChestWindow.cpp index 9a4918aa4..c597f3a9b 100644 --- a/src/UI/EnderChestWindow.cpp +++ b/src/UI/EnderChestWindow.cpp @@ -29,7 +29,9 @@ cEnderChestWindow::cEnderChestWindow(cEnderChestEntity * a_EnderChest) : static_cast(m_BlockX), static_cast(m_BlockY), static_cast(m_BlockZ), - 1, 1); + 1, + 1 + ); // Send out the chest-open packet: m_World->BroadcastBlockAction(m_BlockX, m_BlockY, m_BlockZ, 1, 1, E_BLOCK_ENDER_CHEST); @@ -46,11 +48,12 @@ cEnderChestWindow::~cEnderChestWindow() // Play the closing sound m_World->BroadcastSoundEffect( - "random.chestclosed", - static_cast(m_BlockX), - static_cast(m_BlockY), - static_cast(m_BlockZ), - 1, 1); + "random.chestclosed", + static_cast(m_BlockX), + static_cast(m_BlockY), + static_cast(m_BlockZ), + 1, 1 + ); } diff --git a/src/WebAdmin.cpp b/src/WebAdmin.cpp index 1295d90f7..91fad96c6 100644 --- a/src/WebAdmin.cpp +++ b/src/WebAdmin.cpp @@ -648,7 +648,7 @@ void cWebAdmin::OnRequestBegun(cHTTPConnection & a_Connection, cHTTPRequest & a_ void cWebAdmin::OnRequestBody(cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, size_t a_Size) { UNUSED(a_Connection); - cRequestData * Data = static_cast(a_Request.GetUserData()); + cRequestData * Data = reinterpret_cast(a_Request.GetUserData()); if (Data == nullptr) { return; @@ -681,7 +681,7 @@ void cWebAdmin::OnRequestFinished(cHTTPConnection & a_Connection, cHTTPRequest & } // Delete any request data assigned to the request: - cRequestData * Data = static_cast(a_Request.GetUserData()); + cRequestData * Data = reinterpret_cast(a_Request.GetUserData()); delete Data; Data = nullptr; } -- cgit v1.2.3 From 20b715257284ea486b0bf20358167bea2fe6f7a6 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 28 May 2015 13:03:28 +0100 Subject: Potential crash fixes * Potentially addresses my comment in #1969 * Probably fixes #2145 --- src/ClientHandle.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 765ccdee2..9644679d7 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1902,7 +1902,7 @@ void cClientHandle::Tick(float a_Dt) if (m_TicksSinceLastPacket > 600) // 30 seconds time-out { SendDisconnect("Nooooo!! You timed out! D: Come back!"); - Destroy(); + return; } if (m_Player == nullptr) @@ -2013,7 +2013,6 @@ void cClientHandle::ServerTick(float a_Dt) if (m_TicksSinceLastPacket > 600) // 30 seconds { SendDisconnect("Nooooo!! You timed out! D: Come back!"); - Destroy(); } } @@ -2186,6 +2185,7 @@ void cClientHandle::SendDisconnect(const AString & a_Reason) { LOGD("Sending a DC: \"%s\"", StripColorCodes(a_Reason).c_str()); m_Protocol->SendDisconnect(a_Reason); + Destroy(); m_HasSentDC = true; } } @@ -2922,7 +2922,6 @@ void cClientHandle::PacketBufferFull(void) // Too much data in the incoming queue, the server is probably too busy, kick the client: LOGERROR("Too much data in queue for client \"%s\" @ %s, kicking them.", m_Username.c_str(), m_IPString.c_str()); SendDisconnect("Server busy"); - Destroy(); } @@ -2936,7 +2935,6 @@ void cClientHandle::PacketUnknown(UInt32 a_PacketType) AString Reason; Printf(Reason, "Unknown [C->S] PacketType: 0x%x", a_PacketType); SendDisconnect(Reason); - Destroy(); } @@ -2947,7 +2945,6 @@ void cClientHandle::PacketError(UInt32 a_PacketType) { LOGERROR("Protocol error while parsing packet type 0x%02x; disconnecting client \"%s\"", a_PacketType, m_Username.c_str()); SendDisconnect("Protocol error"); - Destroy(); } @@ -2963,7 +2960,7 @@ void cClientHandle::SocketClosed(void) LOGD("Client %s @ %s disconnected", m_Username.c_str(), m_IPString.c_str()); cRoot::Get()->GetPluginManager()->CallHookDisconnect(*this, "Player disconnected"); } - if (m_State < csDestroying) + if ((m_State < csDestroying) && (m_Player != nullptr)) { cWorld * World = m_Player->GetWorld(); if (World != nullptr) -- cgit v1.2.3 From f1540173da442878e132b0bbca1f8f60141e1cd0 Mon Sep 17 00:00:00 2001 From: SafwatHalaby Date: Thu, 28 May 2015 17:45:47 +0300 Subject: AI - Sane Skeleton --- src/Entities/ArrowEntity.cpp | 21 +++++++++++---------- src/Mobs/AggressiveMonster.cpp | 3 ++- src/Mobs/Monster.cpp | 11 +++++++++-- src/Mobs/Monster.h | 9 ++++++--- src/Mobs/Skeleton.cpp | 7 ++++--- 5 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/Entities/ArrowEntity.cpp b/src/Entities/ArrowEntity.cpp index 32952100c..9b8f77cbc 100644 --- a/src/Entities/ArrowEntity.cpp +++ b/src/Entities/ArrowEntity.cpp @@ -84,7 +84,7 @@ void cArrowEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFa int X = BlockHit.x, Y = BlockHit.y, Z = BlockHit.z; m_HitBlockPos = Vector3i(X, Y, Z); - + // Broadcast arrow hit sound m_World->BroadcastSoundEffect("random.bowhit", (double)X, (double)Y, (double)Z, 0.5f, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); @@ -115,7 +115,7 @@ void cArrowEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) Damage += ExtraDamage; } - int KnockbackAmount = 1; + // int KnockbackAmount = 1; int PunchLevel = m_CreatorData.m_Enchantments.GetLevel(cEnchantments::enchPunch); if (PunchLevel > 0) { @@ -130,8 +130,9 @@ void cArrowEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) a_EntityHit.SetSpeed(FinalSpeed); } - a_EntityHit.TakeDamage(dtRangedAttack, this, Damage, KnockbackAmount); - + // a_EntityHit.TakeDamage(dtRangedAttack, this, Damage, KnockbackAmount); // TODO fix knockback. + a_EntityHit.TakeDamage(dtRangedAttack, this, Damage, 0); // Until knockback is fixed. + if (IsOnFire() && !a_EntityHit.IsSubmerged() && !a_EntityHit.IsSwimming()) { a_EntityHit.StartBurning(100); @@ -139,7 +140,7 @@ void cArrowEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) // Broadcast successful hit sound GetWorld()->BroadcastSoundEffect("random.successful_hit", GetPosX(), GetPosY(), GetPosZ(), 0.5, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); - + Destroy(); } @@ -176,7 +177,7 @@ void cArrowEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); m_Timer += a_Dt; - + if (m_bIsCollected) { if (m_Timer > std::chrono::milliseconds(500)) @@ -190,7 +191,7 @@ void cArrowEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) Destroy(); return; } - + if (m_IsInGround) { if (!m_HasTeleported) // Sent a teleport already, don't do again @@ -205,17 +206,17 @@ void cArrowEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) m_HitGroundTimer += a_Dt; } } - + int RelPosX = m_HitBlockPos.x - a_Chunk.GetPosX() * cChunkDef::Width; int RelPosZ = m_HitBlockPos.z - a_Chunk.GetPosZ() * cChunkDef::Width; cChunk * Chunk = a_Chunk.GetRelNeighborChunkAdjustCoords(RelPosX, RelPosZ); - + if (Chunk == nullptr) { // Inside an unloaded chunk, abort return; } - + if (Chunk->GetBlock(RelPosX, m_HitBlockPos.y, RelPosZ) == E_BLOCK_AIR) // Block attached to was destroyed? { m_IsInGround = false; // Yes, begin simulating physics again diff --git a/src/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp index 648599999..93f7cdb72 100644 --- a/src/Mobs/AggressiveMonster.cpp +++ b/src/Mobs/AggressiveMonster.cpp @@ -80,9 +80,10 @@ void cAggressiveMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) Vector3d AttackDirection(m_Target->GetPosition() + Vector3d(0, m_Target->GetHeight(), 0) - MyHeadPosition); - if (ReachedFinalDestination() && !LineOfSight.Trace(MyHeadPosition, AttackDirection, static_cast(AttackDirection.Length()))) + if (TargetIsInRange() && !LineOfSight.Trace(MyHeadPosition, AttackDirection, static_cast(AttackDirection.Length()))) { // Attack if reached destination, target isn't null, and have a clear line of sight to target (so won't attack through walls) + StopMovingToPosition(); Attack(a_Dt); } } diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 3fbee9a65..c67850248 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -517,8 +517,15 @@ void cMonster::SetPitchAndYawFromDestination() } - - Vector3d BodyDistance = m_NextWayPointPosition - GetPosition(); + Vector3d BodyDistance; + if (!m_IsFollowingPath && (m_Target != nullptr)) + { + BodyDistance = m_Target->GetPosition() - GetPosition(); + } + else + { + BodyDistance = m_NextWayPointPosition - GetPosition(); + } double BodyRotation, BodyPitch; BodyDistance.Normalize(); VectorToEuler(BodyDistance.x, BodyDistance.y, BodyDistance.z, BodyRotation, BodyPitch); diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index c4043b0e5..fa23df3db 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -193,13 +193,16 @@ protected: If no suitable position is found, returns cChunkDef::Height. */ int FindFirstNonAirBlockPosition(double a_PosX, double a_PosZ); - /** Returns if the ultimate, final destination has been reached */ - bool ReachedFinalDestination(void) { return ((m_FinalDestination - GetPosition()).SqrLength() < (m_AttackRange * m_AttackRange)); } + /** Returns if the ultimate, final destination has been reached. */ + bool ReachedFinalDestination(void) { return ((m_FinalDestination - GetPosition()).Length() < GetWidth()/2); } + + /** Returns whether or not the target is close enough for attack. */ + bool TargetIsInRange(void) { return ((m_FinalDestination - GetPosition()).SqrLength() < (m_AttackRange * m_AttackRange)); } /** Returns if the intermediate waypoint of m_NextWayPointPosition has been reached */ bool ReachedNextWaypoint(void) { return ((m_NextWayPointPosition - GetPosition()).SqrLength() < 0.25); } - /** Returns if a monster can reach a given height by jumping */ + /** Returns if a monster can reach a given height by jumping. */ inline bool DoesPosYRequireJump(int a_PosY) { return ((a_PosY > POSY_TOINT) && (a_PosY == POSY_TOINT + 1)); diff --git a/src/Mobs/Skeleton.cpp b/src/Mobs/Skeleton.cpp index f99404669..d1a481960 100644 --- a/src/Mobs/Skeleton.cpp +++ b/src/Mobs/Skeleton.cpp @@ -50,12 +50,13 @@ void cSkeleton::GetDrops(cItems & a_Drops, cEntity * a_Killer) void cSkeleton::Attack(std::chrono::milliseconds a_Dt) { + cFastRandom Random; m_AttackInterval += (static_cast(a_Dt.count()) / 1000) * m_AttackRate; if ((m_Target != nullptr) && (m_AttackInterval > 3.0)) { - // Setting this higher gives us more wiggle room for attackrate - Vector3d Speed = GetLookVector() * 20; - Speed.y = Speed.y + 1; + Vector3d Inaccuracy = Vector3d(Random.NextFloat(0.5) - 0.25, Random.NextFloat(0.5) - 0.25, Random.NextFloat(0.5) - 0.25); + Vector3d Speed = (m_Target->GetPosition() + Inaccuracy - GetPosition()) * 5; + Speed.y = Speed.y - 1 + Random.NextInt(3); cArrowEntity * Arrow = new cArrowEntity(this, GetPosX(), GetPosY() + 1, GetPosZ(), Speed); if (Arrow == nullptr) { -- cgit v1.2.3 From e6ba181bd420e148ce86fc6b7a05df23cbddf362 Mon Sep 17 00:00:00 2001 From: SafwatHalaby Date: Thu, 28 May 2015 22:39:39 +0300 Subject: Removed stray "exit" from compile.sh --- compile.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/compile.sh b/compile.sh index 329d79d81..1e965aecc 100755 --- a/compile.sh +++ b/compile.sh @@ -85,7 +85,6 @@ if [[ $MISSING_PROGRAMS != "" ]]; then missingDepsExit fi -exit # Echo: Branch choice. echo echo "You can choose between 2 branches:" -- cgit v1.2.3 From e7214dff656a7b8b3f71d585ea2a0dd6afeba0d6 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Thu, 28 May 2015 22:12:12 +0200 Subject: Updated DumpInfo plugin. cPluginManager:GetAllPlugins is deprecated --- MCServer/Plugins/DumpInfo/Init.lua | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/MCServer/Plugins/DumpInfo/Init.lua b/MCServer/Plugins/DumpInfo/Init.lua index 1faa8d60f..2c5998e36 100644 --- a/MCServer/Plugins/DumpInfo/Init.lua +++ b/MCServer/Plugins/DumpInfo/Init.lua @@ -33,15 +33,17 @@ function HandleDumpPluginRequest(a_Request) ]] -- Loop through each plugin that is found. - for PluginName, k in pairs(cPluginManager:Get():GetAllPlugins()) do - -- Check if there is a file called 'Info.lua' or 'info.lua' - if (cFile:Exists("Plugins/" .. PluginName .. "/Info.lua")) then - Content = Content .. "\n\n" - Content = Content .. "\t" .. PluginName .. "\n" - Content = Content .. "\t

\n" - Content = Content .. "\n" + cPluginManager:Get():ForEachPlugin( + function(a_Plugin) + -- Check if there is a file called 'Info.lua' + if (cFile:Exists("Plugins/" .. a_Plugin:GetName() .. "/Info.lua")) then + Content = Content .. "\n\n" + Content = Content .. "\t" .. a_Plugin:GetName() .. "\n" + Content = Content .. "\t
\n" + Content = Content .. "\n" + end end - end + ) Content = Content .. [[ ]] -- cgit v1.2.3 From c8b1778847fca653c5f9cde610d25586131698ac Mon Sep 17 00:00:00 2001 From: b33duck Date: Thu, 28 May 2015 13:17:21 -0700 Subject: Fixed the way connecting clients receive player lists and broadcast chat to worlds --- src/ClientHandle.cpp | 4 ++-- src/Root.cpp | 10 ++++++++-- src/Root.h | 4 ++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 9644679d7..161bdeb9d 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -382,7 +382,7 @@ void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID, // Send player list items SendPlayerListAddPlayer(*m_Player); World->BroadcastPlayerListAddPlayer(*m_Player); - World->SendPlayerList(m_Player); + cRoot::Get()->SendPlayerLists(m_Player); m_Player->Initialize(*World); m_State = csAuthenticated; @@ -1475,7 +1475,7 @@ void cClientHandle::HandleChat(const AString & a_Message) Msg.AddTextPart(AString("<") + m_Player->GetName() + "> ", Color); Msg.ParseText(Message); Msg.UnderlineUrls(); - m_Player->GetWorld()->BroadcastChat(Msg); + cRoot::Get()->BroadcastChat(Msg); } diff --git a/src/Root.cpp b/src/Root.cpp index b28e7c894..b60f6ae3a 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -558,6 +558,14 @@ void cRoot::SaveAllChunks(void) +void cRoot::SendPlayerLists(cPlayer * a_DestPlayer) +{ + for (WorldMap::iterator itr = m_WorldsByName.begin(), end = m_WorldsByName.end(); itr != end; ++itr) + { + itr->second->SendPlayerList(a_DestPlayer); + } // for itr - m_WorldsByName[] +} + void cRoot::BroadcastChat(const AString & a_Message, eMessageType a_ChatPrefix) @@ -582,8 +590,6 @@ void cRoot::BroadcastChat(const cCompositeChat & a_Message) - - bool cRoot::ForEachPlayer(cPlayerListCallback & a_Callback) { for (WorldMap::iterator itr = m_WorldsByName.begin(), itr2 = itr; itr != m_WorldsByName.end(); itr = itr2) diff --git a/src/Root.h b/src/Root.h index ab820427f..73fd6638c 100644 --- a/src/Root.h +++ b/src/Root.h @@ -145,6 +145,10 @@ public: /** Finds the player using it's complete username and calls the callback */ bool DoWithPlayer(const AString & a_PlayerName, cPlayerListCallback & a_Callback); + /** Send playerlist of all worlds to player */ + void SendPlayerLists(cPlayer * a_DestPlayer); + + // tolua_begin /// Sends a chat message to all connected clients (in all worlds) -- cgit v1.2.3 From 15d49d0cb9819eb9d544f50e8b491ca8f796b743 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Thu, 28 May 2015 22:22:59 +0200 Subject: Fixed Info.lua documentation The AdditionalInformation table is called AdditionalInfo --- MCServer/Plugins/APIDump/InfoFile.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/MCServer/Plugins/APIDump/InfoFile.html b/MCServer/Plugins/APIDump/InfoFile.html index 3fff06d20..adaae2cb6 100644 --- a/MCServer/Plugins/APIDump/InfoFile.html +++ b/MCServer/Plugins/APIDump/InfoFile.html @@ -15,7 +15,7 @@
  • Introduction
  • The overall structure
  • -
  • AdditionalInformation table
  • +
  • AdditionalInfo table
  • Commands table
  • ConsoleCommands table
  • Permissions table
  • @@ -51,7 +51,7 @@ g_PluginInfo = Description = "This is an example plugin that shows how to use the Info.lua file", -- The following members will be documented in greater detail later: - AdditionalInformation = {}, + AdditionalInfo = {}, Commands = {}, ConsoleCommands = {}, Permissions = {}, @@ -63,13 +63,13 @@ g_PluginInfo =
    -

    AdditionalInformation table

    +

    AdditionalInfo table

    This table is used for more detailed description of the plugin. If there is any non-trivial setup process, dependencies, describe them here. This is where the description should get detailed. Don't worry about using several paragraphs of text here, if it makes the plugin easier to understand.

    The table should have the following layout:

    -AdditionalInformation =
    +AdditionalInfo =
     {
     	{
     		Title = "Chapter 1",
    -- 
    cgit v1.2.3
    
    
    From 022348645e5f4a39c57ab6c899dd9de12bcb3794 Mon Sep 17 00:00:00 2001
    From: b33duck 
    Date: Thu, 28 May 2015 13:17:21 -0700
    Subject: Fix for the way connecting clients receive player lists and broadcast
     chat
    
    ---
     src/ClientHandle.cpp |  6 +++---
     src/Root.cpp         | 19 +++++++++++++++++--
     src/Root.h           |  6 ++++++
     3 files changed, 26 insertions(+), 5 deletions(-)
    
    diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
    index 9644679d7..9cba5619d 100644
    --- a/src/ClientHandle.cpp
    +++ b/src/ClientHandle.cpp
    @@ -381,8 +381,8 @@ void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID,
     
     	// Send player list items
     	SendPlayerListAddPlayer(*m_Player);
    -	World->BroadcastPlayerListAddPlayer(*m_Player);
    -	World->SendPlayerList(m_Player);
    +	cRoot::Get()->BroadcastPlayerListsAddPlayer(*m_Player);
    +	cRoot::Get()->SendPlayerLists(m_Player);
     
     	m_Player->Initialize(*World);
     	m_State = csAuthenticated;
    @@ -1475,7 +1475,7 @@ void cClientHandle::HandleChat(const AString & a_Message)
     	Msg.AddTextPart(AString("<") + m_Player->GetName() + "> ", Color);
     	Msg.ParseText(Message);
     	Msg.UnderlineUrls();
    -	m_Player->GetWorld()->BroadcastChat(Msg);
    +	cRoot::Get()->BroadcastChat(Msg);
     }
     
     
    diff --git a/src/Root.cpp b/src/Root.cpp
    index b28e7c894..54e65b6da 100644
    --- a/src/Root.cpp
    +++ b/src/Root.cpp
    @@ -558,6 +558,23 @@ void cRoot::SaveAllChunks(void)
     
     
     
    +void cRoot::SendPlayerLists(cPlayer * a_DestPlayer)
    +{
    +	for (const auto & itr : m_WorldsByName)
    +	{
    +		itr.second->SendPlayerList(a_DestPlayer);
    +	}  // for itr - m_WorldsByName[]
    +}
    +
    +
    +
    +void cRoot::BroadcastPlayerListsAddPlayer(const cPlayer & a_Player, const cClientHandle * a_Exclude)
    +{
    +	for (const auto & itr : m_WorldsByName)
    +	{
    +		itr.second->BroadcastPlayerListAddPlayer(a_Player);
    +	}  // for itr - m_WorldsByName[]
    +}
     
     
     void cRoot::BroadcastChat(const AString & a_Message, eMessageType a_ChatPrefix)
    @@ -582,8 +599,6 @@ void cRoot::BroadcastChat(const cCompositeChat & a_Message)
     
     
     
    -
    -
     bool cRoot::ForEachPlayer(cPlayerListCallback & a_Callback)
     {
     	for (WorldMap::iterator itr = m_WorldsByName.begin(), itr2 = itr; itr != m_WorldsByName.end(); itr = itr2)
    diff --git a/src/Root.h b/src/Root.h
    index ab820427f..81551a503 100644
    --- a/src/Root.h
    +++ b/src/Root.h
    @@ -145,6 +145,12 @@ public:
     	/** Finds the player using it's complete username and calls the callback */
     	bool DoWithPlayer(const AString & a_PlayerName, cPlayerListCallback & a_Callback);
     
    +	/** Send playerlist of all worlds to player */
    +	void SendPlayerLists(cPlayer * a_DestPlayer);
    +
    +	/** Broadcast Player through all worlds */
    +	void BroadcastPlayerListsAddPlayer(const cPlayer & a_Player, const cClientHandle * a_Exclude = nullptr);
    +
     	// tolua_begin
     
     	/// Sends a chat message to all connected clients (in all worlds)
    -- 
    cgit v1.2.3
    
    
    From 1dfc7bbce27a60b0ded261e851956fb3d2004fab Mon Sep 17 00:00:00 2001
    From: Lane Kolbly 
    Date: Fri, 29 May 2015 16:12:51 -0500
    Subject: Fixed reversed logic in StringToDimension.
    
    ---
     src/BlockID.cpp | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/src/BlockID.cpp b/src/BlockID.cpp
    index 775d60a68..c598df0aa 100644
    --- a/src/BlockID.cpp
    +++ b/src/BlockID.cpp
    @@ -295,7 +295,7 @@ eDimension StringToDimension(const AString & a_DimensionString)
     {
     	// First try decoding as a number
     	int res;
    -	if (!StringToInteger(a_DimensionString, res))
    +	if (StringToInteger(a_DimensionString, res))
     	{
     		// It was a valid number
     		return static_cast(res);
    -- 
    cgit v1.2.3
    
    
    From 4feccaa64af02a7061b60fb17dcedca1e3e3269e Mon Sep 17 00:00:00 2001
    From: tycho 
    Date: Sat, 30 May 2015 00:18:52 +0100
    Subject: Clean up Spawn Prepare Made cSpawnPrepare execute on the same thread
     since it is a syncronous operation, and most of the code happens on the
     lighting thread. Also moved cSpawnPrepare into its own file
    
    ---
     src/CMakeLists.txt   |   2 +
     src/SpawnPrepare.cpp | 105 +++++++++++++++++++++++++++++++++++++++
     src/SpawnPrepare.h   |  47 ++++++++++++++++++
     src/World.cpp        | 138 +--------------------------------------------------
     4 files changed, 156 insertions(+), 136 deletions(-)
     create mode 100644 src/SpawnPrepare.cpp
     create mode 100644 src/SpawnPrepare.h
    
    diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
    index a23e02789..5556ddc4d 100644
    --- a/src/CMakeLists.txt
    +++ b/src/CMakeLists.txt
    @@ -62,6 +62,7 @@ SET (SRCS
     	Scoreboard.cpp
     	Server.cpp
     	SetChunkData.cpp
    +	SpawnPrepare.cpp
     	Statistics.cpp
     	StringCompression.cpp
     	StringUtils.cpp
    @@ -133,6 +134,7 @@ SET (HDRS
     	Server.h
     	SetChunkData.h
     	SettingsRepositoryInterface.h
    +	SpawnPrepare.h
     	Statistics.h
     	StringCompression.h
     	StringUtils.h
    diff --git a/src/SpawnPrepare.cpp b/src/SpawnPrepare.cpp
    new file mode 100644
    index 000000000..80d2c52a1
    --- /dev/null
    +++ b/src/SpawnPrepare.cpp
    @@ -0,0 +1,105 @@
    +
    +#include "Globals.h"
    +
    +#include "SpawnPrepare.h"
    +#include "World.h"
    +
    +
    +
    +
    +
    +
    +
    +cSpawnPrepare::cSpawnPrepare(cWorld & a_World, int a_SpawnChunkX, int a_SpawnChunkZ, int a_PrepareDistance, int a_FirstIdx):
    +	m_World(a_World),
    +	m_SpawnChunkX(a_SpawnChunkX),
    +	m_SpawnChunkZ(a_SpawnChunkZ),
    +	m_PrepareDistance(a_PrepareDistance),
    +	m_NextIdx(a_FirstIdx),
    +	m_MaxIdx(a_PrepareDistance * a_PrepareDistance),
    +	m_NumPrepared(0),
    +	m_LastReportTime(std::chrono::steady_clock::now()),
    +	m_LastReportChunkCount(0)
    +{
    +}
    +
    +
    +
    +
    +
    +
    +
    +void cSpawnPrepare::PrepareChunks(cWorld & a_World, int a_SpawnChunkX, int a_SpawnChunkZ, int a_PrepareDistance)
    +{
    +
    +	// Queue the initial chunks:
    +	int MaxIdx = a_PrepareDistance * a_PrepareDistance;
    +	int maxQueue = std::min(MaxIdx - 1, 100);  // Number of chunks to queue at once
    +	cSpawnPrepare prep(a_World, a_SpawnChunkX, a_SpawnChunkZ, a_PrepareDistance, maxQueue);
    +	for (int i = 0; i < maxQueue; i++)
    +	{
    +		int chunkX, chunkZ;
    +		prep.DecodeChunkCoords(i, chunkX, chunkZ);
    +		a_World.PrepareChunk(chunkX, chunkZ, &prep);
    +	}  // for i
    +
    +	// Wait for the lighting thread to prepare everything. Event is set in the Call() callback:
    +	prep.m_EvtFinished.Wait();
    +}
    +
    +
    +
    +
    +
    +void cSpawnPrepare::DecodeChunkCoords(int a_Idx, int & a_ChunkX, int & a_ChunkZ)
    +{
    +	// A zigzag pattern from the top to bottom, each row alternating between forward-x and backward-x:
    +	int z = a_Idx / m_PrepareDistance;
    +	int x = a_Idx % m_PrepareDistance;
    +	if ((z & 1) == 0)
    +	{
    +		// Reverse every second row:
    +		x = m_PrepareDistance - 1 - x;
    +	}
    +	a_ChunkZ = m_SpawnChunkZ + z - m_PrepareDistance / 2;
    +	a_ChunkX = m_SpawnChunkX + x - m_PrepareDistance / 2;
    +}
    +
    +
    +
    +
    +
    +void cSpawnPrepare::Call(int a_ChunkX, int a_ChunkZ)
    +{
    +	// Check if this was the last chunk:
    +	m_NumPrepared += 1;
    +	if (m_NumPrepared >= m_MaxIdx)
    +	{
    +		m_EvtFinished.Set();
    +		// Must return here, because "this" may have gotten deleted by the previous line
    +		return;
    +	}
    +
    +	// Queue another chunk, if appropriate:
    +	if (m_NextIdx < m_MaxIdx)
    +	{
    +		int chunkX, chunkZ;
    +		DecodeChunkCoords(m_NextIdx, chunkX, chunkZ);
    +		m_World.GetLightingThread().QueueChunk(chunkX, chunkZ, this);
    +		m_NextIdx += 1;
    +	}
    +
    +	// Report progress every 1 second:
    +	auto Now = std::chrono::steady_clock::now();
    +	if (Now - m_LastReportTime > std::chrono::seconds(1))
    +	{
    +		float PercentDone = static_cast(m_NumPrepared * 100) / m_MaxIdx;
    +		float ChunkSpeed = static_cast((m_NumPrepared - m_LastReportChunkCount) * 1000) / std::chrono::duration_cast(Now - m_LastReportTime).count();
    +		LOG("Preparing spawn (%s): %.02f%% (%d/%d; %.02f chunks / sec)",
    +			m_World.GetName().c_str(), PercentDone, m_NumPrepared, m_MaxIdx, ChunkSpeed
    +		);
    +		m_LastReportTime = Now;
    +		m_LastReportChunkCount = m_NumPrepared;
    +	}
    +}
    +
    diff --git a/src/SpawnPrepare.h b/src/SpawnPrepare.h
    new file mode 100644
    index 000000000..bd5c0e0c6
    --- /dev/null
    +++ b/src/SpawnPrepare.h
    @@ -0,0 +1,47 @@
    +
    +#pragma once
    +
    +class cWorld;
    +	
    +
    +
    +/** Generates and lights the spawn area of the world. Runs as a separate thread. */
    +class cSpawnPrepare:
    +	public cChunkCoordCallback
    +{
    +
    +public:
    +	static void PrepareChunks(cWorld & a_World, int a_SpawnChunkX, int a_SpawnChunkZ, int a_PrepareDistance);
    +
    +protected:
    +	cWorld & m_World;
    +	int m_SpawnChunkX;
    +	int m_SpawnChunkZ;
    +	int m_PrepareDistance;
    +
    +	/** The index of the next chunk to be queued in the lighting thread. */
    +	int m_NextIdx;
    +
    +	/** The maximum index of the prepared chunks. Queueing stops when m_NextIdx reaches this number. */
    +	int m_MaxIdx;
    +
    +	/** Total number of chunks already finished preparing. Preparation finishes when this number reaches m_MaxIdx. */
    +	int m_NumPrepared;
    +
    +	/** Event used to signal that the preparation is finished. */
    +	cEvent m_EvtFinished;
    +
    +	/** The timestamp of the last progress report emitted. */
    +	std::chrono::steady_clock::time_point m_LastReportTime;
    +
    +	/** Number of chunks prepared when the last progress report was emitted. */
    +	int m_LastReportChunkCount;
    +
    +	cSpawnPrepare(cWorld & a_World, int a_SpawnChunkX, int a_SpawnChunkZ, int a_PrepareDistance, int a_FirstIdx);
    +
    +	virtual void Call(int a_ChunkX, int a_ChunkZ) override;
    +
    +	/** Decodes the index into chunk coords. Provides the specific chunk ordering. */
    +	void DecodeChunkCoords(int a_Idx, int & a_ChunkX, int & a_ChunkZ);
    +};
    +
    diff --git a/src/World.cpp b/src/World.cpp
    index 27bb3bdbd..aabbd7276 100644
    --- a/src/World.cpp
    +++ b/src/World.cpp
    @@ -58,6 +58,7 @@
     #endif
     
     #include "Broadcaster.h"
    +#include "SpawnPrepare.h"
     
     
     
    @@ -71,140 +72,6 @@ const int TIME_SPAWN_DIVISOR =   148;
     
     
     
    -////////////////////////////////////////////////////////////////////////////////
    -// cSpawnPrepare:
    -
    -/** Generates and lights the spawn area of the world. Runs as a separate thread. */
    -class cSpawnPrepare:
    -	public cIsThread,
    -	public cChunkCoordCallback
    -{
    -	typedef cIsThread super;
    -
    -public:
    -	cSpawnPrepare(cWorld & a_World, int a_SpawnChunkX, int a_SpawnChunkZ, int a_PrepareDistance):
    -		super("SpawnPrepare"),
    -		m_World(a_World),
    -		m_SpawnChunkX(a_SpawnChunkX),
    -		m_SpawnChunkZ(a_SpawnChunkZ),
    -		m_PrepareDistance(a_PrepareDistance),
    -		m_MaxIdx(a_PrepareDistance * a_PrepareDistance),
    -		m_NumPrepared(0),
    -		m_LastReportChunkCount(0)
    -	{
    -		// Start the thread:
    -		Start();
    -
    -		// Wait for start confirmation, so that the thread can be waited-upon after the constructor returns:
    -		m_EvtStarted.Wait();
    -	}
    -
    -
    -	// cIsThread override:
    -	virtual void Execute(void) override
    -	{
    -		// Confirm thread start:
    -		m_EvtStarted.Set();
    -
    -		// Queue the initial chunks:
    -		m_MaxIdx = m_PrepareDistance * m_PrepareDistance;
    -		int maxQueue = std::min(m_MaxIdx - 1, 100);  // Number of chunks to queue at once
    -		m_NextIdx = maxQueue;
    -		m_LastReportTime = std::chrono::steady_clock::now();
    -		for (int i = 0; i < maxQueue; i++)
    -		{
    -			int chunkX, chunkZ;
    -			DecodeChunkCoords(i, chunkX, chunkZ);
    -			m_World.PrepareChunk(chunkX, chunkZ, this);
    -		}  // for i
    -
    -		// Wait for the lighting thread to prepare everything. Event is set in the Call() callback:
    -		m_EvtFinished.Wait();
    -	}
    -
    -protected:
    -	cWorld & m_World;
    -	int m_SpawnChunkX;
    -	int m_SpawnChunkZ;
    -	int m_PrepareDistance;
    -
    -	/** The index of the next chunk to be queued in the lighting thread. */
    -	int m_NextIdx;
    -
    -	/** The maximum index of the prepared chunks. Queueing stops when m_NextIdx reaches this number. */
    -	int m_MaxIdx;
    -
    -	/** Total number of chunks already finished preparing. Preparation finishes when this number reaches m_MaxIdx. */
    -	int m_NumPrepared;
    -
    -	/** Event used to signal that the thread has started. */
    -	cEvent m_EvtStarted;
    -
    -	/** Event used to signal that the preparation is finished. */
    -	cEvent m_EvtFinished;
    -
    -	/** The timestamp of the last progress report emitted. */
    -	std::chrono::steady_clock::time_point m_LastReportTime;
    -
    -	/** Number of chunks prepared when the last progress report was emitted. */
    -	int m_LastReportChunkCount;
    -
    -	// cChunkCoordCallback override:
    -	virtual void Call(int a_ChunkX, int a_ChunkZ) override
    -	{
    -		// Check if this was the last chunk:
    -		m_NumPrepared += 1;
    -		if (m_NumPrepared >= m_MaxIdx)
    -		{
    -			m_EvtFinished.Set();
    -			// Must return here, because "this" may have gotten deleted by the previous line
    -			return;
    -		}
    -
    -		// Queue another chunk, if appropriate:
    -		if (m_NextIdx < m_MaxIdx)
    -		{
    -			int chunkX, chunkZ;
    -			DecodeChunkCoords(m_NextIdx, chunkX, chunkZ);
    -			m_World.GetLightingThread().QueueChunk(chunkX, chunkZ, this);
    -			m_NextIdx += 1;
    -		}
    -
    -		// Report progress every 1 second:
    -		auto Now = std::chrono::steady_clock::now();
    -		if (Now - m_LastReportTime > std::chrono::seconds(1))
    -		{
    -			float PercentDone = static_cast(m_NumPrepared * 100) / m_MaxIdx;
    -			float ChunkSpeed = static_cast((m_NumPrepared - m_LastReportChunkCount) * 1000) / std::chrono::duration_cast(Now - m_LastReportTime).count();
    -			LOG("Preparing spawn (%s): %.02f%% (%d/%d; %.02f chunks / sec)",
    -				m_World.GetName().c_str(), PercentDone, m_NumPrepared, m_MaxIdx, ChunkSpeed
    -			);
    -			m_LastReportTime = Now;
    -			m_LastReportChunkCount = m_NumPrepared;
    -		}
    -	}
    -
    -
    -	/** Decodes the index into chunk coords. Provides the specific chunk ordering. */
    -	void DecodeChunkCoords(int a_Idx, int & a_ChunkX, int & a_ChunkZ)
    -	{
    -		// A zigzag pattern from the top to bottom, each row alternating between forward-x and backward-x:
    -		int z = a_Idx / m_PrepareDistance;
    -		int x = a_Idx % m_PrepareDistance;
    -		if ((z & 1) == 0)
    -		{
    -			// Reverse every second row:
    -			x = m_PrepareDistance - 1 - x;
    -		}
    -		a_ChunkZ = m_SpawnChunkZ + z - m_PrepareDistance / 2;
    -		a_ChunkX = m_SpawnChunkX + x - m_PrepareDistance / 2;
    -	}
    -};
    -
    -
    -
    -
    -
     ////////////////////////////////////////////////////////////////////////////////
     // cWorld::cLock:
     
    @@ -470,8 +337,7 @@ void cWorld::InitializeSpawn(void)
     	int ViewDist = IniFile.GetValueSetI("SpawnPosition", "PregenerateDistance", DefaultViewDist);
     	IniFile.WriteFile(m_IniFileName);
     
    -	cSpawnPrepare prep(*this, ChunkX, ChunkZ, ViewDist);
    -	prep.Wait();
    +	cSpawnPrepare::PrepareChunks(*this, ChunkX, ChunkZ, ViewDist);
     	
     	#ifdef TEST_LINEBLOCKTRACER
     	// DEBUG: Test out the cLineBlockTracer class by tracing a few lines:
    -- 
    cgit v1.2.3
    
    
    From 291370e367f9c51f894ff132860ac2b55727181f Mon Sep 17 00:00:00 2001
    From: Tiger Wang 
    Date: Sat, 30 May 2015 00:23:34 +0100
    Subject: Fix Destroy() calling behaviour
    
    * Fixes Core/#142
    ---
     src/ClientHandle.cpp | 3 ++-
     1 file changed, 2 insertions(+), 1 deletion(-)
    
    diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
    index 9cba5619d..e3f63b091 100644
    --- a/src/ClientHandle.cpp
    +++ b/src/ClientHandle.cpp
    @@ -2181,11 +2181,12 @@ void cClientHandle::SendDestroyEntity(const cEntity & a_Entity)
     
     void cClientHandle::SendDisconnect(const AString & a_Reason)
     {
    +	// Destruction (Destroy()) is called when the client disconnects, not when a disconnect packet (or anything else) is sent
    +	// Otherwise, the cClientHandle instance is can be unexpectedly removed from the associated player - Core/#142
     	if (!m_HasSentDC)
     	{
     		LOGD("Sending a DC: \"%s\"", StripColorCodes(a_Reason).c_str());
     		m_Protocol->SendDisconnect(a_Reason);
    -		Destroy();
     		m_HasSentDC = true;
     	}
     }
    -- 
    cgit v1.2.3
    
    
    From 9c6c6af75a83a8538320f27837cc1b7819759d70 Mon Sep 17 00:00:00 2001
    From: SafwatHalaby 
    Date: Sat, 30 May 2015 09:54:32 +0300
    Subject: Fixed creeper explosions
    
    ---
     src/Mobs/Creeper.cpp | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/src/Mobs/Creeper.cpp b/src/Mobs/Creeper.cpp
    index ef3245894..30bd41f13 100644
    --- a/src/Mobs/Creeper.cpp
    +++ b/src/Mobs/Creeper.cpp
    @@ -27,7 +27,7 @@ void cCreeper::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
     {
     	super::Tick(a_Dt, a_Chunk);
     
    -	if (!ReachedFinalDestination() && !m_BurnedWithFlintAndSteel)
    +	if (!TargetIsInRange() && !m_BurnedWithFlintAndSteel)
     	{
     		m_ExplodingTimer = 0;
     		m_bIsBlowing = false;
    -- 
    cgit v1.2.3
    
    
    From a0f4e182b184f5adf7a73fe2ef6c92d966a9ec47 Mon Sep 17 00:00:00 2001
    From: SafwatHalaby 
    Date: Sat, 30 May 2015 10:03:34 +0300
    Subject: Disabled squid and Guardian Pathfinding
    
    ---
     src/Mobs/Guardian.cpp | 3 ++-
     src/Mobs/Squid.cpp    | 3 ++-
     2 files changed, 4 insertions(+), 2 deletions(-)
    
    diff --git a/src/Mobs/Guardian.cpp b/src/Mobs/Guardian.cpp
    index cfe7861a6..1429e2b13 100644
    --- a/src/Mobs/Guardian.cpp
    +++ b/src/Mobs/Guardian.cpp
    @@ -37,9 +37,10 @@ void cGuardian::GetDrops(cItems & a_Drops, cEntity * a_Killer)
     
     void cGuardian::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
     {
    +	m_IsFollowingPath = false;  // Disable Pathfinding until it's fixed. TODO
    +
     	// We must first process current location, and only then tick, otherwise we risk processing a location in a chunk
     	// that is not where the entity currently resides (FS #411)
    -	
     	Vector3d Pos = GetPosition();
     
     	// TODO: Not a real behavior, but cool :D
    diff --git a/src/Mobs/Squid.cpp b/src/Mobs/Squid.cpp
    index d148d65f3..30fbfa1ff 100644
    --- a/src/Mobs/Squid.cpp
    +++ b/src/Mobs/Squid.cpp
    @@ -35,9 +35,10 @@ void cSquid::GetDrops(cItems & a_Drops, cEntity * a_Killer)
     
     void cSquid::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
     {
    +	m_IsFollowingPath = false;  // Disable Pathfinding until it's fixed. TODO
    +
     	// We must first process current location, and only then tick, otherwise we risk processing a location in a chunk
     	// that is not where the entity currently resides (FS #411)
    -	
     	Vector3d Pos = GetPosition();
     
     	// TODO: Not a real behavior, but cool :D
    -- 
    cgit v1.2.3
    
    
    From d9f5d3c85897cb1b2adfcd86c52d9a0378909132 Mon Sep 17 00:00:00 2001
    From: SafwatHalaby 
    Date: Sat, 30 May 2015 10:50:04 +0300
    Subject: PF - Fixed diagonal cutting
    
    ---
     src/Mobs/Path.cpp | 17 ++++++++++++-----
     1 file changed, 12 insertions(+), 5 deletions(-)
    
    diff --git a/src/Mobs/Path.cpp b/src/Mobs/Path.cpp
    index 1848e144e..c21eb597c 100644
    --- a/src/Mobs/Path.cpp
    +++ b/src/Mobs/Path.cpp
    @@ -216,28 +216,35 @@ bool cPath::Step_Internal()
     	ProcessIfWalkable(CurrentCell->m_Location + Vector3i(0, 0, -1), CurrentCell, 10);
     
     	// Check diagonals on XY plane.
    +	// x = -1: west, x = 1: east.
     	for (int x = -1; x <= 1; x += 2)
     	{
     		if (GetCell(CurrentCell->m_Location + Vector3i(x, 0, 0))->m_IsSolid)  // If there's a solid our east / west.
     		{
    -			ProcessIfWalkable(CurrentCell->m_Location + Vector3i(x, 1, 0), CurrentCell, JUMP_G_COST);  // Check east / west-up.
    +			if (!GetCell(CurrentCell->m_Location + Vector3i(0, 1, 0))->m_IsSolid)  // If there isn't a solid above.
    +			{
    +				ProcessIfWalkable(CurrentCell->m_Location + Vector3i(x, 1, 0), CurrentCell, JUMP_G_COST);  // Check east-up / west-up.
    +			}
     		}
     		else
     		{
    -			ProcessIfWalkable(CurrentCell->m_Location + Vector3i(x, -1, 0), CurrentCell, 14);  // Else check east / west-down.
    +			ProcessIfWalkable(CurrentCell->m_Location + Vector3i(x, -1, 0), CurrentCell, 14);  // Else check east-down / west-down.
     		}
     	}
     
     	// Check diagonals on the YZ plane.
     	for (int z = -1; z <= 1; z += 2)
     	{
    -		if (GetCell(CurrentCell->m_Location + Vector3i(0, 0, z))->m_IsSolid)  // If there's a solid our east / west.
    +		if (GetCell(CurrentCell->m_Location + Vector3i(0, 0, z))->m_IsSolid)  // If there's a solid our north / south.
     		{
    -			ProcessIfWalkable(CurrentCell->m_Location + Vector3i(0, 1, z), CurrentCell, JUMP_G_COST);  // Check east / west-up.
    +			if (!GetCell(CurrentCell->m_Location + Vector3i(0, 1, 0))->m_IsSolid)  // If there isn't a solid above.
    +			{
    +				ProcessIfWalkable(CurrentCell->m_Location + Vector3i(0, 1, z), CurrentCell, JUMP_G_COST);  // Check north-up / south-up.
    +			}
     		}
     		else
     		{
    -			ProcessIfWalkable(CurrentCell->m_Location + Vector3i(0, -1, z), CurrentCell, 14);  // Else check east / west-down.
    +			ProcessIfWalkable(CurrentCell->m_Location + Vector3i(0, -1, z), CurrentCell, 14);  // Else check north-down / south-down.
     		}
     	}
     
    -- 
    cgit v1.2.3
    
    
    From ee34e7131a5a7a308fe431c44741d68a10bb2625 Mon Sep 17 00:00:00 2001
    From: linnemannr 
    Date: Sat, 30 May 2015 02:23:57 -0600
    Subject: Fix FreeBSD/clang errors caused by -Werror
    
    With FreeBSD/clang, -Werror combined with the configured warning flags yields
    some fatal errors, specifically related to signed conversion, 64 to 32 bit
    conversion, and tautological compares.
    
    CONTRIBUTORS
    
    	Add myself to the contributor list
    
    src/Generating/FinishGen.cpp
    
    	In cFinishGenPassiveMobs::GetRandomMob(), change the type of RandMob
    	from size_t to the difference_type of the ListOfSpawnables iterator
    	MobIter. Using size_t triggers a 64 bit to 32 bit conversion if the
    	difference_type of the iterator class is 64 bit
    
    	Also explicitly cast the noise expression to unsigned long so we don't
    	get a signed conversion warning from the modulo against
    	ListOfSpawnables.size()
    
    src/OSSupport/StackTrace.cpp
    
    	FreeBSD 10 and above includes a non glibc implementation of benchmark()
    	for which size_t, not int, is the return type. To account for this and
    	prevent a signed conversion warning, abstract the type for numItems with
    	a macro btsize
    
    src/StringUtils.h
    
    	In StringToInteger(), correct a tautological compare warning for
    	unsigned types with the template. If T is unsigned, comparing
    	std::numeric_limits::min() to the unsigned result is always
    	false. That control can enter this branch in an evaluated template with
    	an unsigned type T may also permit a signed number to be parsed and
    	erroneously stripped of its signedness at runtime. To guard against this
    	and avoid the warning in the case that the number parsed from the string
    	is non-positive, return false and don't try to parse if T is unsigned
    	and control enters the non-positive branch
    ---
     CONTRIBUTORS                 | 1 +
     src/Generating/FinishGen.cpp | 6 +++++-
     src/OSSupport/StackTrace.cpp | 9 ++++++++-
     src/StringUtils.h            | 6 ++++++
     4 files changed, 20 insertions(+), 2 deletions(-)
    
    diff --git a/CONTRIBUTORS b/CONTRIBUTORS
    index 4a6850a2f..3505d7155 100644
    --- a/CONTRIBUTORS
    +++ b/CONTRIBUTORS
    @@ -12,6 +12,7 @@ jasperarmstrong
     keyboard
     Lapayo
     Luksor
    +linnemannr (Reid Linnemann)
     M10360
     marmot21
     Masy98
    diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp
    index 5540f80d4..656dc95db 100644
    --- a/src/Generating/FinishGen.cpp
    +++ b/src/Generating/FinishGen.cpp
    @@ -1375,8 +1375,12 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc)
     		return mtInvalidType;
     	}
     
    -	size_t RandMob = static_cast((m_Noise.IntNoise2DInt(chunkX - chunkZ + 2, chunkX + 5) / 7)) % ListOfSpawnables.size();
     	auto MobIter = ListOfSpawnables.begin();
    +	using diff_type =
    +		std::iterator_traits::difference_type;
    +	diff_type RandMob = static_cast
    +		((unsigned long)(m_Noise.IntNoise2DInt(chunkX - chunkZ + 2, chunkX + 5) / 7)
    +		% ListOfSpawnables.size());
     	std::advance(MobIter, RandMob);
     
     	return *MobIter;
    diff --git a/src/OSSupport/StackTrace.cpp b/src/OSSupport/StackTrace.cpp
    index 015a53ba0..1ec10f20e 100644
    --- a/src/OSSupport/StackTrace.cpp
    +++ b/src/OSSupport/StackTrace.cpp
    @@ -12,6 +12,13 @@
     	#include 
     #endif
     
    +// FreeBSD uses size_t for the return type of backtrace()
    +#if defined(__FreeBSD__) && (__FreeBSD__ >= 10)
    +	#define btsize size_t
    +#else
    +	#define btsize int
    +#endif
    +
     
     
     
    @@ -34,7 +41,7 @@ void PrintStackTrace(void)
     		// Use the backtrace() function to get and output the stackTrace:
     		// Code adapted from http://stackoverflow.com/questions/77005/how-to-generate-a-stacktrace-when-my-gcc-c-app-crashes
     		void * stackTrace[30];
    -		int numItems = backtrace(stackTrace, ARRAYCOUNT(stackTrace));
    +		btsize numItems = backtrace(stackTrace, ARRAYCOUNT(stackTrace));
     		backtrace_symbols_fd(stackTrace, numItems, STDERR_FILENO);
     	#endif
     }
    diff --git a/src/StringUtils.h b/src/StringUtils.h
    index 8f67d8031..62767d007 100644
    --- a/src/StringUtils.h
    +++ b/src/StringUtils.h
    @@ -168,6 +168,12 @@ bool StringToInteger(const AString & a_str, T & a_Num)
     	}
     	else
     	{
    +		// Unsigned result cannot be signed!
    +		if (!std::numeric_limits::is_signed)
    +		{
    +			return false;
    +		}
    +
     		for (size_t size = a_str.size(); i < size; i++)
     		{
     			if ((a_str[i] < '0') || (a_str[i] > '9'))
    -- 
    cgit v1.2.3
    
    
    From 5f7455bc19eb81c98f1e1ceb65fa8e5acda57f8b Mon Sep 17 00:00:00 2001
    From: SafwatHalaby 
    Date: Sat, 30 May 2015 12:48:30 +0300
    Subject: PF - Handle all fencetypes
    
    ---
     src/Mobs/Path.cpp | 8 +++++++-
     1 file changed, 7 insertions(+), 1 deletion(-)
    
    diff --git a/src/Mobs/Path.cpp b/src/Mobs/Path.cpp
    index 1848e144e..325e102b7 100644
    --- a/src/Mobs/Path.cpp
    +++ b/src/Mobs/Path.cpp
    @@ -157,8 +157,14 @@ bool cPath::IsSolid(const Vector3i & a_Location)
     	int RelZ = a_Location.z - m_Chunk->GetPosZ() * cChunkDef::Width;
     
     	m_Chunk->GetBlockTypeMeta(RelX, a_Location.y, RelZ, BlockType, BlockMeta);
    -	if ((BlockType == E_BLOCK_FENCE) || (BlockType == E_BLOCK_FENCE_GATE))
    +	if (
    +			(BlockType == E_BLOCK_FENCE) ||
    +			(BlockType == E_BLOCK_FENCE_GATE) ||
    +			(BlockType == E_BLOCK_NETHER_BRICK_FENCE) ||
    +			((BlockType >= E_BLOCK_SPRUCE_FENCE_GATE) && (BlockType <= E_BLOCK_ACACIA_FENCE))
    +		)
     	{
    +		// TODO move this out of IsSolid to a proper place.
     		GetCell(a_Location + Vector3i(0, 1, 0))->m_IsSolid = true;  // Mobs will always think that the fence is 2 blocks high and therefore won't jump over.
     	}
     	if (BlockType == E_BLOCK_STATIONARY_WATER)
    -- 
    cgit v1.2.3
    
    
    From 06a74e45e247a2d23c6b5a238a3c1b9b17b6c341 Mon Sep 17 00:00:00 2001
    From: tycho 
    Date: Sat, 30 May 2015 11:11:17 +0100
    Subject: Made cLightingThread own its callbacks
    
    ---
     src/Bindings/ManualBindings_World.cpp |  3 +--
     src/ChunkMap.cpp                      |  4 ++--
     src/ChunkMap.h                        |  2 +-
     src/ChunkSender.cpp                   | 23 ++++++++++++++++-------
     src/ChunkSender.h                     | 22 ----------------------
     src/LightingThread.cpp                |  8 ++++----
     src/LightingThread.h                  |  6 +++---
     src/SpawnPrepare.cpp                  | 26 +++++++++++++++++++++++---
     src/SpawnPrepare.h                    |  8 +++++---
     src/World.cpp                         |  8 ++++----
     src/World.h                           |  4 ++--
     11 files changed, 61 insertions(+), 53 deletions(-)
    
    diff --git a/src/Bindings/ManualBindings_World.cpp b/src/Bindings/ManualBindings_World.cpp
    index 8d0288556..ddbebce78 100644
    --- a/src/Bindings/ManualBindings_World.cpp
    +++ b/src/Bindings/ManualBindings_World.cpp
    @@ -303,10 +303,9 @@ static int tolua_cWorld_PrepareChunk(lua_State * tolua_S)
     		cLuaState m_LuaState;
     		cLuaState::cRef m_Callback;
     	};
    -	cCallback * callback = new cCallback(tolua_S);
     
     	// Call the chunk preparation:
    -	world->PrepareChunk(chunkX, chunkZ, callback);
    +	world->PrepareChunk(chunkX, chunkZ, cpp14::make_unique(tolua_S));
     	return 0;
     }
     
    diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp
    index 44acc2013..2f38e4cd6 100644
    --- a/src/ChunkMap.cpp
    +++ b/src/ChunkMap.cpp
    @@ -2401,7 +2401,7 @@ void cChunkMap::TouchChunk(int a_ChunkX, int a_ChunkZ)
     
     
     
    -void cChunkMap::PrepareChunk(int a_ChunkX, int a_ChunkZ, cChunkCoordCallback * a_Callback)
    +void cChunkMap::PrepareChunk(int a_ChunkX, int a_ChunkZ, std::unique_ptr a_Callback)
     {
     	cCSLock Lock(m_CSLayers);
     	cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkZ);
    @@ -2409,7 +2409,7 @@ void cChunkMap::PrepareChunk(int a_ChunkX, int a_ChunkZ, cChunkCoordCallback * a
     	// If the chunk is not prepared, queue it in the lighting thread, that will do all the needed processing:
     	if ((Chunk == nullptr) || !Chunk->IsValid() || !Chunk->IsLightValid())
     	{
    -		m_World->GetLightingThread().QueueChunk(a_ChunkX, a_ChunkZ, a_Callback);
    +		m_World->GetLightingThread().QueueChunk(a_ChunkX, a_ChunkZ, std::move(a_Callback));
     		return;
     	}
     
    diff --git a/src/ChunkMap.h b/src/ChunkMap.h
    index 35f66f339..964188bbe 100644
    --- a/src/ChunkMap.h
    +++ b/src/ChunkMap.h
    @@ -322,7 +322,7 @@ public:
     	The specified chunk is queued to be loaded or generated, and lit if needed.
     	The specified callback is called after the chunk has been prepared. If there's no preparation to do, only the callback is called.
     	It is legal to call without the callback. */
    -	void PrepareChunk(int a_ChunkX, int a_ChunkZ, cChunkCoordCallback * a_CallAfter = nullptr);  // Lua-accessible
    +	void PrepareChunk(int a_ChunkX, int a_ChunkZ, std::unique_ptr a_CallAfter = {});  // Lua-accessible
     
     	/** Queues the chunk for generating.
     	First attempts to load the chunk from the storage. If that fails, queues the chunk for generating.
    diff --git a/src/ChunkSender.cpp b/src/ChunkSender.cpp
    index 70b2e9101..2f18ea75c 100644
    --- a/src/ChunkSender.cpp
    +++ b/src/ChunkSender.cpp
    @@ -21,10 +21,21 @@
     ////////////////////////////////////////////////////////////////////////////////
     // cNotifyChunkSender:
     
    -void cNotifyChunkSender::Call(int a_ChunkX, int a_ChunkZ)
    +
    +/// Callback that can be used to notify chunk sender upon another chunkcoord notification
    +class cNotifyChunkSender :
    +	public cChunkCoordCallback
     {
    -	m_ChunkSender->ChunkReady(a_ChunkX, a_ChunkZ);
    -}
    +	virtual void Call(int a_ChunkX, int a_ChunkZ) override
    +	{
    +		m_ChunkSender->ChunkReady(a_ChunkX, a_ChunkZ);
    +	}
    +
    +	cChunkSender * m_ChunkSender;
    +public:
    +	cNotifyChunkSender(cChunkSender * a_ChunkSender) : m_ChunkSender(a_ChunkSender) {}
    +};
    +
     
     
     
    @@ -36,10 +47,8 @@ void cNotifyChunkSender::Call(int a_ChunkX, int a_ChunkZ)
     cChunkSender::cChunkSender(void) :
     	super("ChunkSender"),
     	m_World(nullptr),
    -	m_RemoveCount(0),
    -	m_Notify(nullptr)
    +	m_RemoveCount(0)
     {
    -	m_Notify.SetChunkSender(this);
     }
     
     
    @@ -272,7 +281,7 @@ void cChunkSender::SendChunk(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Clien
     	// If the chunk is not lighted, queue it for relighting and get notified when it's ready:
     	if (!m_World->IsChunkLighted(a_ChunkX, a_ChunkZ))
     	{
    -		m_World->QueueLightChunk(a_ChunkX, a_ChunkZ, &m_Notify);
    +		m_World->QueueLightChunk(a_ChunkX, a_ChunkZ, cpp14::make_unique(this));
     		return;
     	}
     
    diff --git a/src/ChunkSender.h b/src/ChunkSender.h
    index 8b187c5f9..1376baeb3 100644
    --- a/src/ChunkSender.h
    +++ b/src/ChunkSender.h
    @@ -47,26 +47,6 @@ class cChunkSender;
     
     
     
    -/// Callback that can be used to notify chunk sender upon another chunkcoord notification
    -class cNotifyChunkSender :
    -	public cChunkCoordCallback
    -{
    -	virtual void Call(int a_ChunkX, int a_ChunkZ) override;
    -
    -	cChunkSender * m_ChunkSender;
    -public:
    -	cNotifyChunkSender(cChunkSender * a_ChunkSender) : m_ChunkSender(a_ChunkSender) {}
    -	
    -	void SetChunkSender(cChunkSender * a_ChunkSender)
    -	{
    -		m_ChunkSender = a_ChunkSender;
    -	}
    -} ;
    -
    -
    -
    -
    -
     class cChunkSender:
     	public cIsThread,
     	public cChunkDataSeparateCollector
    @@ -150,8 +130,6 @@ protected:
     	cEvent            m_evtRemoved;  // Set when removed clients are safe to be deleted
     	int               m_RemoveCount;  // Number of threads waiting for a client removal (m_evtRemoved needs to be set this many times)
     	
    -	cNotifyChunkSender m_Notify;  // Used for chunks that don't have a valid lighting - they will be re-queued after lightcalc
    -	
     	// Data about the chunk that is being sent:
     	// NOTE that m_BlockData[] is inherited from the cChunkDataCollector
     	unsigned char m_BiomeMap[cChunkDef::Width * cChunkDef::Width];
    diff --git a/src/LightingThread.cpp b/src/LightingThread.cpp
    index 266744a24..7f13a94fd 100644
    --- a/src/LightingThread.cpp
    +++ b/src/LightingThread.cpp
    @@ -149,11 +149,11 @@ void cLightingThread::Stop(void)
     
     
     
    -void cLightingThread::QueueChunk(int a_ChunkX, int a_ChunkZ, cChunkCoordCallback * a_CallbackAfter)
    +void cLightingThread::QueueChunk(int a_ChunkX, int a_ChunkZ, std::unique_ptr a_CallbackAfter)
     {
     	ASSERT(m_World != nullptr);  // Did you call Start() properly?
     	
    -	cChunkStay * ChunkStay = new cLightingChunkStay(*this, a_ChunkX, a_ChunkZ, a_CallbackAfter);
    +	cChunkStay * ChunkStay = new cLightingChunkStay(*this, a_ChunkX, a_ChunkZ, std::move(a_CallbackAfter));
     	{
     		// The ChunkStay will enqueue itself using the QueueChunkStay() once it is fully loaded
     		// In the meantime, put it into the PendingQueue so that it can be removed when stopping the thread
    @@ -599,11 +599,11 @@ void cLightingThread::QueueChunkStay(cLightingChunkStay & a_ChunkStay)
     ////////////////////////////////////////////////////////////////////////////////
     // cLightingThread::cLightingChunkStay:
     
    -cLightingThread::cLightingChunkStay::cLightingChunkStay(cLightingThread & a_LightingThread, int a_ChunkX, int a_ChunkZ, cChunkCoordCallback * a_CallbackAfter) :
    +cLightingThread::cLightingChunkStay::cLightingChunkStay(cLightingThread & a_LightingThread, int a_ChunkX, int a_ChunkZ, std::unique_ptr a_CallbackAfter) :
     	m_LightingThread(a_LightingThread),
     	m_ChunkX(a_ChunkX),
     	m_ChunkZ(a_ChunkZ),
    -	m_CallbackAfter(a_CallbackAfter)
    +	m_CallbackAfter(std::move(a_CallbackAfter))
     {
     	Add(a_ChunkX + 1, a_ChunkZ + 1);
     	Add(a_ChunkX + 1, a_ChunkZ);
    diff --git a/src/LightingThread.h b/src/LightingThread.h
    index 87eb9c6d8..da6be12c8 100644
    --- a/src/LightingThread.h
    +++ b/src/LightingThread.h
    @@ -61,7 +61,7 @@ public:
     	void Stop(void);
     	
     	/** Queues the entire chunk for lighting */
    -	void QueueChunk(int a_ChunkX, int a_ChunkZ, cChunkCoordCallback * a_CallbackAfter = nullptr);
    +	void QueueChunk(int a_ChunkX, int a_ChunkZ, std::unique_ptr a_CallbackAfter);
     	
     	/** Blocks until the queue is empty or the thread is terminated */
     	void WaitForQueueEmpty(void);
    @@ -77,9 +77,9 @@ protected:
     		cLightingThread & m_LightingThread;
     		int m_ChunkX;
     		int m_ChunkZ;
    -		cChunkCoordCallback * m_CallbackAfter;
    +		std::unique_ptr m_CallbackAfter;
     		
    -		cLightingChunkStay(cLightingThread & a_LightingThread, int a_ChunkX, int a_ChunkZ, cChunkCoordCallback * a_CallbackAfter);
    +		cLightingChunkStay(cLightingThread & a_LightingThread, int a_ChunkX, int a_ChunkZ, std::unique_ptr a_CallbackAfter);
     		
     	protected:
     		virtual void OnChunkAvailable(int a_ChunkX, int a_ChunkZ) override
    diff --git a/src/SpawnPrepare.cpp b/src/SpawnPrepare.cpp
    index 80d2c52a1..74dcb3ecd 100644
    --- a/src/SpawnPrepare.cpp
    +++ b/src/SpawnPrepare.cpp
    @@ -8,6 +8,26 @@
     
     
     
    +class cSpawnPrepareCallback :
    +	public cChunkCoordCallback
    +{
    +public:
    +	cSpawnPrepareCallback(cSpawnPrepare & a_SpawnPrepare) :
    +		m_SpawnPrepare(a_SpawnPrepare)
    +	{
    +	}
    +protected:
    +
    +	cSpawnPrepare & m_SpawnPrepare;
    +	
    +	virtual void Call(int a_ChunkX, int a_ChunkZ) override
    +	{
    +		m_SpawnPrepare.PreparedChunkCallback(a_ChunkX, a_ChunkZ);
    +	}
    +};
    +
    +
    +
     
     
     cSpawnPrepare::cSpawnPrepare(cWorld & a_World, int a_SpawnChunkX, int a_SpawnChunkZ, int a_PrepareDistance, int a_FirstIdx):
    @@ -40,7 +60,7 @@ void cSpawnPrepare::PrepareChunks(cWorld & a_World, int a_SpawnChunkX, int a_Spa
     	{
     		int chunkX, chunkZ;
     		prep.DecodeChunkCoords(i, chunkX, chunkZ);
    -		a_World.PrepareChunk(chunkX, chunkZ, &prep);
    +		a_World.PrepareChunk(chunkX, chunkZ, cpp14::make_unique(prep));
     	}  // for i
     
     	// Wait for the lighting thread to prepare everything. Event is set in the Call() callback:
    @@ -69,7 +89,7 @@ void cSpawnPrepare::DecodeChunkCoords(int a_Idx, int & a_ChunkX, int & a_ChunkZ)
     
     
     
    -void cSpawnPrepare::Call(int a_ChunkX, int a_ChunkZ)
    +void cSpawnPrepare::PreparedChunkCallback(int a_ChunkX, int a_ChunkZ)
     {
     	// Check if this was the last chunk:
     	m_NumPrepared += 1;
    @@ -85,7 +105,7 @@ void cSpawnPrepare::Call(int a_ChunkX, int a_ChunkZ)
     	{
     		int chunkX, chunkZ;
     		DecodeChunkCoords(m_NextIdx, chunkX, chunkZ);
    -		m_World.GetLightingThread().QueueChunk(chunkX, chunkZ, this);
    +		m_World.GetLightingThread().QueueChunk(chunkX, chunkZ, cpp14::make_unique(*this));
     		m_NextIdx += 1;
     	}
     
    diff --git a/src/SpawnPrepare.h b/src/SpawnPrepare.h
    index bd5c0e0c6..cc0da504e 100644
    --- a/src/SpawnPrepare.h
    +++ b/src/SpawnPrepare.h
    @@ -6,8 +6,7 @@ class cWorld;
     
     
     /** Generates and lights the spawn area of the world. Runs as a separate thread. */
    -class cSpawnPrepare:
    -	public cChunkCoordCallback
    +class cSpawnPrepare
     {
     
     public:
    @@ -39,9 +38,12 @@ protected:
     
     	cSpawnPrepare(cWorld & a_World, int a_SpawnChunkX, int a_SpawnChunkZ, int a_PrepareDistance, int a_FirstIdx);
     
    -	virtual void Call(int a_ChunkX, int a_ChunkZ) override;
    +	void PreparedChunkCallback(int a_ChunkX, int a_ChunkZ);
     
     	/** Decodes the index into chunk coords. Provides the specific chunk ordering. */
     	void DecodeChunkCoords(int a_Idx, int & a_ChunkX, int & a_ChunkZ);
    +
    +	friend class cSpawnPrepareCallback;
    +
     };
     
    diff --git a/src/World.cpp b/src/World.cpp
    index aabbd7276..f7d2165c7 100644
    --- a/src/World.cpp
    +++ b/src/World.cpp
    @@ -2872,9 +2872,9 @@ void cWorld::TouchChunk(int a_ChunkX, int a_ChunkZ)
     
     
     
    -void cWorld::PrepareChunk(int a_ChunkX, int a_ChunkZ, cChunkCoordCallback * a_CallAfter)
    +void cWorld::PrepareChunk(int a_ChunkX, int a_ChunkZ, std::unique_ptr a_CallAfter)
     {
    -	m_ChunkMap->PrepareChunk(a_ChunkX, a_ChunkZ, a_CallAfter);
    +	m_ChunkMap->PrepareChunk(a_ChunkX, a_ChunkZ, std::move(a_CallAfter));
     }
     
     
    @@ -2998,9 +2998,9 @@ void cWorld::GenerateChunk(int a_ChunkX, int a_ChunkZ)
     
     
     
    -void cWorld::QueueLightChunk(int a_ChunkX, int a_ChunkZ, cChunkCoordCallback * a_Callback)
    +void cWorld::QueueLightChunk(int a_ChunkX, int a_ChunkZ, std::unique_ptr a_Callback)
     {
    -	m_Lighting.QueueChunk(a_ChunkX, a_ChunkZ, a_Callback);
    +	m_Lighting.QueueChunk(a_ChunkX, a_ChunkZ, std::move(a_Callback));
     }
     
     
    diff --git a/src/World.h b/src/World.h
    index d1ca01989..064b50165 100644
    --- a/src/World.h
    +++ b/src/World.h
    @@ -385,7 +385,7 @@ public:
     	The specified chunk is queued to be loaded or generated, and lit if needed.
     	The specified callback is called after the chunk has been prepared. If there's no preparation to do, only the callback is called.
     	It is legal to call with no callback. */
    -	void PrepareChunk(int a_ChunkX, int a_ChunkZ, cChunkCoordCallback * a_CallAfter = nullptr);
    +	void PrepareChunk(int a_ChunkX, int a_ChunkZ, std::unique_ptr a_CallAfter = {});
     	
     	/** Marks the chunk as failed-to-load: */
     	void ChunkLoadFailed(int a_ChunkX, int a_ChunkZ);
    @@ -409,7 +409,7 @@ public:
     	void GenerateChunk(int a_ChunkX, int a_ChunkZ);  // tolua_export
     	
     	/** Queues a chunk for lighting; a_Callback is called after the chunk is lighted */
    -	void QueueLightChunk(int a_ChunkX, int a_ChunkZ, cChunkCoordCallback * a_Callback = nullptr);
    +	void QueueLightChunk(int a_ChunkX, int a_ChunkZ, std::unique_ptr a_Callback = {});
     	
     	bool IsChunkLighted(int a_ChunkX, int a_ChunkZ);
     	
    -- 
    cgit v1.2.3
    
    
    From 28bab3742582f0818098dd8f3060369f411b1f5a Mon Sep 17 00:00:00 2001
    From: Alexander Harkness 
    Date: Sat, 30 May 2015 11:22:49 +0100
    Subject: Fixed wrong indent.
    
    ---
     src/Mobs/Path.cpp | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/src/Mobs/Path.cpp b/src/Mobs/Path.cpp
    index f6660907c..e987381f7 100644
    --- a/src/Mobs/Path.cpp
    +++ b/src/Mobs/Path.cpp
    @@ -162,7 +162,7 @@ bool cPath::IsSolid(const Vector3i & a_Location)
     			(BlockType == E_BLOCK_FENCE_GATE) ||
     			(BlockType == E_BLOCK_NETHER_BRICK_FENCE) ||
     			((BlockType >= E_BLOCK_SPRUCE_FENCE_GATE) && (BlockType <= E_BLOCK_ACACIA_FENCE))
    -		)
    +	)
     	{
     		// TODO move this out of IsSolid to a proper place.
     		GetCell(a_Location + Vector3i(0, 1, 0))->m_IsSolid = true;  // Mobs will always think that the fence is 2 blocks high and therefore won't jump over.
    -- 
    cgit v1.2.3
    
    
    From bca13d918770d28dda143931bbac4d594a327fac Mon Sep 17 00:00:00 2001
    From: tycho 
    Date: Sat, 30 May 2015 12:31:05 +0100
    Subject: Fixed minor cast warning
    
    ---
     src/Generating/FinishGen.cpp | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp
    index 656dc95db..59af0fd63 100644
    --- a/src/Generating/FinishGen.cpp
    +++ b/src/Generating/FinishGen.cpp
    @@ -1379,7 +1379,7 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc)
     	using diff_type =
     		std::iterator_traits::difference_type;
     	diff_type RandMob = static_cast
    -		((unsigned long)(m_Noise.IntNoise2DInt(chunkX - chunkZ + 2, chunkX + 5) / 7)
    +		(static_cast(m_Noise.IntNoise2DInt(chunkX - chunkZ + 2, chunkX + 5) / 7)
     		% ListOfSpawnables.size());
     	std::advance(MobIter, RandMob);
     
    -- 
    cgit v1.2.3
    
    
    From 4504ec7a67893a329156712851bf8dcec8ac3468 Mon Sep 17 00:00:00 2001
    From: Alexander Harkness 
    Date: Sat, 30 May 2015 13:06:46 +0100
    Subject: Updated MagicCarpet submodule. Fixes #2155
    
    ---
     MCServer/Plugins/MagicCarpet | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/MCServer/Plugins/MagicCarpet b/MCServer/Plugins/MagicCarpet
    index 493f2dfa6..94da343b6 160000
    --- a/MCServer/Plugins/MagicCarpet
    +++ b/MCServer/Plugins/MagicCarpet
    @@ -1 +1 @@
    -Subproject commit 493f2dfa6d39f134e37c4c614cf8d6ffd10c825f
    +Subproject commit 94da343b62f0498a5843247f36d6ee00cbeb8f21
    -- 
    cgit v1.2.3
    
    
    From d5c89eceb8b5596816a74e5c4ce08b851403f19b Mon Sep 17 00:00:00 2001
    From: tycho 
    Date: Sat, 30 May 2015 13:32:22 +0100
    Subject: Moved shared cmake flags to the CMAKE_C_FLAGS var
    
    ---
     SetFlags.cmake | 10 ++--------
     1 file changed, 2 insertions(+), 8 deletions(-)
    
    diff --git a/SetFlags.cmake b/SetFlags.cmake
    index e336bd6c8..b79551eef 100644
    --- a/SetFlags.cmake
    +++ b/SetFlags.cmake
    @@ -16,14 +16,8 @@ macro (add_flags_lnk FLAGS)
     endmacro()
     
     macro(add_flags_cxx FLAGS)
    -	#set(CMAKE_CXX_FLAGS          "${CMAKE_CXX_FLAGS}          ${FLAGS}")
    -	#set(CMAKE_C_FLAGS            "${CMAKE_C_FLAGS}            ${FLAGS}")
    -	set(CMAKE_CXX_FLAGS_DEBUG    "${CMAKE_CXX_FLAGS_DEBUG}    ${FLAGS}")
    -	set(CMAKE_C_FLAGS_DEBUG      "${CMAKE_C_FLAGS_DEBUG}      ${FLAGS}")
    -	set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_COVERAGE} ${FLAGS}")
    -	set(CMAKE_C_FLAGS_COVERAGE   "${CMAKE_C_FLAGS_COVERAGE}   ${FLAGS}")
    -	set(CMAKE_CXX_FLAGS_RELEASE  "${CMAKE_CXX_FLAGS_RELEASE}  ${FLAGS}")
    -	set(CMAKE_C_FLAGS_RELEASE    "${CMAKE_C_FLAGS_RELEASE}    ${FLAGS}")
    +	set(CMAKE_CXX_FLAGS          "${CMAKE_CXX_FLAGS} ${FLAGS}")
    +	set(CMAKE_C_FLAGS            "${CMAKE_C_FLAGS}   ${FLAGS}")
     endmacro()
     
     
    -- 
    cgit v1.2.3
    
    
    From 80bf058c90fd230ff1b8596fa4e0afc31549e29f Mon Sep 17 00:00:00 2001
    From: jammet 
    Date: Sun, 31 May 2015 18:54:49 +0200
    Subject: Fix Daylightsensor recipe
    
    Something like Woodslap^-1 didn't work here, so I split it up into individual recipes.
    ---
     MCServer/crafting.txt | 7 ++++++-
     1 file changed, 6 insertions(+), 1 deletion(-)
    
    diff --git a/MCServer/crafting.txt b/MCServer/crafting.txt
    index daac9e098..c33e91cd7 100644
    --- a/MCServer/crafting.txt
    +++ b/MCServer/crafting.txt
    @@ -303,7 +303,12 @@ Dispenser        = Cobblestone, 1:1, 1:2, 1:3, 2:1, 3:1, 3:2, 3:3      | Redston
     Dropper          = Cobblestone, 1:1, 2:1, 3:1, 1:2, 1:3, 3:2, 3:3 | Hopper, 2:2 | RedstoneDust, 2:3
     Repeater         = Stone,  1:2, 2:2, 3:2            | RedstoneTorchOn, 1:1, 3:1 | RedstoneDust, 2:1
     Comparator       = RedstoneTorchOn, 2:1, 1:2, 3:2   | NetherQuartz, 2:2 | Stone, 1:3, 2:3, 3:3
    -DaylightSensor   = Glass, 1:1, 2:1, 3:1             | NetherQuartz, 1:2, 2:2, 3:2 | Woodslab, 1:3, 2:3, 3:3
    +DaylightSensor   = Glass, 1:1, 2:1, 3:1             | NetherQuartz, 1:2, 2:2, 3:2 | AcaciaWoodslab, 1:3, 2:3, 3:3
    +DaylightSensor   = Glass, 1:1, 2:1, 3:1             | NetherQuartz, 1:2, 2:2, 3:2 | BirchWoodslab, 1:3, 2:3, 3:3
    +DaylightSensor   = Glass, 1:1, 2:1, 3:1             | NetherQuartz, 1:2, 2:2, 3:2 | DarkOakWoodslab, 1:3, 2:3, 3:3
    +DaylightSensor   = Glass, 1:1, 2:1, 3:1             | NetherQuartz, 1:2, 2:2, 3:2 | JungleWoodslab, 1:3, 2:3, 3:3
    +DaylightSensor   = Glass, 1:1, 2:1, 3:1             | NetherQuartz, 1:2, 2:2, 3:2 | OakWoodslab, 1:3, 2:3, 3:3
    +DaylightSensor   = Glass, 1:1, 2:1, 3:1             | NetherQuartz, 1:2, 2:2, 3:2 | SpruceWoodslab, 1:3, 2:3, 3:3
     Hopper           = IronIngot, 1:1, 3:1, 1:2, 3:2, 2:3 | Chest, 2:2
     Piston           = Planks^-1, 1:1, 2:1, 3:1 | RedstoneDust, 2:3 | Cobblestone, 1:2, 3:2, 1:3, 3:3 | IronIngot, 2:2
     StickyPiston     = Piston, * | SlimeBall, *
    -- 
    cgit v1.2.3
    
    
    From 98df75d5ab0bd1af93ed980993698b358037dd15 Mon Sep 17 00:00:00 2001
    From: Mattes D 
    Date: Sun, 31 May 2015 19:44:08 +0200
    Subject: ManualBindings: Fixed DoWithXYZ and ForEachInChunk signatures.
    
    Fixes forum report http://forum.mc-server.org/showthread.php?tid=1993
    ---
     src/Bindings/ManualBindings.h | 10 ++++++----
     1 file changed, 6 insertions(+), 4 deletions(-)
    
    diff --git a/src/Bindings/ManualBindings.h b/src/Bindings/ManualBindings.h
    index 83b960058..f8c9b96de 100644
    --- a/src/Bindings/ManualBindings.h
    +++ b/src/Bindings/ManualBindings.h
    @@ -253,8 +253,9 @@ public:
     		// Check params:
     		cLuaState L(tolua_S);
     		if (
    -			!L.CheckParamNumber(2, 5) ||
    -			!L.CheckParamFunction(6)
    +			!L.CheckParamNumber(2, 4) ||
    +			!L.CheckParamFunction(5) ||
    +			!L.CheckParamEnd(6)
     		)
     		{
     			return 0;
    @@ -316,8 +317,9 @@ public:
     		// Check params:
     		cLuaState L(tolua_S);
     		if (
    -			!L.CheckParamNumber(2, 4) ||
    -			!L.CheckParamFunction(5)
    +			!L.CheckParamNumber(2, 3) ||
    +			!L.CheckParamFunction(4) ||
    +			!L.CheckParamEnd(5)
     		)
     		{
     			return 0;
    -- 
    cgit v1.2.3
    
    
    From 25e83bc1d9ec2d470a684710ad9da119bf6a4209 Mon Sep 17 00:00:00 2001
    From: Mattes D 
    Date: Sun, 31 May 2015 21:21:57 +0200
    Subject: Fixed crafting recipe matching.
    
    Fixes #2096.
    ---
     src/CraftingRecipes.cpp | 3 +++
     1 file changed, 3 insertions(+)
    
    diff --git a/src/CraftingRecipes.cpp b/src/CraftingRecipes.cpp
    index 755b152b0..a95ac5f84 100644
    --- a/src/CraftingRecipes.cpp
    +++ b/src/CraftingRecipes.cpp
    @@ -771,9 +771,12 @@ cCraftingRecipes::cRecipe * cCraftingRecipes::MatchRecipe(const cItem * a_Crafti
     			continue;
     		}
     		Recipe->m_Ingredients.push_back(*itrS);
    +		Recipe->m_Ingredients.back().x += a_OffsetX;
    +		Recipe->m_Ingredients.back().y += a_OffsetY;
     	}
     	Recipe->m_Ingredients.insert(Recipe->m_Ingredients.end(), MatchedSlots.begin(), MatchedSlots.end());
     
    +	// Handle the fireworks-related effects:
     	// We use Recipe instead of a_Recipe because we want the wildcard ingredients' slot numbers as well, which was just added previously
     	HandleFireworks(a_CraftingGrid, Recipe.get(), a_GridStride, a_OffsetX, a_OffsetY);
     
    -- 
    cgit v1.2.3
    
    
    From ff55294583456909d61f8612507bbd484f609cb0 Mon Sep 17 00:00:00 2001
    From: jammet 
    Date: Sun, 31 May 2015 23:41:00 +0200
    Subject: Update crafting.txt
    
    ---
     MCServer/crafting.txt | 7 +------
     1 file changed, 1 insertion(+), 6 deletions(-)
    
    diff --git a/MCServer/crafting.txt b/MCServer/crafting.txt
    index c33e91cd7..050186f66 100644
    --- a/MCServer/crafting.txt
    +++ b/MCServer/crafting.txt
    @@ -303,12 +303,7 @@ Dispenser        = Cobblestone, 1:1, 1:2, 1:3, 2:1, 3:1, 3:2, 3:3      | Redston
     Dropper          = Cobblestone, 1:1, 2:1, 3:1, 1:2, 1:3, 3:2, 3:3 | Hopper, 2:2 | RedstoneDust, 2:3
     Repeater         = Stone,  1:2, 2:2, 3:2            | RedstoneTorchOn, 1:1, 3:1 | RedstoneDust, 2:1
     Comparator       = RedstoneTorchOn, 2:1, 1:2, 3:2   | NetherQuartz, 2:2 | Stone, 1:3, 2:3, 3:3
    -DaylightSensor   = Glass, 1:1, 2:1, 3:1             | NetherQuartz, 1:2, 2:2, 3:2 | AcaciaWoodslab, 1:3, 2:3, 3:3
    -DaylightSensor   = Glass, 1:1, 2:1, 3:1             | NetherQuartz, 1:2, 2:2, 3:2 | BirchWoodslab, 1:3, 2:3, 3:3
    -DaylightSensor   = Glass, 1:1, 2:1, 3:1             | NetherQuartz, 1:2, 2:2, 3:2 | DarkOakWoodslab, 1:3, 2:3, 3:3
    -DaylightSensor   = Glass, 1:1, 2:1, 3:1             | NetherQuartz, 1:2, 2:2, 3:2 | JungleWoodslab, 1:3, 2:3, 3:3
    -DaylightSensor   = Glass, 1:1, 2:1, 3:1             | NetherQuartz, 1:2, 2:2, 3:2 | OakWoodslab, 1:3, 2:3, 3:3
    -DaylightSensor   = Glass, 1:1, 2:1, 3:1             | NetherQuartz, 1:2, 2:2, 3:2 | SpruceWoodslab, 1:3, 2:3, 3:3
    +DaylightSensor   = Glass, 1:1, 2:1, 3:1             | NetherQuartz, 1:2, 2:2, 3:2 | WoodenSlab^-1, 1:3, 2:3, 3:3
     Hopper           = IronIngot, 1:1, 3:1, 1:2, 3:2, 2:3 | Chest, 2:2
     Piston           = Planks^-1, 1:1, 2:1, 3:1 | RedstoneDust, 2:3 | Cobblestone, 1:2, 3:2, 1:3, 3:3 | IronIngot, 2:2
     StickyPiston     = Piston, * | SlimeBall, *
    -- 
    cgit v1.2.3
    
    
    From 65a62601dc3088cc5b076a83963646358eff6b1e Mon Sep 17 00:00:00 2001
    From: Anthony Birkett 
    Date: Mon, 1 Jun 2015 14:41:06 +0100
    Subject: Use the new style command line parameters for Windows Service
     support. Ignore invalid or malformed command line parameters, prevent
     unhandled exceptions. NOTE: Users will need to reinstall the service, now
     uses "-d" instead of "/service" in the start parameters.
    
    ---
     CONTRIBUTORS                         |  1 +
     MCServer/install_windows_service.cmd |  2 +-
     src/main.cpp                         | 19 +++++++++----------
     3 files changed, 11 insertions(+), 11 deletions(-)
    
    diff --git a/CONTRIBUTORS b/CONTRIBUTORS
    index 3505d7155..4dc357ab3 100644
    --- a/CONTRIBUTORS
    +++ b/CONTRIBUTORS
    @@ -3,6 +3,7 @@ Many people have contributed to MCServer, and this list attempts to broadcast at
     BasedDoge (Donated AlchemistVillage prefabs)
     bearbin (Alexander Harkness)
     beeduck
    +birkett (Anthony Birkett)
     derouinw
     Diusrex
     Duralex
    diff --git a/MCServer/install_windows_service.cmd b/MCServer/install_windows_service.cmd
    index ba8a8c128..d6b6c15a3 100644
    --- a/MCServer/install_windows_service.cmd
    +++ b/MCServer/install_windows_service.cmd
    @@ -3,5 +3,5 @@ rem Alter this if you need to install multiple instances.
     set SERVICENAME="MCServer"
     
     set CURRENTDIR=%CD%
    -sc create %SERVICENAME% binPath= "%CURRENTDIR%\MCServer.exe /service" start= auto DisplayName= %SERVICENAME%
    +sc create %SERVICENAME% binPath= "%CURRENTDIR%\MCServer.exe -d" start= auto DisplayName= %SERVICENAME%
     sc description %SERVICENAME% "Minecraft server instance"
    \ No newline at end of file
    diff --git a/src/main.cpp b/src/main.cpp
    index 5cd057278..d5c39cecd 100644
    --- a/src/main.cpp
    +++ b/src/main.cpp
    @@ -382,6 +382,10 @@ std::unique_ptr parseArguments(int argc, char **argv)
     
     		TCLAP::SwitchArg noBufArg("", "no-output-buffering", "Disable output buffering", cmd);
     
    +		TCLAP::SwitchArg runAsServiceArg("d", "run-as-service", "Run as a service on Windows", cmd);
    +
    +		cmd.ignoreUnmatched(true);
    +
     		cmd.parse(argc, argv);
     
     		auto repo = cpp14::make_unique();
    @@ -420,6 +424,11 @@ std::unique_ptr parseArguments(int argc, char **argv)
     			setvbuf(stdout, nullptr, _IONBF, 0);
     		}
     
    +		if (runAsServiceArg.getValue())
    +		{
    +			cRoot::m_RunAsService = true;
    +		}
    +
     		repo->SetReadOnly();
     
     		return repo;
    @@ -493,16 +502,6 @@ int main(int argc, char **argv)
     	
     	auto argsRepo = parseArguments(argc, argv);
     	
    -	// Check if comm logging is to be enabled:
    -	for (int i = 0; i < argc; i++)
    -	{
    -		AString Arg(argv[i]);
    -		if (NoCaseCompare(Arg, "/service") == 0)
    -		{
    -			cRoot::m_RunAsService = true;
    -		}
    -	}  // for i - argv[]
    -
     	#if defined(_WIN32)
     	// Attempt to run as a service
     	if (cRoot::m_RunAsService)
    -- 
    cgit v1.2.3
    
    
    From 48c153bf53d5606e351bd180e2fd9345034f60aa Mon Sep 17 00:00:00 2001
    From: Mattes D 
    Date: Tue, 2 Jun 2015 12:51:43 +0200
    Subject: Fixed warnings in MSVC.
    
    It complained about undefined return values or using uninitialized variables.
    ---
     src/Blocks/BlockButton.h       |  6 ++++++
     src/Blocks/BlockCocoaPod.h     |  4 ++++
     src/Blocks/BlockLadder.h       |  4 ++++
     src/Blocks/BlockLever.h        |  4 ++++
     src/Blocks/BlockQuartz.h       |  5 +++++
     src/Blocks/BlockSideways.h     |  4 ++++
     src/Blocks/BlockTrapdoor.h     |  7 +++++++
     src/Blocks/BlockTripwireHook.h |  8 ++++++++
     src/Defines.h                  | 25 ++++++++++++++++++++++++-
     src/Entities/HangingEntity.h   | 15 ++++++++++++---
     src/Generating/MineShafts.cpp  |  7 +++++++
     src/MobCensus.cpp              |  4 ++++
     src/WorldStorage/FastNBT.cpp   |  3 +++
     13 files changed, 92 insertions(+), 4 deletions(-)
    
    diff --git a/src/Blocks/BlockButton.h b/src/Blocks/BlockButton.h
    index d65d9722d..154cd610e 100644
    --- a/src/Blocks/BlockButton.h
    +++ b/src/Blocks/BlockButton.h
    @@ -73,8 +73,13 @@ public:
     				return 0x0;
     			}
     		}
    +		#if !defined(__clang__)
    +			ASSERT(!"Unknown BLOCK_FACE");
    +			return 0;
    +		#endif
     	}
     
    +
     	inline static eBlockFace BlockMetaDataToBlockFace(NIBBLETYPE a_Meta)
     	{
     		switch (a_Meta & 0x7)
    @@ -93,6 +98,7 @@ public:
     		}
     	}
     
    +
     	virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
     	{
     		NIBBLETYPE Meta;
    diff --git a/src/Blocks/BlockCocoaPod.h b/src/Blocks/BlockCocoaPod.h
    index 50552c788..4d16d2552 100644
    --- a/src/Blocks/BlockCocoaPod.h
    +++ b/src/Blocks/BlockCocoaPod.h
    @@ -89,6 +89,10 @@ public:
     				return 0;
     			}
     		}
    +		#if !defined(__clang__)
    +			ASSERT(!"Unknown BLOCK_FACE");
    +			return 0;
    +		#endif
     	}
     
     } ;
    diff --git a/src/Blocks/BlockLadder.h b/src/Blocks/BlockLadder.h
    index f49f1adc7..d727f8f8e 100644
    --- a/src/Blocks/BlockLadder.h
    +++ b/src/Blocks/BlockLadder.h
    @@ -64,6 +64,10 @@ public:
     				return 0x2;
     			}
     		}
    +		#if !defined(__clang__)
    +			ASSERT(!"Unknown BLOCK_FACE");
    +			return 0;
    +		#endif
     	}
     
     
    diff --git a/src/Blocks/BlockLever.h b/src/Blocks/BlockLever.h
    index 5792d280b..8d676b56f 100644
    --- a/src/Blocks/BlockLever.h
    +++ b/src/Blocks/BlockLever.h
    @@ -67,6 +67,10 @@ public:
     			case BLOCK_FACE_YM:   return 0x0;
     			case BLOCK_FACE_NONE: return 0x6;
     		}
    +		#if !defined(__clang__)
    +			ASSERT(!"Unknown BLOCK_FACE");
    +			return 0;
    +		#endif
     	}
     
     
    diff --git a/src/Blocks/BlockQuartz.h b/src/Blocks/BlockQuartz.h
    index 6f5c23902..b936a7e4a 100644
    --- a/src/Blocks/BlockQuartz.h
    +++ b/src/Blocks/BlockQuartz.h
    @@ -36,6 +36,7 @@ public:
     		return true;
     	}
     
    +
     	inline static NIBBLETYPE BlockFaceToMetaData(eBlockFace a_BlockFace, NIBBLETYPE a_QuartzMeta)
     	{
     		switch (a_BlockFace)
    @@ -64,5 +65,9 @@ public:
     				return a_QuartzMeta;  // No idea, give a special meta (all sides the same)
     			}
     		}
    +		#if !defined(__clang__)
    +			ASSERT(!"Unknown BLOCK_FACE");
    +			return 0;
    +		#endif
     	}
     } ;
    diff --git a/src/Blocks/BlockSideways.h b/src/Blocks/BlockSideways.h
    index 74b05e33c..e52fbaa2f 100644
    --- a/src/Blocks/BlockSideways.h
    +++ b/src/Blocks/BlockSideways.h
    @@ -64,6 +64,10 @@ public:
     				return a_Meta | 0xC;  // No idea, give a special meta
     			}
     		}
    +		#if !defined(__clang__)
    +			ASSERT(!"Unknown BLOCK_FACE");
    +			return 0;
    +		#endif
     	}
     } ;
     
    diff --git a/src/Blocks/BlockTrapdoor.h b/src/Blocks/BlockTrapdoor.h
    index 2841e3e08..a1d2dff6f 100644
    --- a/src/Blocks/BlockTrapdoor.h
    +++ b/src/Blocks/BlockTrapdoor.h
    @@ -66,6 +66,7 @@ public:
     		return true;
     	}
     	
    +
     	inline static NIBBLETYPE BlockFaceToMetaData(eBlockFace a_BlockFace)
     	{
     		switch (a_BlockFace)
    @@ -82,8 +83,13 @@ public:
     				return 0;
     			}
     		}
    +		#if !defined(__clang__)
    +			ASSERT(!"Unknown BLOCK_FACE");
    +			return 0;
    +		#endif
     	}
     
    +
     	inline static eBlockFace BlockMetaDataToBlockFace(NIBBLETYPE a_Meta)
     	{
     		switch (a_Meta & 0x3)
    @@ -100,6 +106,7 @@ public:
     		}
     	}
     
    +
     	virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
     	{
     		NIBBLETYPE Meta;
    diff --git a/src/Blocks/BlockTripwireHook.h b/src/Blocks/BlockTripwireHook.h
    index c7a96d393..39892af5a 100644
    --- a/src/Blocks/BlockTripwireHook.h
    +++ b/src/Blocks/BlockTripwireHook.h
    @@ -16,6 +16,7 @@ public:
     	{
     	}
     
    +
     	virtual bool GetPlacementBlockTypeMeta(
     		cChunkInterface & a_ChunkInterface, cPlayer * a_Player,
     		int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
    @@ -29,6 +30,7 @@ public:
     		return true;
     	}
     
    +
     	inline static NIBBLETYPE DirectionToMetadata(eBlockFace a_Direction)
     	{
     		switch (a_Direction)
    @@ -45,8 +47,13 @@ public:
     				return 0x0;
     			}
     		}
    +		#if !defined(__clang__)
    +			ASSERT(!"Unknown BLOCK_FACE");
    +			return 0;
    +		#endif
     	}
     
    +
     	inline static eBlockFace MetadataToDirection(NIBBLETYPE a_Meta)
     	{
     		switch (a_Meta & 0x03)
    @@ -59,6 +66,7 @@ public:
     		}
     	}
     
    +
     	virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
     	{
     		// Reset meta to zero
    diff --git a/src/Defines.h b/src/Defines.h
    index bbc69f79c..4005c84dd 100644
    --- a/src/Defines.h
    +++ b/src/Defines.h
    @@ -245,6 +245,10 @@ inline eBlockFace MirrorBlockFaceY(eBlockFace a_BlockFace)
     			return a_BlockFace;
     		};
     	}
    +	#if !defined(__clang__)
    +		ASSERT(!"Unknown BLOCK_FACE");
    +		return a_BlockFace;
    +	#endif
     }
     
     
    @@ -267,6 +271,10 @@ inline eBlockFace RotateBlockFaceCCW(eBlockFace a_BlockFace)
     			return a_BlockFace;
     		}
     	}
    +	#if !defined(__clang__)
    +		ASSERT(!"Unknown BLOCK_FACE");
    +		return a_BlockFace;
    +	#endif
     }
     
     
    @@ -288,8 +296,16 @@ inline eBlockFace RotateBlockFaceCW(eBlockFace a_BlockFace)
     			return a_BlockFace;
     		};
     	}
    +	#if !defined(__clang__)
    +		ASSERT(!"Unknown BLOCK_FACE");
    +		return a_BlockFace;
    +	#endif
     }
     
    +
    +
    +
    +
     inline eBlockFace ReverseBlockFace(eBlockFace  a_BlockFace)
     {
     	switch (a_BlockFace)
    @@ -302,9 +318,16 @@ inline eBlockFace ReverseBlockFace(eBlockFace  a_BlockFace)
     		case BLOCK_FACE_ZM:   return BLOCK_FACE_ZP;
     		case BLOCK_FACE_NONE: return a_BlockFace;
     	}
    +	#if !defined(__clang__)
    +		ASSERT(!"Unknown BLOCK_FACE");
    +		return a_BlockFace;
    +	#endif
     }
     
     
    +
    +
    +
     /** Returns the textual representation of the BlockFace constant. */
     inline AString BlockFaceToString(eBlockFace a_BlockFace)
     {
    @@ -320,7 +343,7 @@ inline AString BlockFaceToString(eBlockFace a_BlockFace)
     	}
     	// clang optimisises this line away then warns that it has done so.
     	#if !defined(__clang__)
    -	return Printf("Unknown BLOCK_FACE: %d", a_BlockFace);
    +		return Printf("Unknown BLOCK_FACE: %d", a_BlockFace);
     	#endif
     }
     
    diff --git a/src/Entities/HangingEntity.h b/src/Entities/HangingEntity.h
    index 4d70cd1a0..5d0aa17b3 100644
    --- a/src/Entities/HangingEntity.h
    +++ b/src/Entities/HangingEntity.h
    @@ -46,6 +46,9 @@ public:
     
     protected:
     
    +	Byte m_Facing;
    +
    +
     	virtual void SpawnOn(cClientHandle & a_ClientHandle) override;
     	virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override
     	{
    @@ -53,6 +56,7 @@ protected:
     		UNUSED(a_Chunk);
     	}
     
    +
     	/** Converts protocol hanging item facing to eBlockFace values */
     	inline static eBlockFace ProtocolFaceToBlockFace(Byte a_ProtocolFace)
     	{
    @@ -77,6 +81,7 @@ protected:
     		return Dir;
     	}
     
    +
     	/** Converts eBlockFace values to protocol hanging item faces */
     	inline static Byte BlockFaceToProtocolFace(eBlockFace a_BlockFace)
     	{
    @@ -99,13 +104,17 @@ protected:
     
     				Dir = cHangingEntity::BlockFaceToProtocolFace(BLOCK_FACE_XP);
     			}
    +			#if !defined(__clang__)
    +			default:
    +			{
    +				ASSERT(!"Unknown BLOCK_FACE");
    +				return 0;
    +			}
    +			#endif
     		}
     
     		return Dir;
     	}
    -
    -	Byte m_Facing;
    -
     };  // tolua_export
     
     
    diff --git a/src/Generating/MineShafts.cpp b/src/Generating/MineShafts.cpp
    index 88dade240..4ba896ef6 100644
    --- a/src/Generating/MineShafts.cpp
    +++ b/src/Generating/MineShafts.cpp
    @@ -787,6 +787,13 @@ void cMineShaftCorridor::PlaceChest(cChunkDesc & a_ChunkDesc)
     			Meta = E_META_CHEST_FACING_XP;
     			break;
     		}
    +		#if !defined(__clang__)
    +		default:
    +		{
    +			ASSERT(!"Unknown direction");
    +			return;
    +		}
    +		#endif
     	}  // switch (Dir)
     
     	if (
    diff --git a/src/MobCensus.cpp b/src/MobCensus.cpp
    index ca960a2bc..79b5176d2 100644
    --- a/src/MobCensus.cpp
    +++ b/src/MobCensus.cpp
    @@ -48,6 +48,10 @@ int cMobCensus::GetCapMultiplier(cMonster::eFamily a_MobFamily)
     			return -1;
     		}
     	}
    +	#if !defined(__clang__)
    +		ASSERT(!"Unknown mob family");
    +		return -1;
    +	#endif
     }
     
     
    diff --git a/src/WorldStorage/FastNBT.cpp b/src/WorldStorage/FastNBT.cpp
    index f77197914..860eb3a4a 100644
    --- a/src/WorldStorage/FastNBT.cpp
    +++ b/src/WorldStorage/FastNBT.cpp
    @@ -257,6 +257,9 @@ bool cParsedNBT::ReadTag(void)
     			return true;
     		}
     		
    +		#if !defined(__clang__)
    +		default:
    +		#endif
     		case TAG_Min:
     		{
     			ASSERT(!"Unhandled NBT tag type");
    -- 
    cgit v1.2.3