From 5f0c3d2ffda02391cf00f4e291a8a57c5acf3bc2 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Sun, 14 Jul 2024 22:18:31 +0200 Subject: [PATCH] Add progress bars to loading saved games and scenarios --- data/language/en-GB.txt | 3 +++ src/openrct2/Context.cpp | 17 ++++++++++++++++- src/openrct2/Context.h | 4 +++- src/openrct2/localisation/StringIds.h | 3 +++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/data/language/en-GB.txt b/data/language/en-GB.txt index de56ffc3dd..d662670e4b 100644 --- a/data/language/en-GB.txt +++ b/data/language/en-GB.txt @@ -3720,6 +3720,9 @@ STR_6645 :Makes some UI elements bigger so they are easier to click or tap. STR_6646 :Author: {STRING} STR_6647 :Authors: {STRING} STR_6648 :Loading plugin engine… +STR_6649 :Loading scenario… +STR_6650 :Loading saved game… +STR_6651 :{STRING} ({COMMA32}%) ############# # Scenarios # diff --git a/src/openrct2/Context.cpp b/src/openrct2/Context.cpp index 4557d6f5ad..207ea19914 100644 --- a/src/openrct2/Context.cpp +++ b/src/openrct2/Context.cpp @@ -656,13 +656,20 @@ namespace OpenRCT2 ContextOpenIntent(&intent); } - void SetProgress(uint32_t currentProgress, uint32_t totalCount, StringId format = STR_NONE) override + void SetProgress( + uint32_t currentProgress, uint32_t totalCount, StringId format = STR_NONE, bool forceDraw = false) override { auto intent = Intent(INTENT_ACTION_PROGRESS_SET); intent.PutExtra(INTENT_EXTRA_PROGRESS_OFFSET, currentProgress); intent.PutExtra(INTENT_EXTRA_PROGRESS_TOTAL, totalCount); intent.PutExtra(INTENT_EXTRA_STRING_ID, format); ContextOpenIntent(&intent); + + // Ideally, we'd force a redraw at all times at this point. OpenGL has to be directed + // from the main thread, though, so this cannot be invoked when off main thread. + // It's fine (and indeed useful!) for synchronous calls, so we keep it as an option. + if (!gOpenRCT2Headless && forceDraw) + Draw(); } void CloseProgress() override @@ -755,7 +762,11 @@ namespace OpenRCT2 parkImporter = ParkImporter::CreateS6(*_objectRepository); } + OpenProgress(asScenario ? STR_LOADING_SCENARIO : STR_LOADING_SAVED_GAME); + SetProgress(0, 100, STR_STRING_M_PERCENT, true); + auto result = parkImporter->LoadFromStream(stream, info.Type == FILE_TYPE::SCENARIO, false, path.c_str()); + SetProgress(30, 100, STR_STRING_M_PERCENT, true); // From this point onwards the currently loaded park will be corrupted if loading fails // so reload the title screen if that happens. @@ -763,10 +774,12 @@ namespace OpenRCT2 GameUnloadScripts(); _objectManager->LoadObjects(result.RequiredObjects); + SetProgress(70, 100, STR_STRING_M_PERCENT, true); // TODO: Have a separate GameState and exchange once loaded. auto& gameState = ::GetGameState(); parkImporter->Import(gameState); + SetProgress(100, 100, STR_STRING_M_PERCENT, true); gScenarioSavePath = path; gCurrentLoadedPath = path; @@ -841,6 +854,7 @@ namespace OpenRCT2 windowManager->ShowError(STR_PARK_USES_FALLBACK_IMAGES_WARNING, STR_EMPTY, Formatter()); } + CloseProgress(); return true; } catch (const ObjectLoadException& e) @@ -916,6 +930,7 @@ namespace OpenRCT2 Console::Error::WriteLine(e.what()); } + CloseProgress(); return false; } diff --git a/src/openrct2/Context.h b/src/openrct2/Context.h index bf65c6aa00..5b6302e155 100644 --- a/src/openrct2/Context.h +++ b/src/openrct2/Context.h @@ -160,7 +160,9 @@ namespace OpenRCT2 virtual void DisposeDrawingEngine() = 0; virtual void OpenProgress(StringId captionStringId) = 0; - virtual void SetProgress(uint32_t currentProgress, uint32_t totalCount, StringId format = STR_NONE) = 0; + virtual void SetProgress( + uint32_t currentProgress, uint32_t totalCount, StringId format = STR_NONE, bool forceDraw = false) + = 0; virtual void CloseProgress() = 0; virtual bool LoadParkFromFile(const u8string& path, bool loadTitleScreenOnFail = false, bool asScenario = false) = 0; diff --git a/src/openrct2/localisation/StringIds.h b/src/openrct2/localisation/StringIds.h index 984dcaae77..7fb99d6e54 100644 --- a/src/openrct2/localisation/StringIds.h +++ b/src/openrct2/localisation/StringIds.h @@ -1685,6 +1685,9 @@ enum : StringId STR_STRING_M_OF_N_KIB = 6643, STR_LOADING_PLUGIN_ENGINE = 6648, + STR_LOADING_SCENARIO = 6649, + STR_LOADING_SAVED_GAME = 6650, + STR_STRING_M_PERCENT = 6651, // Have to include resource strings (from scenarios and objects) for the time being now that language is partially working /* MAX_STR_COUNT = 32768 */ // MAX_STR_COUNT - upper limit for number of strings, not the current count strings