From 5e51c89d9ff414307a178b1295c9741ed792cb1f Mon Sep 17 00:00:00 2001 From: mix Date: Sun, 18 May 2025 03:17:36 +0100 Subject: [PATCH] Fix extra viewport invalidating every frame --- src/openrct2-ui/windows/Viewport.cpp | 22 ++++------------------ src/openrct2/interface/Viewport.cpp | 2 +- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/src/openrct2-ui/windows/Viewport.cpp b/src/openrct2-ui/windows/Viewport.cpp index 1beea92aba..ecf3939d52 100644 --- a/src/openrct2-ui/windows/Viewport.cpp +++ b/src/openrct2-ui/windows/Viewport.cpp @@ -98,7 +98,7 @@ namespace OpenRCT2::Ui::Windows viewport->flags |= VIEWPORT_FLAG_SOUND_ON | VIEWPORT_FLAG_INDEPEDENT_ROTATION; - WindowSetResize(*this, { WW, WH }, { WW, WH }); + WindowSetResize(*this, { WW, WH }, { (ContextGetWidth() * 4) / 5, (ContextGetHeight() * 4) / 5 }); } void OnUpdate() override @@ -107,14 +107,11 @@ namespace OpenRCT2::Ui::Windows if (mainWindow == nullptr) return; - if (viewport != nullptr && viewport->flags != mainWindow->viewport->flags) + if (viewport != nullptr && viewport->flags != (mainWindow->viewport->flags | VIEWPORT_FLAG_INDEPEDENT_ROTATION)) { viewport->flags = mainWindow->viewport->flags | VIEWPORT_FLAG_INDEPEDENT_ROTATION; - Invalidate(); + InvalidateWidget(WIDX_VIEWPORT); } - - // Not sure how to invalidate part of the viewport that has changed, this will have to do for now - // widget_invalidate(*this, WIDX_VIEWPORT); } void OnMouseUp(WidgetIndex widgetIndex) override @@ -220,17 +217,6 @@ namespace OpenRCT2::Ui::Windows WindowBase* ViewportOpen() { - int32_t screenWidth = ContextGetWidth(); - int32_t screenHeight = ContextGetHeight(); - int32_t width = (screenWidth / 2); - int32_t height = (screenHeight / 2); - - auto* windowMgr = GetWindowManager(); - auto* w = windowMgr->Create( - WindowClass::Viewport, std::max(WW, width), std::max(WH, height), WF_RESIZABLE); - - if (w != nullptr) - return w; - return nullptr; + return GetWindowManager()->Create(WindowClass::Viewport, 300, 300, WF_RESIZABLE); } } // namespace OpenRCT2::Ui::Windows diff --git a/src/openrct2/interface/Viewport.cpp b/src/openrct2/interface/Viewport.cpp index 8488c9a6c0..fe097a33b7 100644 --- a/src/openrct2/interface/Viewport.cpp +++ b/src/openrct2/interface/Viewport.cpp @@ -589,7 +589,7 @@ namespace OpenRCT2 // rct2: 0x006E7A15 static void ViewportSetUndergroundFlag(int32_t underground, WindowBase* window, Viewport* viewport) { - if (window->classification != WindowClass::MainWindow + if ((window->classification != WindowClass::MainWindow && window->classification != WindowClass::Viewport) || (window->classification == WindowClass::MainWindow && !window->viewport_smart_follow_sprite.IsNull())) { if (!underground)