From db619be0c3a7d91ddd886bc6fb1a57d7ff63025f Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Tue, 23 Dec 2025 11:56:52 +0100 Subject: [PATCH] Rename ViewportInitAll to ContextResetSubsystems (#25690) --- src/openrct2/Context.cpp | 33 +++++++++++++++++-- src/openrct2/Context.h | 3 ++ src/openrct2/Editor.cpp | 11 +++---- src/openrct2/Game.cpp | 2 +- src/openrct2/interface/Viewport.cpp | 28 ---------------- src/openrct2/interface/Viewport.h | 1 - .../scenes/preloader/PreloaderScene.cpp | 2 +- src/openrct2/scenes/title/TitleScene.cpp | 3 +- 8 files changed, 42 insertions(+), 41 deletions(-) diff --git a/src/openrct2/Context.cpp b/src/openrct2/Context.cpp index 7df72e4dfa..8f599f73e8 100644 --- a/src/openrct2/Context.cpp +++ b/src/openrct2/Context.cpp @@ -19,6 +19,7 @@ #include "Game.h" #include "GameState.h" #include "GameStateSnapshots.h" +#include "Input.h" #include "OpenRCT2.h" #include "ParkImporter.h" #include "PlatformEnvironment.h" @@ -42,6 +43,7 @@ #include "drawing/Image.h" #include "drawing/LightFX.h" #include "entity/EntityTweener.h" +#include "entity/PatrolArea.h" #include "interface/Chat.h" #include "interface/StdInOutConsole.h" #include "interface/Viewport.h" @@ -72,6 +74,7 @@ #include "ui/UiContext.h" #include "ui/WindowManager.h" #include "world/MapAnimation.h" +#include "world/MapSelection.h" #include #include @@ -533,9 +536,8 @@ namespace OpenRCT2 Drawing::LightFx::Init(); } - ViewportInitAll(); - ContextInit(); + ResetSubsystems(); if (!gOpenRCT2Headless) { @@ -555,6 +557,28 @@ namespace OpenRCT2 return true; } + /** + * rct2: 0x006E6EAC + */ + void ResetSubsystems() override + { + if (!gOpenRCT2NoGraphics) + { + ColoursInitMaps(); + } + + WindowInitAll(); + + gInputFlags.clearAll(); + InputSetState(InputState::Reset); + gPressedWidget.windowClassification = WindowClass::null; + gPickupPeepImage = ImageId(); + ResetTooltipNotShown(); + gMapSelectFlags.clearAll(); + ClearPatrolAreaToRender(); + TextinputCancel(); + } + private: void InitialiseRepositories() { @@ -1600,6 +1624,11 @@ namespace OpenRCT2 GetWindowManager()->Init(); } + void ContextResetSubsystems() + { + GetContext()->ResetSubsystems(); + } + bool ContextLoadParkFromStream(void* stream) { return GetContext()->LoadParkFromStream(static_cast(stream), ""); diff --git a/src/openrct2/Context.h b/src/openrct2/Context.h index a6ba477f6d..92e9b33eb5 100644 --- a/src/openrct2/Context.h +++ b/src/openrct2/Context.h @@ -119,6 +119,8 @@ namespace OpenRCT2 virtual int32_t RunOpenRCT2(int argc, const char** argv) = 0; virtual bool Initialise() = 0; + virtual void ResetSubsystems() = 0; + virtual void InitialiseDrawingEngine() = 0; virtual void DisposeDrawingEngine() = 0; @@ -151,6 +153,7 @@ namespace OpenRCT2 [[nodiscard]] IContext* GetContext(); void ContextInit(); + void ContextResetSubsystems(); void ContextSetCurrentCursor(CursorID cursor); void ContextUpdateCursorScale(); void ContextHideCursor(); diff --git a/src/openrct2/Editor.cpp b/src/openrct2/Editor.cpp index 7e91e5d5ff..44995fc961 100644 --- a/src/openrct2/Editor.cpp +++ b/src/openrct2/Editor.cpp @@ -28,7 +28,6 @@ #include "entity/Guest.h" #include "entity/PatrolArea.h" #include "entity/Staff.h" -#include "interface/Viewport.h" #include "interface/WindowBase.h" #include "localisation/LocalisationService.h" #include "management/Finance.h" @@ -118,7 +117,7 @@ namespace OpenRCT2::Editor gameState.park.flags |= PARK_FLAGS_SHOW_REAL_GUEST_NAMES; gameState.scenarioOptions.category = Scenario::Category::other; ObjectListLoad(); - ViewportInitAll(); + ContextResetSubsystems(); WindowBase* mainWindow = OpenEditorWindows(); mainWindow->setViewportLocation(TileCoordsXYZ{ 75, 75, 14 }.ToCoordsXYZ()); LoadPalette(); @@ -161,7 +160,7 @@ namespace OpenRCT2::Editor gLegacyScene = LegacyScene::scenarioEditor; gameState.editorStep = EditorStep::OptionsSelection; gameState.scenarioOptions.category = Scenario::Category::other; - ViewportInitAll(); + ContextResetSubsystems(); OpenEditorWindows(); FinaliseMainView(); gScreenAge = 0; @@ -195,7 +194,7 @@ namespace OpenRCT2::Editor gameState.editorStep = EditorStep::ObjectSelection; SetAllLandOwned(); ObjectListLoad(); - ViewportInitAll(); + ContextResetSubsystems(); WindowBase* mainWindow = OpenEditorWindows(); mainWindow->setViewportLocation(TileCoordsXYZ{ 75, 75, 14 }.ToCoordsXYZ()); LoadPalette(); @@ -223,7 +222,7 @@ namespace OpenRCT2::Editor SetAllLandOwned(); gameState.editorStep = EditorStep::ObjectSelection; ObjectListLoad(); - ViewportInitAll(); + ContextResetSubsystems(); WindowBase* mainWindow = OpenEditorWindows(); mainWindow->setViewportLocation(TileCoordsXYZ{ 75, 75, 14 }.ToCoordsXYZ()); LoadPalette(); @@ -263,7 +262,7 @@ namespace OpenRCT2::Editor getGameState().editorStep = EditorStep::LandscapeEditor; gScreenAge = 0; gLegacyScene = LegacyScene::scenarioEditor; - ViewportInitAll(); + ContextResetSubsystems(); OpenEditorWindows(); FinaliseMainView(); diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index fb037c21d6..1314b67094 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -364,7 +364,7 @@ void GameLoadInit() if (!gLoadKeepWindowsOpen) { - ViewportInitAll(); + ContextResetSubsystems(); GameCreateWindows(); } else diff --git a/src/openrct2/interface/Viewport.cpp b/src/openrct2/interface/Viewport.cpp index e2511c36bd..df2a2b42eb 100644 --- a/src/openrct2/interface/Viewport.cpp +++ b/src/openrct2/interface/Viewport.cpp @@ -13,7 +13,6 @@ #include "../Diagnostic.h" #include "../Game.h" #include "../GameState.h" -#include "../Input.h" #include "../OpenRCT2.h" #include "../config/Config.h" #include "../core/Guard.hpp" @@ -24,7 +23,6 @@ #include "../drawing/Rectangle.h" #include "../entity/EntityList.h" #include "../entity/Guest.h" -#include "../entity/PatrolArea.h" #include "../entity/Staff.h" #include "../interface/Cursors.h" #include "../object/LargeSceneryEntry.h" @@ -39,7 +37,6 @@ #include "../ui/WindowManager.h" #include "../world/Climate.h" #include "../world/Map.h" -#include "../world/MapSelection.h" #include "../world/tile_element/LargeSceneryElement.h" #include "../world/tile_element/SmallSceneryElement.h" #include "../world/tile_element/TileElement.h" @@ -90,31 +87,6 @@ namespace OpenRCT2 static void ViewportUpdateSmartFollowVehicle(WindowBase* window); static void ViewportInvalidate(const Viewport* viewport, const ScreenRect& screenRect); - /** - * This is not a viewport function. It is used to setup many variables for - * multiple things. - * rct2: 0x006E6EAC - */ - void ViewportInitAll() - { - if (!gOpenRCT2NoGraphics) - { - ColoursInitMaps(); - } - - WindowInitAll(); - - // ? - gInputFlags.clearAll(); - InputSetState(InputState::Reset); - gPressedWidget.windowClassification = WindowClass::null; - gPickupPeepImage = ImageId(); - ResetTooltipNotShown(); - gMapSelectFlags.clearAll(); - ClearPatrolAreaToRender(); - TextinputCancel(); - } - /** * Converts between 3d point of a sprite to 2d coordinates for centring on that * sprite diff --git a/src/openrct2/interface/Viewport.h b/src/openrct2/interface/Viewport.h index c5fe5f1bf2..4b0fce617f 100644 --- a/src/openrct2/interface/Viewport.h +++ b/src/openrct2/interface/Viewport.h @@ -183,7 +183,6 @@ namespace OpenRCT2 // rct2: 0x014234BC extern Viewport* gMusicTrackingViewport; - void ViewportInitAll(); std::optional centre2dCoordinates(const CoordsXYZ& loc, Viewport* viewport); void ViewportCreate(WindowBase& w, const ScreenCoordsXY& screenCoords, int32_t width, int32_t height, const Focus& focus); void ViewportRemove(Viewport* viewport); diff --git a/src/openrct2/scenes/preloader/PreloaderScene.cpp b/src/openrct2/scenes/preloader/PreloaderScene.cpp index 0a33469f2f..5203d1728a 100644 --- a/src/openrct2/scenes/preloader/PreloaderScene.cpp +++ b/src/openrct2/scenes/preloader/PreloaderScene.cpp @@ -37,7 +37,7 @@ void PreloaderScene::Load() gLegacyScene = LegacyScene::playing; gameStateInitAll(getGameState(), kDefaultMapSize); - ViewportInitAll(); + ContextResetSubsystems(); ContextOpenWindow(WindowClass::mainWindow); WindowSetFlagForAllViewports(VIEWPORT_FLAG_RENDERING_INHIBITED, true); WindowResizeGui(ContextGetWidth(), ContextGetHeight()); diff --git a/src/openrct2/scenes/title/TitleScene.cpp b/src/openrct2/scenes/title/TitleScene.cpp index 239fae6bc0..7eceffa158 100644 --- a/src/openrct2/scenes/title/TitleScene.cpp +++ b/src/openrct2/scenes/title/TitleScene.cpp @@ -20,7 +20,6 @@ #include "../../core/Console.hpp" #include "../../drawing/Text.h" #include "../../interface/Screenshot.h" -#include "../../interface/Viewport.h" #include "../../network/Network.h" #include "../../network/NetworkBase.h" #include "../../scenario/ScenarioRepository.h" @@ -107,7 +106,7 @@ void TitleScene::Load() GetContext().GetNetwork().Close(); #endif gameStateInitAll(getGameState(), kDefaultMapSize); - ViewportInitAll(); + ContextResetSubsystems(); ContextOpenWindow(WindowClass::mainWindow); TitleInitialise();