Skip to content

Commit

Permalink
Move gScenarioRand to GameState_t
Browse files Browse the repository at this point in the history
  • Loading branch information
Gymnasiast committed Jan 26, 2024
1 parent 3f83cad commit 32aa3f5
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/openrct2/GameState.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ namespace OpenRCT2
uint16_t ScenarioParkRatingWarningDays;
money64 ScenarioCompletedCompanyValue;
money64 ScenarioCompanyValueRecord;
random_engine_t ScenarioRand;

SCENARIO_CATEGORY ScenarioCategory;
std::string ScenarioName;
Expand Down
4 changes: 3 additions & 1 deletion src/openrct2/core/Random.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ namespace Random
return std::numeric_limits<result_type>::max();
}

explicit RotateEngine(result_type seed_value = default_seed)
RotateEngine() = default;

explicit RotateEngine(result_type seed_value)
{
seed(seed_value);
}
Expand Down
4 changes: 2 additions & 2 deletions src/openrct2/park/ParkFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,11 +504,11 @@ namespace OpenRCT2
cs.ReadWrite(s0);
cs.ReadWrite(s1);
Random::RCT2::Seed s{ s0, s1 };
gScenarioRand.seed(s);
gameState.ScenarioRand.seed(s);
}
else
{
auto randState = gScenarioRand.state();
auto randState = gameState.ScenarioRand.state();
cs.Write(randState.s0);
cs.Write(randState.s1);
}
Expand Down
10 changes: 4 additions & 6 deletions src/openrct2/scenario/Scenario.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ bool gFirstTimeSaving = true;
uint16_t gSavedAge;
uint32_t gLastAutoSaveUpdate = 0;

random_engine_t gScenarioRand;

bool gAllowEarlyCompletionInNetworkPlay;

std::string gScenarioFileName;
Expand All @@ -97,7 +95,7 @@ void ScenarioReset(GameState_t& gameState)
{
// Set the scenario pseudo-random seeds
Random::RCT2::Seed s{ 0x1234567F ^ Platform::GetTicks(), 0x789FABCD ^ Platform::GetTicks() };
gScenarioRand.seed(s);
gameState.ScenarioRand.seed(s);

ResearchResetCurrentItem();
ScenerySetDefaultPlacementConfiguration();
Expand Down Expand Up @@ -496,13 +494,13 @@ bool ScenarioCreateDucks()

const random_engine_t::state_type& ScenarioRandState()
{
return gScenarioRand.state();
return GetGameState().ScenarioRand.state();
};

void ScenarioRandSeed(random_engine_t::result_type s0, random_engine_t::result_type s1)
{
Random::RCT2::Seed s{ s0, s1 };
gScenarioRand.seed(s);
GetGameState().ScenarioRand.seed(s);
}

/**
Expand All @@ -513,7 +511,7 @@ void ScenarioRandSeed(random_engine_t::result_type s0, random_engine_t::result_t
*/
random_engine_t::result_type ScenarioRand()
{
return gScenarioRand();
return GetGameState().ScenarioRand();
}

uint32_t ScenarioRandMax(uint32_t max)
Expand Down
2 changes: 0 additions & 2 deletions src/openrct2/scenario/Scenario.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,6 @@ static constexpr money64 COMPANY_VALUE_ON_FAILED_OBJECTIVE = 0x8000000000000001;

extern const StringId ScenarioCategoryStringIds[SCENARIO_CATEGORY_COUNT];

extern random_engine_t gScenarioRand;

extern bool gAllowEarlyCompletionInNetworkPlay;

extern std::string gScenarioSavePath;
Expand Down

0 comments on commit 32aa3f5

Please sign in to comment.