Jump to content
  • Advertisement
Sign in to follow this  
durnew

Tight game loop in Windows

This topic is 4749 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!