1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-22 23:33:04 +01:00

Introduce VIEWPORT_FLAG_RENDERING_INHIBITED

This commit is contained in:
Aaron van Geffen
2024-07-15 01:17:57 +02:00
parent 3618f9a8a7
commit ef7dbe496a
8 changed files with 44 additions and 5 deletions

View File

@@ -311,6 +311,9 @@ namespace OpenRCT2::Title
} }
else else
{ {
// Inhibit viewport rendering while we're loading
WindowSetFlagForAllViewports(VIEWPORT_FLAG_RENDERING_INHIBITED, true);
ReportProgress(0); ReportProgress(0);
auto parkImporter = ParkImporter::Create(path); auto parkImporter = ParkImporter::Create(path);
@@ -338,6 +341,9 @@ namespace OpenRCT2::Title
GetContext()->CloseProgress(); GetContext()->CloseProgress();
} }
// Reset viewport rendering inhibition
WindowSetFlagForAllViewports(VIEWPORT_FLAG_RENDERING_INHIBITED, false);
gLoadKeepWindowsOpen = false; gLoadKeepWindowsOpen = false;
return success; return success;
} }
@@ -360,6 +366,9 @@ namespace OpenRCT2::Title
} }
else else
{ {
// Inhibit viewport rendering while we're loading
WindowSetFlagForAllViewports(VIEWPORT_FLAG_RENDERING_INHIBITED, true);
ReportProgress(0); ReportProgress(0);
bool isScenario = ParkImporter::ExtensionIsScenario(hintPath); bool isScenario = ParkImporter::ExtensionIsScenario(hintPath);
auto parkImporter = ParkImporter::Create(hintPath); auto parkImporter = ParkImporter::Create(hintPath);
@@ -387,6 +396,10 @@ namespace OpenRCT2::Title
Console::Error::WriteLine("Unable to load park: %s", hintPath.c_str()); Console::Error::WriteLine("Unable to load park: %s", hintPath.c_str());
GetContext()->CloseProgress(); GetContext()->CloseProgress();
} }
// Reset viewport rendering inhibition
WindowSetFlagForAllViewports(VIEWPORT_FLAG_RENDERING_INHIBITED, false);
gLoadKeepWindowsOpen = false; gLoadKeepWindowsOpen = false;
return success; return success;
} }

View File

@@ -48,10 +48,6 @@ static Widget _mainWidgets[] = {
void OnDraw(DrawPixelInfo& dpi) override void OnDraw(DrawPixelInfo& dpi) override
{ {
// Skip viewport render during preloader
if (GetContext()->GetActiveScene() == GetContext()->GetPreloaderScene())
return;
ViewportRender(dpi, viewport, { { dpi.x, dpi.y }, { dpi.x + dpi.width, dpi.y + dpi.height } }); ViewportRender(dpi, viewport, { { dpi.x, dpi.y }, { dpi.x + dpi.width, dpi.y + dpi.height } });
} }

View File

@@ -671,7 +671,7 @@ namespace OpenRCT2
if (!gOpenRCT2Headless && forceDraw) if (!gOpenRCT2Headless && forceDraw)
{ {
_uiContext->ProcessMessages(); _uiContext->ProcessMessages();
WindowUpdateAll(); WindowInvalidateByClass(WindowClass::ProgressWindow);
Draw(); Draw();
} }
} }
@@ -766,6 +766,9 @@ namespace OpenRCT2
parkImporter = ParkImporter::CreateS6(*_objectRepository); parkImporter = ParkImporter::CreateS6(*_objectRepository);
} }
// Inhibit viewport rendering while we're loading
WindowSetFlagForAllViewports(VIEWPORT_FLAG_RENDERING_INHIBITED, true);
OpenProgress(asScenario ? STR_LOADING_SCENARIO : STR_LOADING_SAVED_GAME); OpenProgress(asScenario ? STR_LOADING_SCENARIO : STR_LOADING_SAVED_GAME);
SetProgress(0, 100, STR_STRING_M_PERCENT, true); SetProgress(0, 100, STR_STRING_M_PERCENT, true);
@@ -785,6 +788,9 @@ namespace OpenRCT2
parkImporter->Import(gameState); parkImporter->Import(gameState);
SetProgress(100, 100, STR_STRING_M_PERCENT, true); SetProgress(100, 100, STR_STRING_M_PERCENT, true);
// Reset viewport rendering inhibition
WindowSetFlagForAllViewports(VIEWPORT_FLAG_RENDERING_INHIBITED, false);
gScenarioSavePath = path; gScenarioSavePath = path;
gCurrentLoadedPath = path; gCurrentLoadedPath = path;
gFirstTimeSaving = true; gFirstTimeSaving = true;
@@ -935,6 +941,7 @@ namespace OpenRCT2
} }
CloseProgress(); CloseProgress();
WindowSetFlagForAllViewports(VIEWPORT_FLAG_RENDERING_INHIBITED, false);
return false; return false;
} }

