Changes between Version 1 and Version 2 of code/doc/Timer
- Timestamp:
- Feb 28, 2008, 1:10:37 AM (17 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
code/doc/Timer
v1 v2 3 3 == Description == 4 4 5 5 The [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 8 void SomeClass::function(void); 9 }}} 10 The [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). 6 11 7 12 == Functions == 8 13 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. 9 17 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. 10 23 11 24 == Example == 12 25 26 Definition of a class with timer: 27 {{{ 28 #!cpp 29 class MyClass 30 { 31 public: 32 MyClass(); 13 33 34 private: 35 void beep(); 36 Timer<MyClass> timer_; 37 }; 38 }}} 39 40 Implementation of the class with timer: 41 {{{ 42 #!cpp 43 MyClass::MyClass() 44 { 45 std::cout << "Created MyClass." << std::endl; 46 this->timer_.setTimer(3.0, true, this, &MyClass::beep); 47 } 48 49 void MyClass::beep() 50 { 51 std::cout << "beep!" << std::endl; 52 } 53 }}} 54 55 Output: One "beep!" every 3 seconds 56 {{{ 57 Created MyClass. 58 beep! 59 beep! 60 beep! 61 beep! 62 beep! 63 beep! 64 beep! 65 beep! 66 beep! 67 ... 68 }}}