🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

c++ timing

Started by
3 comments, last by daviddiligent 16 years, 3 months ago
so, hi to all... i've a little problem with nehe tutorials... they are too fast for my pc [ my video card shoot them out ] i need to limit the fps in the code, but i have not found an usefull code to use... can someone post it to help me? i've seached all the possible things, but noone give an example with an usage mode... thank to all ^^ p.s. sorry for my "deprecated" english :P
Advertisement
Hi,

The simplest way to limit the FPS in the code would be to place a Sleep() call at the end of the main loop. This should work.

If you want to have it exact, measure the time t required for a frame (in milliseconds) and wait 1000/n - t millis (where n is the frame rate you want to reach)

Under Windows you can use timeGetTime() or GetTickCount(). However, these functions are not very exact (they only measure milliseconds).

QueryPerformanceCounter() is - assuming you use Windows - propably the best solution. See MSDN for more details.

Best regards,
Porthos
I think you mean the lessons in the beginning. If you want to learn some timing you can jump to lesson 21 or lesson 32, if i remember correctly. You can consider them as two games that have entire features rather than lessons.

In lesson 21, you will learn how to use time to control the speed or frame rate of your game, whereas in 32 you can learn to control your game without limiting your frame rate, i.e. use time elapsed to update ur game logic.
/*----------------------------------------------------------------------------------------------------------------------------------*/Enthusiastic and wild about game development. Any opportunity would get me sink into any fantastic game-revolution era.
If it helps, I posted a cross-platform timer on my journal ages ago: http://www.gamedev.net/community/forums/mod/journal/journal.asp?jn=351511&reply_id=3097340

Be sure to read the first comment.

Luke.
Member of the NeHe team.
Quote: Original post by Kazade
If it helps, I posted a cross-platform timer on my journal ages ago: http://www.gamedev.net/community/forums/mod/journal/journal.asp?jn=351511&reply_id=3097340

Be sure to read the first comment.

Luke.


Cheers Luke. Seems to be useful.
/*----------------------------------------------------------------------------------------------------------------------------------*/Enthusiastic and wild about game development. Any opportunity would get me sink into any fantastic game-revolution era.

This topic is closed to new replies.

Advertisement