diff --git a/src/Graphics_D3D11.c b/src/Graphics_D3D11.c index 5c77c5251..e5391ecae 100644 --- a/src/Graphics_D3D11.c +++ b/src/Graphics_D3D11.c @@ -942,6 +942,13 @@ void Gfx_EndFrame(void) { // https://docs.microsoft.com/en-us/windows/win32/api/dxgi/nf-dxgi-idxgiswapchain-present // gfx_vsync happens to match SyncInterval parameter HRESULT hr = IDXGISwapChain_Present(swapchain, gfx_vsync, 0); + + // run at reduced FPS when minimised + if (hr == DXGI_STATUS_OCCLUDED) { + TickReducedPerformance(); return; + } + + EndReducedPerformance(); if (hr) Logger_Abort2(hr, "Failed to swap buffers"); } diff --git a/src/Menus.c b/src/Menus.c index fe2a41611..b6758bfb8 100644 --- a/src/Menus.c +++ b/src/Menus.c @@ -3691,7 +3691,7 @@ static const struct ScreenVTABLE TexPackOverlay_VTABLE = { void TexPackOverlay_Show(const cc_string* url) { struct TexPackOverlay* s = &TexPackOverlay; s->grabsInput = true; - /* Too easy to accidentally ESC this important dialog*/ + /* Too easy to accidentally ESC this important dialog */ /* s->closable= true; */ s->VTABLE = &TexPackOverlay_VTABLE; diff --git a/src/_GraphicsBase.h b/src/_GraphicsBase.h index ddbdaa383..524665387 100644 --- a/src/_GraphicsBase.h +++ b/src/_GraphicsBase.h @@ -91,6 +91,21 @@ void Gfx_RecreateContext(void) { Event_RaiseVoid(&GfxEvents.ContextRecreated); } +cc_bool reducedPerformance; +static void TickReducedPerformance(void) { + Thread_Sleep(100); /* 10 FPS */ + + if (reducedPerformance) return; + reducedPerformance = true; /* TODO: also log a message in-game? */ + Platform_LogConst("Entering reduced performance mode"); +} + +static void EndReducedPerformance(void) { + if (!reducedPerformance) return; + reducedPerformance = false; + Platform_LogConst("Exited reduced performance mode"); +} + void Gfx_RecreateDynamicVb(GfxResourceID* vb, VertexFormat fmt, int maxVertices) { Gfx_DeleteDynamicVb(vb);