Tight game loop in Windows
I'm very new to this. The game i'm creating is a very simple 2D sidescroller in Windows. What would be the optimal method of delaying at the end of a game loop iteration so the game doesn't chew up the computer's CPU? I've experimented with Sleep() but i'm getting incosistent performance and i'm curious if this is the preffered way.
Thank you much!
My view is that using nearly 100% of the CPU time is a good thing to do, as long as you don't bring down the rest of the system.
Maybe your game should switch to GetMessage instead of PeekMessage when the window isn't active, but that's about it.
Maybe your game should switch to GetMessage instead of PeekMessage when the window isn't active, but that's about it.
Quote:Original post by durnew
I'm very new to this. The game i'm creating is a very simple 2D sidescroller in Windows. What would be the optimal method of delaying at the end of a game loop iteration so the game doesn't chew up the computer's CPU? I've experimented with Sleep() but i'm getting incosistent performance and i'm curious if this is the preffered way.
Thank you much!
Timers are a problem on Windows in general. See this article by Jon Watte for some a description of problems, and this implementation by Charles Bloom for some solution code.
Sleep() on windows isn't very accurate. It has a 10ms minimum granularity, IIRC.
You can use WaitSingleObject() and timers.
If you decoupled display from physics like you ought to, the issue becomes less severe since you can render frequently but keep the physics at a fixed step.
frob.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement