summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt6
-rw-r--r--SetFlags.cmake15
-rw-r--r--Tools/GrownBiomeGenVisualiser/Globals.h7
-rw-r--r--Tools/NoiseSpeedTest/Globals.h7
-rw-r--r--src/BlockArea.cpp12
-rw-r--r--src/CraftingRecipes.cpp10
-rw-r--r--src/Generating/CompoGen.cpp4
-rw-r--r--src/Globals.h7
-rw-r--r--src/LazyArray.h2
-rw-r--r--src/Noise/OctavedNoise.h4
-rw-r--r--src/Simulator/DelayedFluidSimulator.cpp2
11 files changed, 41 insertions, 35 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 15f1a3e95..f10e961e0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -13,7 +13,7 @@
-cmake_minimum_required (VERSION 2.8.7)
+cmake_minimum_required (VERSION 3.12.4)
if (POLICY CMP0054)
cmake_policy(SET CMP0054 NEW)
@@ -120,6 +120,10 @@ else() # GCC or Clang, so get compiler version directly since CMAKE_CXX_COMPILE
endif()
endif()
+set(CMAKE_CXX_STANDARD 17)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+set(CMAKE_CXX_EXTENSIONS OFF)
+
set(BUILD_TOOLS OFF CACHE BOOL "")
set(SELF_TEST OFF CACHE BOOL "")
diff --git a/SetFlags.cmake b/SetFlags.cmake
index 9d8e11e2d..b8dd26bfd 100644
--- a/SetFlags.cmake
+++ b/SetFlags.cmake
@@ -74,11 +74,6 @@ macro(set_flags)
)
endif()
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
- set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++11")
- set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_COVERAGE} -std=c++11")
- set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++11")
-
#on os x clang adds pthread for us but we need to add it for gcc
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_flags_cxx("-stdlib=libc++")
@@ -87,11 +82,6 @@ macro(set_flags)
add_flags_cxx("-pthread")
endif()
elseif (ANDROID)
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
- set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++11")
- set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_COVERAGE} -std=c++11")
- set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++11")
-
add_flags_cxx("-fsigned-char")
else()
# Let gcc / clang know that we're compiling a multi-threaded app:
@@ -107,11 +97,6 @@ macro(set_flags)
)
endif()
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
- set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++11")
- set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_COVERAGE} -std=c++11")
- set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++11")
-
# We use a signed char (fixes #640 on RasPi)
add_flags_cxx("-fsigned-char")
diff --git a/Tools/GrownBiomeGenVisualiser/Globals.h b/Tools/GrownBiomeGenVisualiser/Globals.h
index 33c983bf3..f062b4ccf 100644
--- a/Tools/GrownBiomeGenVisualiser/Globals.h
+++ b/Tools/GrownBiomeGenVisualiser/Globals.h
@@ -234,6 +234,13 @@ T Clamp(T a_Value, T a_Min, T a_Max)
return (a_Value < a_Min) ? a_Min : ((a_Value > a_Max) ? a_Max : a_Value);
}
+template <typename T>
+auto ToUnsigned(T a_Val)
+{
+ ASSERT(a_Val >= 0);
+ return static_cast<std::make_unsigned_t<T>>(a_Val);
+}
+
diff --git a/Tools/NoiseSpeedTest/Globals.h b/Tools/NoiseSpeedTest/Globals.h
index 22f39575e..f0400f853 100644
--- a/Tools/NoiseSpeedTest/Globals.h
+++ b/Tools/NoiseSpeedTest/Globals.h
@@ -230,3 +230,10 @@ T Clamp(T a_Value, T a_Min, T a_Max)
{
return (a_Value < a_Min) ? a_Min : ((a_Value > a_Max) ? a_Max : a_Value);
}
+
+template <typename T>
+auto ToUnsigned(T a_Val)
+{
+ ASSERT(a_Val >= 0);
+ return static_cast<std::make_unsigned_t<T>>(a_Val);
+}
diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp
index 1d63f147d..4aa5175f2 100644
--- a/src/BlockArea.cpp
+++ b/src/BlockArea.cpp
@@ -2086,7 +2086,7 @@ bool cBlockArea::SetSize(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes)
// Try to allocate the new storage
if ((a_DataTypes & baTypes) != 0)
{
- NewBlocks.reset(new BLOCKTYPE[a_SizeX * a_SizeY * a_SizeZ]);
+ NewBlocks.reset(new BLOCKTYPE[ToUnsigned(a_SizeX * a_SizeY * a_SizeZ)]);
if (NewBlocks == nullptr)
{
return false;
@@ -2094,7 +2094,7 @@ bool cBlockArea::SetSize(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes)
}
if ((a_DataTypes & baMetas) != 0)
{
- NewMetas.reset(new NIBBLETYPE[a_SizeX * a_SizeY * a_SizeZ]);
+ NewMetas.reset(new NIBBLETYPE[ToUnsigned(a_SizeX * a_SizeY * a_SizeZ)]);
if (NewMetas == nullptr)
{
return false;
@@ -2102,7 +2102,7 @@ bool cBlockArea::SetSize(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes)
}
if ((a_DataTypes & baLight) != 0)
{
- NewLight.reset(new NIBBLETYPE[a_SizeX * a_SizeY * a_SizeZ]);
+ NewLight.reset(new NIBBLETYPE[ToUnsigned(a_SizeX * a_SizeY * a_SizeZ)]);
if (NewLight == nullptr)
{
return false;
@@ -2110,7 +2110,7 @@ bool cBlockArea::SetSize(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes)
}
if ((a_DataTypes & baSkyLight) != 0)
{
- NewSkyLight.reset(new NIBBLETYPE[a_SizeX * a_SizeY * a_SizeZ]);
+ NewSkyLight.reset(new NIBBLETYPE[ToUnsigned(a_SizeX * a_SizeY * a_SizeZ)]);
if (NewSkyLight == nullptr)
{
return false;
@@ -2270,7 +2270,7 @@ void cBlockArea::CropBlockTypes(int a_AddMinX, int a_SubMaxX, int a_AddMinY, int
int NewSizeX = GetSizeX() - a_AddMinX - a_SubMaxX;
int NewSizeY = GetSizeY() - a_AddMinY - a_SubMaxY;
int NewSizeZ = GetSizeZ() - a_AddMinZ - a_SubMaxZ;
- BLOCKARRAY NewBlockTypes{ new BLOCKTYPE[NewSizeX * NewSizeY * NewSizeZ] };
+ BLOCKARRAY NewBlockTypes{ new BLOCKTYPE[ToUnsigned(NewSizeX * NewSizeY * NewSizeZ)] };
size_t idx = 0;
for (int y = 0; y < NewSizeY; y++)
{
@@ -2295,7 +2295,7 @@ void cBlockArea::CropNibbles(NIBBLEARRAY & a_Array, int a_AddMinX, int a_SubMaxX
int NewSizeX = GetSizeX() - a_AddMinX - a_SubMaxX;
int NewSizeY = GetSizeY() - a_AddMinY - a_SubMaxY;
int NewSizeZ = GetSizeZ() - a_AddMinZ - a_SubMaxZ;
- NIBBLEARRAY NewNibbles{ new NIBBLETYPE[NewSizeX * NewSizeY * NewSizeZ] };
+ NIBBLEARRAY NewNibbles{ new NIBBLETYPE[ToUnsigned(NewSizeX * NewSizeY * NewSizeZ)] };
size_t idx = 0;
for (int y = 0; y < NewSizeY; y++)
{
diff --git a/src/CraftingRecipes.cpp b/src/CraftingRecipes.cpp
index 1a8a68523..fc0ce92f1 100644
--- a/src/CraftingRecipes.cpp
+++ b/src/CraftingRecipes.cpp
@@ -18,7 +18,7 @@
cCraftingGrid::cCraftingGrid(int a_Width, int a_Height) :
m_Width(a_Width),
m_Height(a_Height),
- m_Items(new cItem[a_Width * a_Height])
+ m_Items(new cItem[ToUnsigned(a_Width * a_Height)])
{
}
@@ -27,9 +27,7 @@ cCraftingGrid::cCraftingGrid(int a_Width, int a_Height) :
cCraftingGrid::cCraftingGrid(const cItem * a_Items, int a_Width, int a_Height) :
- m_Width(a_Width),
- m_Height(a_Height),
- m_Items(new cItem[a_Width * a_Height])
+ cCraftingGrid(a_Width, a_Height)
{
for (int i = a_Width * a_Height - 1; i >= 0; i--)
{
@@ -42,9 +40,7 @@ cCraftingGrid::cCraftingGrid(const cItem * a_Items, int a_Width, int a_Height) :
cCraftingGrid::cCraftingGrid(const cCraftingGrid & a_Original) :
- m_Width(a_Original.m_Width),
- m_Height(a_Original.m_Height),
- m_Items(new cItem[a_Original.m_Width * a_Original.m_Height])
+ cCraftingGrid(a_Original.m_Width, a_Original.m_Height)
{
for (int i = m_Width * m_Height - 1; i >= 0; i--)
{
diff --git a/src/Generating/CompoGen.cpp b/src/Generating/CompoGen.cpp
index 899ff54c1..13b05222c 100644
--- a/src/Generating/CompoGen.cpp
+++ b/src/Generating/CompoGen.cpp
@@ -332,8 +332,8 @@ void cCompoGenNether::InitializeCompoGen(cIniFile & a_IniFile)
cCompoGenCache::cCompoGenCache(cTerrainCompositionGenPtr a_Underlying, int a_CacheSize) :
m_Underlying(a_Underlying),
m_CacheSize(a_CacheSize),
- m_CacheOrder(new int[a_CacheSize]),
- m_CacheData(new sCacheData[a_CacheSize]),
+ m_CacheOrder(new int[ToUnsigned(a_CacheSize)]),
+ m_CacheData(new sCacheData[ToUnsigned(a_CacheSize)]),
m_NumHits(0),
m_NumMisses(0),
m_TotalChain(0)
diff --git a/src/Globals.h b/src/Globals.h
index 02b007e09..e6fde373e 100644
--- a/src/Globals.h
+++ b/src/Globals.h
@@ -390,6 +390,13 @@ using cTickTimeLong = std::chrono::duration<Int64, cTickTime::period>;
#error TOLUA_EXPOSITION should never actually be defined
#endif
+template <typename T>
+auto ToUnsigned(T a_Val)
+{
+ ASSERT(a_Val >= 0);
+ return static_cast<std::make_unsigned_t<T>>(a_Val);
+}
+
diff --git a/src/LazyArray.h b/src/LazyArray.h
index 7015d6c47..310a1e2c6 100644
--- a/src/LazyArray.h
+++ b/src/LazyArray.h
@@ -83,7 +83,7 @@ public:
{
if (m_Array == nullptr)
{
- m_Array.reset(new T[m_Size]);
+ m_Array.reset(new T[ToUnsigned(m_Size)]);
}
return m_Array.get();
}
diff --git a/src/Noise/OctavedNoise.h b/src/Noise/OctavedNoise.h
index 6dd79365f..b9f3d132e 100644
--- a/src/Noise/OctavedNoise.h
+++ b/src/Noise/OctavedNoise.h
@@ -61,7 +61,7 @@ public:
std::unique_ptr<NOISE_DATATYPE[]> workspaceHeap;
if (a_Workspace == nullptr)
{
- workspaceHeap.reset(new NOISE_DATATYPE[a_SizeX * a_SizeY]);
+ workspaceHeap.reset(new NOISE_DATATYPE[ToUnsigned(a_SizeX * a_SizeY)]);
a_Workspace = workspaceHeap.get();
}
@@ -121,7 +121,7 @@ public:
std::unique_ptr<NOISE_DATATYPE[]> workspaceHeap;
if (a_Workspace == nullptr)
{
- workspaceHeap.reset(new NOISE_DATATYPE[a_SizeX * a_SizeY * a_SizeZ]);
+ workspaceHeap.reset(new NOISE_DATATYPE[ToUnsigned(a_SizeX * a_SizeY * a_SizeZ)]);
a_Workspace = workspaceHeap.get();
}
diff --git a/src/Simulator/DelayedFluidSimulator.cpp b/src/Simulator/DelayedFluidSimulator.cpp
index 784e40250..d4537656d 100644
--- a/src/Simulator/DelayedFluidSimulator.cpp
+++ b/src/Simulator/DelayedFluidSimulator.cpp
@@ -44,7 +44,7 @@ bool cDelayedFluidSimulatorChunkData::cSlot::Add(int a_RelX, int a_RelY, int a_R
// cDelayedFluidSimulatorChunkData:
cDelayedFluidSimulatorChunkData::cDelayedFluidSimulatorChunkData(int a_TickDelay) :
- m_Slots(new cSlot[a_TickDelay])
+ m_Slots(new cSlot[ToUnsigned(a_TickDelay)])
{
}