diff --git a/src/openrct2/Context.cpp b/src/openrct2/Context.cpp index f2d8d53446..63b063acc0 100644 --- a/src/openrct2/Context.cpp +++ b/src/openrct2/Context.cpp @@ -105,6 +105,7 @@ namespace OpenRCT2 // Game states std::unique_ptr _titleScreen; + std::unique_ptr _park; sint32 _drawingEngineType = DRAWING_ENGINE_SOFTWARE; std::unique_ptr _drawingEngine; @@ -165,6 +166,11 @@ namespace OpenRCT2 return _uiContext; } + Park * GetPark() override + { + return _park.get(); + } + std::shared_ptr GetPlatformEnvironment() override { return _env; @@ -445,6 +451,7 @@ namespace OpenRCT2 game_init_all(150); _titleScreen = std::make_unique(); + _park = std::make_unique(); return true; } diff --git a/src/openrct2/Context.h b/src/openrct2/Context.h index 15b9a51854..b6e1cb243d 100644 --- a/src/openrct2/Context.h +++ b/src/openrct2/Context.h @@ -71,6 +71,7 @@ enum namespace OpenRCT2 { interface IPlatformEnvironment; + class Park; namespace Audio { @@ -101,6 +102,7 @@ namespace OpenRCT2 virtual std::shared_ptr GetAudioContext() abstract; virtual std::shared_ptr GetUiContext() abstract; + virtual Park * GetPark() abstract; virtual std::shared_ptr GetPlatformEnvironment() abstract; virtual Localisation::LocalisationService& GetLocalisationService() abstract; virtual std::shared_ptr GetObjectManager() abstract; diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index a3aa578523..b0934b7565 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -111,6 +111,8 @@ rct_string_id gGameCommandErrorText; uint8 gErrorType; rct_string_id gErrorStringId; +using namespace OpenRCT2; + sint32 game_command_callback_get_index(GAME_COMMAND_CALLBACK_POINTER * callback) { for (uint32 i = 0; i < Util::CountOf(game_command_callback_table); i++) @@ -489,7 +491,7 @@ void game_logic_update() vehicle_update_all(); sprite_misc_update_all(); ride_update_all(); - park_update(); + GetContext()->GetPark()->Update(); research_update(); ride_ratings_update_all(); ride_measurements_update(); diff --git a/src/openrct2/world/Park.cpp b/src/openrct2/world/Park.cpp index 981b03625f..6655780516 100644 --- a/src/openrct2/world/Park.cpp +++ b/src/openrct2/world/Park.cpp @@ -545,30 +545,6 @@ static void park_generate_new_guests() } } -/** - * - * rct2: 0x006674F7 - */ -void park_update() -{ - if (gScreenFlags & (SCREEN_FLAGS_SCENARIO_EDITOR | SCREEN_FLAGS_TRACK_DESIGNER | SCREEN_FLAGS_TRACK_MANAGER)) - return; - - // Every 5 seconds approximately - if (gCurrentTicks % 512 == 0) { - gParkRating = calculate_park_rating(); - gParkValue = calculate_park_value(); - gCompanyValue = calculate_company_value(); - window_invalidate_by_class(WC_FINANCES); - _guestGenerationProbability = park_calculate_guest_generation_probability(); - auto intent = Intent(INTENT_ACTION_UPDATE_PARK_RATING); - context_broadcast_intent(&intent); - } - - // Generate new guests - park_generate_new_guests(); -} - uint8 calculate_guest_initial_happiness(uint8 percentage) { if (percentage < 15) { // There is a minimum of 15% happiness @@ -1039,6 +1015,21 @@ bool park_entry_price_unlocked() using namespace OpenRCT2; +static Park * _singleton = nullptr; + +Park::Park() +{ + _singleton = this; +} + +Park::~Park() +{ + if (_singleton == this) + { + _singleton = nullptr; + } +} + uint16 Park::GetParkRating() const { return gParkRating; @@ -1056,7 +1047,19 @@ money32 Park::GetCompanyValue() const void Park::Update() { - park_update(); + // Every 5 seconds approximately + if (gCurrentTicks % 512 == 0) + { + gParkRating = CalculateParkRating(); + gParkValue = CalculateParkValue(); + gCompanyValue = CalculateCompanyValue(); + _guestGenerationProbability = park_calculate_guest_generation_probability(); + window_invalidate_by_class(WC_FINANCES); + auto intent = Intent(INTENT_ACTION_UPDATE_PARK_RATING); + context_broadcast_intent(&intent); + } + + park_generate_new_guests(); } sint32 Park::CalculateParkRating() const diff --git a/src/openrct2/world/Park.h b/src/openrct2/world/Park.h index 5822c48a0d..392fa1ce9f 100644 --- a/src/openrct2/world/Park.h +++ b/src/openrct2/world/Park.h @@ -54,6 +54,9 @@ namespace OpenRCT2 class Park final { public: + Park(); + ~Park(); + uint16 GetParkRating() const; money32 GetParkValue() const; money32 GetCompanyValue() const; @@ -113,7 +116,6 @@ money32 calculate_company_value(); void reset_park_entry(); rct_peep * park_generate_new_guest(); -void park_update(); void park_update_histories(); void update_park_fences(sint32 x, sint32 y); void update_park_fences_around_tile(sint32 x, sint32 y);