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() { public function manageTimings() {
$time = microtime(true); $time = microtime(true);
foreach($this->timerListenings as $key => &$listening) { foreach($this->timerListenings as $key => &$listening) {
if (($listening->lastTrigger + $listening->deltaTime) <= $time) { 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 //Unregister one time Listening
if ($listening->oneTime == true) { if ($listening->oneTime == true) {
unset($this->timerListenings[$key]); unset($this->timerListenings[$key]);
continue;
} }
if ($listening->lastTrigger != -1) { //Call the User func (at the end to avoid endless loops)
$listening->lastTrigger += $listening->deltaTime; call_user_func(array($listening->listener, $listening->method), $time);
} else {
//Initial Time Initialize (self increment needed to improve accuracy)
$listening->lastTrigger = microtime(true);
}
} }
} }
} }