Sign in to follow this  

Tight game loop in Windows

This topic is 4379 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 4379 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this