diff options
118 files changed, 672 insertions, 521 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/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<T> { public: - cListAllocationPool(std::auto_ptr<typename cAllocationPool<T>::cStarvationCallbacks> a_Callbacks) : - m_Callbacks(a_Callbacks) + cListAllocationPool(std::unique_ptr<typename cAllocationPool<T>::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<T> private: std::list<void *> m_FreeList; - std::auto_ptr<typename cAllocationPool<T>::cStarvationCallbacks> m_Callbacks; + std::unique_ptr<typename cAllocationPool<T>::cStarvationCallbacks> m_Callbacks; }; 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/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/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<BLOCKTYPE>(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<cPluginManager::CommandResult>(static_cast<int>((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<float>(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<eWeather>(Clamp( static_cast<int>(tolua_tonumber(m_LuaState, a_StackPos, a_ReturnedVal)), static_cast<int>(wSunny), static_cast<int>(wThunderstorm)) ); -} - - - - - -void cLuaState::GetStackValue(int a_StackPos, int & a_ReturnedVal) -{ - if (lua_isnumber(m_LuaState, a_StackPos)) - { - a_ReturnedVal = static_cast<int>(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 <class T> + bool GetStackValue(int a_StackPos, T & a_ReturnedVal, typename std::enable_if<std::is_integral<T>::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<T>::max()) + { + return false; + } + if (Val < std::numeric_limits<T>::min()) + { + return false; + } + a_ReturnedVal = static_cast<T>(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 <typename T, typename... Args> - 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<size_t>(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<int, 2> 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<size_t>(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) { 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/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<NIBBLETYPE>(0x2 | Meta << 2); break; + case 1: a_BlockMeta = static_cast<NIBBLETYPE>(0x3 | Meta << 2); break; + case 2: a_BlockMeta = static_cast<NIBBLETYPE>(0x0 | Meta << 2); break; + case 3: a_BlockMeta = static_cast<NIBBLETYPE>(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 4d4610fd8..5c9283979 100644 --- a/src/Blocks/BlockLeaves.h +++ b/src/Blocks/BlockLeaves.h @@ -59,7 +59,7 @@ public: cItem( E_BLOCK_SAPLING, 1, - (m_BlockType == E_BLOCK_LEAVES) ? (a_BlockMeta & 0x03) : (4 + (a_BlockMeta & 0x01)) + (m_BlockType == E_BLOCK_LEAVES) ? (a_BlockMeta & 0x03) : static_cast<short>(4 + (a_BlockMeta & 0x01)) ) ); } 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/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/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/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/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/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/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<int, int> cMap; + typedef std::map<int, unsigned int> 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<short>(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/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<size_t>(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<size_t>((((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<size_t>(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<size_t>(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<size_t>(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<size_t>(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<size_t>(a_ChunkX * cChunkDef::Width), static_cast<size_t>(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/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/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<NIBBLETYPE>(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..60f7e7520 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<HEIGHTTYPE>(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<size_t>(rnd) % ARRAYCOUNT(layerSizes))]; + NIBBLETYPE Color = allowedColors[static_cast<size_t>(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 @@ -411,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; @@ -427,7 +435,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<size_t>(CacheSize), static_cast<size_t>(MultiCacheLength))); } else { - m_BiomeGen = cBiomeGenPtr(new cBioGenCache(m_BiomeGen, CacheSize)); + m_BiomeGen = cBiomeGenPtr(new cBioGenCache(m_BiomeGen, static_cast<size_t>(CacheSize))); } } diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index 69ae59c18..e0349f012 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<size_t>(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<size_t>(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<size_t>(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<HEIGHTTYPE>(HeightY)); } // for x } // for z } @@ -1375,7 +1375,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<size_t>((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..6aa52c4a5 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<size_t>(a_ChunkX * cChunkDef::Width), static_cast<size_t>(a_ChunkZ * cChunkDef::Width), static_cast<size_t>(cChunkDef::Width), static_cast<size_t>(cChunkDef::Width), heights); for (size_t i = 0; i < ARRAYCOUNT(heights); i++) { a_HeightMap[i] = static_cast<HEIGHTTYPE>(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<HEIGHTTYPE>(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<HEIGHTTYPE>(Clamp(static_cast<int>(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<HEIGHTTYPE>(Clamp(100 - static_cast<int>((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<HEIGHTTYPE>(Height[x + 17 * z])); } } //*/ @@ -817,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/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..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; @@ -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/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<size_t>(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<difType>(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<difType>(NumProcessed)); NumProcessed = 0; } } 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<int>(a_MinX + x), static_cast<int>(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<int>(a_MinX + x), static_cast<int>(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<int>(x + lowerMinX) * 2; + int RndZ = static_cast<int>(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<int>(a_MinX + x), static_cast<int>(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<int>(BaseZ), static_cast<int>(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<int>(a_MinX + x), static_cast<int>(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<int>(a_MinX + x), static_cast<int>(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<int>(a_MinX + x), static_cast<int>(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<int>(a_MinX + x), static_cast<int>(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<int>(a_MinX + x), static_cast<int>(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<int>(a_MinX + x), static_cast<int>(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<size_t>(val) % ARRAYCOUNT(biomesInGroups)]; + int rnd = (super::m_Noise.IntNoise2DInt(static_cast<int>(x + a_MinX), static_cast<int>(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<int>(x + a_MinX), static_cast<int>(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<int>(x + a_MinX), static_cast<int>(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<int>(x + a_MinX), static_cast<int>(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<int>(x + a_MinX), static_cast<int>(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/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<size_t>(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); 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<size_t>(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<size_t>(a_Noise.IntNoise3DInt(a_BlockX, a_BlockY + i, a_BlockZ)) % ARRAYCOUNT(AvailableDirections)]; + Vector3d BranchDirection = AvailableDirections[static_cast<size_t>(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<size_t>(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<size_t>(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<size_t>(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<size_t>(TrunkHeight)); + a_OtherBlocks.reserve(static_cast<size_t>(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<size_t>(Height)); + a_OtherBlocks.reserve(2 * ARRAYCOUNT(BigO2) + 2 * ARRAYCOUNT(BigO3) + static_cast<size_t>(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<size_t>(Height) * 4); + a_OtherBlocks.reserve(2 * ARRAYCOUNT(BigO4) + ARRAYCOUNT(BigO3) + static_cast<size_t>(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<size_t>(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<size_t>(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<size_t>(rnd) % ARRAYCOUNT(g_PlainsVillagePools)]; + cVillagePiecePool * DesertVillage = g_DesertVillagePools[static_cast<size_t>(rnd) % ARRAYCOUNT(g_DesertVillagePools)]; for (size_t i = 0; i < ARRAYCOUNT(Biomes); i++) { switch (Biomes[i]) 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/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/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<char>(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<char>(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<short>(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<char>(NumDrops), static_cast<short>(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/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<unsigned char>(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<unsigned char>(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<unsigned char>(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..6327b3505 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) -int cFile::Tell (void) const +long 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 +long cFile::GetSize(void) const { ASSERT(IsOpen()); @@ -226,7 +226,7 @@ int cFile::GetSize(void) const return -1; } - int CurPos = Tell(); + long CurPos = Tell(); if (CurPos < 0) { return -1; @@ -235,7 +235,7 @@ int cFile::GetSize(void) const { return -1; } - int res = Tell(); + long 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(); + long TotalSize = GetSize(); + if (TotalSize < 0) + { + return -1; + } + + long Position = Tell(); + if (Position < 0) + { + return -1; + } + + auto DataSize = static_cast<size_t>(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) +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 1b5e71a17..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 */ - int Tell (void) const; + long Tell (void) const; /** Returns the size of file, in bytes, or -1 for failure; asserts if not open */ - int 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 int 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); 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<size_t>(res); if (NumBytes == 0) { return true; 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/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<UInt16>(std::max<int>(Player->GetXpLevel(), std::numeric_limits<UInt16>::max()))); - Pkt.WriteBEInt16(static_cast<UInt16>(std::max<int>(Player->GetCurrentXp(), std::numeric_limits<UInt16>::max()))); + Pkt.WriteBEInt16(static_cast<Int16>(std::max<int>(Player->GetXpLevel(), std::numeric_limits<Int16>::max()))); + Pkt.WriteBEInt16(static_cast<Int16>(std::max<int>(Player->GetCurrentXp(), std::numeric_limits<Int16>::max()))); } 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<int>(a_Iteration); } // 5 blocks away, bail out 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<T>(a_str[i] - '0'); if (std::numeric_limits<T>::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<T>(a_str[i] - '0'); if (std::numeric_limits<T>::min() + digit > result) { return false; 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/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); } 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 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<Int16>(itr->first)); + a_Writer.AddShort("lvl", static_cast<Int16>(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<unsigned int>(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<u_long>(a_NumElements)); + u_int len = htonl(static_cast<u_int>(a_NumElements)); m_Result.append(reinterpret_cast<const char *>(&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<u_long>(a_NumElements)); + u_int len = htonl(static_cast<u_int>(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<Byte>(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<Byte>(m_Map->GetScale())); + a_Writer.AddByte("dimension", static_cast<Byte>(m_Map->GetDimension())); - a_Writer.AddShort("width", m_Map->GetWidth()); - a_Writer.AddShort("height", m_Map->GetHeight()); + a_Writer.AddShort("width", static_cast<Int16>(m_Map->GetWidth())); + a_Writer.AddShort("height", static_cast<Int16>(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<unsigned int>(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<Int16>(m_MapCount - 1)); } Writer.Finish(); |