From dcff6895b5e49e42c8ba1ac03f024670182ce9ee Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Sun, 27 May 2018 17:11:54 +0200 Subject: [PATCH] Refactor game_init_all into GameState::InitAll. --- src/openrct2/Context.cpp | 3 ++- src/openrct2/Editor.cpp | 6 ++--- src/openrct2/Game.cpp | 33 --------------------------- src/openrct2/Game.h | 1 - src/openrct2/GameState.cpp | 36 ++++++++++++++++++++++++++++++ src/openrct2/GameState.h | 1 + src/openrct2/rct1/S4Importer.cpp | 5 +++-- src/openrct2/rct2/S6Importer.cpp | 2 +- src/openrct2/title/TitleScreen.cpp | 4 ++-- src/openrct2/world/Park.cpp | 10 --------- src/openrct2/world/Park.h | 1 - 11 files changed, 48 insertions(+), 54 deletions(-) diff --git a/src/openrct2/Context.cpp b/src/openrct2/Context.cpp index 27b088c9e1..5aca86365c 100644 --- a/src/openrct2/Context.cpp +++ b/src/openrct2/Context.cpp @@ -449,9 +449,10 @@ namespace OpenRCT2 util_srand((uint32)time(nullptr)); input_reset_place_obj_modifier(); viewport_init_all(); - game_init_all(150); _gameState = std::make_unique(); + _gameState->InitAll(150); + _titleScreen = std::make_unique(_gameState.get()); return true; } diff --git a/src/openrct2/Editor.cpp b/src/openrct2/Editor.cpp index f39b11b8f7..b1eec7caef 100644 --- a/src/openrct2/Editor.cpp +++ b/src/openrct2/Editor.cpp @@ -62,7 +62,7 @@ namespace Editor audio_stop_all_music_and_sounds(); object_manager_unload_all_objects(); object_list_load(); - game_init_all(150); + OpenRCT2::GetContext()->GetGameState()->InitAll(150); gScreenFlags = SCREEN_FLAGS_SCENARIO_EDITOR; gS6Info.editor_step = EDITOR_STEP_OBJECT_SELECTION; gParkFlags |= PARK_FLAGS_SHOW_REAL_GUEST_NAMES; @@ -141,7 +141,7 @@ namespace Editor object_manager_unload_all_objects(); object_list_load(); - game_init_all(150); + OpenRCT2::GetContext()->GetGameState()->InitAll(150); SetAllLandOwned(); gS6Info.editor_step = EDITOR_STEP_OBJECT_SELECTION; viewport_init_all(); @@ -162,7 +162,7 @@ namespace Editor object_manager_unload_all_objects(); object_list_load(); - game_init_all(150); + OpenRCT2::GetContext()->GetGameState()->InitAll(150); SetAllLandOwned(); gS6Info.editor_step = EDITOR_STEP_OBJECT_SELECTION; viewport_init_all(); diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index f0329100ce..6b947ac39d 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -1420,39 +1420,6 @@ void game_load_or_quit_no_save_prompt() } } -/** - * Initialises the map, park etc. basically all S6 data. - */ -void game_init_all(sint32 mapSize) -{ - gInMapInitCode = true; - - map_init(mapSize); - park_init(); - finance_init(); - reset_park_entry(); - banner_init(); - ride_init_all(); - reset_sprite_list(); - staff_reset_modes(); - date_reset(); - climate_reset(CLIMATE_COOL_AND_WET); - news_item_init_queue(); - user_string_clear_all(); - - gInMapInitCode = false; - - gNextGuestNumber = 1; - - context_init(); - scenery_set_default_placement_configuration(); - - auto intent = Intent(INTENT_ACTION_CLEAR_TILE_INSPECTOR_CLIPBOARD); - context_broadcast_intent(&intent); - - load_palette(); -} - GAME_COMMAND_POINTER * new_game_command_table[GAME_COMMAND_COUNT] = { game_command_set_ride_appearance, game_command_set_land_height, diff --git a/src/openrct2/Game.h b/src/openrct2/Game.h index 4f1feae745..54ea931422 100644 --- a/src/openrct2/Game.h +++ b/src/openrct2/Game.h @@ -186,4 +186,3 @@ void game_convert_strings_to_rct2(rct_s6_data * s6); void utf8_to_rct2_self(char * buffer, size_t length); void rct2_to_utf8_self(char * buffer, size_t length); void game_fix_save_vars(); -void game_init_all(sint32 mapSize); diff --git a/src/openrct2/GameState.cpp b/src/openrct2/GameState.cpp index 62bd6d5aba..313e7db7a0 100644 --- a/src/openrct2/GameState.cpp +++ b/src/openrct2/GameState.cpp @@ -21,6 +21,7 @@ #include "Input.h" #include "interface/Screenshot.h" #include "localisation/Date.h" +#include "localisation/Localisation.h" #include "management/NewsItem.h" #include "network/network.h" #include "OpenRCT2.h" @@ -28,9 +29,11 @@ #include "scenario/Scenario.h" #include "title/TitleScreen.h" #include "title/TitleSequencePlayer.h" +#include "windows/Intent.h" #include "world/Climate.h" #include "world/MapAnimation.h" #include "world/Park.h" +#include "world/Scenery.h" using namespace OpenRCT2; @@ -39,6 +42,39 @@ GameState::GameState() _park = std::make_unique(); } +/** + * Initialises the map, park etc. basically all S6 data. + */ +void GameState::InitAll(sint32 mapSize) +{ + gInMapInitCode = true; + + map_init(mapSize); + _park->Initialise(); + finance_init(); + reset_park_entry(); + banner_init(); + ride_init_all(); + reset_sprite_list(); + staff_reset_modes(); + date_reset(); + climate_reset(CLIMATE_COOL_AND_WET); + news_item_init_queue(); + user_string_clear_all(); + + gInMapInitCode = false; + + gNextGuestNumber = 1; + + context_init(); + scenery_set_default_placement_configuration(); + + auto intent = Intent(INTENT_ACTION_CLEAR_TILE_INSPECTOR_CLIPBOARD); + context_broadcast_intent(&intent); + + load_palette(); +} + void GameState::Update() { gInUpdateCode = true; diff --git a/src/openrct2/GameState.h b/src/openrct2/GameState.h index 7ac8d2773d..a4c21902ea 100644 --- a/src/openrct2/GameState.h +++ b/src/openrct2/GameState.h @@ -38,6 +38,7 @@ namespace OpenRCT2 Date * GetDate() { return &_date; } Park * GetPark() { return _park.get(); } + void InitAll(sint32 mapSize); void Update(); void UpdateLogic(); }; diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index c16388abc3..419d7c1c62 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -340,8 +340,9 @@ private: String::Set(gScenarioFileName, sizeof(gScenarioFileName), GetRCT1ScenarioName().c_str()); // Do map initialisation, same kind of stuff done when loading scenario editor - OpenRCT2::GetContext()->GetObjectManager()->UnloadAll(); - game_init_all(mapSize); + auto context = OpenRCT2::GetContext(); + context->GetObjectManager()->UnloadAll(); + context->GetGameState()->InitAll(mapSize); gS6Info.editor_step = EDITOR_STEP_OBJECT_SELECTION; gParkFlags |= PARK_FLAGS_SHOW_REAL_GUEST_NAMES; gS6Info.category = SCENARIO_CATEGORY_OTHER; diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 70e4d0c5c4..85d8ac3f61 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -771,7 +771,7 @@ public: void Initialise() { - game_init_all(_s6.map_size); + OpenRCT2::GetContext()->GetGameState()->InitAll(_s6.map_size); } /** diff --git a/src/openrct2/title/TitleScreen.cpp b/src/openrct2/title/TitleScreen.cpp index 6547fb0f81..e45eadea57 100644 --- a/src/openrct2/title/TitleScreen.cpp +++ b/src/openrct2/title/TitleScreen.cpp @@ -130,7 +130,7 @@ void TitleScreen::Load() network_close(); audio_stop_all_music_and_sounds(); - game_init_all(150); + GetContext()->GetGameState()->InitAll(150); viewport_init_all(); context_open_window(WC_MAIN_WINDOW); CreateWindows(); @@ -276,7 +276,7 @@ bool TitleScreen::TryLoadSequence(bool loadPreview) _loadedTitleSequenceId = SIZE_MAX; if (!loadPreview) { - game_init_all(150); + GetContext()->GetGameState()->InitAll(150); } return false; } diff --git a/src/openrct2/world/Park.cpp b/src/openrct2/world/Park.cpp index 00c718879b..b3389d0532 100644 --- a/src/openrct2/world/Park.cpp +++ b/src/openrct2/world/Park.cpp @@ -1060,16 +1060,6 @@ sint32 park_is_open() return GetContext()->GetGameState()->GetPark()->IsOpen(); } -void park_init() -{ - auto park = GetContext()->GetGameState()->GetPark(); - if (park == nullptr) - { - return; - } - park->Initialise(); -} - sint32 park_calculate_size() { auto tiles = GetContext()->GetGameState()->GetPark()->CalculateParkSize(); diff --git a/src/openrct2/world/Park.h b/src/openrct2/world/Park.h index 0c15e87c01..40d97cccaf 100644 --- a/src/openrct2/world/Park.h +++ b/src/openrct2/world/Park.h @@ -128,7 +128,6 @@ void set_forced_park_rating(sint32 rating); sint32 get_forced_park_rating(); sint32 park_is_open(); -void park_init(); sint32 park_calculate_size(); void reset_park_entry();