Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changes between Version 1 and Version 2 of code/doc/Timer


Ignore:
Timestamp:
Feb 28, 2008, 1:10:37 AM (17 years ago)
Author:
landauf
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • code/doc/Timer

    v1 v2  
    33== Description ==
    44
    5 
     5The [wiki:Timer] calls a function after a specific amount of time. The function has to be a member-function of the following form:
     6{{{
     7#!cpp
     8void SomeClass::function(void);
     9}}}
     10The [wiki:Timer] allows you to call a function every ''xxx'' seconds (loop) or once after ''xxx'' seconds (no loop). You can stop and restart the [wiki:Timer] or pause/unpause it. In some cases the [wiki:Timer] can replace the [wiki:Tickable tick(dt)] function of an object or just simplify the process of waiting a specific amount of time befor doing some action (for example if you want to delete an object after 10 seconds).
    611
    712== Functions ==
    813
     14 * '''Creation''':
     15   * '''Timer('''''interval''''', '''''bLoop''''', '''''object''''', '''''timerFunction''''')''': The constructor creates a new [wiki:Timer] that calls the ''timerFunction'' of ''object'' after ''interval'' seconds and loops if ''bLoop'' is true.
     16   * '''setTimer('''''interval''''', '''''bLoop''''', '''''object''''', '''''timerFunction''''')''': Does exactly the same like the constructor.
    917
     18 * '''Manipulation''':
     19   * '''startTimer()''': (Re)starts the timer.
     20   * '''stopTimer()''': Stops the timer. You can activate it againg by restarting it.
     21   * '''pauseTimer()''': Pauses the timer - the current state gets saved, unpausing is possible.
     22   * '''unpauseTimer()''': Unpauses the timer - it continuous with the saved state.
    1023
    1124== Example ==
    1225
     26Definition of a class with timer:
     27{{{
     28#!cpp
     29class MyClass
     30{
     31  public:
     32    MyClass();
    1333
     34  private:
     35    void beep();
     36    Timer<MyClass> timer_;
     37};
     38}}}
     39
     40Implementation of the class with timer:
     41{{{
     42#!cpp
     43MyClass::MyClass()
     44{
     45  std::cout << "Created MyClass." << std::endl;
     46  this->timer_.setTimer(3.0, true, this, &MyClass::beep);
     47}
     48
     49void MyClass::beep()
     50{
     51  std::cout << "beep!" << std::endl;
     52}
     53}}}
     54
     55Output: One "beep!" every 3 seconds
     56{{{
     57Created MyClass.
     58beep!
     59beep!
     60beep!
     61beep!
     62beep!
     63beep!
     64beep!
     65beep!
     66beep!
     67...
     68}}}