Handmade Hero » Forums » Code » timeBeginPeriod without corresponding call to timeEndPeriod
wesrobb
Wesley Robb
7 posts
#14889 timeBeginPeriod without corresponding call to timeEndPeriod
2 weeks, 2 days ago Edited by Wesley Robb on April 9, 2018, 11:57 a.m. 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!
mmozeiko
Mārtiņš Možeiko
1638 posts
1 project
#14890 timeBeginPeriod without corresponding call to timeEndPeriod
2 weeks, 2 days ago

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
wesrobb
Wesley Robb
7 posts
#14891 timeBeginPeriod without corresponding call to timeEndPeriod
2 weeks, 1 day ago

Oh damn! Bad me for not searching first. Thanks for the heads up!