= Timer = [[TracNav(TracNav/TOC_Development)]] == Description == The [wiki:Timer] calls a function after a specific amount of time. The function has to be a member-function of the following form: {{{ #!cpp void SomeClass::function(void); }}} 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). == Functions == * '''Creation''': * '''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. * '''setTimer('''''interval''''', '''''bLoop''''', '''''object''''', '''''timerFunction''''')''': Does exactly the same like the constructor. * '''Manipulation''': * '''startTimer()''': (Re)starts the timer. * '''stopTimer()''': Stops the timer. You can activate it againg by restarting it. * '''pauseTimer()''': Pauses the timer - the current state gets saved, unpausing is possible. * '''unpauseTimer()''': Unpauses the timer - it continuous with the saved state. == Example == Definition of a class with timer: {{{ #!cpp class MyClass { public: MyClass(); private: void beep(); Timer timer_; }; }}} Implementation of the class with timer: {{{ #!cpp MyClass::MyClass() { std::cout << "Created MyClass." << std::endl; this->timer_.setTimer(3.0, true, this, &MyClass::beep); } void MyClass::beep() { std::cout << "beep!" << std::endl; } }}} Output: One "beep!" every 3 seconds {{{ Created MyClass. beep! beep! beep! beep! beep! beep! beep! beep! beep! ... }}}