Direct3D9Ex: Also enter reduced performance mode when minimised, and showe a message in chat when that happens

This commit is contained in:
UnknownShadow200 2021-11-05 17:18:14 +11:00
parent 05f8fe0555
commit 513d2d9a7b
5 changed files with 13 additions and 8 deletions

View File

@ -52,8 +52,9 @@ static void CreateDeviceAndSwapChain(void) {
DXGI_SWAP_CHAIN_DESC desc = { 0 }; DXGI_SWAP_CHAIN_DESC desc = { 0 };
desc.BufferCount = 1; desc.BufferCount = 1;
// todo see if BGRA slightly faster
desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; 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.BufferDesc.RefreshRate.Denominator = 1;
desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
desc.OutputWindow = WindowInfo.Handle; desc.OutputWindow = WindowInfo.Handle;

View File

@ -815,7 +815,12 @@ void Gfx_EndFrame(void) {
cc_result res = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL); cc_result res = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
/* Direct3D9Ex returns S_PRESENT_OCCLUDED when e.g.window is minimised */ /* Direct3D9Ex returns S_PRESENT_OCCLUDED when e.g.window is minimised */
if (res && res != S_PRESENT_OCCLUDED) { if (res == S_PRESENT_OCCLUDED) {
TickReducedPerformance(); return;
}
EndReducedPerformance();
if (res) {
if (res != D3DERR_DEVICELOST) Logger_Abort2(res, "D3D9_EndFrame"); if (res != D3DERR_DEVICELOST) Logger_Abort2(res, "D3D9_EndFrame");
/* TODO: Make sure this actually works on all graphics cards. */ /* TODO: Make sure this actually works on all graphics cards. */
Gfx_LoseContext(" (Direct3D9 device lost)"); Gfx_LoseContext(" (Direct3D9 device lost)");

View File

@ -1,7 +1,6 @@
#include "Core.h" #include "Core.h"
#if defined CC_BUILD_GL && !defined CC_BUILD_GLMODERN #if defined CC_BUILD_GL && !defined CC_BUILD_GLMODERN
#include "_GraphicsBase.h" #include "_GraphicsBase.h"
#include "Chat.h"
#include "Errors.h" #include "Errors.h"
#include "Logger.h" #include "Logger.h"
#include "Window.h" #include "Window.h"

View File

@ -1,7 +1,6 @@
#include "Core.h" #include "Core.h"
#if defined CC_BUILD_GL && defined CC_BUILD_GLMODERN #if defined CC_BUILD_GL && defined CC_BUILD_GLMODERN
#include "_GraphicsBase.h" #include "_GraphicsBase.h"
#include "Chat.h"
#include "Errors.h" #include "Errors.h"
#include "Logger.h" #include "Logger.h"
#include "Window.h" #include "Window.h"

View File

@ -8,6 +8,7 @@
#include "Block.h" #include "Block.h"
#include "Options.h" #include "Options.h"
#include "Bitmap.h" #include "Bitmap.h"
#include "Chat.h"
struct _GfxData Gfx; struct _GfxData Gfx;
GfxResourceID Gfx_defaultIb; GfxResourceID Gfx_defaultIb;
@ -96,14 +97,14 @@ static void TickReducedPerformance(void) {
Thread_Sleep(100); /* 10 FPS */ Thread_Sleep(100); /* 10 FPS */
if (reducedPerformance) return; if (reducedPerformance) return;
reducedPerformance = true; /* TODO: also log a message in-game? */ reducedPerformance = true;
Platform_LogConst("Entering reduced performance mode"); Chat_AddRaw("&eEntering reduced performance mode (game minimised or hidden)");
} }
static void EndReducedPerformance(void) { static void EndReducedPerformance(void) {
if (!reducedPerformance) return; if (!reducedPerformance) return;
reducedPerformance = false; reducedPerformance = false;
Platform_LogConst("Exited reduced performance mode"); Chat_AddRaw("&eExited reduced performance mode");
} }