I was going back through HMH Day 18, to refresh my memory on Game Loop stuff, and I was a bit confused about something.
DWORD SleepMS = (DWORD)(1000.0f * (TargetSecondsPerFrame - SecondsElapsedForFrame));
In Day 18, Casey wrote the above code, and when asked if it could cause us to miss the target FPS he said no because we made a call that allowed us to be MS granular, and the SleepMS is truncated.
I understand his point; however, can't we still miss the SleepMS here, because even if the scheduler is MS granular, if it wakes up at a different offset from when we actually called Sleep there may be some inaccuracy depending on the fractional part of SleepMS right?
For example, if SleepMS is 10.3 and so we call Sleep(10), but we called Sleep(10) 0.2ms after the last run of the scheduler then the scheduler will miss the 10ms and actually wake up after 10.8ms of sleeping. (the arithmetic may be wrong here, but I think the question still hopefully makes sense).
I added an Assert and it does seem like the Sleep can overshoot.
Would appreciate any insight!