Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2023-06-25 20:01:32 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2023-06-25 20:01:32 +1000
commit13a74602bd4c46149da9949d448387a40b8ebd1c (patch)
tree74c5d7c4f3732155e65e8df454017c5b7d2ca35d
parentdf661be1a3623d0a655758095fb08cb953448336 (diff)
Upgrade to C++17
-rw-r--r--scripts/osx/ycm_extra_conf.py2
-rw-r--r--source/CMakeLists.txt12
-rw-r--r--source/application/CMakeLists.txt1
-rw-r--r--source/base/CMakeLists.txt1
-rw-r--r--source/client/CMakeLists.txt3
-rw-r--r--source/core/CMakeLists.txt2
-rw-r--r--source/core/StarAlgorithm.hpp9
-rw-r--r--source/core/StarConfig.hpp19
-rw-r--r--source/core/StarPch.hpp25
-rw-r--r--source/core/StarRandom.hpp6
-rw-r--r--source/core/StarStaticRandom.hpp22
-rw-r--r--source/frontend/CMakeLists.txt1
-rw-r--r--source/game/StarProjectile.cpp4
-rw-r--r--source/rendering/CMakeLists.txt1
-rw-r--r--source/server/CMakeLists.txt3
-rw-r--r--source/test/btree_database_test.cpp14
-rw-r--r--source/test/btree_test.cpp11
17 files changed, 82 insertions, 54 deletions
diff --git a/scripts/osx/ycm_extra_conf.py b/scripts/osx/ycm_extra_conf.py
index b9b969d..5098960 100644
--- a/scripts/osx/ycm_extra_conf.py
+++ b/scripts/osx/ycm_extra_conf.py
@@ -46,7 +46,7 @@ flags = [
# a "-std=<something>".
# For a C project, you would set this to something like 'c99' instead of
# 'c++11'.
-'-std=c++14',
+'-std=c++17',
'-stdlib=libc++',
# ...and the same thing goes for the magic -x option which specifies the
# language that the files to be compiled are written in. This is mostly
diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt
index d8f01a4..1b65707 100644
--- a/source/CMakeLists.txt
+++ b/source/CMakeLists.txt
@@ -1,4 +1,4 @@
-CMAKE_MINIMUM_REQUIRED (VERSION 3.4)
+CMAKE_MINIMUM_REQUIRED (VERSION 3.16)
# Find CCache
FIND_PROGRAM(CCACHE_PATH ccache)
@@ -227,7 +227,7 @@ ENDIF ()
IF (STAR_COMPILER_GNU)
SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wuninitialized -Wunreachable-code -Wformat -no-pie")
- SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wextra -Wuninitialized -Wunreachable-code -Wformat -no-pie")
+ SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -Wall -Wextra -Wuninitialized -Wunreachable-code -Wformat -no-pie")
IF (STAR_SYSTEM_FAMILY_WINDOWS)
SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mthreads")
@@ -261,11 +261,11 @@ IF (STAR_COMPILER_GNU)
ELSEIF (STAR_COMPILER_CLANG)
SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wuninitialized -Wno-parentheses-equality -Wno-deprecated-declarations")
- SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wextra -Wuninitialized -Wno-parentheses-equality -Wno-deprecated-declarations")
+ SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -Wall -Wextra -Wuninitialized -Wno-parentheses-equality -Wno-deprecated-declarations")
IF (STAR_SYSTEM_MACOS)
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
- SET (CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++14")
+ SET (CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++17")
SET (CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
ELSEIF ()
SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread -D_REENTRANT")
@@ -313,7 +313,7 @@ ELSEIF (STAR_COMPILER_MSVC)
# using unions in interesting ways.
SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP /EHsc /bigobj /wd4996 /wd4351 /wd4800 /wd4244 /wd4305 /wd4267 /wd4456 /wd4503 /wd4250 /wd4624")
- SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /EHsc /bigobj /wd4996 /wd4351 /wd4800 /wd4244 /wd4305 /wd4267 /wd4456 /wd4503 /wd4250 /wd4624")
+ SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17 /MP /EHsc /bigobj /wd4996 /wd4351 /wd4800 /wd4244 /wd4305 /wd4267 /wd4456 /wd4503 /wd4250 /wd4624")
IF (STAR_ENABLE_STATIC_MSVC_RUNTIME)
SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MT")
@@ -351,7 +351,7 @@ ELSEIF (STAR_COMPILER_MSVC)
ELSE ()
SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -pthread -D_REENTRANT")
- SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -pthread -D_REENTRANT")
+ SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -Wall -pthread -D_REENTRANT")
SET (CMAKE_C_FLAGS_DEBUG "-g")
SET (CMAKE_CXX_FLAGS_DEBUG "-g")
diff --git a/source/application/CMakeLists.txt b/source/application/CMakeLists.txt
index db557aa..0394655 100644
--- a/source/application/CMakeLists.txt
+++ b/source/application/CMakeLists.txt
@@ -63,3 +63,4 @@ IF (STAR_ENABLE_DISCORD_INTEGRATION)
ENDIF ()
ADD_LIBRARY (star_application OBJECT ${star_application_SOURCES} ${star_application_HEADERS})
+TARGET_PRECOMPILE_HEADERS (star_application REUSE_FROM star_core) \ No newline at end of file
diff --git a/source/base/CMakeLists.txt b/source/base/CMakeLists.txt
index 03f767f..d5e0750 100644
--- a/source/base/CMakeLists.txt
+++ b/source/base/CMakeLists.txt
@@ -35,3 +35,4 @@ SET (star_base_SOURCES
CONFIGURE_FILE (StarVersion.cpp.in ${CMAKE_CURRENT_BINARY_DIR}/StarVersion.cpp)
ADD_LIBRARY (star_base OBJECT ${star_base_SOURCES} ${star_base_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/StarVersion.cpp)
+TARGET_PRECOMPILE_HEADERS (star_base REUSE_FROM star_core)
diff --git a/source/client/CMakeLists.txt b/source/client/CMakeLists.txt
index 0e6335a..b9a3e1c 100644
--- a/source/client/CMakeLists.txt
+++ b/source/client/CMakeLists.txt
@@ -28,4 +28,5 @@ ADD_EXECUTABLE (starbound WIN32
$<TARGET_OBJECTS:star_extern> $<TARGET_OBJECTS:star_core> $<TARGET_OBJECTS:star_base> $<TARGET_OBJECTS:star_game>
$<TARGET_OBJECTS:star_application> $<TARGET_OBJECTS:star_rendering> $<TARGET_OBJECTS:star_windowing> $<TARGET_OBJECTS:star_frontend>
${star_client_HEADERS} ${star_client_SOURCES} ${star_client_RESOURCES})
-TARGET_LINK_LIBRARIES (starbound ${STAR_EXT_LIBS} ${STAR_EXT_GUI_LIBS})
+TARGET_PRECOMPILE_HEADERS (starbound REUSE_FROM star_core)
+TARGET_LINK_LIBRARIES (starbound ${STAR_EXT_LIBS} ${STAR_EXT_GUI_LIBS}) \ No newline at end of file
diff --git a/source/core/CMakeLists.txt b/source/core/CMakeLists.txt
index 6668109..34d890f 100644
--- a/source/core/CMakeLists.txt
+++ b/source/core/CMakeLists.txt
@@ -84,6 +84,7 @@ SET (star_core_HEADERS
StarOrderedMap.hpp
StarOrderedSet.hpp
StarParametricFunction.hpp
+ StarPch.hpp
StarPeriodic.hpp
StarPeriodicFunction.hpp
StarPerlin.hpp
@@ -203,3 +204,4 @@ ELSEIF (STAR_SYSTEM_FAMILY_WINDOWS)
ENDIF ()
ADD_LIBRARY (star_core OBJECT ${star_core_SOURCES} ${star_core_HEADERS})
+TARGET_PRECOMPILE_HEADERS (star_core PUBLIC StarPch.hpp) \ No newline at end of file
diff --git a/source/core/StarAlgorithm.hpp b/source/core/StarAlgorithm.hpp
index 331f653..e26917a 100644
--- a/source/core/StarAlgorithm.hpp
+++ b/source/core/StarAlgorithm.hpp
@@ -1,10 +1,6 @@
#ifndef STAR_ALGORITHM_HPP
#define STAR_ALGORITHM_HPP
-#include <type_traits>
-#include <vector>
-#include <iterator>
-
#include "StarException.hpp"
namespace Star {
@@ -268,11 +264,6 @@ void stableSortByComputedValue(Container& container, Getter&& valueGetter) {
}
template <typename Container>
-void shuffle(Container& c) {
- std::random_shuffle(c.begin(), c.end());
-}
-
-template <typename Container>
void reverse(Container& c) {
std::reverse(c.begin(), c.end());
}
diff --git a/source/core/StarConfig.hpp b/source/core/StarConfig.hpp
index 22c2607..e7a5ff0 100644
--- a/source/core/StarConfig.hpp
+++ b/source/core/StarConfig.hpp
@@ -1,23 +1,8 @@
+#include "StarPch.hpp"
+
#ifndef STAR_CONFIG_HPP
#define STAR_CONFIG_HPP
-#include <cstdint>
-#include <cstdlib>
-#include <cstddef>
-#include <cstring>
-#include <cmath>
-#include <tuple>
-#include <memory>
-#include <functional>
-#include <algorithm>
-#include <iostream>
-#include <initializer_list>
-#include <exception>
-#include <stdexcept>
-#include <atomic>
-#include <string>
-#include <iterator>
-
namespace Star {
// Some really common std namespace includes
diff --git a/source/core/StarPch.hpp b/source/core/StarPch.hpp
new file mode 100644
index 0000000..809156c
--- /dev/null
+++ b/source/core/StarPch.hpp
@@ -0,0 +1,25 @@
+#ifndef STAR_PCH_HPP
+#define STAR_PCH_HPP
+
+#include <cstdint>
+#include <cstdlib>
+#include <cstddef>
+#include <cstring>
+#include <cmath>
+#include <tuple>
+#include <memory>
+#include <functional>
+#include <algorithm>
+#include <iostream>
+#include <initializer_list>
+#include <exception>
+#include <stdexcept>
+#include <atomic>
+#include <string>
+#include <string_view>
+#include <iterator>
+#include <type_traits>
+#include <vector>
+
+
+#endif \ No newline at end of file
diff --git a/source/core/StarRandom.hpp b/source/core/StarRandom.hpp
index b3c8ba2..c39f6ef 100644
--- a/source/core/StarRandom.hpp
+++ b/source/core/StarRandom.hpp
@@ -187,7 +187,8 @@ typename Container::value_type RandomSource::randValueFrom(
template <typename Container>
void RandomSource::shuffle(Container& container) {
- std::random_shuffle(container.begin(), container.end(), [this](size_t max) { return randUInt(max - 1); });
+ size_t max = container.size();
+ std::shuffle(container.begin(), container.end(), URBG<size_t>([this, max]() { return randUInt(max - 1); }));
}
template <typename Container>
@@ -208,7 +209,8 @@ typename Container::value_type Random::randValueFrom(
template <typename Container>
void Random::shuffle(Container& container) {
- std::random_shuffle(container.begin(), container.end(), [](size_t max) { return Random::randUInt(max - 1); });
+ size_t max = container.size();
+ std::shuffle(container.begin(), container.end(), URBG<size_t>([max]() { return Random::randUInt(max - 1); }));
}
}
diff --git a/source/core/StarStaticRandom.hpp b/source/core/StarStaticRandom.hpp
index 97cfdef..b55b411 100644
--- a/source/core/StarStaticRandom.hpp
+++ b/source/core/StarStaticRandom.hpp
@@ -118,12 +118,28 @@ typename Container::value_type staticRandomValueFrom(Container const& container,
}
}
+template <typename T>
+class URBG {
+public:
+ typedef function <T()> Function;
+
+ URBG(Function func) : m_func(func) {};
+
+ typedef T result_type;
+ static constexpr T min() { return std::numeric_limits<T>::min(); };
+ static constexpr T max() { return std::numeric_limits<T>::max(); };
+ T operator()() { return m_func(); };
+private:
+ Function m_func;
+};
+
template <typename Container, typename T, typename... TL>
void staticRandomShuffle(Container& container, T const& d, TL const&... rest) {
int mix = 0;
- std::random_shuffle(container.begin(),
- container.end(),
- [&](size_t max) { return staticRandomU32Range(0, max - 1, ++mix, d, rest...); });
+ size_t max = container.size();
+ std::shuffle(container.begin(), container.end(), URBG<size_t>([&]() {
+ return staticRandomU32Range(0, max - 1, ++mix, d, rest...);
+ }));
}
}
diff --git a/source/frontend/CMakeLists.txt b/source/frontend/CMakeLists.txt
index 75145bd..cd06ce7 100644
--- a/source/frontend/CMakeLists.txt
+++ b/source/frontend/CMakeLists.txt
@@ -103,3 +103,4 @@ SET (star_frontend_SOURCES
)
ADD_LIBRARY (star_frontend OBJECT ${star_frontend_SOURCES} ${star_frontend_HEADERS})
+TARGET_PRECOMPILE_HEADERS (star_frontend REUSE_FROM star_core) \ No newline at end of file
diff --git a/source/game/StarProjectile.cpp b/source/game/StarProjectile.cpp
index d094797..698428b 100644
--- a/source/game/StarProjectile.cpp
+++ b/source/game/StarProjectile.cpp
@@ -584,8 +584,8 @@ void Projectile::processAction(Json const& action) {
bool allowEntityOverlap = parameters.getBool("allowEntityOverlap", true);
- random_shuffle(tileDrops.begin(), tileDrops.end(), [](int i) { return Random::randu64() % i; });
- for (auto tile : zip(openSpaces, tileDrops)) {
+ Random::shuffle(tileDrops);
+ for (auto& tile : zip(openSpaces, tileDrops)) {
if (!world()->modifyTile(std::get<0>(tile), PlaceMaterial{TileLayer::Foreground, std::get<1>(tile), MaterialHue()}, allowEntityOverlap)) {
auto itemDrop = ItemDrop::createRandomizedDrop(materialDatabase->materialItemDrop(std::get<1>(tile)), (Vec2F)std::get<0>(tile));
world()->addEntity(itemDrop);
diff --git a/source/rendering/CMakeLists.txt b/source/rendering/CMakeLists.txt
index d45153a..c683daa 100644
--- a/source/rendering/CMakeLists.txt
+++ b/source/rendering/CMakeLists.txt
@@ -33,3 +33,4 @@ SET (star_rendering_SOURCES
)
ADD_LIBRARY (star_rendering OBJECT ${star_rendering_SOURCES} ${star_rendering_HEADERS})
+TARGET_PRECOMPILE_HEADERS (star_rendering REUSE_FROM star_core) \ No newline at end of file
diff --git a/source/server/CMakeLists.txt b/source/server/CMakeLists.txt
index d6a22e6..98c1179 100644
--- a/source/server/CMakeLists.txt
+++ b/source/server/CMakeLists.txt
@@ -22,4 +22,5 @@ SET (star_server_SOURCES
ADD_EXECUTABLE (starbound_server
$<TARGET_OBJECTS:star_extern> $<TARGET_OBJECTS:star_core> $<TARGET_OBJECTS:star_base> $<TARGET_OBJECTS:star_game>
${star_server_HEADERS} ${star_server_SOURCES})
-TARGET_LINK_LIBRARIES (starbound_server ${STAR_EXT_LIBS})
+TARGET_PRECOMPILE_HEADERS (starbound_server REUSE_FROM star_core)
+TARGET_LINK_LIBRARIES (starbound_server ${STAR_EXT_LIBS}) \ No newline at end of file
diff --git a/source/test/btree_database_test.cpp b/source/test/btree_database_test.cpp
index 9b9bee4..09b4b16 100644
--- a/source/test/btree_database_test.cpp
+++ b/source/test/btree_database_test.cpp
@@ -101,25 +101,25 @@ namespace {
db.open();
// record writes/reads repeated writeRepeat times randomly each cycle
- std::random_shuffle(keys.begin(), keys.end());
+ Random::shuffle(keys);
putAll(db, keys);
EXPECT_EQ(db.recordCount(), testCount);
- std::random_shuffle(keys.begin(), keys.end());
+ Random::shuffle(keys);
checkAll(db, keys);
// Random reads/writes with randCount cycles...
for (uint32_t i = 0; i < randCount; ++i) {
List<uint32_t> keysTemp(keys.begin(), keys.begin() + keys.size() / 2);
- std::random_shuffle(keysTemp.begin(), keysTemp.end());
+ Random::shuffle(keysTemp);
removeAll(db, keysTemp);
- std::random_shuffle(keysTemp.begin(), keysTemp.end());
+ Random::shuffle(keysTemp);
putAll(db, keysTemp);
- std::random_shuffle(keys.begin(), keys.end());
+ Random::shuffle(keys);
checkAll(db, keys);
}
@@ -128,7 +128,7 @@ namespace {
// Random reads/writes/rollbacks with rollbackCount cycles...
for (uint32_t i = 0; i < rollbackCount ; ++i) {
List<uint32_t> keysTemp(keys.begin(), keys.begin() + keys.size() / 2);
- std::random_shuffle(keysTemp.begin(), keysTemp.end());
+ Random::shuffle(keysTemp);
removeAll(db, keysTemp);
db.rollback();
@@ -193,7 +193,7 @@ TEST(BTreeDatabaseTest, Threading) {
if (Random::randf() > 0.3)
deleteKeySet.append(key);
}
- std::random_shuffle(writeKeySet.begin(), writeKeySet.end());
+ Random::shuffle(writeKeySet);
{
auto writer = Thread::invoke("databaseTestWriter",
diff --git a/source/test/btree_test.cpp b/source/test/btree_test.cpp
index aa413d6..2d22631 100644
--- a/source/test/btree_test.cpp
+++ b/source/test/btree_test.cpp
@@ -3,6 +3,7 @@
#include "StarMap.hpp"
#include "StarSet.hpp"
#include "StarLexicalCast.hpp"
+#include "StarRandom.hpp"
#include "gtest/gtest.h"
@@ -614,25 +615,25 @@ void testBTree(size_t maxIndexSize, size_t maxLeafSize) {
}
// record writes/reads repeated WriteRepeat times randomly each cycle
- std::random_shuffle(keys.begin(), keys.end());
+ Random::shuffle(keys);
putAll(db, keys);
EXPECT_EQ(db.recordCount(), TestCount);
- std::random_shuffle(keys.begin(), keys.end());
+ Random::shuffle(keys);
checkAll(db, keys);
// Random reads/writes with ShrinkCount cycles...
for (size_t i = 0; i < ShrinkCount; ++i) {
- std::random_shuffle(keys.begin(), keys.end());
+ Random::shuffle(keys);
List<int> keysTemp = keys.slice(0, keys.size() / 2);
removeAll(db, keysTemp);
- std::random_shuffle(keysTemp.begin(), keysTemp.end());
+ Random::shuffle(keysTemp);
putAll(db, keysTemp);
- std::random_shuffle(keysTemp.begin(), keysTemp.end());
+ Random::shuffle(keysTemp);
checkAll(db, keys);
}