navi homePPSaboutscreenshotsdownloaddevelopmentforum

HowTo: Timer

It's possible to delay a function call by using a doc/Timer. In fact it's even possible to delay a whole call including an object and several arguments. This is achievec by using an doc/Executor.

Static functions

For static functions, use StaticTimer. A StaticTimer is created either in the constructor or by calling setTimer:

  • StaticTimer(interval, bLoop, executor)
  • setTimer(interval, bLoop, executor)

interval is the time in seconds until the function gets executed.
bLoop is a bool. If set to true, the Timer will continue calling the function after every interval seconds.
executor is an ExecutorStatic of a static function

#include "tools/Timer.h"

void myFunction();
void myAdvancedFunction(int value);

// Call myFunctionafter 5 seconds
StaticTimer myTimer(5.0f, false, createExecutor(createFunctor(&myFunction)));

// Call myAdvancedFunction(10) after 3 seconds
ExectorStatic* executor = createExecutor(createFunctor(&myAdvancedFunction));
executor->setDefaultValue(0, 10.0f); // Bind the value
StaticTimer myAdvancedTimer(3.0f, false, executor);

See this for more information about how to find values.

Member functions

For member functions you additionally have to add the object:

  • StaticTimer(interval, bLoop, object, executor)
  • setTimer(interval, bLoop, object, executor)

interval, bLoop and executor are like in StaticTimer (except executor has to be an ExecutorMember).
object the object on which to call the function.

#include "tools/Timer.h"

class MyClass
    void myFunction();

// Create an instance of MyClass:
MyClass* object = new MyClass();

// Call MyClass::myFunctionafter after 5 seconds
Timer myTimer(5.0f, false, object, createExecutor(createFunctor(&MyClass::myFunction)));
Last modified 3 years ago Last modified on Apr 12, 2017, 11:49:55 PM