diff --git a/application/core/Callbacks/TimerManager.php b/application/core/Callbacks/TimerManager.php index a46c70e1..739bd18c 100644 --- a/application/core/Callbacks/TimerManager.php +++ b/application/core/Callbacks/TimerManager.php @@ -85,21 +85,23 @@ class TimerManager { public function manageTimings() { $time = microtime(true); foreach($this->timerListenings as $key => &$listening) { + if (($listening->lastTrigger + $listening->deltaTime) <= $time) { - call_user_func(array($listening->listener, $listening->method), $time); + //Increase the lastTrigger time manually (to improve accuracy) + if ($listening->lastTrigger != -1) { + $listening->lastTrigger += $listening->deltaTime; + } else { + //Initialize Timer + $listening->lastTrigger = $time; + } //Unregister one time Listening if ($listening->oneTime == true) { unset($this->timerListenings[$key]); - continue; } - if ($listening->lastTrigger != -1) { - $listening->lastTrigger += $listening->deltaTime; - } else { - //Initial Time Initialize (self increment needed to improve accuracy) - $listening->lastTrigger = microtime(true); - } + //Call the User func (at the end to avoid endless loops) + call_user_func(array($listening->listener, $listening->method), $time); } } }