From 255e89ec3771593845e690c1fae06de293516281 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Tue, 23 Apr 2024 21:31:05 +0200 Subject: [PATCH] Refactor TitleScreen to TitleScene; introduce GameScene MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: ζeh Matt <5415177+ZehMatt@users.noreply.github.com> --- src/openrct2-ui/UiContext.cpp | 2 +- src/openrct2-ui/input/Shortcuts.cpp | 2 +- src/openrct2-ui/scripting/ScTitleSequence.hpp | 8 +- src/openrct2-ui/title/TitleSequencePlayer.cpp | 8 +- .../windows/EditorObjectSelection.cpp | 6 +- src/openrct2-ui/windows/LoadSave.cpp | 6 +- src/openrct2-ui/windows/Options.cpp | 4 +- src/openrct2/Context.cpp | 82 +++++---- src/openrct2/Context.h | 8 +- src/openrct2/Game.cpp | 17 +- src/openrct2/GameState.cpp | 4 +- src/openrct2/libopenrct2.vcxproj | 56 +++--- src/openrct2/paint/Painter.cpp | 2 +- src/openrct2/scenes/Scene.h | 2 +- src/openrct2/scenes/game/GameScene.cpp | 37 ++++ src/openrct2/scenes/game/GameScene.h | 27 +++ .../{ => scenes}/title/Command/End.cpp | 0 src/openrct2/{ => scenes}/title/Command/End.h | 0 .../title/Command/FollowEntity.cpp | 2 +- .../{ => scenes}/title/Command/FollowEntity.h | 6 +- .../{ => scenes}/title/Command/LoadPark.cpp | 0 .../{ => scenes}/title/Command/LoadPark.h | 0 .../title/Command/LoadScenario.cpp | 0 .../{ => scenes}/title/Command/LoadScenario.h | 2 +- .../{ => scenes}/title/Command/Restart.cpp | 0 .../{ => scenes}/title/Command/Restart.h | 0 .../{ => scenes}/title/Command/RotateView.cpp | 4 +- .../{ => scenes}/title/Command/RotateView.h | 0 .../title/Command/SetLocation.cpp | 8 +- .../{ => scenes}/title/Command/SetLocation.h | 0 .../{ => scenes}/title/Command/SetSpeed.cpp | 2 +- .../{ => scenes}/title/Command/SetSpeed.h | 0 .../{ => scenes}/title/Command/SetZoom.cpp | 4 +- .../{ => scenes}/title/Command/SetZoom.h | 0 .../{ => scenes}/title/Command/Wait.cpp | 2 +- .../{ => scenes}/title/Command/Wait.h | 0 .../title/TitleScene.cpp} | 166 +++++++++--------- .../title/TitleScene.h} | 16 +- .../{ => scenes}/title/TitleSequence.cpp | 32 ++-- .../{ => scenes}/title/TitleSequence.h | 4 +- .../title/TitleSequenceManager.cpp | 22 +-- .../{ => scenes}/title/TitleSequenceManager.h | 4 +- .../{ => scenes}/title/TitleSequencePlayer.h | 2 +- src/openrct2/util/Util.cpp | 2 +- 44 files changed, 323 insertions(+), 226 deletions(-) create mode 100644 src/openrct2/scenes/game/GameScene.cpp create mode 100644 src/openrct2/scenes/game/GameScene.h rename src/openrct2/{ => scenes}/title/Command/End.cpp (100%) rename src/openrct2/{ => scenes}/title/Command/End.h (100%) rename src/openrct2/{ => scenes}/title/Command/FollowEntity.cpp (95%) rename src/openrct2/{ => scenes}/title/Command/FollowEntity.h (88%) rename src/openrct2/{ => scenes}/title/Command/LoadPark.cpp (100%) rename src/openrct2/{ => scenes}/title/Command/LoadPark.h (100%) rename src/openrct2/{ => scenes}/title/Command/LoadScenario.cpp (100%) rename src/openrct2/{ => scenes}/title/Command/LoadScenario.h (95%) rename src/openrct2/{ => scenes}/title/Command/Restart.cpp (100%) rename src/openrct2/{ => scenes}/title/Command/Restart.h (100%) rename src/openrct2/{ => scenes}/title/Command/RotateView.cpp (89%) rename src/openrct2/{ => scenes}/title/Command/RotateView.h (100%) rename src/openrct2/{ => scenes}/title/Command/SetLocation.cpp (88%) rename src/openrct2/{ => scenes}/title/Command/SetLocation.h (100%) rename src/openrct2/{ => scenes}/title/Command/SetSpeed.cpp (96%) rename src/openrct2/{ => scenes}/title/Command/SetSpeed.h (100%) rename src/openrct2/{ => scenes}/title/Command/SetZoom.cpp (90%) rename src/openrct2/{ => scenes}/title/Command/SetZoom.h (100%) rename src/openrct2/{ => scenes}/title/Command/Wait.cpp (96%) rename src/openrct2/{ => scenes}/title/Command/Wait.h (100%) rename src/openrct2/{title/TitleScreen.cpp => scenes/title/TitleScene.cpp} (74%) rename src/openrct2/{title/TitleScreen.h => scenes/title/TitleScene.h} (88%) rename src/openrct2/{ => scenes}/title/TitleSequence.cpp (97%) rename src/openrct2/{ => scenes}/title/TitleSequence.h (97%) rename src/openrct2/{ => scenes}/title/TitleSequenceManager.cpp (96%) rename src/openrct2/{ => scenes}/title/TitleSequenceManager.h (96%) rename src/openrct2/{ => scenes}/title/TitleSequencePlayer.h (96%) diff --git a/src/openrct2-ui/UiContext.cpp b/src/openrct2-ui/UiContext.cpp index 40ebaf3d06..d5b05ba446 100644 --- a/src/openrct2-ui/UiContext.cpp +++ b/src/openrct2-ui/UiContext.cpp @@ -41,8 +41,8 @@ #include #include #include +#include #include -#include #include #include #include diff --git a/src/openrct2-ui/input/Shortcuts.cpp b/src/openrct2-ui/input/Shortcuts.cpp index 6921a59f17..8652a7d985 100644 --- a/src/openrct2-ui/input/Shortcuts.cpp +++ b/src/openrct2-ui/input/Shortcuts.cpp @@ -38,7 +38,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/openrct2-ui/scripting/ScTitleSequence.hpp b/src/openrct2-ui/scripting/ScTitleSequence.hpp index c7063a3f0d..fdbffea92f 100644 --- a/src/openrct2-ui/scripting/ScTitleSequence.hpp +++ b/src/openrct2-ui/scripting/ScTitleSequence.hpp @@ -21,11 +21,11 @@ # include # include # include +# include +# include +# include +# include # include -# include -# include -# include -# include # include # include diff --git a/src/openrct2-ui/title/TitleSequencePlayer.cpp b/src/openrct2-ui/title/TitleSequencePlayer.cpp index edbc2ff7f6..4e0c24a4f5 100644 --- a/src/openrct2-ui/title/TitleSequencePlayer.cpp +++ b/src/openrct2-ui/title/TitleSequencePlayer.cpp @@ -30,10 +30,10 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include diff --git a/src/openrct2-ui/windows/EditorObjectSelection.cpp b/src/openrct2-ui/windows/EditorObjectSelection.cpp index 7110640fdc..3901f2e0d4 100644 --- a/src/openrct2-ui/windows/EditorObjectSelection.cpp +++ b/src/openrct2-ui/windows/EditorObjectSelection.cpp @@ -35,8 +35,8 @@ #include #include #include +#include #include -#include #include #include #include @@ -368,7 +368,9 @@ static std::vector _window_editor_object_selection_widgets = { { GameNotifyMapChange(); GameUnloadScripts(); - TitleLoad(); + + auto* context = OpenRCT2::GetContext(); + context->SetActiveScene(context->GetTitleScene()); } break; case WIDX_FILTER_RIDE_TAB_ALL: diff --git a/src/openrct2-ui/windows/LoadSave.cpp b/src/openrct2-ui/windows/LoadSave.cpp index 743d5b90ca..0bd215d791 100644 --- a/src/openrct2-ui/windows/LoadSave.cpp +++ b/src/openrct2-ui/windows/LoadSave.cpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include #include @@ -354,7 +354,9 @@ static Widget window_loadsave_widgets[] = { WindowCloseByClass(WindowClass::Loadsave); InvokeCallback(MODAL_RESULT_OK, pathBuffer); - TitleLoad(); + + auto* context = OpenRCT2::GetContext(); + context->SetActiveScene(context->GetTitleScene()); } else { diff --git a/src/openrct2-ui/windows/Options.cpp b/src/openrct2-ui/windows/Options.cpp index 325f915ff5..01c31d0cf9 100644 --- a/src/openrct2-ui/windows/Options.cpp +++ b/src/openrct2-ui/windows/Options.cpp @@ -40,9 +40,9 @@ #include #include #include +#include +#include #include -#include -#include #include #include diff --git a/src/openrct2/Context.cpp b/src/openrct2/Context.cpp index e8c78064a8..fe82237c51 100644 --- a/src/openrct2/Context.cpp +++ b/src/openrct2/Context.cpp @@ -66,11 +66,11 @@ #include "ride/TrackDesignRepository.h" #include "scenario/Scenario.h" #include "scenario/ScenarioRepository.h" -#include "scenes/Scene.h" +#include "scenes/game/GameScene.h" +#include "scenes/title/TitleScene.h" +#include "scenes/title/TitleSequenceManager.h" #include "scripting/HookEngine.h" #include "scripting/ScriptEngine.h" -#include "title/TitleScreen.h" -#include "title/TitleSequenceManager.h" #include "ui/UiContext.h" #include "ui/WindowManager.h" #include "util/Util.h" @@ -124,11 +124,10 @@ namespace OpenRCT2 #endif // Scenes + std::unique_ptr _titleScene; + std::unique_ptr _gameScene; IScene* _activeScene = nullptr; - // Game states - std::unique_ptr _titleScreen; - DrawingEngine _drawingEngineType = DrawingEngine::Software; std::unique_ptr _drawingEngine; std::unique_ptr _painter; @@ -175,7 +174,8 @@ namespace OpenRCT2 #ifndef DISABLE_NETWORK , _network(*this) #endif - , _titleScreen(std::make_unique()) + , _titleScene(std::make_unique(*this)) + , _gameScene(std::make_unique(*this)) , _painter(std::make_unique(uiContext)) { // Can't have more than one context currently. @@ -309,7 +309,35 @@ namespace OpenRCT2 return EXIT_FAILURE; } - virtual IScene* GetActiveScene() override + IScene* GetLoadingScene() override + { + // TODO: Implement me. + return nullptr; + } + + IScene* GetIntroScene() override + { + // TODO: Implement me. + return nullptr; + } + + IScene* GetTitleScene() override + { + return _titleScene.get(); + } + + IScene* GetGameScene() override + { + return _gameScene.get(); + } + + IScene* GetEditorScene() override + { + // TODO: Implement me. + return nullptr; + } + + IScene* GetActiveScene() override { return _activeScene; } @@ -610,7 +638,7 @@ namespace OpenRCT2 Console::Error::WriteLine(e.what()); if (loadTitleScreenOnFail) { - TitleLoad(); + SetActiveScene(GetTitleScene()); } auto windowManager = _uiContext->GetWindowManager(); windowManager->ShowError(STR_FAILED_TO_LOAD_FILE_CONTAINS_INVALID_DATA, STR_NONE, {}); @@ -746,7 +774,7 @@ namespace OpenRCT2 // If loading the SV6 or SV4 failed return to the title screen if requested. if (loadTitleScreenFirstOnFail) { - TitleLoad(); + SetActiveScene(GetTitleScene()); } // The path needs to be duplicated as it's a const here // which the window function doesn't like @@ -765,7 +793,7 @@ namespace OpenRCT2 // If loading the SV6 or SV4 failed return to the title screen if requested. if (loadTitleScreenFirstOnFail) { - TitleLoad(); + SetActiveScene(GetTitleScene()); } auto windowManager = _uiContext->GetWindowManager(); windowManager->ShowError(STR_FILE_CONTAINS_UNSUPPORTED_RIDE_TYPES, STR_NONE, {}); @@ -776,7 +804,7 @@ namespace OpenRCT2 if (loadTitleScreenFirstOnFail) { - TitleLoad(); + SetActiveScene(GetTitleScene()); } auto windowManager = _uiContext->GetWindowManager(); Formatter ft; @@ -807,7 +835,7 @@ namespace OpenRCT2 // If loading the SV6 or SV4 failed return to the title screen if requested. if (loadTitleScreenFirstOnFail) { - TitleLoad(); + SetActiveScene(GetTitleScene()); } Console::Error::WriteLine(e.what()); } @@ -910,10 +938,10 @@ namespace OpenRCT2 { case StartupAction::Intro: gIntroState = IntroState::PublisherBegin; - TitleLoad(); + SetActiveScene(GetTitleScene()); break; case StartupAction::Title: - TitleLoad(); + SetActiveScene(GetTitleScene()); break; case StartupAction::Open: { @@ -926,7 +954,7 @@ namespace OpenRCT2 auto data = DownloadPark(gOpenRCT2StartupActionPath); if (data.empty()) { - TitleLoad(); + SetActiveScene(GetTitleScene()); break; } @@ -934,7 +962,7 @@ namespace OpenRCT2 if (!LoadParkFromStream(&ms, gOpenRCT2StartupActionPath, true)) { Console::Error::WriteLine("Failed to load '%s'", gOpenRCT2StartupActionPath); - TitleLoad(); + SetActiveScene(GetTitleScene()); break; } #endif @@ -952,12 +980,12 @@ namespace OpenRCT2 { Console::Error::WriteLine("Failed to load '%s'", gOpenRCT2StartupActionPath); Console::Error::WriteLine("%s", ex.what()); - TitleLoad(); + SetActiveScene(GetTitleScene()); break; } } - gScreenFlags = SCREEN_FLAGS_PLAYING; + SetActiveScene(GetGameScene()); #ifndef DISABLE_NETWORK if (gNetworkStart == NETWORK_MODE_SERVER) @@ -997,7 +1025,7 @@ namespace OpenRCT2 } else if (!Editor::LoadLandscape(gOpenRCT2StartupActionPath)) { - TitleLoad(); + SetActiveScene(GetTitleScene()); } break; default: @@ -1201,18 +1229,8 @@ namespace OpenRCT2 DateUpdateRealTimeOfDay(); - if (gIntroState != IntroState::None) - { - IntroUpdate(); - } - else if ((gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) && !gOpenRCT2Headless) - { - _titleScreen->Tick(); - } - else - { - gameStateTick(); - } + if (_activeScene) + _activeScene->Tick(); #ifdef __ENABLE_DISCORD__ if (_discordService != nullptr) diff --git a/src/openrct2/Context.h b/src/openrct2/Context.h index f576a6bce2..e6c843adbf 100644 --- a/src/openrct2/Context.h +++ b/src/openrct2/Context.h @@ -144,8 +144,14 @@ namespace OpenRCT2 virtual NetworkBase& GetNetwork() abstract; #endif + virtual IScene* GetLoadingScene() abstract; + virtual IScene* GetIntroScene() abstract; + virtual IScene* GetTitleScene() abstract; + virtual IScene* GetGameScene() abstract; + virtual IScene* GetEditorScene() abstract; + virtual IScene* GetActiveScene() abstract; - virtual void SetActiveScene(IScene * screen) abstract; + virtual void SetActiveScene(IScene* screen) abstract; virtual int32_t RunOpenRCT2(int argc, const char** argv) abstract; diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index bc2e86661b..ba1a7cbfc1 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -53,8 +53,8 @@ #include "ride/TrackDesign.h" #include "ride/Vehicle.h" #include "scenario/Scenario.h" +#include "scenes/title/TitleScene.h" #include "scripting/ScriptEngine.h" -#include "title/TitleScreen.h" #include "ui/UiContext.h" #include "ui/WindowManager.h" #include "util/SawyerCoding.h" @@ -511,11 +511,13 @@ void GameFixSaveVars() void GameLoadInit() { - IGameStateSnapshots* snapshots = GetContext()->GetGameStateSnapshots(); + auto* context = GetContext(); + + IGameStateSnapshots* snapshots = context->GetGameStateSnapshots(); snapshots->Reset(); - gScreenFlags = SCREEN_FLAGS_PLAYING; - OpenRCT2::Audio::StopAll(); + context->SetActiveScene(context->GetGameScene()); + if (!gLoadKeepWindowsOpen) { ViewportInitAll(); @@ -527,7 +529,7 @@ void GameLoadInit() WindowUnfollowSprite(*mainWindow); } - auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); + auto windowManager = context->GetUiContext()->GetWindowManager(); auto& gameState = GetGameState(); windowManager->SetMainView(gameState.SavedView, gameState.SavedViewZoom, gameState.SavedViewRotation); @@ -553,7 +555,6 @@ void GameLoadInit() ContextBroadcastIntent(&intent); } - OpenRCT2::Audio::StopTitleMusic(); gGameSpeed = 1; } @@ -841,7 +842,9 @@ void GameLoadOrQuitNoSavePrompt() gFirstTimeSaving = true; GameNotifyMapChange(); GameUnloadScripts(); - TitleLoad(); + + auto* context = OpenRCT2::GetContext(); + context->SetActiveScene(context->GetTitleScene()); break; } case PromptMode::SaveBeforeNewGame: diff --git a/src/openrct2/GameState.cpp b/src/openrct2/GameState.cpp index 4d50e4ee99..119a483360 100644 --- a/src/openrct2/GameState.cpp +++ b/src/openrct2/GameState.cpp @@ -34,9 +34,9 @@ #include "profiling/Profiling.h" #include "ride/Vehicle.h" #include "scenario/Scenario.h" +#include "scenes/title/TitleScene.h" +#include "scenes/title/TitleSequencePlayer.h" #include "scripting/ScriptEngine.h" -#include "title/TitleScreen.h" -#include "title/TitleSequencePlayer.h" #include "ui/UiContext.h" #include "windows/Intent.h" #include "world/Climate.h" diff --git a/src/openrct2/libopenrct2.vcxproj b/src/openrct2/libopenrct2.vcxproj index 6e70f650ce..ca3b0e6ce1 100644 --- a/src/openrct2/libopenrct2.vcxproj +++ b/src/openrct2/libopenrct2.vcxproj @@ -512,6 +512,21 @@ + + + + + + + + + + + + + + + @@ -552,20 +567,6 @@ - - - - - - - - - - - - - - @@ -1001,6 +1002,20 @@ + + + + + + + + + + + + + + @@ -1022,19 +1037,6 @@ - - - - - - - - - - - - - diff --git a/src/openrct2/paint/Painter.cpp b/src/openrct2/paint/Painter.cpp index d91d24d94a..e8d5b210c3 100644 --- a/src/openrct2/paint/Painter.cpp +++ b/src/openrct2/paint/Painter.cpp @@ -24,7 +24,7 @@ #include "../localisation/Language.h" #include "../paint/Paint.h" #include "../profiling/Profiling.h" -#include "../title/TitleScreen.h" +#include "../scenes/title/TitleScene.h" #include "../ui/UiContext.h" #include "../world/TileInspector.h" diff --git a/src/openrct2/scenes/Scene.h b/src/openrct2/scenes/Scene.h index 71389bd862..4e1e135d88 100644 --- a/src/openrct2/scenes/Scene.h +++ b/src/openrct2/scenes/Scene.h @@ -25,7 +25,7 @@ namespace OpenRCT2 virtual IContext& GetContext() = 0; virtual void Load() = 0; - virtual void Update() = 0; + virtual void Tick() = 0; virtual void Stop() = 0; }; diff --git a/src/openrct2/scenes/game/GameScene.cpp b/src/openrct2/scenes/game/GameScene.cpp new file mode 100644 index 0000000000..dbbf86d8ff --- /dev/null +++ b/src/openrct2/scenes/game/GameScene.cpp @@ -0,0 +1,37 @@ +/***************************************************************************** + * Copyright (c) 2014-2019 OpenRCT2 developers + * + * For a complete list of all authors, please refer to contributors.md + * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is licensed under the GNU General Public License version 3. + *****************************************************************************/ + +#include "GameScene.h" + +#include "../../Context.h" +#include "../../Game.h" +#include "../../GameState.h" +#include "../../OpenRCT2.h" +#include "../../audio/audio.h" + +using namespace OpenRCT2; + +void GameScene::Load() +{ + LOG_VERBOSE("GameScene::Load()"); + + gScreenFlags = SCREEN_FLAGS_PLAYING; + + LOG_VERBOSE("GameScene::Load() finished"); +} + +void GameScene::Tick() +{ + gameStateTick(); +} + +void GameScene::Stop() +{ + Audio::StopAll(); +} diff --git a/src/openrct2/scenes/game/GameScene.h b/src/openrct2/scenes/game/GameScene.h new file mode 100644 index 0000000000..7cf4bcd35c --- /dev/null +++ b/src/openrct2/scenes/game/GameScene.h @@ -0,0 +1,27 @@ +/***************************************************************************** + * Copyright (c) 2014-2019 OpenRCT2 developers + * + * For a complete list of all authors, please refer to contributors.md + * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is licensed under the GNU General Public License version 3. + *****************************************************************************/ + +#pragma once + +#include "../../common.h" +#include "../../drawing/Drawing.h" +#include "../Scene.h" + +namespace OpenRCT2 +{ + class GameScene final : public Scene + { + public: + using Scene::Scene; + + void Load() override; + void Tick() override; + void Stop() override; + }; +} // namespace OpenRCT2 diff --git a/src/openrct2/title/Command/End.cpp b/src/openrct2/scenes/title/Command/End.cpp similarity index 100% rename from src/openrct2/title/Command/End.cpp rename to src/openrct2/scenes/title/Command/End.cpp diff --git a/src/openrct2/title/Command/End.h b/src/openrct2/scenes/title/Command/End.h similarity index 100% rename from src/openrct2/title/Command/End.h rename to src/openrct2/scenes/title/Command/End.h diff --git a/src/openrct2/title/Command/FollowEntity.cpp b/src/openrct2/scenes/title/Command/FollowEntity.cpp similarity index 95% rename from src/openrct2/title/Command/FollowEntity.cpp rename to src/openrct2/scenes/title/Command/FollowEntity.cpp index 90c5552a8c..1b9623e7e1 100644 --- a/src/openrct2/title/Command/FollowEntity.cpp +++ b/src/openrct2/scenes/title/Command/FollowEntity.cpp @@ -9,7 +9,7 @@ #include "FollowEntity.h" -#include "../../interface/Window.h" +#include "../../../interface/Window.h" namespace OpenRCT2::Title { diff --git a/src/openrct2/title/Command/FollowEntity.h b/src/openrct2/scenes/title/Command/FollowEntity.h similarity index 88% rename from src/openrct2/title/Command/FollowEntity.h rename to src/openrct2/scenes/title/Command/FollowEntity.h index 9c21d9abeb..4499292efa 100644 --- a/src/openrct2/title/Command/FollowEntity.h +++ b/src/openrct2/scenes/title/Command/FollowEntity.h @@ -9,9 +9,9 @@ #pragma once -#include "../../Identifiers.h" -#include "../../core/String.hpp" -#include "../../localisation/Localisation.h" +#include "../../../Identifiers.h" +#include "../../../core/String.hpp" +#include "../../../localisation/Localisation.h" #include diff --git a/src/openrct2/title/Command/LoadPark.cpp b/src/openrct2/scenes/title/Command/LoadPark.cpp similarity index 100% rename from src/openrct2/title/Command/LoadPark.cpp rename to src/openrct2/scenes/title/Command/LoadPark.cpp diff --git a/src/openrct2/title/Command/LoadPark.h b/src/openrct2/scenes/title/Command/LoadPark.h similarity index 100% rename from src/openrct2/title/Command/LoadPark.h rename to src/openrct2/scenes/title/Command/LoadPark.h diff --git a/src/openrct2/title/Command/LoadScenario.cpp b/src/openrct2/scenes/title/Command/LoadScenario.cpp similarity index 100% rename from src/openrct2/title/Command/LoadScenario.cpp rename to src/openrct2/scenes/title/Command/LoadScenario.cpp diff --git a/src/openrct2/title/Command/LoadScenario.h b/src/openrct2/scenes/title/Command/LoadScenario.h similarity index 95% rename from src/openrct2/title/Command/LoadScenario.h rename to src/openrct2/scenes/title/Command/LoadScenario.h index a8caaf9ae5..0500e30816 100644 --- a/src/openrct2/title/Command/LoadScenario.h +++ b/src/openrct2/scenes/title/Command/LoadScenario.h @@ -9,7 +9,7 @@ #pragma once -#include "../../core/String.hpp" +#include "../../../core/String.hpp" #include diff --git a/src/openrct2/title/Command/Restart.cpp b/src/openrct2/scenes/title/Command/Restart.cpp similarity index 100% rename from src/openrct2/title/Command/Restart.cpp rename to src/openrct2/scenes/title/Command/Restart.cpp diff --git a/src/openrct2/title/Command/Restart.h b/src/openrct2/scenes/title/Command/Restart.h similarity index 100% rename from src/openrct2/title/Command/Restart.h rename to src/openrct2/scenes/title/Command/Restart.h diff --git a/src/openrct2/title/Command/RotateView.cpp b/src/openrct2/scenes/title/Command/RotateView.cpp similarity index 89% rename from src/openrct2/title/Command/RotateView.cpp rename to src/openrct2/scenes/title/Command/RotateView.cpp index b49cf5b313..fe896a04e0 100644 --- a/src/openrct2/title/Command/RotateView.cpp +++ b/src/openrct2/scenes/title/Command/RotateView.cpp @@ -9,8 +9,8 @@ #include "RotateView.h" -#include "../../interface/Viewport.h" -#include "../../interface/Window.h" +#include "../../../interface/Viewport.h" +#include "../../../interface/Window.h" namespace OpenRCT2::Title { diff --git a/src/openrct2/title/Command/RotateView.h b/src/openrct2/scenes/title/Command/RotateView.h similarity index 100% rename from src/openrct2/title/Command/RotateView.h rename to src/openrct2/scenes/title/Command/RotateView.h diff --git a/src/openrct2/title/Command/SetLocation.cpp b/src/openrct2/scenes/title/Command/SetLocation.cpp similarity index 88% rename from src/openrct2/title/Command/SetLocation.cpp rename to src/openrct2/scenes/title/Command/SetLocation.cpp index 0ecb56ebbf..b577a2c80b 100644 --- a/src/openrct2/title/Command/SetLocation.cpp +++ b/src/openrct2/scenes/title/Command/SetLocation.cpp @@ -9,10 +9,10 @@ #include "SetLocation.h" -#include "../../OpenRCT2.h" -#include "../../interface/Window.h" -#include "../../interface/Window_internal.h" -#include "../../world/Map.h" +#include "../../../OpenRCT2.h" +#include "../../../interface/Window.h" +#include "../../../interface/Window_internal.h" +#include "../../../world/Map.h" namespace OpenRCT2::Title { diff --git a/src/openrct2/title/Command/SetLocation.h b/src/openrct2/scenes/title/Command/SetLocation.h similarity index 100% rename from src/openrct2/title/Command/SetLocation.h rename to src/openrct2/scenes/title/Command/SetLocation.h diff --git a/src/openrct2/title/Command/SetSpeed.cpp b/src/openrct2/scenes/title/Command/SetSpeed.cpp similarity index 96% rename from src/openrct2/title/Command/SetSpeed.cpp rename to src/openrct2/scenes/title/Command/SetSpeed.cpp index c728b627b5..d7c02a7ee4 100644 --- a/src/openrct2/title/Command/SetSpeed.cpp +++ b/src/openrct2/scenes/title/Command/SetSpeed.cpp @@ -9,7 +9,7 @@ #include "SetSpeed.h" -#include "../../Game.h" +#include "../../../Game.h" #include diff --git a/src/openrct2/title/Command/SetSpeed.h b/src/openrct2/scenes/title/Command/SetSpeed.h similarity index 100% rename from src/openrct2/title/Command/SetSpeed.h rename to src/openrct2/scenes/title/Command/SetSpeed.h diff --git a/src/openrct2/title/Command/SetZoom.cpp b/src/openrct2/scenes/title/Command/SetZoom.cpp similarity index 90% rename from src/openrct2/title/Command/SetZoom.cpp rename to src/openrct2/scenes/title/Command/SetZoom.cpp index b1da73c58b..bbf7ead270 100644 --- a/src/openrct2/title/Command/SetZoom.cpp +++ b/src/openrct2/scenes/title/Command/SetZoom.cpp @@ -9,8 +9,8 @@ #include "SetZoom.h" -#include "../../interface/Window.h" -#include "../../interface/ZoomLevel.h" +#include "../../../interface/Window.h" +#include "../../../interface/ZoomLevel.h" namespace OpenRCT2::Title { diff --git a/src/openrct2/title/Command/SetZoom.h b/src/openrct2/scenes/title/Command/SetZoom.h similarity index 100% rename from src/openrct2/title/Command/SetZoom.h rename to src/openrct2/scenes/title/Command/SetZoom.h diff --git a/src/openrct2/title/Command/Wait.cpp b/src/openrct2/scenes/title/Command/Wait.cpp similarity index 96% rename from src/openrct2/title/Command/Wait.cpp rename to src/openrct2/scenes/title/Command/Wait.cpp index 85383c578d..1915b0c5d4 100644 --- a/src/openrct2/title/Command/Wait.cpp +++ b/src/openrct2/scenes/title/Command/Wait.cpp @@ -9,7 +9,7 @@ #include "Wait.h" -#include "../../Context.h" +#include "../../../Context.h" #include diff --git a/src/openrct2/title/Command/Wait.h b/src/openrct2/scenes/title/Command/Wait.h similarity index 100% rename from src/openrct2/title/Command/Wait.h rename to src/openrct2/scenes/title/Command/Wait.h diff --git a/src/openrct2/title/TitleScreen.cpp b/src/openrct2/scenes/title/TitleScene.cpp similarity index 74% rename from src/openrct2/title/TitleScreen.cpp rename to src/openrct2/scenes/title/TitleScene.cpp index ba68b02eeb..d198c51a31 100644 --- a/src/openrct2/title/TitleScreen.cpp +++ b/src/openrct2/scenes/title/TitleScene.cpp @@ -7,28 +7,28 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ -#include "TitleScreen.h" +#include "TitleScene.h" -#include "../Context.h" -#include "../Game.h" -#include "../GameState.h" -#include "../Input.h" -#include "../OpenRCT2.h" -#include "../Version.h" -#include "../audio/audio.h" -#include "../config/Config.h" -#include "../core/Console.hpp" -#include "../drawing/Drawing.h" -#include "../interface/Screenshot.h" -#include "../interface/Viewport.h" -#include "../interface/Window.h" -#include "../localisation/Localisation.h" -#include "../network/NetworkBase.h" -#include "../network/network.h" -#include "../scenario/Scenario.h" -#include "../scenario/ScenarioRepository.h" -#include "../ui/UiContext.h" -#include "../util/Util.h" +#include "../../Context.h" +#include "../../Game.h" +#include "../../GameState.h" +#include "../../Input.h" +#include "../../OpenRCT2.h" +#include "../../Version.h" +#include "../../audio/audio.h" +#include "../../config/Config.h" +#include "../../core/Console.hpp" +#include "../../drawing/Drawing.h" +#include "../../interface/Screenshot.h" +#include "../../interface/Viewport.h" +#include "../../interface/Window.h" +#include "../../localisation/Localisation.h" +#include "../../network/NetworkBase.h" +#include "../../network/network.h" +#include "../../scenario/Scenario.h" +#include "../../scenario/ScenarioRepository.h" +#include "../../ui/UiContext.h" +#include "../../util/Util.h" #include "TitleSequence.h" #include "TitleSequenceManager.h" #include "TitleSequencePlayer.h" @@ -37,29 +37,18 @@ using namespace OpenRCT2; // TODO Remove when no longer required. bool gPreviewingTitleSequenceInGame; -static TitleScreen* _singleton = nullptr; -TitleScreen::TitleScreen() -{ - _singleton = this; -} - -TitleScreen::~TitleScreen() -{ - _singleton = nullptr; -} - -ITitleSequencePlayer* TitleScreen::GetSequencePlayer() +ITitleSequencePlayer* TitleScene::GetSequencePlayer() { return _sequencePlayer; } -size_t TitleScreen::GetCurrentSequence() +size_t TitleScene::GetCurrentSequence() { return _currentSequence; } -bool TitleScreen::PreviewSequence(size_t value) +bool TitleScene::PreviewSequence(size_t value) { _currentSequence = value; _previewingSequence = TryLoadSequence(true); @@ -81,7 +70,7 @@ bool TitleScreen::PreviewSequence(size_t value) return _previewingSequence; } -void TitleScreen::StopPreviewingSequence() +void TitleScene::StopPreviewingSequence() { if (_previewingSequence) { @@ -96,24 +85,24 @@ void TitleScreen::StopPreviewingSequence() } } -bool TitleScreen::IsPreviewingSequence() +bool TitleScene::IsPreviewingSequence() { return _previewingSequence; } -bool TitleScreen::ShouldHideVersionInfo() +bool TitleScene::ShouldHideVersionInfo() { return _hideVersionInfo; } -void TitleScreen::SetHideVersionInfo(bool value) +void TitleScene::SetHideVersionInfo(bool value) { _hideVersionInfo = value; } -void TitleScreen::Load() +void TitleScene::Load() { - LOG_VERBOSE("TitleScreen::Load()"); + LOG_VERBOSE("TitleScene::Load()"); if (GameIsPaused()) { @@ -125,9 +114,8 @@ void TitleScreen::Load() gCurrentLoadedPath.clear(); #ifndef DISABLE_NETWORK - GetContext()->GetNetwork().Close(); + GetContext().GetNetwork().Close(); #endif - OpenRCT2::Audio::StopAll(); gameStateInitAll(GetGameState(), DEFAULT_MAP_SIZE); ViewportInitAll(); ContextOpenWindow(WindowClass::MainWindow); @@ -150,10 +138,10 @@ void TitleScreen::Load() _sequencePlayer->Update(); } - LOG_VERBOSE("TitleScreen::Load() finished"); + LOG_VERBOSE("TitleScene::Load() finished"); } -void TitleScreen::Tick() +void TitleScene::Tick() { gInUpdateCode = true; @@ -188,7 +176,12 @@ void TitleScreen::Tick() gInUpdateCode = false; } -void TitleScreen::ChangePresetSequence(size_t preset) +void TitleScene::Stop() +{ + Audio::StopAll(); +} + +void TitleScene::ChangePresetSequence(size_t preset) { size_t count = TitleSequenceManager::GetCount(); if (preset >= count) @@ -208,7 +201,7 @@ void TitleScreen::ChangePresetSequence(size_t preset) * Creates the windows shown on the title screen; New game, load game, * tutorial, toolbox and exit. */ -void TitleScreen::CreateWindows() +void TitleScene::CreateWindows() { ContextOpenWindow(WindowClass::TitleMenu); ContextOpenWindow(WindowClass::TitleExit); @@ -218,11 +211,11 @@ void TitleScreen::CreateWindows() _hideVersionInfo = false; } -void TitleScreen::TitleInitialise() +void TitleScene::TitleInitialise() { if (_sequencePlayer == nullptr) { - _sequencePlayer = GetContext()->GetUiContext()->GetTitleSequencePlayer(); + _sequencePlayer = GetContext().GetUiContext()->GetTitleSequencePlayer(); } if (gConfigInterface.RandomTitleSequence) { @@ -298,13 +291,13 @@ void TitleScreen::TitleInitialise() ChangePresetSequence(static_cast(seqId)); } -bool TitleScreen::TryLoadSequence(bool loadPreview) +bool TitleScene::TryLoadSequence(bool loadPreview) { if (_loadedTitleSequenceId != _currentSequence || loadPreview) { if (_sequencePlayer == nullptr) { - _sequencePlayer = GetContext()->GetUiContext()->GetTitleSequencePlayer(); + _sequencePlayer = GetContext().GetUiContext()->GetTitleSequencePlayer(); } size_t numSequences = TitleSequenceManager::GetCount(); @@ -343,55 +336,55 @@ bool TitleScreen::TryLoadSequence(bool loadPreview) return true; } -void TitleLoad() -{ - if (_singleton != nullptr) - { - _singleton->Load(); - } -} - void TitleCreateWindows() { - if (_singleton != nullptr) + auto* context = OpenRCT2::GetContext(); + auto* titleScene = static_cast(context->GetTitleScene()); + if (titleScene != nullptr) { - _singleton->CreateWindows(); + titleScene->CreateWindows(); } } void* TitleGetSequencePlayer() { - void* result = nullptr; - if (_singleton != nullptr) + auto* context = OpenRCT2::GetContext(); + auto* titleScene = static_cast(context->GetTitleScene()); + if (titleScene != nullptr) { - result = _singleton->GetSequencePlayer(); + return titleScene->GetSequencePlayer(); } - return result; + return nullptr; } void TitleSequenceChangePreset(size_t preset) { - if (_singleton != nullptr) + auto* context = OpenRCT2::GetContext(); + auto* titleScene = static_cast(context->GetTitleScene()); + if (titleScene != nullptr) { - _singleton->ChangePresetSequence(preset); + titleScene->ChangePresetSequence(preset); } } bool TitleShouldHideVersionInfo() { - bool result = false; - if (_singleton != nullptr) + auto* context = OpenRCT2::GetContext(); + auto* titleScene = static_cast(context->GetTitleScene()); + if (titleScene != nullptr) { - result = _singleton->ShouldHideVersionInfo(); + return titleScene->ShouldHideVersionInfo(); } - return result; + return false; } void TitleSetHideVersionInfo(bool value) { - if (_singleton != nullptr) + auto* context = OpenRCT2::GetContext(); + auto* titleScene = static_cast(context->GetTitleScene()); + if (titleScene != nullptr) { - _singleton->SetHideVersionInfo(value); + titleScene->SetHideVersionInfo(value); } } @@ -402,36 +395,43 @@ size_t TitleGetConfigSequence() size_t TitleGetCurrentSequence() { - size_t result = 0; - if (_singleton != nullptr) + auto* context = OpenRCT2::GetContext(); + auto* titleScene = static_cast(context->GetTitleScene()); + if (titleScene != nullptr) { - result = _singleton->GetCurrentSequence(); + return titleScene->GetCurrentSequence(); } - return result; + return 0; } bool TitlePreviewSequence(size_t value) { - if (_singleton != nullptr) + auto* context = OpenRCT2::GetContext(); + auto* titleScene = static_cast(context->GetTitleScene()); + if (titleScene != nullptr) { - return _singleton->PreviewSequence(value); + return titleScene->PreviewSequence(value); } return false; } void TitleStopPreviewingSequence() { - if (_singleton != nullptr) + auto* context = OpenRCT2::GetContext(); + auto* titleScene = static_cast(context->GetTitleScene()); + if (titleScene != nullptr) { - _singleton->StopPreviewingSequence(); + titleScene->StopPreviewingSequence(); } } bool TitleIsPreviewingSequence() { - if (_singleton != nullptr) + auto* context = OpenRCT2::GetContext(); + auto* titleScene = static_cast(context->GetTitleScene()); + if (titleScene != nullptr) { - return _singleton->IsPreviewingSequence(); + return titleScene->IsPreviewingSequence(); } return false; } diff --git a/src/openrct2/title/TitleScreen.h b/src/openrct2/scenes/title/TitleScene.h similarity index 88% rename from src/openrct2/title/TitleScreen.h rename to src/openrct2/scenes/title/TitleScene.h index eeadff5d4f..6cdf914d73 100644 --- a/src/openrct2/title/TitleScreen.h +++ b/src/openrct2/scenes/title/TitleScene.h @@ -9,18 +9,18 @@ #pragma once -#include "../common.h" -#include "../drawing/Drawing.h" +#include "../../common.h" +#include "../../drawing/Drawing.h" +#include "../Scene.h" struct ITitleSequencePlayer; namespace OpenRCT2 { - class TitleScreen final + class TitleScene final : public Scene { public: - TitleScreen(); - ~TitleScreen(); + using Scene::Scene; ITitleSequencePlayer* GetSequencePlayer(); size_t GetCurrentSequence(); @@ -30,8 +30,9 @@ namespace OpenRCT2 bool ShouldHideVersionInfo(); void SetHideVersionInfo(bool value); - void Load(); - void Tick(); + void Load() override; + void Tick() override; + void Stop() override; void CreateWindows(); void ChangePresetSequence(size_t preset); @@ -50,7 +51,6 @@ namespace OpenRCT2 // When testing title sequences within a normal game extern bool gPreviewingTitleSequenceInGame; -void TitleLoad(); void TitleCreateWindows(); void* TitleGetSequencePlayer(); void TitleSequenceChangePreset(size_t preset); diff --git a/src/openrct2/title/TitleSequence.cpp b/src/openrct2/scenes/title/TitleSequence.cpp similarity index 97% rename from src/openrct2/title/TitleSequence.cpp rename to src/openrct2/scenes/title/TitleSequence.cpp index 21cfa27bed..3b42732c55 100644 --- a/src/openrct2/title/TitleSequence.cpp +++ b/src/openrct2/scenes/title/TitleSequence.cpp @@ -9,22 +9,22 @@ #include "TitleSequence.h" -#include "../common.h" -#include "../core/Collections.hpp" -#include "../core/Console.hpp" -#include "../core/File.h" -#include "../core/FileScanner.h" -#include "../core/FileStream.h" -#include "../core/Guard.hpp" -#include "../core/Memory.hpp" -#include "../core/MemoryStream.h" -#include "../core/Path.hpp" -#include "../core/String.hpp" -#include "../core/StringBuilder.h" -#include "../core/Zip.h" -#include "../scenario/ScenarioRepository.h" -#include "../scenario/ScenarioSources.h" -#include "../util/Util.h" +#include "../../common.h" +#include "../../core/Collections.hpp" +#include "../../core/Console.hpp" +#include "../../core/File.h" +#include "../../core/FileScanner.h" +#include "../../core/FileStream.h" +#include "../../core/Guard.hpp" +#include "../../core/Memory.hpp" +#include "../../core/MemoryStream.h" +#include "../../core/Path.hpp" +#include "../../core/String.hpp" +#include "../../core/StringBuilder.h" +#include "../../core/Zip.h" +#include "../../scenario/ScenarioRepository.h" +#include "../../scenario/ScenarioSources.h" +#include "../../util/Util.h" #include #include diff --git a/src/openrct2/title/TitleSequence.h b/src/openrct2/scenes/title/TitleSequence.h similarity index 97% rename from src/openrct2/title/TitleSequence.h rename to src/openrct2/scenes/title/TitleSequence.h index 12d9dcf555..c786de1ae3 100644 --- a/src/openrct2/title/TitleSequence.h +++ b/src/openrct2/scenes/title/TitleSequence.h @@ -9,8 +9,8 @@ #pragma once -#include "../common.h" -#include "../openrct2/core/IStream.hpp" +#include "../../common.h" +#include "../../core/IStream.hpp" #include "Command/End.h" #include "Command/FollowEntity.h" #include "Command/LoadPark.h" diff --git a/src/openrct2/title/TitleSequenceManager.cpp b/src/openrct2/scenes/title/TitleSequenceManager.cpp similarity index 96% rename from src/openrct2/title/TitleSequenceManager.cpp rename to src/openrct2/scenes/title/TitleSequenceManager.cpp index 968c6ab5c2..ccbd9131e9 100644 --- a/src/openrct2/title/TitleSequenceManager.cpp +++ b/src/openrct2/scenes/title/TitleSequenceManager.cpp @@ -9,17 +9,17 @@ #include "TitleSequenceManager.h" -#include "../Context.h" -#include "../OpenRCT2.h" -#include "../PlatformEnvironment.h" -#include "../core/Collections.hpp" -#include "../core/File.h" -#include "../core/FileScanner.h" -#include "../core/Memory.hpp" -#include "../core/Path.hpp" -#include "../core/String.hpp" -#include "../localisation/Localisation.h" -#include "../platform/Platform.h" +#include "../../Context.h" +#include "../../OpenRCT2.h" +#include "../../PlatformEnvironment.h" +#include "../../core/Collections.hpp" +#include "../../core/File.h" +#include "../../core/FileScanner.h" +#include "../../core/Memory.hpp" +#include "../../core/Path.hpp" +#include "../../core/String.hpp" +#include "../../localisation/Localisation.h" +#include "../../platform/Platform.h" #include "TitleSequence.h" #include diff --git a/src/openrct2/title/TitleSequenceManager.h b/src/openrct2/scenes/title/TitleSequenceManager.h similarity index 96% rename from src/openrct2/title/TitleSequenceManager.h rename to src/openrct2/scenes/title/TitleSequenceManager.h index c619c4bac3..98912f9969 100644 --- a/src/openrct2/title/TitleSequenceManager.h +++ b/src/openrct2/scenes/title/TitleSequenceManager.h @@ -8,8 +8,8 @@ *****************************************************************************/ #pragma once -#include "../common.h" -#include "../core/String.hpp" +#include "../../common.h" +#include "../../core/String.hpp" #include #include diff --git a/src/openrct2/title/TitleSequencePlayer.h b/src/openrct2/scenes/title/TitleSequencePlayer.h similarity index 96% rename from src/openrct2/title/TitleSequencePlayer.h rename to src/openrct2/scenes/title/TitleSequencePlayer.h index 671575c93b..3c04f30501 100644 --- a/src/openrct2/title/TitleSequencePlayer.h +++ b/src/openrct2/scenes/title/TitleSequencePlayer.h @@ -9,7 +9,7 @@ #pragma once -#include "../common.h" +#include "../../common.h" struct ITitleSequencePlayer { diff --git a/src/openrct2/util/Util.cpp b/src/openrct2/util/Util.cpp index 38cca489d9..996337b923 100644 --- a/src/openrct2/util/Util.cpp +++ b/src/openrct2/util/Util.cpp @@ -15,7 +15,7 @@ #include "../interface/Window.h" #include "../localisation/Localisation.h" #include "../platform/Platform.h" -#include "../title/TitleScreen.h" +#include "../scenes/title/TitleScene.h" #include "zlib.h" #include