Hello,
I was looking through the day18 code again and checked some of the docs regarding Sleep
and timeBeginPeriod
.
The doc for Sleep
says we must call the timeEndPeriod
at the end of the application, and vaguely threatens that not doing so will do something to the battery (I don't quite understand what its trying to say). timeEndPeriod
was not called in the lesson. So, is it important that I call it at the end?
From the doc:
Use caution when calling timeBeginPeriod, as frequent calls can significantly affect the system clock, system power usage, and the scheduler. If you call timeBeginPeriod, call it one time early in the application and be sure to call the timeEndPeriod function at the very end of the application.
So what does the timeBeginPeriod
function actually do? Does it actually set the granularity of the system clock for the whole computer, instead of just this application? And if so, what is to prevent some application from setting it to something bad and then crashing before unsetting it? Or even just not unsetting it, like the game?
Another question about variable refresh rates. I remember Casey Muratori explaining how variable refresh rates do not make sense (for gaming at least) because we need to know what the fixed refresh rate is in order to do simulation of the game. While reading the above I came across this doc: https://learn.microsoft.com/en-us/windows/win32/directcomp/compositor-clock/compositor-clock
which says that its used for latency sensitive stuff such as drawing on the screen with a pen.
And this doc has a function that lets you wait for the next frame (of the monitor)
DWORD DCompositionWaitForCompositorClock( UINT count, const HANDLE *handles, DWORD timeoutInMs );
So can we use this to get the refresh rate at the startup of the game? For example something like:
LARGE_INTEGER FrameStart; QueryPerformanceCounter(&FrameStart); DCompositionWaitForCompositorClock(1, Handle, INFINITE); LARGE_INTEGER FrameEnd; QueryPerformanceCounter(&FrameEnd); int32 RefreshRate = (FrameEnd.QuadPart - FrameStart.QuadPart)/CounterFrequency;
I can't figure out what it wants in the second argument as Handle
though.