From 513d2d9a7bb1d207bae5de8cdee177fc2bcb0844 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Fri, 5 Nov 2021 17:18:14 +1100 Subject: [PATCH] Direct3D9Ex: Also enter reduced performance mode when minimised, and showe a message in chat when that happens --- src/Graphics_D3D11.c | 3 ++- src/Graphics_D3D9.c | 9 +++++++-- src/Graphics_GL1.c | 1 - src/Graphics_GL2.c | 1 - src/_GraphicsBase.h | 7 ++++--- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/Graphics_D3D11.c b/src/Graphics_D3D11.c index f3c70c44d..88a60b19c 100644 --- a/src/Graphics_D3D11.c +++ b/src/Graphics_D3D11.c @@ -52,8 +52,9 @@ static void CreateDeviceAndSwapChain(void) { DXGI_SWAP_CHAIN_DESC desc = { 0 }; desc.BufferCount = 1; + // todo see if BGRA slightly faster desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; - desc.BufferDesc.RefreshRate.Numerator = 60; + desc.BufferDesc.RefreshRate.Numerator = 60; // TODO just leave at 0? check DXGI docs again desc.BufferDesc.RefreshRate.Denominator = 1; desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; desc.OutputWindow = WindowInfo.Handle; diff --git a/src/Graphics_D3D9.c b/src/Graphics_D3D9.c index 3770e0bd0..a96cf5c4c 100644 --- a/src/Graphics_D3D9.c +++ b/src/Graphics_D3D9.c @@ -814,8 +814,13 @@ void Gfx_EndFrame(void) { IDirect3DDevice9_EndScene(device); cc_result res = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL); - /* Direct3D9Ex returns S_PRESENT_OCCLUDED when e.g. window is minimised */ - if (res && res != S_PRESENT_OCCLUDED) { + /* Direct3D9Ex returns S_PRESENT_OCCLUDED when e.g.window is minimised */ + if (res == S_PRESENT_OCCLUDED) { + TickReducedPerformance(); return; + } + EndReducedPerformance(); + + if (res) { if (res != D3DERR_DEVICELOST) Logger_Abort2(res, "D3D9_EndFrame"); /* TODO: Make sure this actually works on all graphics cards. */ Gfx_LoseContext(" (Direct3D9 device lost)"); diff --git a/src/Graphics_GL1.c b/src/Graphics_GL1.c index 670c83a7c..5bb7ba43b 100644 --- a/src/Graphics_GL1.c +++ b/src/Graphics_GL1.c @@ -1,7 +1,6 @@ #include "Core.h" #if defined CC_BUILD_GL && !defined CC_BUILD_GLMODERN #include "_GraphicsBase.h" -#include "Chat.h" #include "Errors.h" #include "Logger.h" #include "Window.h" diff --git a/src/Graphics_GL2.c b/src/Graphics_GL2.c index 3ff64947b..a93f079e2 100644 --- a/src/Graphics_GL2.c +++ b/src/Graphics_GL2.c @@ -1,7 +1,6 @@ #include "Core.h" #if defined CC_BUILD_GL && defined CC_BUILD_GLMODERN #include "_GraphicsBase.h" -#include "Chat.h" #include "Errors.h" #include "Logger.h" #include "Window.h" diff --git a/src/_GraphicsBase.h b/src/_GraphicsBase.h index 524665387..cbaac6b7c 100644 --- a/src/_GraphicsBase.h +++ b/src/_GraphicsBase.h @@ -8,6 +8,7 @@ #include "Block.h" #include "Options.h" #include "Bitmap.h" +#include "Chat.h" struct _GfxData Gfx; GfxResourceID Gfx_defaultIb; @@ -96,14 +97,14 @@ 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"); + reducedPerformance = true; + Chat_AddRaw("&eEntering reduced performance mode (game minimised or hidden)"); } static void EndReducedPerformance(void) { if (!reducedPerformance) return; reducedPerformance = false; - Platform_LogConst("Exited reduced performance mode"); + Chat_AddRaw("&eExited reduced performance mode"); }