From 2be84dc636d5cb5f6a89500a560ea00c02ce609f Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Fri, 4 May 2018 11:24:37 +0300 Subject: [PATCH] - skip rendering when application is not active Use vid_activeinbackground CVAR to override this behavior --- src/d_main.cpp | 15 ++++++++------- src/gl/system/gl_framebuffer.cpp | 6 ------ src/posix/cocoa/gl_sysfb.h | 1 - src/posix/cocoa/i_main.mm | 8 +++++++- src/posix/cocoa/i_video.mm | 5 ----- src/posix/sdl/gl_sysfb.h | 1 - src/posix/sdl/i_input.cpp | 9 ++++++++- src/posix/sdl/sdlglvideo.cpp | 5 ----- src/win32/gl_sysfb.h | 1 - src/win32/i_input.cpp | 4 ++-- src/win32/win32gliface.cpp | 15 --------------- 11 files changed, 25 insertions(+), 45 deletions(-) diff --git a/src/d_main.cpp b/src/d_main.cpp index b4849a742..aa81b9f5a 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -28,13 +28,6 @@ // HEADER FILES ------------------------------------------------------------ -#ifdef _WIN32 -#include -#define mkdir(a,b) _mkdir (a) -#else -#include -#endif - #ifdef HAVE_FPU_CONTROL #include #endif @@ -237,6 +230,7 @@ FStartupInfo DoomStartupInfo; FString lastIWAD; int restart = 0; bool batchrun; // just run the startup and collect all error messages in a logfile, then quit without any interaction +bool AppActive = true; cycle_t FrameCycles; @@ -645,6 +639,8 @@ CVAR (Flag, compat_multiexit, compatflags2, COMPATF2_MULTIEXIT); CVAR (Flag, compat_teleport, compatflags2, COMPATF2_TELEPORT); CVAR (Flag, compat_pushwindow, compatflags2, COMPATF2_PUSHWINDOW); +CVAR(Bool, vid_activeinbackground, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) + //========================================================================== // // D_Display @@ -660,6 +656,11 @@ void D_Display () if (nodrawers || screen == NULL) return; // for comparative timing / profiling + if (!AppActive && (screen->IsFullscreen() || !vid_activeinbackground)) + { + return; + } + cycle_t cycles; cycles.Reset(); diff --git a/src/gl/system/gl_framebuffer.cpp b/src/gl/system/gl_framebuffer.cpp index 65879e9ff..75c4fd165 100644 --- a/src/gl/system/gl_framebuffer.cpp +++ b/src/gl/system/gl_framebuffer.cpp @@ -148,12 +148,6 @@ void OpenGLFrameBuffer::InitializeState() void OpenGLFrameBuffer::Update() { - if (!CanUpdate()) - { - GLRenderer->Flush(); - return; - } - DrawRateStuff(); GLRenderer->Flush(); diff --git a/src/posix/cocoa/gl_sysfb.h b/src/posix/cocoa/gl_sysfb.h index b88570b64..f132111f1 100644 --- a/src/posix/cocoa/gl_sysfb.h +++ b/src/posix/cocoa/gl_sysfb.h @@ -65,7 +65,6 @@ protected: void InitializeState(); - bool CanUpdate(); void SwapBuffers(); void SetGammaTable(uint16_t* table); diff --git a/src/posix/cocoa/i_main.mm b/src/posix/cocoa/i_main.mm index 327628e95..0a4d16df9 100644 --- a/src/posix/cocoa/i_main.mm +++ b/src/posix/cocoa/i_main.mm @@ -296,18 +296,24 @@ ApplicationController* appCtrl; } +extern bool AppActive; + - (void)applicationDidBecomeActive:(NSNotification*)aNotification { ZD_UNUSED(aNotification); S_SetSoundPaused(1); + + AppActive = true; } - (void)applicationWillResignActive:(NSNotification*)aNotification { ZD_UNUSED(aNotification); - S_SetSoundPaused((!!i_soundinbackground) || 0); + S_SetSoundPaused(i_soundinbackground); + + AppActive = false; } diff --git a/src/posix/cocoa/i_video.mm b/src/posix/cocoa/i_video.mm index 939e3c28b..8539fdcf2 100644 --- a/src/posix/cocoa/i_video.mm +++ b/src/posix/cocoa/i_video.mm @@ -701,11 +701,6 @@ void SystemFrameBuffer::InitializeState() { } -bool SystemFrameBuffer::CanUpdate() -{ - return true; -} - void SystemFrameBuffer::SwapBuffers() { [[NSOpenGLContext currentContext] flushBuffer]; diff --git a/src/posix/sdl/gl_sysfb.h b/src/posix/sdl/gl_sysfb.h index d68492e59..447ced562 100644 --- a/src/posix/sdl/gl_sysfb.h +++ b/src/posix/sdl/gl_sysfb.h @@ -33,7 +33,6 @@ public: virtual int GetTrueHeight() { return GetClientHeight(); } protected: - bool CanUpdate(); void SetGammaTable(uint16_t *tbl); void ResetGammaTable(); void InitializeState(); diff --git a/src/posix/sdl/i_input.cpp b/src/posix/sdl/i_input.cpp index 1998823b6..cc3acd5ba 100644 --- a/src/posix/sdl/i_input.cpp +++ b/src/posix/sdl/i_input.cpp @@ -305,9 +305,16 @@ void MessagePump (const SDL_Event &sev) case SDL_WINDOWEVENT: switch (sev.window.event) { + extern bool AppActive; + case SDL_WINDOWEVENT_FOCUS_GAINED: + S_SetSoundPaused(1); + AppActive = true; + break; + case SDL_WINDOWEVENT_FOCUS_LOST: - S_SetSoundPaused((!!i_soundinbackground) || sev.window.event == SDL_WINDOWEVENT_FOCUS_GAINED); + S_SetSoundPaused(i_soundinbackground); + AppActive = false; break; } break; diff --git a/src/posix/sdl/sdlglvideo.cpp b/src/posix/sdl/sdlglvideo.cpp index 4d3b48131..4ed9e3a9f 100644 --- a/src/posix/sdl/sdlglvideo.cpp +++ b/src/posix/sdl/sdlglvideo.cpp @@ -394,11 +394,6 @@ void SystemFrameBuffer::InitializeState() { } -bool SystemFrameBuffer::CanUpdate () -{ - return true; -} - void SystemFrameBuffer::SetGammaTable(uint16_t *tbl) { if (m_supportsGamma) diff --git a/src/win32/gl_sysfb.h b/src/win32/gl_sysfb.h index 52054615f..db505501e 100644 --- a/src/win32/gl_sysfb.h +++ b/src/win32/gl_sysfb.h @@ -30,7 +30,6 @@ public: protected: - bool CanUpdate(); void ResetGammaTable(); void SetGammaTable(uint16_t * tbl); diff --git a/src/win32/i_input.cpp b/src/win32/i_input.cpp index 050e32a8b..4234868c7 100644 --- a/src/win32/i_input.cpp +++ b/src/win32/i_input.cpp @@ -144,7 +144,7 @@ LPDIRECTINPUT8 g_pdi; LPDIRECTINPUT g_pdi3; -BOOL AppActive = TRUE; +extern bool AppActive; int SessionState = 0; int BlockMouseMove; @@ -527,7 +527,7 @@ LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) break; case WM_ACTIVATEAPP: - AppActive = wParam; + AppActive = wParam == TRUE; if (wParam) { SetPriorityClass (GetCurrentProcess (), INGAME_PRIORITY_CLASS); diff --git a/src/win32/win32gliface.cpp b/src/win32/win32gliface.cpp index 903a370c7..76e6756da 100644 --- a/src/win32/win32gliface.cpp +++ b/src/win32/win32gliface.cpp @@ -55,7 +55,6 @@ #include "gl/system/gl_framebuffer.h" extern HWND Window; -extern BOOL AppActive; extern "C" { __declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001; @@ -71,8 +70,6 @@ PFNWGLSWAPINTERVALEXTPROC myWglSwapIntervalExtProc; -CVAR(Bool, vid_activeinbackground, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) - CUSTOM_CVAR(Bool, gl_debug, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL) { Printf("This won't take effect until " GAMENAME " is restarted.\n"); @@ -1118,18 +1115,6 @@ void SystemFrameBuffer::InitializeState() // //========================================================================== -bool SystemFrameBuffer::CanUpdate() -{ - if (!AppActive && (IsFullscreen() || !vid_activeinbackground)) return false; - return true; -} - -//========================================================================== -// -// -// -//========================================================================== - void SystemFrameBuffer::ResetGammaTable() { if (m_supportsGamma)