Timing functions and application
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.
There is sleep() and usleep() in Linux. usleep() is for micro-seconds i think and sleep is for seconds.
ace
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.
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.
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.
gettimeofday is fine for game needs; if POSIX realtime extensions are available, clock_gettime's interface offers the potential for even higher resolution.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement