Main - Overview - Documentation - FAQ - Media


Timers are structures that act on data and execute callbacks based on time.  They have high precision and some retroactive capabilities.  The server maintains them and they are associated with both the object that they are acting on and the callback object if they are present (meaning that if either of them are deallocated then the Timer is as well).  Timer maintenance and evaluation happens once every server event loop.  To create a Timer you send a message to the Timer class with specific parameters:

Object:(id)dsin (NOT optional) If the Data parameter is part of an object is should be the address of that object.
Data:(float*)datain (optional) The address of the Data to be altered.  Must be a GLfloat.
Destination:(float)destin (optional) The end value of what you want *data (see Timer.h) to be.
Method:(SEL)vcbin (optional) Callback selector to the function that defines the numerical progress of data given time. (ie: linear:, sinusodal:, hyperbolic:)
Start:(float)arstart (optional) The initial value that *data is set to.
Time:(float)timein (optional) How long in seconds the timer is supposed to run.
CallbackObject:(id)cobj Callback:(SEL)ccbin (optional) Callback object/selector to be invoked upon the death of this timer; can be used to define advanced timer behavior (ie: Repeatlinearly:, Oscilatesinusodally:)
Flags:(char)flagsin (NOT optional) Various settings.

Object is an object that you specify that this Timer is associated with for purposes of deallocation and such(if the Data:Destination:Method: parameters are present then it is almost always going to be the object that the "data" member that the Data: parameter is pointing to belongs to).  Typically Timers deallocate upon their completion but some types of Timers can keep going and avoid expiration.  Data, Destination and Method must all be present if any are.  They represent a pointer to data that should be modified over the lifespan of this Timer, what value it should be at the end and what computation function should be used to get it there.  Start is a value that the data variable is set to on the initial creation of the Timer. Timer is the amount of time in seconds that this Timer will exist or how long between events if it does not expire.  CallbackObject and Callback are the parameters that dictate the object and routine to be executed when the Timer completes.  Flags is a bit field in which various Timer settings are passed in in OR'ed form.

A simple usage example would be a simple situation in which you wanted to move an object from one place to another smoothly over a period of time.  The code to perform that is as follows:

[Timer Object:MyObject Data:&MyObject->posx Destination:5.0 Method:@selector(linear:) Time:3.0 Flags:0];

Copyright © 2004-2011 Aoren LLC All rights reserved.
[email protected]