View File

@@ -927,6 +927,9 @@ void ViewportRotateAll(int32_t direction)
*/ */
void ViewportRender(DrawPixelInfo& dpi, const Viewport* viewport, const ScreenRect& screenRect) void ViewportRender(DrawPixelInfo& dpi, const Viewport* viewport, const ScreenRect& screenRect)
{ {
if (viewport->flags & VIEWPORT_FLAG_RENDERING_INHIBITED)
return;
auto [topLeft, bottomRight] = screenRect; auto [topLeft, bottomRight] = screenRect;
if (bottomRight.x <= viewport->pos.x) if (bottomRight.x <= viewport->pos.x)
@@ -1018,6 +1021,9 @@ static void ViewportPaint(const Viewport* viewport, DrawPixelInfo& dpi, const Sc
PROFILED_FUNCTION(); PROFILED_FUNCTION();
const uint32_t viewFlags = viewport->flags; const uint32_t viewFlags = viewport->flags;
if (viewFlags & VIEWPORT_FLAG_RENDERING_INHIBITED)
return;
uint32_t width = screenRect.GetWidth(); uint32_t width = screenRect.GetWidth();
uint32_t height = screenRect.GetHeight(); uint32_t height = screenRect.GetHeight();
const uint32_t bitmask = viewport->zoom >= ZoomLevel{ 0 } ? 0xFFFFFFFF & (viewport->zoom.ApplyTo(0xFFFFFFFF)) : 0xFFFFFFFF; const uint32_t bitmask = viewport->zoom >= ZoomLevel{ 0 } ? 0xFFFFFFFF & (viewport->zoom.ApplyTo(0xFFFFFFFF)) : 0xFFFFFFFF;

View File

@@ -66,6 +66,7 @@ enum : uint32_t
VIEWPORT_FLAG_INVISIBLE_SUPPORTS = (1u << 29), VIEWPORT_FLAG_INVISIBLE_SUPPORTS = (1u << 29),
VIEWPORT_FLAG_INDEPEDENT_ROTATION = (1u << 30), VIEWPORT_FLAG_INDEPEDENT_ROTATION = (1u << 30),
VIEWPORT_FLAG_RENDERING_INHIBITED = (1u << 31),
}; };
enum class VisibilityKind enum class VisibilityKind

View File

@@ -101,6 +101,19 @@ void WindowVisitEach(std::function<void(WindowBase*)> func)
} }
} }
void WindowSetFlagForAllViewports(uint32_t viewportFlag, bool enabled)
{
WindowVisitEach([&](WindowBase* w) {
if (w->viewport != nullptr)
{
if (enabled)
w->viewport->flags |= viewportFlag;
else
w->viewport->flags &= ~viewportFlag;
}
});
}
/** /**
* *
* rct2: 0x006ED7B0 * rct2: 0x006ED7B0

View File

@@ -491,6 +491,8 @@ extern bool gDisableErrorWindowSound;
std::list<std::shared_ptr<WindowBase>>::iterator WindowGetIterator(const WindowBase* w); std::list<std::shared_ptr<WindowBase>>::iterator WindowGetIterator(const WindowBase* w);
void WindowVisitEach(std::function<void(WindowBase*)> func); void WindowVisitEach(std::function<void(WindowBase*)> func);
void WindowSetFlagForAllViewports(uint32_t viewportFlag, bool enabled);
void WindowDispatchUpdateAll(); void WindowDispatchUpdateAll();
void WindowUpdateAllViewports(); void WindowUpdateAllViewports();
void WindowUpdateAll(); void WindowUpdateAll();

View File

@@ -41,6 +41,7 @@ void PreloaderScene::Load()
gameStateInitAll(GetGameState(), DEFAULT_MAP_SIZE); gameStateInitAll(GetGameState(), DEFAULT_MAP_SIZE);
ViewportInitAll(); ViewportInitAll();
ContextOpenWindow(WindowClass::MainWindow); ContextOpenWindow(WindowClass::MainWindow);
WindowSetFlagForAllViewports(VIEWPORT_FLAG_RENDERING_INHIBITED, true);
WindowResizeGui(ContextGetWidth(), ContextGetHeight()); WindowResizeGui(ContextGetWidth(), ContextGetHeight());
// Reset screen // Reset screen