DTimer periodically calls an event handler at a set interval. There are two ways to respond to the event; by creating a child class that implements the event handler, or by specifying a function to call with setHandler. The timer's resolution depends on how often DEngine::update is called, up to a maximum accuracy of 1 millisecond.
The default constructor accepts a DEngine that will handle our events.
Creates a DTimer that is a copy of source.
Sets this DTimer to be a copy of source.
Returns the interval at which the event handler will be called, in milliseconds.
Returns true if this timer is currently running, false otherwise.
Sets the interval at which the event handler will be called, in milliseconds.
Specify a handler to call when the timer elapses. If the handler a static function, it can be assigned to the DTimer by reference:
void timeup(void)
{
}
myTimer->setHandler(&timeup);
If the handler is a non-static member function, we can use boost::bind to assign it to the DTimer:
class MyClass { public: void timeup(void) { } } MyClass anObject; myTimer->setHandler(boost::bind(&MyClass::timeup, &anObject));Once this function finishes, handler will be called instead of the elapsed function. Set handler to NULL to start calling elapsed again.
Start the timer. The event handler will be called at the specified interval. If the timer is currently running, it resets the timer so that interval milliseconds will pass before the handler is called.
Stop the timer.
An event handler that's called whenever the timer elapses. It should be implemented in a child class of DTimer.