From a6f0913b3d1921fbfe4746f8ea8f2deb8ec22014 Mon Sep 17 00:00:00 2001 From: martin nylin Date: Fri, 9 Aug 2024 14:01:06 +0200 Subject: [PATCH] Replace std::random_shuffle with std::shuffle std::random_shuffle was removed in c++17 --- src/karts/kart_properties_manager.cpp | 6 +++--- src/karts/kart_properties_manager.hpp | 3 +++ src/modes/three_strikes_battle.cpp | 6 +++--- src/modes/three_strikes_battle.hpp | 4 +++- src/states_screens/easter_egg_screen.cpp | 4 ++-- src/states_screens/easter_egg_screen.hpp | 3 +++ src/states_screens/online/tracks_screen.cpp | 2 +- src/states_screens/online/tracks_screen.hpp | 4 +++- src/states_screens/tracks_and_gp_screen.cpp | 2 +- src/states_screens/tracks_and_gp_screen.hpp | 4 +++- src/tracks/track.cpp | 2 +- src/tracks/track.hpp | 4 +++- 12 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/karts/kart_properties_manager.cpp b/src/karts/kart_properties_manager.cpp index 2eb0f09a8d5..732f8a09e9f 100644 --- a/src/karts/kart_properties_manager.cpp +++ b/src/karts/kart_properties_manager.cpp @@ -50,7 +50,7 @@ KartPropertiesManager *kart_properties_manager=0; std::vector KartPropertiesManager::m_kart_search_path; /** Constructor, only clears internal data structures. */ -KartPropertiesManager::KartPropertiesManager() +KartPropertiesManager::KartPropertiesManager() : m_random_number_generator(std::random_device{}()) { m_all_groups.clear(); } // KartPropertiesManager @@ -601,8 +601,8 @@ void KartPropertiesManager::getRandomKartList(int count, assert(random_kart_queue.size() > 0); - std::random_shuffle(random_kart_queue.begin(), - random_kart_queue.end() ); + std::shuffle(random_kart_queue.begin(), + random_kart_queue.end(), m_random_number_generator); } while (count > 0 && random_kart_queue.size() > 0) diff --git a/src/karts/kart_properties_manager.hpp b/src/karts/kart_properties_manager.hpp index 9466020a60f..ff969585101 100644 --- a/src/karts/kart_properties_manager.hpp +++ b/src/karts/kart_properties_manager.hpp @@ -23,6 +23,7 @@ #include "utils/ptr_vector.hpp" #include #include +#include #include #include "network/remote_kart_info.hpp" @@ -70,6 +71,8 @@ class KartPropertiesManager: public NoCopy std::map > m_kart_type_characteristics; std::map > m_player_characteristics; + std::mt19937 m_random_number_generator; + protected: typedef PtrVector KartPropertiesVector; diff --git a/src/modes/three_strikes_battle.cpp b/src/modes/three_strikes_battle.cpp index 4029f68aaf3..c21027ff15a 100644 --- a/src/modes/three_strikes_battle.cpp +++ b/src/modes/three_strikes_battle.cpp @@ -48,7 +48,7 @@ //----------------------------------------------------------------------------- /** Constructor. Sets up the clock mode etc. */ -ThreeStrikesBattle::ThreeStrikesBattle() : WorldWithRank() +ThreeStrikesBattle::ThreeStrikesBattle() : WorldWithRank(), m_random_number_generator(std::random_device{}()) { WorldStatus::setClockMode(CLOCK_CHRONO); m_use_highscores = false; @@ -684,8 +684,8 @@ void ThreeStrikesBattle::loadCustomModels() } // Find random nodes to pre-spawn spare tire karts - std::random_shuffle(sta_possible_nodes.begin(), - sta_possible_nodes.end()); + std::shuffle(sta_possible_nodes.begin(), + sta_possible_nodes.end(), m_random_number_generator); // Compute a random kart list std::vector sta_list; diff --git a/src/modes/three_strikes_battle.hpp b/src/modes/three_strikes_battle.hpp index 95f25dbe7d1..282e106d148 100644 --- a/src/modes/three_strikes_battle.hpp +++ b/src/modes/three_strikes_battle.hpp @@ -23,7 +23,7 @@ #include "modes/world_with_rank.hpp" #include "tracks/track_object.hpp" #include "states_screens/race_gui_base.hpp" - +#include #include class PhysicalObject; @@ -92,6 +92,8 @@ class ThreeStrikesBattle : public WorldWithRank std::vector m_spare_tire_karts; int m_next_sta_spawn_ticks; + std::mt19937 m_random_number_generator; + public: /** Used to show a nice graph when battle is over */ struct BattleEvent diff --git a/src/states_screens/easter_egg_screen.cpp b/src/states_screens/easter_egg_screen.cpp index 6c348c2f726..d6f15a563f1 100644 --- a/src/states_screens/easter_egg_screen.cpp +++ b/src/states_screens/easter_egg_screen.cpp @@ -42,7 +42,7 @@ static const char ALL_TRACK_GROUPS_ID[] = "all"; // ----------------------------------------------------------------------------- -EasterEggScreen::EasterEggScreen() : Screen("easter_egg.stkgui") +EasterEggScreen::EasterEggScreen() : Screen("easter_egg.stkgui"), m_random_number_generator(std::random_device{}()) { } @@ -278,7 +278,7 @@ void EasterEggScreen::buildTrackList() 0 /* no badge */, IconButtonWidget::ICON_PATH_TYPE_RELATIVE); tracks_widget->updateItemDisplay(); - std::random_shuffle( m_random_track_list.begin(), m_random_track_list.end() ); + std::shuffle( m_random_track_list.begin(), m_random_track_list.end(), m_random_number_generator ); } // ----------------------------------------------------------------------------- diff --git a/src/states_screens/easter_egg_screen.hpp b/src/states_screens/easter_egg_screen.hpp index fca29858dbc..f70478cfc21 100644 --- a/src/states_screens/easter_egg_screen.hpp +++ b/src/states_screens/easter_egg_screen.hpp @@ -20,6 +20,7 @@ #include "guiengine/screen.hpp" #include +#include namespace GUIEngine { class Widget; } @@ -31,6 +32,8 @@ class EasterEggScreen : public GUIEngine::Screen, public GUIEngine::ScreenSingle { friend class GUIEngine::ScreenSingleton; + std::mt19937 m_random_number_generator; + EasterEggScreen(); /** adds the tracks from the current track group into the tracks ribbon */ diff --git a/src/states_screens/online/tracks_screen.cpp b/src/states_screens/online/tracks_screen.cpp index 49d53a0a8aa..e70710c312b 100644 --- a/src/states_screens/online/tracks_screen.cpp +++ b/src/states_screens/online/tracks_screen.cpp @@ -644,7 +644,7 @@ void TracksScreen::buildTrackList() IconButtonWidget::ICON_PATH_TYPE_RELATIVE); tracks_widget->updateItemDisplay(); - std::random_shuffle( m_random_track_list.begin(), m_random_track_list.end() ); + std::shuffle( m_random_track_list.begin(), m_random_track_list.end(), m_random_number_generator ); } // buildTrackList // ----------------------------------------------------------------------------- diff --git a/src/states_screens/online/tracks_screen.hpp b/src/states_screens/online/tracks_screen.hpp index 227194c7146..aa2742711d1 100644 --- a/src/states_screens/online/tracks_screen.hpp +++ b/src/states_screens/online/tracks_screen.hpp @@ -23,6 +23,7 @@ #include #include +#include #include #include @@ -88,7 +89,8 @@ class TracksScreen : public GUIEngine::Screen, void voteForPlayer(); - TracksScreen() : Screen("tracks.stkgui") + std::mt19937 m_random_number_generator; + TracksScreen() : Screen("tracks.stkgui"), m_random_number_generator(std::random_device{}()) { m_network_tracks = false; m_quit_server = false; diff --git a/src/states_screens/tracks_and_gp_screen.cpp b/src/states_screens/tracks_and_gp_screen.cpp index b0eca47a2f6..550ea6fb165 100644 --- a/src/states_screens/tracks_and_gp_screen.cpp +++ b/src/states_screens/tracks_and_gp_screen.cpp @@ -341,7 +341,7 @@ void TracksAndGPScreen::buildTrackList() IconButtonWidget::ICON_PATH_TYPE_RELATIVE); tracks_widget->updateItemDisplay(); - std::random_shuffle( m_random_track_list.begin(), m_random_track_list.end() ); + std::shuffle( m_random_track_list.begin(), m_random_track_list.end(), m_random_number_generator ); } // buildTrackList // ----------------------------------------------------------------------------- diff --git a/src/states_screens/tracks_and_gp_screen.hpp b/src/states_screens/tracks_and_gp_screen.hpp index 65dfdaadb75..746e93061ef 100644 --- a/src/states_screens/tracks_and_gp_screen.hpp +++ b/src/states_screens/tracks_and_gp_screen.hpp @@ -21,6 +21,7 @@ #include "guiengine/screen.hpp" #include "guiengine/widgets/text_box_widget.hpp" #include +#include namespace GUIEngine { class Widget; } @@ -37,7 +38,8 @@ class TracksAndGPScreen : public GUIEngine::Screen, private: GUIEngine::TextBoxWidget* m_search_box; - TracksAndGPScreen() : Screen("tracks_and_gp.stkgui") {} + std::mt19937 m_random_number_generator; + TracksAndGPScreen() : Screen("tracks_and_gp.stkgui"), m_random_number_generator(std::random_device{}()) {} /** adds the tracks from the current track group into the tracks ribbon */ void buildTrackList(); diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index 63e4cef4ac0..56c1070c3b6 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -112,7 +112,7 @@ bool Track::m_dont_load_navmesh = false; std::atomic Track::m_current_track[PT_COUNT]; // ---------------------------------------------------------------------------- -Track::Track(const std::string &filename) +Track::Track(const std::string &filename) : m_random_number_generator(std::random_device{}()) { #ifdef DEBUG m_magic_number = 0x17AC3802; diff --git a/src/tracks/track.hpp b/src/tracks/track.hpp index a417dd9af48..dbed750d855 100644 --- a/src/tracks/track.hpp +++ b/src/tracks/track.hpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -138,6 +139,7 @@ class Track std::vector m_subtitles; + std::mt19937 m_random_number_generator; /** Start transforms of karts (either the default, or the ones taken * from the scene file). */ AlignedArray m_start_transforms; @@ -562,7 +564,7 @@ class Track */ void shuffleStartTransforms() { - std::random_shuffle(m_start_transforms.begin(), m_start_transforms.end()); + std::shuffle(m_start_transforms.begin(), m_start_transforms.end(), m_random_number_generator); } // ------------------------------------------------------------------------ /** Sets pointer to the aabb of this track. */