Writing a Timer

The timer function takes the form.

pascal void TimerFunction(EventLoopTimerRef theTimer, void* userData)

The pascal keyword tells the compiler to use Pascal language parameter passing conventions. Timer functions require the Pascal language conventions. The userData argument is the data you supplied when you called InstallEventLoopTimer().

C++ programs that want timer functions to be member functions of a class must declare the timer to be a static function in the header file.

static pascal void TimerFunction(EventLoopTimerRef theTimer, void* userData);

You can give your timer function any name you want, but remember the name of the timer must match the name you supply to the function NewEventTimerUPP() when installing the timer.

What do you put in a timer? Generally you call a function from the timer. The following example calls the GameLoop() function for a GameApp class:

pascal void GameApp::GameLoopTimer(EventLoopTimerRef theTimer, void* userData) 
{ 
    GameAppPtr currentApp = (GameAppPtr)userData;     
    currentApp->GameLoop(); 
}

Next (Starting a Timer)
Previous (Installing a Timer)