Skip to content

Commit

Permalink
Raised executable priority on windows to avoid stuter, helps #25162
Browse files Browse the repository at this point in the history
  • Loading branch information
reduz committed Jan 22, 2019
1 parent 6a187f6 commit ab843b1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions platform/windows/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def configure_msvc(env, manual_msvc_config):

LIBS = ['winmm', 'opengl32', 'dsound', 'kernel32', 'ole32', 'oleaut32',
'user32', 'gdi32', 'IPHLPAPI', 'Shlwapi', 'wsock32', 'Ws2_32',
'shell32', 'advapi32', 'dinput8', 'dxguid', 'imm32', 'bcrypt']
'shell32', 'advapi32', 'dinput8', 'dxguid', 'imm32', 'bcrypt','Avrt']
env.Append(LINKFLAGS=[p + env["LIBSUFFIX"] for p in LIBS])

if manual_msvc_config:
Expand Down Expand Up @@ -329,7 +329,7 @@ def configure_mingw(env):
env.Append(CCFLAGS=['-DRTAUDIO_ENABLED'])
env.Append(CCFLAGS=['-DWASAPI_ENABLED'])
env.Append(CCFLAGS=['-DWINVER=%s' % env['target_win_version'], '-D_WIN32_WINNT=%s' % env['target_win_version']])
env.Append(LIBS=['mingw32', 'opengl32', 'dsound', 'ole32', 'd3d9', 'winmm', 'gdi32', 'iphlpapi', 'shlwapi', 'wsock32', 'ws2_32', 'kernel32', 'oleaut32', 'dinput8', 'dxguid', 'ksuser', 'imm32', 'bcrypt'])
env.Append(LIBS=['mingw32', 'opengl32', 'dsound', 'ole32', 'd3d9', 'winmm', 'gdi32', 'iphlpapi', 'shlwapi', 'wsock32', 'ws2_32', 'kernel32', 'oleaut32', 'dinput8', 'dxguid', 'ksuser', 'imm32', 'bcrypt','avrt'])

env.Append(CPPFLAGS=['-DMINGW_ENABLED'])

Expand Down
14 changes: 14 additions & 0 deletions platform/windows/os_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include "servers/visual/visual_server_raster.h"
#include "servers/visual/visual_server_wrap_mt.h"
#include "windows_terminal_logger.h"
#include <avrt.h>

#include <process.h>
#include <regstr.h>
Expand Down Expand Up @@ -1373,6 +1374,19 @@ Error OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int

set_ime_active(false);

if (!OS::get_singleton()->is_in_low_processor_usage_mode()) {
//SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS);
SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS);
DWORD index = 0;
HANDLE handle = AvSetMmThreadCharacteristics("Games", &index);
if (handle)
AvSetMmThreadPriority(handle, AVRT_PRIORITY_CRITICAL);

// This is needed to make sure that background work does not starve the main thread.
// This is only setting priority of this thread, not the whole process.
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
}

return OK;
}

Expand Down

0 comments on commit ab843b1

Please sign in to comment.