From 93ccb908b55942cea36403ee8eb5bda49efdcb24 Mon Sep 17 00:00:00 2001 From: Hielke Morsink Date: Thu, 19 Feb 2026 13:57:11 +0100 Subject: [PATCH] Move ownership and details to IntroSceneImpl --- src/openrct2/scenes/intro/IntroScene.cpp | 116 +++++++++++++++++------ src/openrct2/scenes/intro/IntroScene.h | 9 +- 2 files changed, 93 insertions(+), 32 deletions(-) diff --git a/src/openrct2/scenes/intro/IntroScene.cpp b/src/openrct2/scenes/intro/IntroScene.cpp index 731d7dc9fc..b8d66f481c 100644 --- a/src/openrct2/scenes/intro/IntroScene.cpp +++ b/src/openrct2/scenes/intro/IntroScene.cpp @@ -19,27 +19,13 @@ #include "../../drawing/Drawing.h" #include "../../drawing/Rectangle.h" -#include +#include using OpenRCT2::Audio::SoundId; using namespace OpenRCT2::Drawing; namespace OpenRCT2 { - enum class IntroState : uint8_t - { - None, - PublisherBegin, - PublisherScroll, - DeveloperBegin, - DeveloperScroll, - LogoFadeIn, - LogoWait, - LogoFadeOut, - Clear = 254, - Finish = 255, - }; - static constexpr PaletteIndex kBackgroundColourDark = PaletteIndex::pi10; static constexpr PaletteIndex kBackgroundColourLogo = PaletteIndex::primaryRemap2; static constexpr PaletteIndex kBorderColourPublisher = PaletteIndex::pi129; @@ -47,37 +33,98 @@ namespace OpenRCT2 static constexpr ImageIndex kPaletteChrisSawyerLogo = 23217; static constexpr ImageIndex kPaletteRCT2Logo = 23224; - static IntroState _introState; + static std::weak_ptr introSceneImplementation; - // Used mainly for timing but also for Y coordinate and fading. - static int32_t _introStateCounter; + class IntroSceneImpl + { + public: + bool IntroIsPlaying(); + void IntroDraw(Drawing::RenderTarget& rt); + void Load(); + void Stop(); + void Tick(IContext& sceneContext); - static std::shared_ptr _soundChannel = nullptr; - static bool _chainLiftFinished; + private: + void ScreenIntroProcessMouseInput(); + void ScreenIntroProcessKeyboardInput(); + void ScreenIntroSkipPart(); + void ScreenIntroDrawLogo(RenderTarget& rt); + + private: + enum class IntroState : uint8_t + { + None, + PublisherBegin, + PublisherScroll, + DeveloperBegin, + DeveloperScroll, + LogoFadeIn, + LogoWait, + LogoFadeOut, + Clear = 254, + Finish = 255, + }; + + IntroState _introState; + + // Used mainly for timing but also for Y coordinate and fading. + int32_t _introStateCounter; + + std::shared_ptr _soundChannel = nullptr; + bool _chainLiftFinished; + }; bool IntroIsPlaying() + { + if (auto impl = introSceneImplementation.lock()) + { + return impl->IntroIsPlaying(); + } + + return false; + } + + bool IntroSceneImpl::IntroIsPlaying() { return _introState != IntroState::None; } + IntroScene::IntroScene(IContext& context) + : Scene(context) + , _impl(std::make_shared()) + { + introSceneImplementation = _impl; + } + void IntroScene::Load() + { + _impl->Load(); + } + + void IntroSceneImpl::Load() { _introState = IntroState::PublisherBegin; } void IntroScene::Stop() + { + _impl->Stop(); + } + + void IntroSceneImpl::Stop() { _introState = IntroState::None; LoadPalette(); } - static void ScreenIntroProcessMouseInput(); - static void ScreenIntroProcessKeyboardInput(); - static void ScreenIntroSkipPart(); - static void ScreenIntroDrawLogo(RenderTarget& rt); - // rct2: 0x0068E966 void IntroScene::Tick() + { + auto& sceneContext = GetContext(); + _impl->Tick(sceneContext); + } + + void IntroSceneImpl::Tick(IContext& sceneContext) { ScreenIntroProcessMouseInput(); ScreenIntroProcessKeyboardInput(); @@ -195,8 +242,7 @@ namespace OpenRCT2 break; case IntroState::Finish: { - auto& context = GetContext(); - context.SetActiveScene(context.GetTitleScene()); + sceneContext.SetActiveScene(sceneContext.GetTitleScene()); break; } default: @@ -205,6 +251,14 @@ namespace OpenRCT2 } void IntroDraw(RenderTarget& rt) + { + if (auto impl = introSceneImplementation.lock()) + { + impl->IntroDraw(rt); + } + } + + void IntroSceneImpl::IntroDraw(RenderTarget& rt) { int32_t screenWidth = ContextGetWidth(); @@ -278,7 +332,7 @@ namespace OpenRCT2 } } - static void ScreenIntroProcessMouseInput() + void IntroSceneImpl::ScreenIntroProcessMouseInput() { if (ContextGetCursorState()->any & CURSOR_DOWN) { @@ -290,7 +344,7 @@ namespace OpenRCT2 * * rct2: 0x006E3AEC */ - static void ScreenIntroProcessKeyboardInput() + void IntroSceneImpl::ScreenIntroProcessKeyboardInput() { const uint8_t* keys = ContextGetKeysState(); for (int i = 0; i < 256; i++) @@ -303,7 +357,7 @@ namespace OpenRCT2 } } - static void ScreenIntroSkipPart() + void IntroSceneImpl::ScreenIntroSkipPart() { switch (_introState) { @@ -315,7 +369,7 @@ namespace OpenRCT2 } } - static void ScreenIntroDrawLogo(RenderTarget& rt) + void IntroSceneImpl::ScreenIntroDrawLogo(RenderTarget& rt) { int32_t screenWidth = ContextGetWidth(); int32_t imageWidth = 640; diff --git a/src/openrct2/scenes/intro/IntroScene.h b/src/openrct2/scenes/intro/IntroScene.h index a29a5ec0d4..e3cbbfdc9d 100644 --- a/src/openrct2/scenes/intro/IntroScene.h +++ b/src/openrct2/scenes/intro/IntroScene.h @@ -11,7 +11,7 @@ #include "../Scene.h" -#include +#include namespace OpenRCT2::Drawing { @@ -20,14 +20,21 @@ namespace OpenRCT2::Drawing namespace OpenRCT2 { + class IntroSceneImpl; + class IntroScene final : public Scene { public: using Scene::Scene; + IntroScene(IContext& context); + void Load() override; void Tick() override; void Stop() override; + + private: + std::shared_ptr _impl; }; bool IntroIsPlaying();