From 701bbda1645b97c12885816c3e1f08b7acf74146 Mon Sep 17 00:00:00 2001 From: Harry Hopkinson <63599884+Harry-Hopkinson@users.noreply.github.com> Date: Fri, 1 Mar 2024 20:26:20 +0000 Subject: [PATCH] Move gEditorStep to GameState_t (#21492) * Move gEditorStep to GameState_t * Fix compilation on GCC --------- Co-authored-by: Gymnasiast --- src/openrct2-ui/input/Shortcuts.cpp | 16 +++++----- .../interface/ViewportInteraction.cpp | 10 +++--- .../windows/EditorBottomToolbar.cpp | 31 ++++++++++--------- .../windows/EditorObjectSelection.cpp | 17 +++++----- src/openrct2-ui/windows/LoadSave.cpp | 4 +-- src/openrct2-ui/windows/TopToolbar.cpp | 12 ++++--- src/openrct2/Editor.cpp | 26 +++++++--------- src/openrct2/Editor.h | 2 -- src/openrct2/EditorObjectSelectionSession.cpp | 6 ++-- src/openrct2/GameState.h | 3 ++ src/openrct2/interface/Window.cpp | 19 +++++++----- src/openrct2/park/ParkFile.cpp | 2 +- src/openrct2/rct1/S4Importer.cpp | 2 +- src/openrct2/rct2/S6Importer.cpp | 2 +- src/openrct2/ride/Ride.cpp | 2 +- src/openrct2/ride/Vehicle.cpp | 4 +-- 16 files changed, 86 insertions(+), 72 deletions(-) diff --git a/src/openrct2-ui/input/Shortcuts.cpp b/src/openrct2-ui/input/Shortcuts.cpp index d8312c8f12..d314610b67 100644 --- a/src/openrct2-ui/input/Shortcuts.cpp +++ b/src/openrct2-ui/input/Shortcuts.cpp @@ -193,7 +193,7 @@ static void ShortcutAdjustLand() if (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) return; - if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || gEditorStep == EditorStep::LandscapeEditor) + if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || GetGameState().EditorStep == EditorStep::LandscapeEditor) { if (!(gScreenFlags & (SCREEN_FLAGS_TRACK_DESIGNER | SCREEN_FLAGS_TRACK_MANAGER))) { @@ -212,7 +212,7 @@ static void ShortcutAdjustWater() if (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) return; - if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || gEditorStep == EditorStep::LandscapeEditor) + if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || GetGameState().EditorStep == EditorStep::LandscapeEditor) { if (!(gScreenFlags & (SCREEN_FLAGS_TRACK_DESIGNER | SCREEN_FLAGS_TRACK_MANAGER))) { @@ -231,7 +231,7 @@ static void ShortcutBuildScenery() if (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) return; - if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || gEditorStep == EditorStep::LandscapeEditor) + if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || GetGameState().EditorStep == EditorStep::LandscapeEditor) { if (!(gScreenFlags & (SCREEN_FLAGS_TRACK_DESIGNER | SCREEN_FLAGS_TRACK_MANAGER))) { @@ -250,7 +250,7 @@ static void ShortcutBuildPaths() if (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) return; - if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || gEditorStep == EditorStep::LandscapeEditor) + if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || GetGameState().EditorStep == EditorStep::LandscapeEditor) { if (!(gScreenFlags & (SCREEN_FLAGS_TRACK_DESIGNER | SCREEN_FLAGS_TRACK_MANAGER))) { @@ -357,7 +357,7 @@ static void ShortcutShowMap() if (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) return; - if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || gEditorStep == EditorStep::LandscapeEditor) + if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || GetGameState().EditorStep == EditorStep::LandscapeEditor) if (!(gScreenFlags & (SCREEN_FLAGS_TRACK_DESIGNER | SCREEN_FLAGS_TRACK_MANAGER))) ContextOpenWindow(WindowClass::Map); } @@ -413,7 +413,7 @@ static void ShortcutClearScenery() if (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) return; - if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || gEditorStep == EditorStep::LandscapeEditor) + if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || GetGameState().EditorStep == EditorStep::LandscapeEditor) { if (!(gScreenFlags & (SCREEN_FLAGS_TRACK_DESIGNER | SCREEN_FLAGS_TRACK_MANAGER))) { @@ -456,7 +456,7 @@ static void ShortcutLoadGame() static void ShortcutOpenSceneryPicker() { if ((gScreenFlags & (SCREEN_FLAGS_TITLE_DEMO | SCREEN_FLAGS_TRACK_DESIGNER | SCREEN_FLAGS_TRACK_MANAGER)) - || (gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR && gEditorStep != EditorStep::LandscapeEditor)) + || (gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR && GetGameState().EditorStep != EditorStep::LandscapeEditor)) return; WindowBase* window_scenery = WindowFindByClass(WindowClass::Scenery); @@ -760,7 +760,7 @@ void ShortcutManager::RegisterDefaultShortcuts() { WindowCloseAll(); } - else if (gEditorStep == EditorStep::LandscapeEditor) + else if (GetGameState().EditorStep == EditorStep::LandscapeEditor) { WindowCloseTop(); } diff --git a/src/openrct2-ui/interface/ViewportInteraction.cpp b/src/openrct2-ui/interface/ViewportInteraction.cpp index 7645a45d78..77d11d6fd5 100644 --- a/src/openrct2-ui/interface/ViewportInteraction.cpp +++ b/src/openrct2-ui/interface/ViewportInteraction.cpp @@ -52,6 +52,8 @@ #include #include +using namespace OpenRCT2; + static void ViewportInteractionRemoveScenery(const SmallSceneryElement& smallSceneryElement, const CoordsXY& mapCoords); static void ViewportInteractionRemoveFootpath(const PathElement& pathElement, const CoordsXY& mapCoords); static void ViewportInteractionRemovePathAddition(const PathElement& pathElement, const CoordsXY& mapCoords); @@ -72,7 +74,7 @@ InteractionInfo ViewportInteractionGetItemLeft(const ScreenCoordsXY& screenCoord return info; // - if ((gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER) && gEditorStep != EditorStep::RollercoasterDesigner) + if ((gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER) && GetGameState().EditorStep != EditorStep::RollercoasterDesigner) return info; info = GetMapCoordinatesFromPos( @@ -131,7 +133,7 @@ InteractionInfo ViewportInteractionGetItemLeft(const ScreenCoordsXY& screenCoord break; case ViewportInteractionItem::ParkEntrance: { - auto& park = OpenRCT2::GetContext()->GetGameState()->GetPark(); + auto& park = GetContext()->GetGameState()->GetPark(); auto parkName = park.Name.c_str(); auto ft = Formatter(); @@ -258,7 +260,7 @@ InteractionInfo ViewportInteractionGetItemRight(const ScreenCoordsXY& screenCoor return info; // - if ((gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER) && gEditorStep != EditorStep::RollercoasterDesigner) + if ((gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER) && GetGameState().EditorStep != EditorStep::RollercoasterDesigner) return info; constexpr auto flags = static_cast( @@ -434,7 +436,7 @@ InteractionInfo ViewportInteractionGetItemRight(const ScreenCoordsXY& screenCoor auto banner = tileElement->AsBanner()->GetBanner(); if (banner != nullptr) { - auto* bannerEntry = OpenRCT2::ObjectManager::GetObjectEntry(banner->type); + auto* bannerEntry = ObjectManager::GetObjectEntry(banner->type); auto ft = Formatter(); ft.Add(STR_MAP_TOOLTIP_BANNER_STRINGID_STRINGID); diff --git a/src/openrct2-ui/windows/EditorBottomToolbar.cpp b/src/openrct2-ui/windows/EditorBottomToolbar.cpp index 8421a97272..9d52496352 100644 --- a/src/openrct2-ui/windows/EditorBottomToolbar.cpp +++ b/src/openrct2-ui/windows/EditorBottomToolbar.cpp @@ -92,11 +92,13 @@ public: } else { - if (gEditorStep == EditorStep::ObjectSelection) + auto& gameState = GetGameState(); + + if (gameState.EditorStep == EditorStep::ObjectSelection) { HidePreviousStepButton(); } - else if (gEditorStep == EditorStep::RollercoasterDesigner) + else if (gameState.EditorStep == EditorStep::RollercoasterDesigner) { HideNextStepButton(); } @@ -134,17 +136,18 @@ public: void OnMouseUp(WidgetIndex widgetIndex) override { + auto& gameState = GetGameState(); if (widgetIndex == WIDX_PREVIOUS_STEP_BUTTON) { if ((gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER) || (GetNumFreeEntities() == MAX_ENTITIES && !(GetGameState().ParkFlags & PARK_FLAGS_SPRITES_INITIALISED))) { - ((this)->*(_previousButtonMouseUp[EnumValue(gEditorStep)]))(); + ((this)->*(_previousButtonMouseUp[EnumValue(gameState.EditorStep)]))(); } } else if (widgetIndex == WIDX_NEXT_STEP_BUTTON) { - ((this)->*(_nextButtonMouseUp[EnumValue(gEditorStep)]))(); + ((this)->*(_nextButtonMouseUp[EnumValue(gameState.EditorStep)]))(); } } @@ -152,7 +155,7 @@ private: void JumpBackToObjectSelection() const { WindowCloseAll(); - gEditorStep = EditorStep::ObjectSelection; + GetGameState().EditorStep = EditorStep::ObjectSelection; GfxInvalidateScreen(); } @@ -161,7 +164,7 @@ private: WindowCloseAll(); SetAllSceneryItemsInvented(); ScenerySetDefaultPlacementConfiguration(); - gEditorStep = EditorStep::LandscapeEditor; + GetGameState().EditorStep = EditorStep::LandscapeEditor; ContextOpenWindow(WindowClass::Map); GfxInvalidateScreen(); } @@ -170,7 +173,7 @@ private: { WindowCloseAll(); ContextOpenWindow(WindowClass::EditorInventionList); - gEditorStep = EditorStep::InventionsListSetUp; + GetGameState().EditorStep = EditorStep::InventionsListSetUp; GfxInvalidateScreen(); } @@ -178,7 +181,7 @@ private: { WindowCloseAll(); ContextOpenWindow(WindowClass::EditorScenarioOptions); - gEditorStep = EditorStep::OptionsSelection; + GetGameState().EditorStep = EditorStep::OptionsSelection; GfxInvalidateScreen(); } @@ -226,7 +229,7 @@ private: { WindowCloseAll(); ContextOpenWindow(WindowClass::EditorInventionList); - gEditorStep = EditorStep::InventionsListSetUp; + GetGameState().EditorStep = EditorStep::InventionsListSetUp; } else { @@ -240,7 +243,7 @@ private: { WindowCloseAll(); ContextOpenWindow(WindowClass::EditorScenarioOptions); - gEditorStep = EditorStep::OptionsSelection; + GetGameState().EditorStep = EditorStep::OptionsSelection; GfxInvalidateScreen(); } @@ -248,7 +251,7 @@ private: { WindowCloseAll(); ContextOpenWindow(WindowClass::EditorObjectiveOptions); - gEditorStep = EditorStep::ObjectiveSelection; + GetGameState().EditorStep = EditorStep::ObjectiveSelection; GfxInvalidateScreen(); } @@ -312,7 +315,7 @@ private: int16_t textX = (widgets[WIDX_PREVIOUS_IMAGE].left + 30 + widgets[WIDX_PREVIOUS_IMAGE].right) / 2 + windowPos.x; int16_t textY = widgets[WIDX_PREVIOUS_IMAGE].top + 6 + windowPos.y; - StringId stringId = _editorStepNames[EnumValue(gEditorStep) - 1]; + StringId stringId = _editorStepNames[EnumValue(GetGameState().EditorStep) - 1]; if (gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER) stringId = STR_EDITOR_STEP_OBJECT_SELECTION; @@ -350,7 +353,7 @@ private: int16_t textX = (widgets[WIDX_NEXT_IMAGE].left + widgets[WIDX_NEXT_IMAGE].right - 30) / 2 + windowPos.x; int16_t textY = widgets[WIDX_NEXT_IMAGE].top + 6 + windowPos.y; - StringId stringId = _editorStepNames[EnumValue(gEditorStep) + 1]; + StringId stringId = _editorStepNames[EnumValue(GetGameState().EditorStep) + 1]; if (gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER) stringId = STR_EDITOR_STEP_ROLLERCOASTER_DESIGNER; @@ -363,7 +366,7 @@ private: int16_t stateX = (widgets[WIDX_PREVIOUS_IMAGE].right + widgets[WIDX_NEXT_IMAGE].left) / 2 + windowPos.x; int16_t stateY = height - 0x0C + windowPos.y; DrawTextBasic( - dpi, { stateX, stateY }, _editorStepNames[EnumValue(gEditorStep)], {}, + dpi, { stateX, stateY }, _editorStepNames[EnumValue(GetGameState().EditorStep)], {}, { static_cast(NOT_TRANSLUCENT(colours[2]) | COLOUR_FLAG_OUTLINE), TextAlignment::CENTRE }); } diff --git a/src/openrct2-ui/windows/EditorObjectSelection.cpp b/src/openrct2-ui/windows/EditorObjectSelection.cpp index de84c9bb06..8f0cf44c86 100644 --- a/src/openrct2-ui/windows/EditorObjectSelection.cpp +++ b/src/openrct2-ui/windows/EditorObjectSelection.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -41,6 +42,8 @@ #include #include +using namespace OpenRCT2; + enum { FILTER_RCT1 = (1 << 0), @@ -454,7 +457,7 @@ public: if (_loadedObject != nullptr) { auto descriptor = _loadedObject->GetDescriptor(); - auto& objectManager = OpenRCT2::GetContext()->GetObjectManager(); + auto& objectManager = GetContext()->GetObjectManager(); auto entryIndex = objectManager.GetLoadedObjectEntryIndex(descriptor); if (entryIndex != OBJECT_ENTRY_INDEX_NULL) { @@ -604,7 +607,7 @@ public: Invalidate(); const CursorState* state = ContextGetCursorState(); - OpenRCT2::Audio::Play(OpenRCT2::Audio::SoundId::Click1, 0, state->position.x); + Audio::Play(Audio::SoundId::Click1, 0, state->position.x); if (gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER) { @@ -619,9 +622,9 @@ public: _loadedObject = nullptr; } - auto& objRepository = OpenRCT2::GetContext()->GetObjectRepository(); + auto& objRepository = GetContext()->GetObjectRepository(); _loadedObject = objRepository.LoadObject(listItem->repositoryItem); - auto& objManager = OpenRCT2::GetContext()->GetObjectManager(); + auto& objManager = GetContext()->GetObjectManager(); objManager.LoadObject(_loadedObject.get()->GetIdentifier()); // This function calls window_track_list_open @@ -698,7 +701,7 @@ public: if (selectedObject != -1) { auto listItem = &_listItems[selectedObject]; - auto& objRepository = OpenRCT2::GetContext()->GetObjectRepository(); + auto& objRepository = GetContext()->GetObjectRepository(); _loadedObject = objRepository.LoadObject(listItem->repositoryItem); if (_loadedObject != nullptr) { @@ -1544,7 +1547,7 @@ private: SetEveryRideTypeInvented(); SetEveryRideEntryInvented(); - gEditorStep = EditorStep::DesignsManager; + GetGameState().EditorStep = EditorStep::DesignsManager; int32_t entry_index = 0; for (; ObjectEntryGetChunk(ObjectType::Ride, entry_index) == nullptr; entry_index++) @@ -1606,7 +1609,7 @@ static StringId GetRideTypeStringId(const ObjectRepositoryItem* item) */ void EditorLoadSelectedObjects() { - auto& objManager = OpenRCT2::GetContext()->GetObjectManager(); + auto& objManager = GetContext()->GetObjectManager(); int32_t numItems = static_cast(ObjectRepositoryGetItemsCount()); const ObjectRepositoryItem* items = ObjectRepositoryGetItems(); bool showFallbackWarning = false; diff --git a/src/openrct2-ui/windows/LoadSave.cpp b/src/openrct2-ui/windows/LoadSave.cpp index 8d0866ae3b..aac1fd5180 100644 --- a/src/openrct2-ui/windows/LoadSave.cpp +++ b/src/openrct2-ui/windows/LoadSave.cpp @@ -345,7 +345,7 @@ static void Select(const char* path) SetAndSaveConfigPath(gConfigGeneral.LastSaveScenarioDirectory, pathBuffer); int32_t parkFlagsBackup = gameState.ParkFlags; gameState.ParkFlags &= ~PARK_FLAGS_SPRITES_INITIALISED; - gEditorStep = EditorStep::Invalid; + gameState.EditorStep = EditorStep::Invalid; gScenarioFileName = std::string(String::ToStringView(pathBuffer, std::size(pathBuffer))); int32_t success = ScenarioSave(gameState, pathBuffer, gConfigGeneral.SavePluginData ? 3 : 2); gameState.ParkFlags = parkFlagsBackup; @@ -359,7 +359,7 @@ static void Select(const char* path) else { ContextShowError(STR_FILE_DIALOG_TITLE_SAVE_SCENARIO, STR_SCENARIO_SAVE_FAILED, {}); - gEditorStep = EditorStep::ObjectiveSelection; + gameState.EditorStep = EditorStep::ObjectiveSelection; InvokeCallback(MODAL_RESULT_FAIL, pathBuffer); } break; diff --git a/src/openrct2-ui/windows/TopToolbar.cpp b/src/openrct2-ui/windows/TopToolbar.cpp index 93043edaf0..93845d9853 100644 --- a/src/openrct2-ui/windows/TopToolbar.cpp +++ b/src/openrct2-ui/windows/TopToolbar.cpp @@ -3047,20 +3047,22 @@ public: widgets[WIDX_NEWS].type = WindowWidgetType::Empty; widgets[WIDX_NETWORK].type = WindowWidgetType::Empty; - if (gEditorStep != EditorStep::LandscapeEditor) + auto& gameState = GetGameState(); + if (gameState.EditorStep != EditorStep::LandscapeEditor) { widgets[WIDX_LAND].type = WindowWidgetType::Empty; widgets[WIDX_WATER].type = WindowWidgetType::Empty; } - if (gEditorStep != EditorStep::RollercoasterDesigner) + if (gameState.EditorStep != EditorStep::RollercoasterDesigner) { widgets[WIDX_RIDES].type = WindowWidgetType::Empty; widgets[WIDX_CONSTRUCT_RIDE].type = WindowWidgetType::Empty; widgets[WIDX_FASTFORWARD].type = WindowWidgetType::Empty; } - if (gEditorStep != EditorStep::LandscapeEditor && gEditorStep != EditorStep::RollercoasterDesigner) + if (gameState.EditorStep != EditorStep::LandscapeEditor + && gameState.EditorStep != EditorStep::RollercoasterDesigner) { widgets[WIDX_MAP].type = WindowWidgetType::Empty; widgets[WIDX_SCENERY].type = WindowWidgetType::Empty; @@ -3537,7 +3539,7 @@ void TopToolbar::InitMapMenu(Widget& widget) auto i = 0; gDropdownItems[i++].Format = STR_SHORTCUT_SHOW_MAP; gDropdownItems[i++].Format = STR_EXTRA_VIEWPORT; - if ((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && gEditorStep == EditorStep::LandscapeEditor) + if ((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && GetGameState().EditorStep == EditorStep::LandscapeEditor) { gDropdownItems[i++].Format = STR_MAPGEN_WINDOW_TITLE; } @@ -3568,7 +3570,7 @@ void TopToolbar::InitMapMenu(Widget& widget) void TopToolbar::MapMenuDropdown(int16_t dropdownIndex) { int32_t customStartIndex = 3; - if ((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && gEditorStep == EditorStep::LandscapeEditor) + if ((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && GetGameState().EditorStep == EditorStep::LandscapeEditor) { customStartIndex++; } diff --git a/src/openrct2/Editor.cpp b/src/openrct2/Editor.cpp index b4128b21bf..f415059550 100644 --- a/src/openrct2/Editor.cpp +++ b/src/openrct2/Editor.cpp @@ -54,8 +54,6 @@ using namespace OpenRCT2; -EditorStep gEditorStep; - namespace Editor { static std::array, EnumValue(ObjectType::Count)> _editorSelectedObjectFlags; @@ -105,11 +103,11 @@ namespace Editor void Load() { auto& gameState = GetGameState(); - OpenRCT2::Audio::StopAll(); + Audio::StopAll(); ObjectListLoad(); - OpenRCT2::GetContext()->GetGameState()->InitAll(DEFAULT_MAP_SIZE); + GetContext()->GetGameState()->InitAll(DEFAULT_MAP_SIZE); gScreenFlags = SCREEN_FLAGS_SCENARIO_EDITOR; - gEditorStep = EditorStep::ObjectSelection; + gameState.EditorStep = EditorStep::ObjectSelection; gameState.ParkFlags |= PARK_FLAGS_SHOW_REAL_GUEST_NAMES; gameState.ScenarioCategory = SCENARIO_CATEGORY_OTHER; ViewportInitAll(); @@ -149,7 +147,7 @@ namespace Editor ScenarioReset(gameState); gScreenFlags = SCREEN_FLAGS_SCENARIO_EDITOR; - gEditorStep = EditorStep::ObjectiveSelection; + gameState.EditorStep = EditorStep::ObjectiveSelection; gameState.ScenarioCategory = SCENARIO_CATEGORY_OTHER; ViewportInitAll(); OpenEditorWindows(); @@ -163,15 +161,15 @@ namespace Editor */ void LoadTrackDesigner() { - OpenRCT2::Audio::StopAll(); + Audio::StopAll(); gScreenFlags = SCREEN_FLAGS_TRACK_DESIGNER; gScreenAge = 0; ObjectManagerUnloadAllObjects(); ObjectListLoad(); - OpenRCT2::GetContext()->GetGameState()->InitAll(DEFAULT_MAP_SIZE); + GetContext()->GetGameState()->InitAll(DEFAULT_MAP_SIZE); SetAllLandOwned(); - gEditorStep = EditorStep::ObjectSelection; + GetGameState().EditorStep = EditorStep::ObjectSelection; ViewportInitAll(); WindowBase* mainWindow = OpenEditorWindows(); mainWindow->SetLocation(TileCoordsXYZ{ 75, 75, 14 }.ToCoordsXYZ()); @@ -184,15 +182,15 @@ namespace Editor */ void LoadTrackManager() { - OpenRCT2::Audio::StopAll(); + Audio::StopAll(); gScreenFlags = SCREEN_FLAGS_TRACK_MANAGER; gScreenAge = 0; ObjectManagerUnloadAllObjects(); ObjectListLoad(); - OpenRCT2::GetContext()->GetGameState()->InitAll(DEFAULT_MAP_SIZE); + GetContext()->GetGameState()->InitAll(DEFAULT_MAP_SIZE); SetAllLandOwned(); - gEditorStep = EditorStep::ObjectSelection; + GetGameState().EditorStep = EditorStep::ObjectSelection; ViewportInitAll(); WindowBase* mainWindow = OpenEditorWindows(); mainWindow->SetLocation(TileCoordsXYZ{ 75, 75, 14 }.ToCoordsXYZ()); @@ -246,7 +244,7 @@ namespace Editor { ClearMapForEditing(loadedFromSave); - gEditorStep = EditorStep::LandscapeEditor; + GetGameState().EditorStep = EditorStep::LandscapeEditor; gScreenAge = 0; gScreenFlags = SCREEN_FLAGS_SCENARIO_EDITOR; ViewportInitAll(); @@ -367,7 +365,7 @@ namespace Editor return; } - switch (gEditorStep) + switch (GetGameState().EditorStep) { case EditorStep::ObjectSelection: if (WindowFindByClass(WindowClass::EditorObjectSelection) != nullptr) diff --git a/src/openrct2/Editor.h b/src/openrct2/Editor.h index 10289d1930..e10843fdb2 100644 --- a/src/openrct2/Editor.h +++ b/src/openrct2/Editor.h @@ -45,6 +45,4 @@ enum class EditorStep : uint8_t Invalid = 255, // 255 }; -extern EditorStep gEditorStep; - void EditorOpenWindowsForCurrentStep(); diff --git a/src/openrct2/EditorObjectSelectionSession.cpp b/src/openrct2/EditorObjectSelectionSession.cpp index f20f9cb163..5a793d0136 100644 --- a/src/openrct2/EditorObjectSelectionSession.cpp +++ b/src/openrct2/EditorObjectSelectionSession.cpp @@ -12,6 +12,7 @@ #include "Context.h" #include "Editor.h" #include "Game.h" +#include "GameState.h" #include "OpenRCT2.h" #include "drawing/Drawing.h" #include "localisation/Formatter.h" @@ -479,6 +480,7 @@ void ResetSelectedObjectCountAndSize() void FinishObjectSelection() { + auto& gameState = OpenRCT2::GetGameState(); if (gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER) { SetEveryRideTypeInvented(); @@ -491,14 +493,14 @@ void FinishObjectSelection() gLastEntranceStyle = 0; } - gEditorStep = EditorStep::RollercoasterDesigner; + gameState.EditorStep = EditorStep::RollercoasterDesigner; GfxInvalidateScreen(); } else { SetAllSceneryItemsInvented(); ScenerySetDefaultPlacementConfiguration(); - gEditorStep = EditorStep::LandscapeEditor; + gameState.EditorStep = EditorStep::LandscapeEditor; GfxInvalidateScreen(); } } diff --git a/src/openrct2/GameState.h b/src/openrct2/GameState.h index b944d83113..6a6eec7706 100644 --- a/src/openrct2/GameState.h +++ b/src/openrct2/GameState.h @@ -10,6 +10,7 @@ #pragma once #include "Date.h" +#include "Editor.h" #include "Limits.h" #include "interface/ZoomLevel.h" #include "management/Finance.h" @@ -75,6 +76,8 @@ namespace OpenRCT2 random_engine_t ScenarioRand; TileCoordsXY MapSize; + ::EditorStep EditorStep; + SCENARIO_CATEGORY ScenarioCategory; std::string ScenarioName; std::string ScenarioDetails; diff --git a/src/openrct2/interface/Window.cpp b/src/openrct2/interface/Window.cpp index 2a71c91224..c6c764edab 100644 --- a/src/openrct2/interface/Window.cpp +++ b/src/openrct2/interface/Window.cpp @@ -12,6 +12,7 @@ #include "../Context.h" #include "../Editor.h" #include "../Game.h" +#include "../GameState.h" #include "../Input.h" #include "../OpenRCT2.h" #include "../audio/audio.h" @@ -39,6 +40,8 @@ #include #include +using namespace OpenRCT2; + std::list> g_window_list; WindowBase* gWindowAudioExclusive; @@ -152,7 +155,7 @@ void WindowUpdateAll() } }); - auto windowManager = OpenRCT2::GetContext()->GetUiContext()->GetWindowManager(); + auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); windowManager->UpdateMouseWheel(); } @@ -331,7 +334,7 @@ void WindowCloseTop() if (gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) { - if (gEditorStep != EditorStep::LandscapeEditor) + if (GetGameState().EditorStep != EditorStep::LandscapeEditor) return; } @@ -1088,7 +1091,7 @@ void MainWindowZoom(bool zoomIn, bool atCursor) if (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) return; - if (gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR && gEditorStep != EditorStep::LandscapeEditor) + if (gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR && GetGameState().EditorStep != EditorStep::LandscapeEditor) return; if (gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER) @@ -1649,7 +1652,7 @@ void WindowCloseConstructionWindows() */ void WindowUpdateViewportRideMusic() { - OpenRCT2::RideAudio::ClearAllViewportInstances(); + RideAudio::ClearAllViewportInstances(); g_music_tracking_viewport = nullptr; for (auto it = g_window_list.rbegin(); it != g_window_list.rend(); it++) @@ -1663,11 +1666,11 @@ void WindowUpdateViewportRideMusic() gWindowAudioExclusive = w; if (viewport->zoom <= ZoomLevel{ 0 }) - OpenRCT2::Audio::gVolumeAdjustZoom = 0; + Audio::gVolumeAdjustZoom = 0; else if (viewport->zoom == ZoomLevel{ 1 }) - OpenRCT2::Audio::gVolumeAdjustZoom = 30; + Audio::gVolumeAdjustZoom = 30; else - OpenRCT2::Audio::gVolumeAdjustZoom = 60; + Audio::gVolumeAdjustZoom = 60; break; } } @@ -1854,7 +1857,7 @@ void WindowStartTextbox( if (existing_text != STR_NONE) { char tempBuf[TEXT_INPUT_SIZE]{}; - size_t len = OpenRCT2::FormatStringLegacy(tempBuf, TEXT_INPUT_SIZE, existing_text, &existing_args); + size_t len = FormatStringLegacy(tempBuf, TEXT_INPUT_SIZE, existing_text, &existing_args); gTextBoxInput.assign(tempBuf, len); } diff --git a/src/openrct2/park/ParkFile.cpp b/src/openrct2/park/ParkFile.cpp index fc9650c133..799c829b68 100644 --- a/src/openrct2/park/ParkFile.cpp +++ b/src/openrct2/park/ParkFile.cpp @@ -618,7 +618,7 @@ namespace OpenRCT2 } cs.ReadWrite(gameState.SavedViewRotation); cs.ReadWrite(gLastEntranceStyle); - cs.ReadWrite(gEditorStep); + cs.ReadWrite(gameState.EditorStep); }); } diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 6ca90e9a33..eeaf791825 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -326,7 +326,7 @@ namespace RCT1 // Do map initialisation, same kind of stuff done when loading scenario editor auto context = OpenRCT2::GetContext(); context->GetGameState()->InitAll({ mapSize, mapSize }); - gEditorStep = EditorStep::ObjectSelection; + gameState.EditorStep = EditorStep::ObjectSelection; gameState.ParkFlags |= PARK_FLAGS_SHOW_REAL_GUEST_NAMES; gameState.ScenarioCategory = SCENARIO_CATEGORY_OTHER; } diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 8cc31513f8..9093aa1050 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -231,7 +231,7 @@ namespace RCT2 { Initialise(); - gEditorStep = _s6.Info.EditorStep; + gameState.EditorStep = _s6.Info.EditorStep; gameState.ScenarioCategory = static_cast(_s6.Info.Category); // Some scenarios have their scenario details in UTF-8, due to earlier bugs in OpenRCT2. diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 93ff66922e..9b8746528b 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -979,7 +979,7 @@ void Ride::UpdateAll() // Remove all rides if scenario editor if (gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) { - switch (gEditorStep) + switch (GetGameState().EditorStep) { case EditorStep::ObjectSelection: case EditorStep::LandscapeEditor: diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 5f33ccba62..3b57f5b7ac 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -664,7 +664,7 @@ bool Vehicle::SoundCanPlay() const if (gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) return false; - if ((gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER) && gEditorStep != EditorStep::RollercoasterDesigner) + if ((gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER) && GetGameState().EditorStep != EditorStep::RollercoasterDesigner) return false; if (sound1_id == OpenRCT2::Audio::SoundId::Null && sound2_id == OpenRCT2::Audio::SoundId::Null) @@ -1180,7 +1180,7 @@ void VehicleUpdateAll() if (gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) return; - if ((gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER) && gEditorStep != EditorStep::RollercoasterDesigner) + if ((gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER) && GetGameState().EditorStep != EditorStep::RollercoasterDesigner) return; for (auto vehicle : TrainManager::View())