Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changes between Initial Version and Version 1 of code/howto/Timer


Ignore:
Timestamp:
Oct 10, 2008, 3:52:31 AM (16 years ago)
Author:
landauf
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • code/howto/Timer

    v1 v1  
     1= HowTo: Timer =
     2[[TracNav(TracNav/TOC_Development)]]
     3
     4It's possible to delay a function call by using a [wiki:Timer]. In fact it's even possible to delay a whole call including an object and several arguments. This is achievec by using an [wiki:Executor].
     5
     6== Static functions ==
     7For static functions, use StaticTimer. A StaticTimer is created either in the constructor or by calling setTimer:
     8 * '''StaticTimer('''''interval, bLoop, executor''''')'''
     9 * '''setTimer('''''interval, bLoop, executor''''')'''
     10''interval'' is the time in seconds until the function gets executed.[[br]]
     11''bLoop'' is a bool. If set to true, the Timer will continue calling the function after every ''interval'' seconds.[[br]]
     12''executor'' is an ExecutorStatic of a static functio
     13
     14{{{
     15#include "tools/Timer.h"
     16
     17void myFunction();
     18void myAdvancedFunction(int value);
     19
     20// Call myFunctionafter 5 seconds
     21StaticTimer myTimer(5.0f, false, createExecutor(createFunctor(&myFunction)));
     22
     23// Call myAdvancedFunction(10) after 3 seconds
     24ExectorStatic* executor = createExecutor(createFunctor(&myAdvancedFunction));
     25executor->setDefaultValue(0, 10.0f); // Bind the value
     26StaticTimer myAdvancedTimer(3.0f, false, executor);
     27}}}
     28
     29See [wiki:Executor#DefaultValues] for more information on how to find values.
     30
     31== Member functions ==
     32For member functions you additionally have to add the object:
     33 * '''StaticTimer('''''interval, bLoop, object, executor''''')'''
     34 * '''setTimer('''''interval, bLoop, object, executor''''')'''
     35''interval'', ''bLoop'' and ''executor'' are like in StaticTimer (except executor has to be an ExecutorMember).[[br]]
     36''object'' the object on which to call the function.
     37
     38{{{
     39#include "tools/Timer.h"
     40
     41class MyClass
     42{
     43    void myFunction();
     44};
     45
     46// Create an instance of MyClass:
     47MyClass* object = new MyClass();
     48
     49// Call MyClass::myFunctionafter after 5 seconds
     50Timer myTimer(5.0f, false, object, createExecutor(createFunctor(&MyClass::myFunction)));
     51}}}