Jump to content
  • Advertisement
Sign in to follow this  
DesignerX

Application Timing

This topic is 5473 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

Can someone tell me how do I use a timer for making game's speed constant, and also how do I limit the frames per second to a constant value as well ??? Thanks !

Share this post


Link to post
Share on other sites
Advertisement
The second question is easier. If you want 30 FPS, that means that each frame takes 0.0333 seconds (33.3ms) to complete. You time each frame, and if its taken less than 33.3ms to complete, then you Sleep() for the remaining time: Sleep(33-time)
E.g, if you time your frame, and find it took 18ms, then you'd do Sleep(33-18) = Sleep(15).

As for using timers, you can do something simple (but not very accurate), and just check with GetTickCount() to see what the current time is. If you want something to execute every 100ms, you just see what the current time is, and if its >= lastTime+100, then you run the part thats to run every 100ms.
You can get more accurate timing with QueryPerformanceCounter(), but it has some rather annoying issues. Theres been a few threads about different timing methods, and I think theres an article on it too. Have a search and you'll see what I mean.

Share this post


Link to post
Share on other sites
Do not use GetTickCount!
It's very inaccurate, use timeGetTime instead.
It doesn't have the flaws that QueryPerformanceCounter deals with and compared to GetTickCount; Very precise!

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!