Throttle down the engine in the background to 15 fps

This commit is contained in:
Robert Beckebans 2025-01-22 22:03:16 +01:00
parent 3382365feb
commit 57ee767d46
4 changed files with 22 additions and 4 deletions

View file

@ -3,7 +3,7 @@
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
Copyright (C) 2012-2014 Robert Beckebans
Copyright (C) 2012-2025 Robert Beckebans
Copyright (C) 2022 Stephen Pridham
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
@ -97,12 +97,13 @@ idCVar net_inviteOnly( "net_inviteOnly", "1", CVAR_BOOL | CVAR_ARCHIVE, "whether
// DG: add cvar for pause
idCVar com_pause( "com_pause", "0", CVAR_BOOL | CVAR_SYSTEM | CVAR_NOCHEAT, "set to 1 to pause game, to 0 to unpause again" );
// DG end
idCVar com_activeApp( "com_activeApp", "1", CVAR_BOOL | CVAR_SYSTEM | CVAR_NOCHEAT, "this is set to 0 if running in background" );
extern idCVar g_demoMode;
idCVar com_engineHz( "com_engineHz", "60", CVAR_FLOAT | CVAR_ARCHIVE, "Frames per second the engine runs at", 10.0f, 1024.0f );
float com_engineHz_latched = 60.0f; // Latched version of cvar, updated between map loads
int64 com_engineHz_numerator = 100LL * 1000LL;
const int64 com_engineHz_numerator = 100LL * 1000LL;
int64 com_engineHz_denominator = 100LL * 60LL;
// RB begin

View file

@ -3,7 +3,7 @@
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
Copyright (C) 2014-2016 Robert Beckebans
Copyright (C) 2014-2025 Robert Beckebans
Copyright (C) 2014-2016 Kot in Action Creative Artel
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
@ -41,7 +41,7 @@ If you have questions concerning this license or the applicable additional terms
extern idCVar com_engineHz;
extern float com_engineHz_latched;
extern int64 com_engineHz_numerator;
extern const int64 com_engineHz_numerator;
extern int64 com_engineHz_denominator;
// Returns the msec the frame starts on

View file

@ -520,6 +520,7 @@ void idCommonLocal::ProcessGameReturn( const gameReturn_t& ret )
extern idCVar com_forceGenericSIMD;
extern idCVar com_pause;
extern idCVar com_activeApp;
/*
=================
@ -641,6 +642,21 @@ void idCommonLocal::Frame()
}
frameTiming.finishSyncTime = Sys_Microseconds();
// RB: slow down engine in background so it does not eat up so many resources along other 3D tools
if( !com_activeApp.GetBool() /* and not VR */ )
{
const float backgroundEngineHz = 15.0f;
com_engineHz_denominator = 100LL * backgroundEngineHz;
com_engineHz_latched = backgroundEngineHz;
}
else
{
// allow com_engineHz to be changed between map loads
com_engineHz_denominator = 100LL * com_engineHz.GetFloat();
com_engineHz_latched = com_engineHz.GetFloat();
}
// RB end
//--------------------------------------------
// Determine how many game tics we are going to run,
// now that the previous frame is completely finished.

View file

@ -296,6 +296,7 @@ LONG WINAPI MainWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
// DG: set com_pause so game pauses when focus is lost
// and continues when focus is regained
cvarSystem->SetCVarBool( "com_pause", !win32.activeApp );
cvarSystem->SetCVarBool( "com_activeApp", win32.activeApp );
// DG end
// we do not actually grab or release the mouse here,