Consistency

This commit is contained in:
Tom Lankhorst 2019-02-01 21:00:12 +01:00
parent 16691b22ba
commit dfe7f0614c
No known key found for this signature in database
GPG Key ID: 52BF82B885592251
3 changed files with 25 additions and 21 deletions

View File

@ -27,12 +27,12 @@ namespace Random
/** /**
* FixedSeedSequence adheres to the _Named Requirement_ `SeedSequence`. * FixedSeedSequence adheres to the _Named Requirement_ `SeedSequence`.
*/ */
template<size_t _N = 0> class FixedSeedSequence template<size_t __N = 0> class FixedSeedSequence
{ {
public: 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; static constexpr result_type default_seed = 0x1234567F;
explicit FixedSeedSequence() explicit FixedSeedSequence()
@ -60,7 +60,7 @@ namespace Random
{ {
} }
template<typename _It> void generate(_It begin, _It end) template<typename _It> void generate(_It begin, _It end) const
{ {
std::copy_n(v.begin(), std::min((size_t)(end - begin), N), begin); std::copy_n(v.begin(), std::min((size_t)(end - begin), N), begin);
} }
@ -79,12 +79,12 @@ namespace Random
std::array<result_type, N> v; std::array<result_type, N> v;
}; };
typedef FixedSeedSequence<2> Rct2Seed;
template<typename UIntType> struct RotateEngineState template<typename UIntType> struct RotateEngineState
{ {
UIntType s0; using value_type = UIntType;
UIntType s1;
value_type s0;
value_type s1;
}; };
/** /**
@ -100,8 +100,8 @@ namespace Random
using RotateEngineState<UIntType>::s1; using RotateEngineState<UIntType>::s1;
public: public:
typedef UIntType result_type; using result_type = UIntType;
typedef RotateEngineState<result_type> state_type; using state_type = RotateEngineState<UIntType>;
static constexpr result_type x = __x; static constexpr result_type x = __x;
static constexpr size_t r1 = __r1; static constexpr size_t r1 = __r1;
@ -162,16 +162,16 @@ namespace Random
return s1; 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 const state_type& state() const
{ {
return *this; 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) friend std::ostream& operator<<(std::ostream& os, const RotateEngine& e)
{ {
os << e.s0 << ' ' << e.s1; os << e.s0 << ' ' << e.s1;
@ -186,6 +186,10 @@ namespace Random
} }
}; };
typedef RotateEngine<uint32_t, 0x1234567F, 7, 3> Rct2Engine; namespace Rct2
{
using Engine = RotateEngine<uint32_t, 0x1234567F, 7, 3>;
using Seed = FixedSeedSequence<2>;
using State = Engine::state_type;
} // namespace Rct2
} // namespace Random } // namespace Random

View File

@ -68,7 +68,7 @@ uint16_t gSavedAge;
uint32_t gLastAutoSaveUpdate = 0; uint32_t gLastAutoSaveUpdate = 0;
uint32_t gScenarioTicks; uint32_t gScenarioTicks;
Random::Rct2Engine gScenarioRand; random_engine_t gScenarioRand;
uint8_t gScenarioObjectiveType; uint8_t gScenarioObjectiveType;
uint8_t gScenarioObjectiveYear; uint8_t gScenarioObjectiveYear;
@ -91,7 +91,7 @@ void scenario_begin()
game_load_init(); game_load_init();
// Set the scenario pseudo-random seeds // 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); gScenarioRand.seed(s);
gParkFlags &= ~PARK_FLAGS_NO_MONEY; 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) 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); gScenarioRand.seed(s);
} }

View File

@ -24,7 +24,7 @@
#include "../world/MapAnimation.h" #include "../world/MapAnimation.h"
#include "../world/Sprite.h" #include "../world/Sprite.h"
using random_engine_t = Random::Rct2Engine; using random_engine_t = Random::Rct2::Engine;
struct ParkLoadResult; struct ParkLoadResult;