From dfe7f0614cc392f8db29133bdbbae6209c2ac641 Mon Sep 17 00:00:00 2001 From: Tom Lankhorst Date: Fri, 1 Feb 2019 21:00:12 +0100 Subject: [PATCH] Consistency --- src/openrct2/core/Random.hpp | 38 +++++++++++++++++------------- src/openrct2/scenario/Scenario.cpp | 6 ++--- src/openrct2/scenario/Scenario.h | 2 +- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/openrct2/core/Random.hpp b/src/openrct2/core/Random.hpp index eea44ee9bc..60431abc37 100644 --- a/src/openrct2/core/Random.hpp +++ b/src/openrct2/core/Random.hpp @@ -27,12 +27,12 @@ namespace Random /** * FixedSeedSequence adheres to the _Named Requirement_ `SeedSequence`. */ - template class FixedSeedSequence + template class FixedSeedSequence { public: - typedef uint32_t result_type; + using result_type = uint32_t; - static constexpr size_t N = _N; + static constexpr size_t N = __N; static constexpr result_type default_seed = 0x1234567F; explicit FixedSeedSequence() @@ -60,7 +60,7 @@ namespace Random { } - template void generate(_It begin, _It end) + template void generate(_It begin, _It end) const { std::copy_n(v.begin(), std::min((size_t)(end - begin), N), begin); } @@ -79,12 +79,12 @@ namespace Random std::array v; }; - typedef FixedSeedSequence<2> Rct2Seed; - template struct RotateEngineState { - UIntType s0; - UIntType s1; + using value_type = UIntType; + + value_type s0; + value_type s1; }; /** @@ -100,8 +100,8 @@ namespace Random using RotateEngineState::s1; public: - typedef UIntType result_type; - typedef RotateEngineState state_type; + using result_type = UIntType; + using state_type = RotateEngineState; static constexpr result_type x = __x; static constexpr size_t r1 = __r1; @@ -162,16 +162,16 @@ namespace Random return s1; } - friend bool operator==(const RotateEngine& lhs, const RotateEngine& rhs) - { - return lhs.s0 == rhs.s0 && lhs.s1 == rhs.s1; - } - const state_type& state() const { return *this; } + friend bool operator==(const RotateEngine& lhs, const RotateEngine& rhs) + { + return lhs.s0 == rhs.s0 && lhs.s1 == rhs.s1; + } + friend std::ostream& operator<<(std::ostream& os, const RotateEngine& e) { os << e.s0 << ' ' << e.s1; @@ -186,6 +186,10 @@ namespace Random } }; - typedef RotateEngine Rct2Engine; - + namespace Rct2 + { + using Engine = RotateEngine; + using Seed = FixedSeedSequence<2>; + using State = Engine::state_type; + } // namespace Rct2 } // namespace Random diff --git a/src/openrct2/scenario/Scenario.cpp b/src/openrct2/scenario/Scenario.cpp index 3a45ca5375..91f4e4ba96 100644 --- a/src/openrct2/scenario/Scenario.cpp +++ b/src/openrct2/scenario/Scenario.cpp @@ -68,7 +68,7 @@ uint16_t gSavedAge; uint32_t gLastAutoSaveUpdate = 0; uint32_t gScenarioTicks; -Random::Rct2Engine gScenarioRand; +random_engine_t gScenarioRand; uint8_t gScenarioObjectiveType; uint8_t gScenarioObjectiveYear; @@ -91,7 +91,7 @@ void scenario_begin() game_load_init(); // Set the scenario pseudo-random seeds - Random::Rct2Seed s{ 0x1234567F ^ platform_get_ticks(), 0x789FABCD ^ platform_get_ticks() }; + Random::Rct2::Seed s{ 0x1234567F ^ platform_get_ticks(), 0x789FABCD ^ platform_get_ticks() }; gScenarioRand.seed(s); gParkFlags &= ~PARK_FLAGS_NO_MONEY; @@ -484,7 +484,7 @@ const random_engine_t::state_type& scenario_rand_state() void scenario_rand_seed(random_engine_t::result_type s0, random_engine_t::result_type s1) { - Random::Rct2Seed s{ s0, s1 }; + Random::Rct2::Seed s{ s0, s1 }; gScenarioRand.seed(s); } diff --git a/src/openrct2/scenario/Scenario.h b/src/openrct2/scenario/Scenario.h index 992728208c..3b2a68188a 100644 --- a/src/openrct2/scenario/Scenario.h +++ b/src/openrct2/scenario/Scenario.h @@ -24,7 +24,7 @@ #include "../world/MapAnimation.h" #include "../world/Sprite.h" -using random_engine_t = Random::Rct2Engine; +using random_engine_t = Random::Rct2::Engine; struct ParkLoadResult;