From 49b75e6606236fca9057f4613d9e99ac47880485 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Tue, 23 Apr 2024 20:42:16 +0200 Subject: [PATCH 1/3] Introduce Scene class and handling 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/Context.cpp | 18 +++++++++++++ src/openrct2/Context.h | 5 ++++ src/openrct2/libopenrct2.vcxproj | 2 ++ src/openrct2/scenes/Scene.cpp | 30 ++++++++++++++++++++++ src/openrct2/scenes/Scene.h | 44 ++++++++++++++++++++++++++++++++ 5 files changed, 99 insertions(+) create mode 100644 src/openrct2/scenes/Scene.cpp create mode 100644 src/openrct2/scenes/Scene.h diff --git a/src/openrct2/Context.cpp b/src/openrct2/Context.cpp index 024f9eb280..e8c78064a8 100644 --- a/src/openrct2/Context.cpp +++ b/src/openrct2/Context.cpp @@ -66,6 +66,7 @@ #include "ride/TrackDesignRepository.h" #include "scenario/Scenario.h" #include "scenario/ScenarioRepository.h" +#include "scenes/Scene.h" #include "scripting/HookEngine.h" #include "scripting/ScriptEngine.h" #include "title/TitleScreen.h" @@ -122,6 +123,9 @@ namespace OpenRCT2 NetworkBase _network; #endif + // Scenes + IScene* _activeScene = nullptr; + // Game states std::unique_ptr _titleScreen; @@ -305,6 +309,20 @@ namespace OpenRCT2 return EXIT_FAILURE; } + virtual IScene* GetActiveScene() override + { + return _activeScene; + } + + void SetActiveScene(IScene* screen) override + { + if (_activeScene != nullptr) + _activeScene->Stop(); + _activeScene = screen; + if (_activeScene) + _activeScene->Load(); + } + void WriteLine(const std::string& s) override { _stdInOutConsole.WriteLine(s); diff --git a/src/openrct2/Context.h b/src/openrct2/Context.h index 42b3b1c96a..f576a6bce2 100644 --- a/src/openrct2/Context.h +++ b/src/openrct2/Context.h @@ -84,6 +84,7 @@ namespace OpenRCT2 struct IPlatformEnvironment; struct IReplayManager; + struct IScene; namespace Audio { @@ -142,6 +143,10 @@ namespace OpenRCT2 #ifndef DISABLE_NETWORK virtual NetworkBase& GetNetwork() abstract; #endif + + virtual IScene* GetActiveScene() abstract; + virtual void SetActiveScene(IScene * screen) abstract; + virtual int32_t RunOpenRCT2(int argc, const char** argv) abstract; virtual bool Initialise() abstract; diff --git a/src/openrct2/libopenrct2.vcxproj b/src/openrct2/libopenrct2.vcxproj index 6634d74614..6e70f650ce 100644 --- a/src/openrct2/libopenrct2.vcxproj +++ b/src/openrct2/libopenrct2.vcxproj @@ -511,6 +511,7 @@ + @@ -999,6 +1000,7 @@ + diff --git a/src/openrct2/scenes/Scene.cpp b/src/openrct2/scenes/Scene.cpp new file mode 100644 index 0000000000..8f2681b29e --- /dev/null +++ b/src/openrct2/scenes/Scene.cpp @@ -0,0 +1,30 @@ +/***************************************************************************** + * Copyright (c) 2014-2024 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 "Scene.h" + +#include "../Context.h" +#include "../GameState.h" + +using namespace OpenRCT2; + +Scene::Scene(IContext& context) + : _context(context) +{ +} + +IContext& Scene::GetContext() +{ + return _context; +} + +GameState_t& Scene::GetGameState() +{ + return OpenRCT2::GetGameState(); +} diff --git a/src/openrct2/scenes/Scene.h b/src/openrct2/scenes/Scene.h new file mode 100644 index 0000000000..71389bd862 --- /dev/null +++ b/src/openrct2/scenes/Scene.h @@ -0,0 +1,44 @@ +/***************************************************************************** + * Copyright (c) 2014-2024 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" + +namespace OpenRCT2 +{ + struct GameState_t; + struct IContext; + + struct IScene + { + public: + virtual ~IScene() = default; + + virtual GameState_t& GetGameState() = 0; + virtual IContext& GetContext() = 0; + + virtual void Load() = 0; + virtual void Update() = 0; + virtual void Stop() = 0; + }; + + class Scene : public IScene + { + public: + Scene(IContext& context); + + GameState_t& GetGameState() override; + IContext& GetContext() override; + + protected: + IContext& _context; + }; + +} // namespace OpenRCT2 From 255e89ec3771593845e690c1fae06de293516281 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Tue, 23 Apr 2024 21:31:05 +0200 Subject: [PATCH 2/3] 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 From 56cbc0eb8a4c63d54ced03320eb65c064803d28d Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Fri, 26 Apr 2024 20:35:16 +0200 Subject: [PATCH 3/3] Refactor intro into IntroScene --- .../engines/opengl/OpenGLDrawingEngine.cpp | 1 - src/openrct2-ui/windows/TitleExit.cpp | 4 - src/openrct2-ui/windows/TitleOptions.cpp | 1 - src/openrct2/Context.cpp | 11 +- src/openrct2/Intro.cpp | 303 ---------------- src/openrct2/Intro.h | 35 -- src/openrct2/audio/Audio.cpp | 4 +- src/openrct2/drawing/X8DrawingEngine.cpp | 6 +- src/openrct2/interface/Screenshot.cpp | 2 - src/openrct2/libopenrct2.vcxproj | 4 +- src/openrct2/paint/Painter.cpp | 5 +- src/openrct2/scenes/game/GameScene.h | 1 - src/openrct2/scenes/intro/IntroScene.cpp | 326 ++++++++++++++++++ src/openrct2/scenes/intro/IntroScene.h | 48 +++ 14 files changed, 389 insertions(+), 362 deletions(-) delete mode 100644 src/openrct2/Intro.cpp delete mode 100644 src/openrct2/Intro.h create mode 100644 src/openrct2/scenes/intro/IntroScene.cpp create mode 100644 src/openrct2/scenes/intro/IntroScene.h diff --git a/src/openrct2-ui/drawing/engines/opengl/OpenGLDrawingEngine.cpp b/src/openrct2-ui/drawing/engines/opengl/OpenGLDrawingEngine.cpp index a06afd3ef2..80abd9dc44 100644 --- a/src/openrct2-ui/drawing/engines/opengl/OpenGLDrawingEngine.cpp +++ b/src/openrct2-ui/drawing/engines/opengl/OpenGLDrawingEngine.cpp @@ -25,7 +25,6 @@ # include # include # include -# include # include # include # include diff --git a/src/openrct2-ui/windows/TitleExit.cpp b/src/openrct2-ui/windows/TitleExit.cpp index 0c56d4ab6e..8f08fe9280 100644 --- a/src/openrct2-ui/windows/TitleExit.cpp +++ b/src/openrct2-ui/windows/TitleExit.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -38,9 +37,6 @@ static Widget _titleExitWidgets[] = { void OnMouseUp(WidgetIndex widgetIndex) override { - if (gIntroState != IntroState::None) - return; - switch (widgetIndex) { case WIDX_EXIT: diff --git a/src/openrct2-ui/windows/TitleOptions.cpp b/src/openrct2-ui/windows/TitleOptions.cpp index 07a359e3e7..cbde63d877 100644 --- a/src/openrct2-ui/windows/TitleOptions.cpp +++ b/src/openrct2-ui/windows/TitleOptions.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include diff --git a/src/openrct2/Context.cpp b/src/openrct2/Context.cpp index fe82237c51..ceabc0b150 100644 --- a/src/openrct2/Context.cpp +++ b/src/openrct2/Context.cpp @@ -19,7 +19,6 @@ #include "GameState.h" #include "GameStateSnapshots.h" #include "Input.h" -#include "Intro.h" #include "OpenRCT2.h" #include "ParkImporter.h" #include "PlatformEnvironment.h" @@ -67,6 +66,7 @@ #include "scenario/Scenario.h" #include "scenario/ScenarioRepository.h" #include "scenes/game/GameScene.h" +#include "scenes/intro/IntroScene.h" #include "scenes/title/TitleScene.h" #include "scenes/title/TitleSequenceManager.h" #include "scripting/HookEngine.h" @@ -124,6 +124,7 @@ namespace OpenRCT2 #endif // Scenes + std::unique_ptr _introScene; std::unique_ptr _titleScene; std::unique_ptr _gameScene; IScene* _activeScene = nullptr; @@ -174,6 +175,7 @@ namespace OpenRCT2 #ifndef DISABLE_NETWORK , _network(*this) #endif + , _introScene(std::make_unique(*this)) , _titleScene(std::make_unique(*this)) , _gameScene(std::make_unique(*this)) , _painter(std::make_unique(uiContext)) @@ -317,8 +319,7 @@ namespace OpenRCT2 IScene* GetIntroScene() override { - // TODO: Implement me. - return nullptr; + return _introScene.get(); } IScene* GetTitleScene() override @@ -917,7 +918,6 @@ namespace OpenRCT2 }); } - gIntroState = IntroState::None; if (gOpenRCT2Headless) { // NONE or OPEN are the only allowed actions for headless mode @@ -937,8 +937,7 @@ namespace OpenRCT2 switch (gOpenRCT2StartupAction) { case StartupAction::Intro: - gIntroState = IntroState::PublisherBegin; - SetActiveScene(GetTitleScene()); + SetActiveScene(GetIntroScene()); break; case StartupAction::Title: SetActiveScene(GetTitleScene()); diff --git a/src/openrct2/Intro.cpp b/src/openrct2/Intro.cpp deleted file mode 100644 index 3fb9106a88..0000000000 --- a/src/openrct2/Intro.cpp +++ /dev/null @@ -1,303 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2014-2024 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 "Intro.h" - -#include "Context.h" -#include "audio/AudioChannel.h" -#include "audio/AudioMixer.h" -#include "audio/audio.h" -#include "drawing/Drawing.h" -#include "sprites.h" - -#include - -using namespace OpenRCT2::Audio; - -static constexpr PaletteIndex kBackgroundColourDark = PALETTE_INDEX_10; -static constexpr PaletteIndex kBackgroundColourLogo = PALETTE_INDEX_245; -static constexpr PaletteIndex kBorderColourPublisher = PALETTE_INDEX_129; - -constexpr int32_t PALETTE_G1_IDX_DEVELOPER = 23217; -constexpr int32_t PALETTE_G1_IDX_LOGO = 23224; - -IntroState gIntroState; - -// Used mainly for timing but also for Y coordinate and fading. -static int32_t _introStateCounter; - -static std::shared_ptr _soundChannel = nullptr; -static bool _chainLiftFinished; - -static void ScreenIntroProcessMouseInput(); -static void ScreenIntroProcessKeyboardInput(); -static void ScreenIntroSkipPart(); -static void ScreenIntroDrawLogo(DrawPixelInfo& dpi); - -// rct2: 0x0068E966 -void IntroUpdate() -{ - ScreenIntroProcessMouseInput(); - ScreenIntroProcessKeyboardInput(); - - switch (gIntroState) - { - case IntroState::Disclaimer1: - case IntroState::Disclaimer2: - // Originally used for the disclaimer text - gIntroState = IntroState::PublisherBegin; - [[fallthrough]]; - case IntroState::PublisherBegin: - LoadPalette(); - - // Set the Y for the Infogrames logo - _introStateCounter = -580; - - // Play the chain lift sound - _soundChannel = CreateAudioChannel(SoundId::LiftBM, true); - _chainLiftFinished = false; - gIntroState = IntroState::PublisherScroll; - break; - case IntroState::PublisherScroll: - // Move the Infogrames logo down - _introStateCounter += 5; - - // Check if logo is off the screen...ish - if (_introStateCounter > ContextGetHeight() - 120) - { - _introStateCounter = -116; - gIntroState = IntroState::DeveloperBegin; - } - - break; - case IntroState::DeveloperBegin: - // Set the Y for the Chris Sawyer logo - _introStateCounter = -116; - - gIntroState = IntroState::DeveloperScroll; - break; - case IntroState::DeveloperScroll: - _introStateCounter += 5; - - // Check if logo is almost scrolled to the bottom - if (!_chainLiftFinished && _introStateCounter >= ContextGetHeight() + 40 - 421) - { - _chainLiftFinished = true; - - // Stop the chain lift sound - if (_soundChannel != nullptr) - { - _soundChannel->Stop(); - _soundChannel = nullptr; - } - - // Play the track friction sound - _soundChannel = CreateAudioChannel(SoundId::TrackFrictionBM, true, kMixerVolumeMax, 0.25f, 0.75); - } - - // Check if logo is off the screen...ish - if (_introStateCounter >= ContextGetHeight() + 40) - { - // Stop the track friction sound - if (_soundChannel != nullptr) - { - _soundChannel->Stop(); - _soundChannel = nullptr; - } - - // Play long peep scream sound - _soundChannel = CreateAudioChannel(SoundId::Scream1); - - gIntroState = IntroState::LogoFadeIn; - _introStateCounter = 0; - } - break; - case IntroState::LogoFadeIn: - // Fade in, add 4 / 256 to fading - _introStateCounter += 0x400; - if (_introStateCounter > 0xFF00) - { - gIntroState = IntroState::LogoWait; - _introStateCounter = 0; - } - break; - case IntroState::LogoWait: - // Wait 80 game ticks - _introStateCounter++; - if (_introStateCounter >= 80) - { - // Set fading to 256 - _introStateCounter = 0xFF00; - - gIntroState = IntroState::LogoFadeOut; - } - break; - case IntroState::LogoFadeOut: - // Fade out, subtract 4 / 256 from fading - _introStateCounter -= 0x400; - if (_introStateCounter < 0) - { - gIntroState = IntroState::Clear; - } - break; - case IntroState::Clear: - // Stop any playing sound - if (_soundChannel != nullptr) - { - _soundChannel->Stop(); - _soundChannel = nullptr; - } - - // Move to next part - gIntroState = IntroState::Finish; - _introStateCounter = 0; - break; - case IntroState::Finish: - gIntroState = IntroState::None; - LoadPalette(); - OpenRCT2::Audio::PlayTitleMusic(); - break; - default: - break; - } -} - -void IntroDraw(DrawPixelInfo& dpi) -{ - int32_t screenWidth = ContextGetWidth(); - - switch (gIntroState) - { - case IntroState::Disclaimer1: - case IntroState::Disclaimer2: - break; - case IntroState::PublisherBegin: - GfxClear(dpi, kBackgroundColourDark); - break; - case IntroState::PublisherScroll: - GfxClear(dpi, kBackgroundColourDark); - - // Draw a white rectangle for the logo background (gives a bit of white margin) - GfxFillRect( - dpi, - { { (screenWidth / 2) - 320 + 50, _introStateCounter + 50 }, - { (screenWidth / 2) - 320 + 50 + 540, _introStateCounter + 50 + 425 } }, - kBorderColourPublisher); - - // Draw Infogrames logo - GfxDrawSprite(dpi, ImageId(SPR_INTRO_INFOGRAMES_00), { (screenWidth / 2) - 320 + 69, _introStateCounter + 69 }); - GfxDrawSprite(dpi, ImageId(SPR_INTRO_INFOGRAMES_10), { (screenWidth / 2) - 320 + 319, _introStateCounter + 69 }); - GfxDrawSprite(dpi, ImageId(SPR_INTRO_INFOGRAMES_01), { (screenWidth / 2) - 320 + 69, _introStateCounter + 319 }); - GfxDrawSprite(dpi, ImageId(SPR_INTRO_INFOGRAMES_11), { (screenWidth / 2) - 320 + 319, _introStateCounter + 319 }); - break; - case IntroState::DeveloperBegin: - GfxClear(dpi, kBackgroundColourDark); - GfxTransposePalette(PALETTE_G1_IDX_DEVELOPER, 255); - break; - case IntroState::DeveloperScroll: - GfxClear(dpi, kBackgroundColourDark); - - // Draw Chris Sawyer logo - GfxDrawSprite(dpi, ImageId(SPR_INTRO_CHRIS_SAWYER_00), { (screenWidth / 2) - 320 + 70, _introStateCounter }); - GfxDrawSprite(dpi, ImageId(SPR_INTRO_CHRIS_SAWYER_10), { (screenWidth / 2) - 320 + 320, _introStateCounter }); - break; - case IntroState::LogoFadeIn: - if (_introStateCounter <= 0xFF00) - { - GfxTransposePalette(PALETTE_G1_IDX_LOGO, (_introStateCounter >> 8) & 0xFF); - } - else - { - GfxTransposePalette(PALETTE_G1_IDX_LOGO, 255); - } - ScreenIntroDrawLogo(dpi); - break; - case IntroState::LogoWait: - ScreenIntroDrawLogo(dpi); - break; - case IntroState::LogoFadeOut: - if (_introStateCounter >= 0) - { - GfxTransposePalette(PALETTE_G1_IDX_LOGO, (_introStateCounter >> 8) & 0xFF); - } - else - { - GfxTransposePalette(PALETTE_G1_IDX_LOGO, 0); - } - ScreenIntroDrawLogo(dpi); - break; - case IntroState::Clear: - GfxClear(dpi, kBackgroundColourDark); - break; - default: - break; - } -} - -static void ScreenIntroProcessMouseInput() -{ - if (ContextGetCursorState()->any == CURSOR_PRESSED) - { - ScreenIntroSkipPart(); - } -} - -/** - * - * rct2: 0x006E3AEC - */ -static void ScreenIntroProcessKeyboardInput() -{ - const uint8_t* keys = ContextGetKeysState(); - for (int i = 0; i < 256; i++) - { - if (keys[i] != 0) - { - ScreenIntroSkipPart(); - break; - } - } -} - -static void ScreenIntroSkipPart() -{ - switch (gIntroState) - { - case IntroState::None: - break; - case IntroState::Disclaimer2: - gIntroState = IntroState::PublisherBegin; - break; - default: - gIntroState = IntroState::Clear; - break; - } -} - -static void ScreenIntroDrawLogo(DrawPixelInfo& dpi) -{ - int32_t screenWidth = ContextGetWidth(); - int32_t imageWidth = 640; - int32_t imageX = (screenWidth - imageWidth) / 2; - - DrawingEngineInvalidateImage(SPR_INTRO_LOGO_00); - DrawingEngineInvalidateImage(SPR_INTRO_LOGO_10); - DrawingEngineInvalidateImage(SPR_INTRO_LOGO_20); - DrawingEngineInvalidateImage(SPR_INTRO_LOGO_01); - DrawingEngineInvalidateImage(SPR_INTRO_LOGO_11); - DrawingEngineInvalidateImage(SPR_INTRO_LOGO_21); - - GfxClear(dpi, kBackgroundColourLogo); - GfxDrawSprite(dpi, ImageId(SPR_INTRO_LOGO_00), { imageX + 0, 0 }); - GfxDrawSprite(dpi, ImageId(SPR_INTRO_LOGO_10), { imageX + 220, 0 }); - GfxDrawSprite(dpi, ImageId(SPR_INTRO_LOGO_20), { imageX + 440, 0 }); - GfxDrawSprite(dpi, ImageId(SPR_INTRO_LOGO_01), { imageX + 0, 240 }); - GfxDrawSprite(dpi, ImageId(SPR_INTRO_LOGO_11), { imageX + 220, 240 }); - GfxDrawSprite(dpi, ImageId(SPR_INTRO_LOGO_21), { imageX + 440, 240 }); -} diff --git a/src/openrct2/Intro.h b/src/openrct2/Intro.h deleted file mode 100644 index 3fb8f90d21..0000000000 --- a/src/openrct2/Intro.h +++ /dev/null @@ -1,35 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2014-2024 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" - -struct DrawPixelInfo; - -enum class IntroState : uint8_t -{ - None, - PublisherBegin, - PublisherScroll, - DeveloperBegin, - DeveloperScroll, - LogoFadeIn, - LogoWait, - LogoFadeOut, - Disclaimer1, - Disclaimer2, - Clear = 254, - Finish = 255, -}; - -extern IntroState gIntroState; - -void IntroUpdate(); -void IntroDraw(DrawPixelInfo& dpi); diff --git a/src/openrct2/audio/Audio.cpp b/src/openrct2/audio/Audio.cpp index fbac597e0c..753c469532 100644 --- a/src/openrct2/audio/Audio.cpp +++ b/src/openrct2/audio/Audio.cpp @@ -10,7 +10,6 @@ #include "audio.h" #include "../Context.h" -#include "../Intro.h" #include "../OpenRCT2.h" #include "../PlatformEnvironment.h" #include "../config/Config.h" @@ -26,6 +25,7 @@ #include "../object/ObjectManager.h" #include "../ride/Ride.h" #include "../ride/RideAudio.h" +#include "../scenes/intro/IntroScene.h" #include "../ui/UiContext.h" #include "../util/Util.h" #include "../world/Climate.h" @@ -294,7 +294,7 @@ namespace OpenRCT2::Audio void PlayTitleMusic() { - if (gGameSoundsOff || !(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) || gIntroState != IntroState::None) + if (gGameSoundsOff || !(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) || IntroIsPlaying()) { StopTitleMusic(); return; diff --git a/src/openrct2/drawing/X8DrawingEngine.cpp b/src/openrct2/drawing/X8DrawingEngine.cpp index 5af091d8ab..ca0ef40a26 100644 --- a/src/openrct2/drawing/X8DrawingEngine.cpp +++ b/src/openrct2/drawing/X8DrawingEngine.cpp @@ -10,12 +10,12 @@ #include "X8DrawingEngine.h" #include "../Context.h" -#include "../Intro.h" #include "../config/Config.h" #include "../core/Numerics.hpp" #include "../interface/Screenshot.h" #include "../interface/Viewport.h" #include "../interface/Window.h" +#include "../scenes/intro/IntroScene.h" #include "../ui/UiContext.h" #include "../util/Util.h" #include "Drawing.h" @@ -184,7 +184,7 @@ void X8DrawingEngine::Invalidate(int32_t left, int32_t top, int32_t right, int32 void X8DrawingEngine::BeginDraw() { - if (gIntroState == IntroState::None) + if (!IntroIsPlaying()) { // HACK we need to re-configure the bits if light fx has been enabled / disabled if (_lastLightFXenabled != (gConfigGeneral.EnableLightFx != 0)) @@ -837,4 +837,4 @@ void X8DrawingContext::DrawTTFBitmap( else DrawTTFBitmapInternal(dpi, fgColor, surface, x, y, 0); #endif // NO_TTF -} \ No newline at end of file +} diff --git a/src/openrct2/interface/Screenshot.cpp b/src/openrct2/interface/Screenshot.cpp index 36c5e5025d..b3214d9161 100644 --- a/src/openrct2/interface/Screenshot.cpp +++ b/src/openrct2/interface/Screenshot.cpp @@ -12,7 +12,6 @@ #include "../Context.h" #include "../Game.h" #include "../GameState.h" -#include "../Intro.h" #include "../OpenRCT2.h" #include "../PlatformEnvironment.h" #include "../actions/CheatSetAction.h" @@ -490,7 +489,6 @@ int32_t CommandLineForScreenshot(const char** argv, int32_t argc, ScreenshotOpti throw std::runtime_error("Failed to load park."); } - gIntroState = IntroState::None; gScreenFlags = SCREEN_FLAGS_PLAYING; Viewport viewport{}; diff --git a/src/openrct2/libopenrct2.vcxproj b/src/openrct2/libopenrct2.vcxproj index ca3b0e6ce1..b3184b2c57 100644 --- a/src/openrct2/libopenrct2.vcxproj +++ b/src/openrct2/libopenrct2.vcxproj @@ -275,7 +275,6 @@ - @@ -512,6 +511,7 @@ + @@ -793,7 +793,6 @@ - @@ -1003,6 +1002,7 @@ + diff --git a/src/openrct2/paint/Painter.cpp b/src/openrct2/paint/Painter.cpp index e8d5b210c3..d24813d1af 100644 --- a/src/openrct2/paint/Painter.cpp +++ b/src/openrct2/paint/Painter.cpp @@ -11,7 +11,6 @@ #include "../Game.h" #include "../GameState.h" -#include "../Intro.h" #include "../OpenRCT2.h" #include "../ReplayManager.h" #include "../config/Config.h" @@ -24,6 +23,7 @@ #include "../localisation/Language.h" #include "../paint/Paint.h" #include "../profiling/Profiling.h" +#include "../scenes/intro/IntroScene.h" #include "../scenes/title/TitleScene.h" #include "../ui/UiContext.h" #include "../world/TileInspector.h" @@ -43,7 +43,8 @@ void Painter::Paint(IDrawingEngine& de) PROFILED_FUNCTION(); auto dpi = de.GetDrawingPixelInfo(); - if (gIntroState != IntroState::None) + + if (IntroIsPlaying()) { IntroDraw(*dpi); } diff --git a/src/openrct2/scenes/game/GameScene.h b/src/openrct2/scenes/game/GameScene.h index 7cf4bcd35c..c0b39ca89c 100644 --- a/src/openrct2/scenes/game/GameScene.h +++ b/src/openrct2/scenes/game/GameScene.h @@ -10,7 +10,6 @@ #pragma once #include "../../common.h" -#include "../../drawing/Drawing.h" #include "../Scene.h" namespace OpenRCT2 diff --git a/src/openrct2/scenes/intro/IntroScene.cpp b/src/openrct2/scenes/intro/IntroScene.cpp new file mode 100644 index 0000000000..82d0a1cb40 --- /dev/null +++ b/src/openrct2/scenes/intro/IntroScene.cpp @@ -0,0 +1,326 @@ +/***************************************************************************** + * Copyright (c) 2014-2024 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 "IntroScene.h" + +#include "../../Context.h" +#include "../../audio/AudioChannel.h" +#include "../../audio/AudioMixer.h" +#include "../../audio/audio.h" +#include "../../drawing/Drawing.h" +#include "../../sprites.h" + +#include + +using OpenRCT2::Audio::SoundId; + +namespace OpenRCT2 +{ + static constexpr PaletteIndex kBackgroundColourDark = PALETTE_INDEX_10; + static constexpr PaletteIndex kBackgroundColourLogo = PALETTE_INDEX_245; + static constexpr PaletteIndex kBorderColourPublisher = PALETTE_INDEX_129; + + constexpr int32_t PALETTE_G1_IDX_DEVELOPER = 23217; + constexpr int32_t PALETTE_G1_IDX_LOGO = 23224; + + static IntroState _introState; + + // Used mainly for timing but also for Y coordinate and fading. + static int32_t _introStateCounter; + + static std::shared_ptr _soundChannel = nullptr; + static bool _chainLiftFinished; + + bool IntroIsPlaying() + { + return _introState != IntroState::None; + } + + void IntroScene::Load() + { + _introState = IntroState::PublisherBegin; + } + + void IntroScene::Stop() + { + _introState = IntroState::None; + LoadPalette(); + } + + static void ScreenIntroProcessMouseInput(); + static void ScreenIntroProcessKeyboardInput(); + static void ScreenIntroSkipPart(); + static void ScreenIntroDrawLogo(DrawPixelInfo& dpi); + + // rct2: 0x0068E966 + void IntroScene::Tick() + { + ScreenIntroProcessMouseInput(); + ScreenIntroProcessKeyboardInput(); + + switch (_introState) + { + case IntroState::Disclaimer1: + case IntroState::Disclaimer2: + // Originally used for the disclaimer text + _introState = IntroState::PublisherBegin; + [[fallthrough]]; + case IntroState::PublisherBegin: + LoadPalette(); + + // Set the Y for the Infogrames logo + _introStateCounter = -580; + + // Play the chain lift sound + _soundChannel = Audio::CreateAudioChannel(SoundId::LiftBM, true); + _chainLiftFinished = false; + _introState = IntroState::PublisherScroll; + break; + case IntroState::PublisherScroll: + // Move the Infogrames logo down + _introStateCounter += 5; + + // Check if logo is off the screen...ish + if (_introStateCounter > ContextGetHeight() - 120) + { + _introStateCounter = -116; + _introState = IntroState::DeveloperBegin; + } + + break; + case IntroState::DeveloperBegin: + // Set the Y for the Chris Sawyer logo + _introStateCounter = -116; + + _introState = IntroState::DeveloperScroll; + break; + case IntroState::DeveloperScroll: + _introStateCounter += 5; + + // Check if logo is almost scrolled to the bottom + if (!_chainLiftFinished && _introStateCounter >= ContextGetHeight() + 40 - 421) + { + _chainLiftFinished = true; + + // Stop the chain lift sound + if (_soundChannel != nullptr) + { + _soundChannel->Stop(); + _soundChannel = nullptr; + } + + // Play the track friction sound + _soundChannel = Audio::CreateAudioChannel( + SoundId::TrackFrictionBM, true, Audio::kMixerVolumeMax, 0.25f, 0.75); + } + + // Check if logo is off the screen...ish + if (_introStateCounter >= ContextGetHeight() + 40) + { + // Stop the track friction sound + if (_soundChannel != nullptr) + { + _soundChannel->Stop(); + _soundChannel = nullptr; + } + + // Play long peep scream sound + _soundChannel = Audio::CreateAudioChannel(SoundId::Scream1); + + _introState = IntroState::LogoFadeIn; + _introStateCounter = 0; + } + break; + case IntroState::LogoFadeIn: + // Fade in, add 4 / 256 to fading + _introStateCounter += 0x400; + if (_introStateCounter > 0xFF00) + { + _introState = IntroState::LogoWait; + _introStateCounter = 0; + } + break; + case IntroState::LogoWait: + // Wait 80 game ticks + _introStateCounter++; + if (_introStateCounter >= 80) + { + // Set fading to 256 + _introStateCounter = 0xFF00; + + _introState = IntroState::LogoFadeOut; + } + break; + case IntroState::LogoFadeOut: + // Fade out, subtract 4 / 256 from fading + _introStateCounter -= 0x400; + if (_introStateCounter < 0) + { + _introState = IntroState::Clear; + } + break; + case IntroState::Clear: + // Stop any playing sound + if (_soundChannel != nullptr) + { + _soundChannel->Stop(); + _soundChannel = nullptr; + } + + // Move to next part + _introState = IntroState::Finish; + _introStateCounter = 0; + break; + case IntroState::Finish: + { + auto& context = GetContext(); + context.SetActiveScene(context.GetTitleScene()); + } + default: + break; + } + } + + void IntroDraw(DrawPixelInfo& dpi) + { + int32_t screenWidth = ContextGetWidth(); + + switch (_introState) + { + case IntroState::Disclaimer1: + case IntroState::Disclaimer2: + break; + case IntroState::PublisherBegin: + GfxClear(dpi, kBackgroundColourDark); + break; + case IntroState::PublisherScroll: + GfxClear(dpi, kBackgroundColourDark); + + // Draw a white rectangle for the logo background (gives a bit of white margin) + GfxFillRect( + dpi, + { { (screenWidth / 2) - 320 + 50, _introStateCounter + 50 }, + { (screenWidth / 2) - 320 + 50 + 540, _introStateCounter + 50 + 425 } }, + kBorderColourPublisher); + + // Draw Infogrames logo + GfxDrawSprite(dpi, ImageId(SPR_INTRO_INFOGRAMES_00), { (screenWidth / 2) - 320 + 69, _introStateCounter + 69 }); + GfxDrawSprite( + dpi, ImageId(SPR_INTRO_INFOGRAMES_10), { (screenWidth / 2) - 320 + 319, _introStateCounter + 69 }); + GfxDrawSprite( + dpi, ImageId(SPR_INTRO_INFOGRAMES_01), { (screenWidth / 2) - 320 + 69, _introStateCounter + 319 }); + GfxDrawSprite( + dpi, ImageId(SPR_INTRO_INFOGRAMES_11), { (screenWidth / 2) - 320 + 319, _introStateCounter + 319 }); + break; + case IntroState::DeveloperBegin: + GfxClear(dpi, kBackgroundColourDark); + GfxTransposePalette(PALETTE_G1_IDX_DEVELOPER, 255); + break; + case IntroState::DeveloperScroll: + GfxClear(dpi, kBackgroundColourDark); + + // Draw Chris Sawyer logo + GfxDrawSprite(dpi, ImageId(SPR_INTRO_CHRIS_SAWYER_00), { (screenWidth / 2) - 320 + 70, _introStateCounter }); + GfxDrawSprite(dpi, ImageId(SPR_INTRO_CHRIS_SAWYER_10), { (screenWidth / 2) - 320 + 320, _introStateCounter }); + break; + case IntroState::LogoFadeIn: + if (_introStateCounter <= 0xFF00) + { + GfxTransposePalette(PALETTE_G1_IDX_LOGO, (_introStateCounter >> 8) & 0xFF); + } + else + { + GfxTransposePalette(PALETTE_G1_IDX_LOGO, 255); + } + ScreenIntroDrawLogo(dpi); + break; + case IntroState::LogoWait: + ScreenIntroDrawLogo(dpi); + break; + case IntroState::LogoFadeOut: + if (_introStateCounter >= 0) + { + GfxTransposePalette(PALETTE_G1_IDX_LOGO, (_introStateCounter >> 8) & 0xFF); + } + else + { + GfxTransposePalette(PALETTE_G1_IDX_LOGO, 0); + } + ScreenIntroDrawLogo(dpi); + break; + case IntroState::Clear: + GfxClear(dpi, kBackgroundColourDark); + break; + default: + break; + } + } + + static void ScreenIntroProcessMouseInput() + { + if (ContextGetCursorState()->any == CURSOR_PRESSED) + { + ScreenIntroSkipPart(); + } + } + + /** + * + * rct2: 0x006E3AEC + */ + static void ScreenIntroProcessKeyboardInput() + { + const uint8_t* keys = ContextGetKeysState(); + for (int i = 0; i < 256; i++) + { + if (keys[i] != 0) + { + ScreenIntroSkipPart(); + break; + } + } + } + + static void ScreenIntroSkipPart() + { + switch (_introState) + { + case IntroState::None: + break; + case IntroState::Disclaimer2: + _introState = IntroState::PublisherBegin; + break; + default: + _introState = IntroState::Clear; + break; + } + } + + static void ScreenIntroDrawLogo(DrawPixelInfo& dpi) + { + int32_t screenWidth = ContextGetWidth(); + int32_t imageWidth = 640; + int32_t imageX = (screenWidth - imageWidth) / 2; + + DrawingEngineInvalidateImage(SPR_INTRO_LOGO_00); + DrawingEngineInvalidateImage(SPR_INTRO_LOGO_10); + DrawingEngineInvalidateImage(SPR_INTRO_LOGO_20); + DrawingEngineInvalidateImage(SPR_INTRO_LOGO_01); + DrawingEngineInvalidateImage(SPR_INTRO_LOGO_11); + DrawingEngineInvalidateImage(SPR_INTRO_LOGO_21); + + GfxClear(dpi, kBackgroundColourLogo); + GfxDrawSprite(dpi, ImageId(SPR_INTRO_LOGO_00), { imageX + 0, 0 }); + GfxDrawSprite(dpi, ImageId(SPR_INTRO_LOGO_10), { imageX + 220, 0 }); + GfxDrawSprite(dpi, ImageId(SPR_INTRO_LOGO_20), { imageX + 440, 0 }); + GfxDrawSprite(dpi, ImageId(SPR_INTRO_LOGO_01), { imageX + 0, 240 }); + GfxDrawSprite(dpi, ImageId(SPR_INTRO_LOGO_11), { imageX + 220, 240 }); + GfxDrawSprite(dpi, ImageId(SPR_INTRO_LOGO_21), { imageX + 440, 240 }); + } +} // namespace OpenRCT2 diff --git a/src/openrct2/scenes/intro/IntroScene.h b/src/openrct2/scenes/intro/IntroScene.h new file mode 100644 index 0000000000..df6f3da349 --- /dev/null +++ b/src/openrct2/scenes/intro/IntroScene.h @@ -0,0 +1,48 @@ +/***************************************************************************** + * Copyright (c) 2014-2024 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 "../Scene.h" + +struct DrawPixelInfo; + +namespace OpenRCT2 +{ + enum class IntroState : uint8_t + { + None, + PublisherBegin, + PublisherScroll, + DeveloperBegin, + DeveloperScroll, + LogoFadeIn, + LogoWait, + LogoFadeOut, + Disclaimer1, + Disclaimer2, + Clear = 254, + Finish = 255, + }; + + class IntroScene final : public Scene + { + public: + using Scene::Scene; + + void Load() override; + void Tick() override; + void Stop() override; + }; + + bool IntroIsPlaying(); + void IntroUpdate(); + void IntroDraw(DrawPixelInfo& dpi); +} // namespace OpenRCT2