From 6e2b854544a540371408a2559789638f90f5582f Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Thu, 28 Apr 2022 17:34:54 +0300 Subject: [PATCH] Set timer resolution to lowest possible value in all Windows systems --- Source/Engine/Platform/Windows/WindowsPlatform.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Source/Engine/Platform/Windows/WindowsPlatform.cpp b/Source/Engine/Platform/Windows/WindowsPlatform.cpp index 075bf7f90..8860ab912 100644 --- a/Source/Engine/Platform/Windows/WindowsPlatform.cpp +++ b/Source/Engine/Platform/Windows/WindowsPlatform.cpp @@ -626,10 +626,17 @@ bool WindowsPlatform::Init() return true; } - // Set lowest possible timer resolution for previous Windows versions - if (VersionMajor < 10 || (VersionMajor == 10 && VersionBuild < 17134)) + // Set the lowest possible timer resolution + const HMODULE ntdll = LoadLibraryW(L"ntdll.dll"); + if (ntdll) { - timeBeginPeriod(1); + typedef LONG (WIN_API_CALLCONV *NtSetTimerResolution)(ULONG DesiredResolution, unsigned char SetResolution, ULONG* CurrentResolution); + const NtSetTimerResolution ntSetTimerResolution = (NtSetTimerResolution)GetProcAddress(ntdll, "NtSetTimerResolution"); + + ULONG currentResolution; + ntSetTimerResolution(1, TRUE, ¤tResolution); + + ::FreeLibrary(ntdll); } DWORD tmp;