From 8503faa289a34a3d1b9068d2882489b97dcc376e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Fri, 25 Apr 2025 17:23:43 +0300 Subject: [PATCH] Set viewport location immediately, fixes rotation using stale position --- src/openrct2/interface/Window.cpp | 116 +++++++++++++------------- src/openrct2/interface/WindowBase.cpp | 6 ++ 2 files changed, 66 insertions(+), 56 deletions(-) diff --git a/src/openrct2/interface/Window.cpp b/src/openrct2/interface/Window.cpp index ffb0ecb29c..aca5cf8891 100644 --- a/src/openrct2/interface/Window.cpp +++ b/src/openrct2/interface/Window.cpp @@ -292,78 +292,82 @@ static constexpr float kWindowScrollLocations[][2] = { void WindowScrollToLocation(WindowBase& w, const CoordsXYZ& coords) { WindowUnfollowSprite(w); - if (w.viewport != nullptr) + + if (w.viewport == nullptr) { - int16_t height = TileElementHeight(coords); - if (coords.z < height - 16) + return; + } + + int16_t height = TileElementHeight(coords); + if (coords.z < height - 16) + { + if (!(w.viewport->flags & VIEWPORT_FLAG_UNDERGROUND_INSIDE)) { - if (!(w.viewport->flags & VIEWPORT_FLAG_UNDERGROUND_INSIDE)) - { - w.viewport->flags |= VIEWPORT_FLAG_UNDERGROUND_INSIDE; - w.Invalidate(); - } + w.viewport->flags |= VIEWPORT_FLAG_UNDERGROUND_INSIDE; + w.Invalidate(); } - else + } + else + { + if (w.viewport->flags & VIEWPORT_FLAG_UNDERGROUND_INSIDE) { - if (w.viewport->flags & VIEWPORT_FLAG_UNDERGROUND_INSIDE) - { - w.viewport->flags &= ~VIEWPORT_FLAG_UNDERGROUND_INSIDE; - w.Invalidate(); - } + w.viewport->flags &= ~VIEWPORT_FLAG_UNDERGROUND_INSIDE; + w.Invalidate(); } + } - auto screenCoords = Translate3DTo2DWithZ(w.viewport->rotation, coords); + auto screenCoords = Translate3DTo2DWithZ(w.viewport->rotation, coords); - int32_t i = 0; - if (gLegacyScene != LegacyScene::titleSequence) + int32_t i = 0; + if (gLegacyScene != LegacyScene::titleSequence) + { + bool found = false; + while (!found) { - bool found = false; - while (!found) - { - auto x2 = w.viewport->pos.x + static_cast(w.viewport->width * kWindowScrollLocations[i][0]); - auto y2 = w.viewport->pos.y + static_cast(w.viewport->height * kWindowScrollLocations[i][1]); + auto x2 = w.viewport->pos.x + static_cast(w.viewport->width * kWindowScrollLocations[i][0]); + auto y2 = w.viewport->pos.y + static_cast(w.viewport->height * kWindowScrollLocations[i][1]); - auto it = WindowGetIterator(&w); - for (; it != g_window_list.end(); it++) + auto it = WindowGetIterator(&w); + for (; it != g_window_list.end(); it++) + { + if ((*it)->flags & WF_DEAD) + continue; + + auto w2 = (*it).get(); + auto x1 = w2->windowPos.x - 10; + auto y1 = w2->windowPos.y - 10; + if (x2 >= x1 && x2 <= w2->width + x1 + 20) { - if ((*it)->flags & WF_DEAD) - continue; - - auto w2 = (*it).get(); - auto x1 = w2->windowPos.x - 10; - auto y1 = w2->windowPos.y - 10; - if (x2 >= x1 && x2 <= w2->width + x1 + 20) + if (y2 >= y1 && y2 <= w2->height + y1 + 20) { - if (y2 >= y1 && y2 <= w2->height + y1 + 20) - { - // window is covering this area, try the next one - i++; - found = false; - break; - } + // window is covering this area, try the next one + i++; + found = false; + break; } } - if (it == g_window_list.end()) - { - found = true; - } - if (i >= static_cast(std::size(kWindowScrollLocations))) - { - i = 0; - found = true; - } + } + if (it == g_window_list.end()) + { + found = true; + } + if (i >= static_cast(std::size(kWindowScrollLocations))) + { + i = 0; + found = true; } } - // rct2: 0x006E7C76 - if (w.viewport_target_sprite.IsNull()) + } + + // rct2: 0x006E7C76 + if (w.viewport_target_sprite.IsNull()) + { + if (!(w.flags & WF_NO_SCROLLING)) { - if (!(w.flags & WF_NO_SCROLLING)) - { - w.savedViewPos = screenCoords - - ScreenCoordsXY{ static_cast(w.viewport->ViewWidth() * kWindowScrollLocations[i][0]), - static_cast(w.viewport->ViewHeight() * kWindowScrollLocations[i][1]) }; - w.flags |= WF_SCROLLING_TO_LOCATION; - } + w.savedViewPos = screenCoords + - ScreenCoordsXY{ static_cast(w.viewport->ViewWidth() * kWindowScrollLocations[i][0]), + static_cast(w.viewport->ViewHeight() * kWindowScrollLocations[i][1]) }; + w.flags |= WF_SCROLLING_TO_LOCATION; } } } diff --git a/src/openrct2/interface/WindowBase.cpp b/src/openrct2/interface/WindowBase.cpp index 87e1439775..cc2bbd4d84 100644 --- a/src/openrct2/interface/WindowBase.cpp +++ b/src/openrct2/interface/WindowBase.cpp @@ -12,6 +12,12 @@ namespace OpenRCT2 { WindowScrollToLocation(*this, coords); flags &= ~WF_SCROLLING_TO_LOCATION; + + // Immediately update the viewport position since we are not scrolling. + if (viewport != nullptr) + { + viewport->viewPos = savedViewPos; + } } void WindowBase::Invalidate()