Skip to content

Commit 9ecc9ad

Browse files
committed
Use timeBeginPeriod on Windows
We need a high resolution timer so we can wake up at the right time when we are pacing out packets, etc. Without this call, we get the crappy default resolution. Up to this point it looks like we have just been getting saved by some other code in the game, or Steam client, calling this for us. But really we need to do it ourselves. https://randomascii.wordpress.com/2020/10/04/windows-timer-resolution-the-great-rule-change/ P4:6571383
1 parent d3b08d6 commit 9ecc9ad

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/steamnetworkingsockets/clientlib/steamnetworkingsockets_lowlevel.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2349,6 +2349,17 @@ bool BSteamNetworkingSocketsLowLevelAddRef( SteamDatagramErrMsg &errMsg )
23492349
V_strcpy_safe( errMsg, "WSAStartup failed" );
23502350
return false;
23512351
}
2352+
2353+
#pragma comment( lib, "winmm.lib" )
2354+
if ( ::timeBeginPeriod( 1 ) != 0 )
2355+
{
2356+
::WSACleanup();
2357+
#ifdef _XBOX_ONE
2358+
::CoUninitialize();
2359+
#endif
2360+
V_strcpy_safe( errMsg, "timeBeginPeriod failed" );
2361+
return false;
2362+
}
23522363
}
23532364
#endif
23542365

@@ -2505,6 +2516,7 @@ void SteamNetworkingSocketsLowLevelDecRef()
25052516

25062517
// Nuke sockets and COM
25072518
#ifdef _WIN32
2519+
::timeEndPeriod( 1 );
25082520
::WSACleanup();
25092521
#endif
25102522
#ifdef _XBOX_ONE

0 commit comments

Comments
 (0)