small improvements timermanager

This commit is contained in:
kremsy 2014-01-31 00:41:10 +01:00 committed by Steffen Schröder
parent 1c0dd7e83d
commit 337e6e18f9

View File

@ -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);
}
}
}