From 4810a7223207bc1b2e5777b42071c900bbceee9f Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Wed, 27 Mar 2024 21:11:47 +0000 Subject: [PATCH 1/2] Move a number of ui only updates into UiContext tick --- src/openrct2-ui/UiContext.cpp | 22 ++++++++++++++++++++++ src/openrct2/Context.cpp | 6 ------ src/openrct2/Context.h | 1 - src/openrct2/GameState.cpp | 22 ---------------------- src/openrct2/scenes/title/TitleScene.cpp | 3 --- 5 files changed, 22 insertions(+), 32 deletions(-) diff --git a/src/openrct2-ui/UiContext.cpp b/src/openrct2-ui/UiContext.cpp index d5b05ba446..b1f6420f7d 100644 --- a/src/openrct2-ui/UiContext.cpp +++ b/src/openrct2-ui/UiContext.cpp @@ -140,6 +140,28 @@ public: void Tick() override { _inGameConsole.Update(); + + // the flickering frequency is reduced by 4, compared to the original + // it was done due to inability to reproduce original frequency + // and decision that the original one looks too fast + if (gCurrentRealTimeTicks % 4 == 0) + gWindowMapFlashingFlags ^= MapFlashingFlags::SwitchColour; + + // Handle guest map flashing + gWindowMapFlashingFlags &= ~MapFlashingFlags::FlashGuests; + if (gWindowMapFlashingFlags & MapFlashingFlags::GuestListOpen) + gWindowMapFlashingFlags |= MapFlashingFlags::FlashGuests; + gWindowMapFlashingFlags &= ~MapFlashingFlags::GuestListOpen; + + // Handle staff map flashing + gWindowMapFlashingFlags &= ~MapFlashingFlags::FlashStaff; + if (gWindowMapFlashingFlags & MapFlashingFlags::StaffListOpen) + gWindowMapFlashingFlags |= MapFlashingFlags::FlashStaff; + gWindowMapFlashingFlags &= ~MapFlashingFlags::StaffListOpen; + + _windowManager->UpdateMapTooltip(); + + WindowDispatchUpdateAll(); } void Draw(DrawPixelInfo& dpi) override diff --git a/src/openrct2/Context.cpp b/src/openrct2/Context.cpp index ceabc0b150..c69e4906a1 100644 --- a/src/openrct2/Context.cpp +++ b/src/openrct2/Context.cpp @@ -1561,12 +1561,6 @@ WindowBase* ContextShowError(StringId title, StringId message, const Formatter& return windowManager->ShowError(title, message, args); } -void ContextUpdateMapTooltip() -{ - auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); - windowManager->UpdateMapTooltip(); -} - void ContextHandleInput() { auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); diff --git a/src/openrct2/Context.h b/src/openrct2/Context.h index e6c843adbf..380242729a 100644 --- a/src/openrct2/Context.h +++ b/src/openrct2/Context.h @@ -225,7 +225,6 @@ WindowBase* ContextShowError(StringId title, StringId message, const class Forma WindowBase* ContextOpenIntent(Intent* intent); void ContextBroadcastIntent(Intent* intent); void ContextForceCloseWindowByClass(WindowClass wc); -void ContextUpdateMapTooltip(); void ContextHandleInput(); void ContextInputHandleKeyboard(bool isTitle); void ContextQuit(); diff --git a/src/openrct2/GameState.cpp b/src/openrct2/GameState.cpp index 119a483360..16b916e2e3 100644 --- a/src/openrct2/GameState.cpp +++ b/src/openrct2/GameState.cpp @@ -222,26 +222,6 @@ namespace OpenRCT2 if (!gOpenRCT2Headless) { InputSetFlag(INPUT_FLAG_VIEWPORT_SCROLLING, false); - - // the flickering frequency is reduced by 4, compared to the original - // it was done due to inability to reproduce original frequency - // and decision that the original one looks too fast - if (gCurrentRealTimeTicks % 4 == 0) - gWindowMapFlashingFlags ^= MapFlashingFlags::SwitchColour; - - // Handle guest map flashing - gWindowMapFlashingFlags &= ~MapFlashingFlags::FlashGuests; - if (gWindowMapFlashingFlags & MapFlashingFlags::GuestListOpen) - gWindowMapFlashingFlags |= MapFlashingFlags::FlashGuests; - gWindowMapFlashingFlags &= ~MapFlashingFlags::GuestListOpen; - - // Handle staff map flashing - gWindowMapFlashingFlags &= ~MapFlashingFlags::FlashStaff; - if (gWindowMapFlashingFlags & MapFlashingFlags::StaffListOpen) - gWindowMapFlashingFlags |= MapFlashingFlags::FlashStaff; - gWindowMapFlashingFlags &= ~MapFlashingFlags::StaffListOpen; - - ContextUpdateMapTooltip(); } // Always perform autosave check, even when paused @@ -251,8 +231,6 @@ namespace OpenRCT2 ScenarioAutosaveCheck(); } - WindowDispatchUpdateAll(); - if (didRunSingleFrame && GameIsNotPaused() && !(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO)) { PauseToggle(); diff --git a/src/openrct2/scenes/title/TitleScene.cpp b/src/openrct2/scenes/title/TitleScene.cpp index d198c51a31..bc9e06b89a 100644 --- a/src/openrct2/scenes/title/TitleScene.cpp +++ b/src/openrct2/scenes/title/TitleScene.cpp @@ -168,9 +168,6 @@ void TitleScene::Tick() InputSetFlag(INPUT_FLAG_VIEWPORT_SCROLLING, false); - ContextUpdateMapTooltip(); - WindowDispatchUpdateAll(); - ContextHandleInput(); gInUpdateCode = false; From f6c34ddd5933c60f7359b2617c32a596b89d8b3e Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Thu, 28 Mar 2024 08:02:37 +0000 Subject: [PATCH 2/2] Simplify map flashing flags and move into map --- src/openrct2-ui/UiContext.cpp | 18 -------------- src/openrct2-ui/windows/GuestList.cpp | 2 -- src/openrct2-ui/windows/Map.cpp | 36 ++++++++++++++++++++++----- src/openrct2-ui/windows/StaffList.cpp | 1 - src/openrct2/interface/Window.cpp | 1 - src/openrct2/interface/Window.h | 9 ------- 6 files changed, 30 insertions(+), 37 deletions(-) diff --git a/src/openrct2-ui/UiContext.cpp b/src/openrct2-ui/UiContext.cpp index b1f6420f7d..de1e93c9e0 100644 --- a/src/openrct2-ui/UiContext.cpp +++ b/src/openrct2-ui/UiContext.cpp @@ -141,24 +141,6 @@ public: { _inGameConsole.Update(); - // the flickering frequency is reduced by 4, compared to the original - // it was done due to inability to reproduce original frequency - // and decision that the original one looks too fast - if (gCurrentRealTimeTicks % 4 == 0) - gWindowMapFlashingFlags ^= MapFlashingFlags::SwitchColour; - - // Handle guest map flashing - gWindowMapFlashingFlags &= ~MapFlashingFlags::FlashGuests; - if (gWindowMapFlashingFlags & MapFlashingFlags::GuestListOpen) - gWindowMapFlashingFlags |= MapFlashingFlags::FlashGuests; - gWindowMapFlashingFlags &= ~MapFlashingFlags::GuestListOpen; - - // Handle staff map flashing - gWindowMapFlashingFlags &= ~MapFlashingFlags::FlashStaff; - if (gWindowMapFlashingFlags & MapFlashingFlags::StaffListOpen) - gWindowMapFlashingFlags |= MapFlashingFlags::FlashStaff; - gWindowMapFlashingFlags &= ~MapFlashingFlags::StaffListOpen; - _windowManager->UpdateMapTooltip(); WindowDispatchUpdateAll(); diff --git a/src/openrct2-ui/windows/GuestList.cpp b/src/openrct2-ui/windows/GuestList.cpp index 59fdee7677..8770ed1210 100644 --- a/src/openrct2-ui/windows/GuestList.cpp +++ b/src/openrct2-ui/windows/GuestList.cpp @@ -275,8 +275,6 @@ static Widget window_guest_list_widgets[] = { if (_tabAnimationIndex >= (_selectedTab == TabId::Individual ? 24uL : 32uL)) _tabAnimationIndex = 0; InvalidateWidget(WIDX_TAB_1 + static_cast(_selectedTab)); - - gWindowMapFlashingFlags |= MapFlashingFlags::GuestListOpen; } void OnMouseUp(WidgetIndex widgetIndex) override diff --git a/src/openrct2-ui/windows/Map.cpp b/src/openrct2-ui/windows/Map.cpp index 56c22bb2ad..84e9397ca2 100644 --- a/src/openrct2-ui/windows/Map.cpp +++ b/src/openrct2-ui/windows/Map.cpp @@ -184,6 +184,13 @@ static constexpr ScreenCoordsXY MiniMapOffsets[] = { MapColour(PALETTE_INDEX_0), // TILE_ELEMENT_TYPE_BANNER }; + namespace MapFlashingFlags + { + constexpr uint16_t FlashGuests = (1 << 1); + constexpr uint16_t FlashStaff = (1 << 3); + constexpr uint16_t SwitchColour = (1 << 15); // Every couple ticks the colour switches + } // namespace MapFlashingFlags + class MapWindow final : public Window { uint8_t _rotation; @@ -200,6 +207,7 @@ static constexpr ScreenCoordsXY MiniMapOffsets[] = { X, Y, } _resizeDirection{ ResizeDirection::Both }; + uint16_t _flashingFlags = 0; public: MapWindow() @@ -387,6 +395,22 @@ static constexpr ScreenCoordsXY MiniMapOffsets[] = { void OnUpdate() override { + // the flickering frequency is reduced by 4, compared to the original + // it was done due to inability to reproduce original frequency + // and decision that the original one looks too fast + if (gCurrentRealTimeTicks % 4 == 0) + _flashingFlags ^= MapFlashingFlags::SwitchColour; + + // Handle guest map flashing + _flashingFlags &= ~MapFlashingFlags::FlashGuests; + if (WindowFindByClass(WindowClass::GuestList) != nullptr) + _flashingFlags |= MapFlashingFlags::FlashGuests; + + // Handle staff map flashing + _flashingFlags &= ~MapFlashingFlags::FlashStaff; + if (WindowFindByClass(WindowClass::StaffList) != nullptr) + _flashingFlags |= MapFlashingFlags::FlashStaff; + if (GetCurrentRotation() != _rotation) { _rotation = GetCurrentRotation(); @@ -1269,25 +1293,25 @@ static constexpr ScreenCoordsXY MiniMapOffsets[] = { GfxFillRect(dpi, { leftTop, rightBottom }, colour); } - static uint8_t GetGuestFlashColour() + uint8_t GetGuestFlashColour() const { uint8_t colour = DefaultPeepMapColour; - if ((gWindowMapFlashingFlags & MapFlashingFlags::FlashGuests) != 0) + if ((_flashingFlags & MapFlashingFlags::FlashGuests) != 0) { colour = GuestMapColour; - if ((gWindowMapFlashingFlags & MapFlashingFlags::SwitchColour) == 0) + if ((_flashingFlags & MapFlashingFlags::SwitchColour) == 0) colour = GuestMapColourAlternate; } return colour; } - static uint8_t GetStaffFlashColour() + uint8_t GetStaffFlashColour() const { uint8_t colour = DefaultPeepMapColour; - if ((gWindowMapFlashingFlags & MapFlashingFlags::FlashStaff) != 0) + if ((_flashingFlags & MapFlashingFlags::FlashStaff) != 0) { colour = StaffMapColour; - if ((gWindowMapFlashingFlags & MapFlashingFlags::SwitchColour) == 0) + if ((_flashingFlags & MapFlashingFlags::SwitchColour) == 0) colour = StaffMapColourAlternate; } return colour; diff --git a/src/openrct2-ui/windows/StaffList.cpp b/src/openrct2-ui/windows/StaffList.cpp index ef163bffd0..33aa616c1b 100644 --- a/src/openrct2-ui/windows/StaffList.cpp +++ b/src/openrct2-ui/windows/StaffList.cpp @@ -198,7 +198,6 @@ static Widget _staffListWidgets[] = { // Enable highlighting of these staff members in map window if (WindowFindByClass(WindowClass::Map) != nullptr) { - gWindowMapFlashingFlags |= MapFlashingFlags::StaffListOpen; for (auto peep : EntityList()) { EntitySetFlashing(peep, false); diff --git a/src/openrct2/interface/Window.cpp b/src/openrct2/interface/Window.cpp index 52cc76ef1b..b62b44dae3 100644 --- a/src/openrct2/interface/Window.cpp +++ b/src/openrct2/interface/Window.cpp @@ -48,7 +48,6 @@ WindowBase* gWindowAudioExclusive; WindowCloseModifier gLastCloseModifier = { { WindowClass::Null, 0 }, CloseWindowModifier::None }; uint32_t gWindowUpdateTicks; -uint16_t gWindowMapFlashingFlags; colour_t gCurrentWindowColours[4]; // converted from uint16_t values at 0x009A41EC - 0x009A4230 diff --git a/src/openrct2/interface/Window.h b/src/openrct2/interface/Window.h index 1e58689a92..62d494f2a8 100644 --- a/src/openrct2/interface/Window.h +++ b/src/openrct2/interface/Window.h @@ -489,15 +489,6 @@ constexpr int8_t kWindowLimitReserved = 4; // Used to reserve room for the main extern WindowBase* gWindowAudioExclusive; extern uint32_t gWindowUpdateTicks; -namespace MapFlashingFlags -{ - constexpr uint16_t GuestListOpen = (1 << 0); - constexpr uint16_t FlashGuests = (1 << 1); - constexpr uint16_t StaffListOpen = (1 << 2); - constexpr uint16_t FlashStaff = (1 << 3); - constexpr uint16_t SwitchColour = (1 << 15); // Every couple ticks the colour switches -} // namespace MapFlashingFlags -extern uint16_t gWindowMapFlashingFlags; extern colour_t gCurrentWindowColours[4];