Skip to content

Commit f21b68c

Browse files
- revamp priority changing on windows, add cvar i_allowprioritychange to disallow priority changing entirely, allowing batch scripts to dictate GZDoom's process priority
1 parent 59ac494 commit f21b68c

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/common/platform/win32/i_input.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ EXTERN_CVAR(Bool, i_pauseinbackground);
128128

129129

130130
CVAR (Bool, k_allowfullscreentoggle, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
131+
CVAR (Bool, i_allowprioritychange, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
131132

132133
static void I_CheckGUICapture ()
133134
{
@@ -485,13 +486,16 @@ LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
485486

486487
case WM_ACTIVATEAPP:
487488
AppActive = (wParam == TRUE);
488-
if (wParam || !i_pauseinbackground)
489+
if (!i_pauseinbackground && i_allowprioritychange)
489490
{
490-
SetPriorityClass (GetCurrentProcess (), INGAME_PRIORITY_CLASS);
491-
}
492-
else if (!noidle && !(sysCallbacks.NetGame && sysCallbacks.NetGame()))
493-
{
494-
SetPriorityClass (GetCurrentProcess (), IDLE_PRIORITY_CLASS);
491+
if (wParam)
492+
{
493+
SetPriorityClass (GetCurrentProcess (), INGAME_PRIORITY_CLASS);
494+
}
495+
else if (!noidle && !(sysCallbacks.NetGame && sysCallbacks.NetGame()))
496+
{
497+
SetPriorityClass (GetCurrentProcess (), IDLE_PRIORITY_CLASS);
498+
}
495499
}
496500
S_SetSoundPaused (wParam);
497501
break;

src/common/platform/win32/i_system.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ void CalculateCPUSpeed()
244244
// probably never use the performance statistics.
245245
min_diff = freq.LowPart * 11 / 200;
246246

247+
// just in case we were launched with a custom priority class, keep it
248+
DWORD OldPriorityClass = GetPriorityClass(GetCurrentProcess());
249+
247250
// Minimize the chance of task switching during the testing by going very
248251
// high priority. This is another reason to avoid timing for too long.
249252
SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
@@ -258,7 +261,7 @@ void CalculateCPUSpeed()
258261
do { QueryPerformanceCounter(&count1); } while ((count1.QuadPart - count2.QuadPart) < min_diff);
259262
ClockCalibration.Unclock();
260263

261-
SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS);
264+
SetPriorityClass(GetCurrentProcess(), OldPriorityClass);
262265
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);
263266

264267
PerfToSec = double(count1.QuadPart - count2.QuadPart) / (double(ClockCalibration.GetRawCounter()) * freq.QuadPart);

0 commit comments

Comments
 (0)