-
Sleep hiccuping
I have a directx and I am doing a crube fps limiter using Sleep. Before I use Sleep I use timeBeginPeriod(1) to make Sleep prcise to about 1ms. Everything works fine and it limits nearly perfectly except for occasional hiccups.
I am just wondering if anyone else experienced this problem or has any fixes.
-
fix: don't use sleep...
Just keep track of the elapsed time and only call the render function if the desired amount has passed.
Code:
...
long diff = time() - oldTime;
oldTime = time();
if (diff > desiredTime) {
drawScene();
}
-
Well the point of Sleep is to keep the cpu usage low. I know your all gonna say it doesn't matter but it does to me. And why not use Sleep when it produces virtualy exactly as I want, except for this weird hiccup, and if I fix this hiccup problem this method that I am using will be perfect (and accurate to 0.01 seconds with very low CPU usage).
-
What do you mean by a hiccup? A temporary lack in accuracy? I've never had a problem with Sleep although I don't watch it too closely.
-
Ok I have figured out that the hiccup has to do with timeBeginPeriod(1). If I don't use that than it goes away.
By hiccup I mean a pause for 500ms or more. But without timeBeginPeriod(1) the method is still very accurate and with no hiccups. I havn't tested on any other windows besides xp though.