From c6ea47c631b4f4e19099d3d41959fc6af312c5ef Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 12 May 2019 11:32:33 +0200 Subject: [PATCH] Make util_rand thread safe --- src/openrct2/Context.cpp | 1 - src/openrct2/util/Util.cpp | 8 +------- src/openrct2/util/Util.h | 1 - src/openrct2/world/MapGen.cpp | 2 -- 4 files changed, 1 insertion(+), 11 deletions(-) diff --git a/src/openrct2/Context.cpp b/src/openrct2/Context.cpp index 11674063fe..59382c20d9 100644 --- a/src/openrct2/Context.cpp +++ b/src/openrct2/Context.cpp @@ -426,7 +426,6 @@ namespace OpenRCT2 } gScenarioTicks = 0; - util_srand((uint32_t)time(nullptr)); input_reset_place_obj_modifier(); viewport_init_all(); diff --git a/src/openrct2/util/Util.cpp b/src/openrct2/util/Util.cpp index 29d858ee3c..0cd47c5cfb 100644 --- a/src/openrct2/util/Util.cpp +++ b/src/openrct2/util/Util.cpp @@ -23,8 +23,6 @@ #include #include -static std::mt19937 _prng; - int32_t squaredmetres_to_squaredfeet(int32_t squaredMetres) { // 1 metre squared = 10.7639104 feet squared @@ -529,13 +527,9 @@ bool str_is_null_or_empty(const char* str) return str == nullptr || str[0] == 0; } -void util_srand(int32_t source) -{ - _prng.seed(source); -} - uint32_t util_rand() { + thread_local std::mt19937 _prng(std::random_device{}()); return _prng(); } diff --git a/src/openrct2/util/Util.h b/src/openrct2/util/Util.h index 3fc0d2f1f0..ec046e8036 100644 --- a/src/openrct2/util/Util.h +++ b/src/openrct2/util/Util.h @@ -50,7 +50,6 @@ char* strcasestr(const char* haystack, const char* needle); bool utf8_is_bom(const char* str); bool str_is_null_or_empty(const char* str); -void util_srand(int32_t source); uint32_t util_rand(); uint8_t* util_zlib_deflate(const uint8_t* data, size_t data_in_size, size_t* data_out_size); diff --git a/src/openrct2/world/MapGen.cpp b/src/openrct2/world/MapGen.cpp index 33dbba1254..b624879531 100644 --- a/src/openrct2/world/MapGen.cpp +++ b/src/openrct2/world/MapGen.cpp @@ -136,8 +136,6 @@ void mapgen_generate(mapgen_settings* settings) int32_t x, y, mapSize, floorTexture, wallTexture, waterLevel; TileElement* tileElement; - util_srand((int32_t)platform_get_ticks()); - mapSize = settings->mapSize; floorTexture = settings->floor; wallTexture = settings->wall;