Class DTimer



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.

Functions

Event Handlers


DTimer(DEngine *newEngine)

The default constructor accepts a DEngine that will handle our events.


DTimer(const DTimer &source)

Creates a DTimer that is a copy of source.


DTimer& operator= (const DTimer &source)

Sets this DTimer to be a copy of source.


unsigned int getInterval(void)

Returns the interval at which the event handler will be called, in milliseconds.


bool isRunning(void)

Returns true if this timer is currently running, false otherwise.


void setInterval(unsigned int interval)

Sets the interval at which the event handler will be called, in milliseconds.


void setHandler(boost::function<void (void)> handler)

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.

void start(void)

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.


void stop(void)

Stop the timer.


virtual void elapsed(void)

An event handler that's called whenever the timer elapses. It should be implemented in a child class of DTimer.











Back to class reference