Timing functions and application

Started by
6 comments, last by Jan Wassenberg 18 years, 8 months ago
Question about timing. 1. Under linux using C, what functions are an accurate and reliable way to keep timing for game loops? 2. What is a good way to wait for the next game loop? Especially in respect with being friendly to other processes. 3. What are some typical game loop lengths? .5/1/2/5 seconds? I assume its based on the type of game, if so, what are common ones for say a mud, fps, rpg, mmorpg? I am starting in on a generic C timing library which will be used in linux, and want it to be flexible enough for a fast or slow game loop game.
Advertisement
There is sleep() and usleep() in Linux. usleep() is for micro-seconds i think and sleep is for seconds.

ace
On my BSD machine, there are man pages for sleep, usleep [microsleep] and even nanosleep. All listed as C standard functions. I'm a little skeptical of how standard that nanosleep is, or how accurate it gets in real life.

In my timer I use for windows code the default 'tick' of the timer is 33ms. Rendering goes as fast as possible, even though the app's timer isn't incremented any faster than 30 [and some change] times per second.
My game loop lengths are pretty much 20ms (1/50 sec).. I have them fixed at that accutually..
Still wondering about functions that are accurate and reliable to get time in C under linux. I was looking at gettimeofday but don't know if that is good enough.
If there is a better way I would love to hear it.
Read to understand what accuracy is and what you are actually looking for.
gettimeofday is fine for game needs; if POSIX realtime extensions are available, clock_gettime's interface offers the potential for even higher resolution.
E8 17 00 42 CE DC D2 DC E4 EA C4 40 CA DA C2 D8 CC 40 CA D0 E8 40E0 CA CA 96 5B B0 16 50 D7 D4 02 B2 02 86 E2 CD 21 58 48 79 F2 C3
Thanks for that link Jan, lots of good info there, and I do have POSIX extensions available so I will check out clock_gettime as well.
Cool, glad to!
E8 17 00 42 CE DC D2 DC E4 EA C4 40 CA DA C2 D8 CC 40 CA D0 E8 40E0 CA CA 96 5B B0 16 50 D7 D4 02 B2 02 86 E2 CD 21 58 48 79 F2 C3

This topic is closed to new replies.

Advertisement