Handmade Hero»Forums»Code
Wesley Robb
7 posts
timeBeginPeriod without corresponding call to timeEndPeriod
Edited by Wesley Robb on Reason: Initial post
Hey guys,

So I recently started going through HH again after I fell off of the wagon a few years ago (yes, I'm starting from the beginning again). In episode 18 Casey adds a call to timeBeginPeriod to improve the resolution of the Sleep command. This should be followed by a corresponding call to timeEndPeriod but it isn't and even after checking the latest version of the code it still isn't.

Here is why we need it (pulled from MSDN):

This function affects a global Windows setting. Windows uses the lowest value (that is, highest resolution) requested by any process. Setting a higher resolution can improve the accuracy of time-out intervals in wait functions. However, it can also reduce overall system performance, because the thread scheduler switches tasks more often. High resolutions can also prevent the CPU power management system from entering power-saving modes. Setting a higher resolution does not improve the accuracy of the high-resolution performance counter.

Anyway, I hope Casey sees this so the game doesn't permanently interfere with any Windows players who happen to be playing on a laptop or anything where Power Management is important.

Thanks!
Mārtiņš Možeiko
2559 posts / 2 projects
timeBeginPeriod without corresponding call to timeEndPeriod
Its not well documented, but Windows will restore default timer period once process exits.

See older discussion on this topic: https://hero.handmade.network/for...od_without_matching_timeendperiod
Wesley Robb
7 posts
timeBeginPeriod without corresponding call to timeEndPeriod
Oh damn! Bad me for not searching first. Thanks for the heads up!