From 49b75e6606236fca9057f4613d9e99ac47880485 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Tue, 23 Apr 2024 20:42:16 +0200 Subject: [PATCH] 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