RaydiumWikiNi

ApiTimecallsIntro

PagePrincipale :: DerniersChangements :: ParametresUtilisateur :: Vous êtes ec2-3-94-21-209.compute-1.amazonaws.com

27.1 Introduction to timecalls.c


27.1.1 Concept


As you may already know, in a real time application (as a game), you need to control in-game time evolution.

For example, you cannot increment a car position by 1 at each frame since it will generate an irregular scrolling (a frame is never rendered within the same time as the previous or the next one).

Raydium supports timecalls, wich are a great solution for this problem. Usage is very simple: write a simple function, and ask Raydium to call it at the desired rate.

27.1.2 Constraints


There is an important risk with timecalls: infinite loops.

If a callback is long, it may take more CPU time than he would, as in this very simple example:

foo() is a function, taking 200 ms for his own execution. If you ask for a 6 Hz execution, Raydium will execute foo() six times on the first frame, taking 1200 ms. On the next frame, Raydium will need to execute foo() 7 times (the asked 6 times, and one more for the 200 ms lost during the last frame), taking 1400 ms, so 8 times will be needed for the next frame, then 9, ...

So you need to create callbacks as short as possible, since long callbacks may cause a game freeze on slower machines than yours. (1 FPS syndrom)

27.1.3 Hardware devices and methods


Raydium must use a very accurate system timer, and will try many methods:

/dev/rtc , gettimeofday() (linux only) and GetTickCount??() for win32.

gettimeofday() will use a CPU counter and is extremely accurate. It's far the best method. (0.001 ms accuracy is possible)

/dev/rtc is quite good, and Raydium will try to configure RTC at RAYDIUM_TIMECALL_FREQ_PREFERED rate (8192 Hz by default), but may require a "/proc/sys/dev/rtc/max-user-freq" modification:

echo 8192 > /proc/sys/dev/rtc/max-user-freq

GetTickCount??() is (for now) the only timer available for windows, allowing a 100 Hz timer in most cases.

You may want to look at index.c for interesting defines about timecalls.



Return to RaydiumApiReference index.