let timer listenings be called right after start

This commit is contained in:
Steffen Schröder 2014-05-09 13:19:57 +02:00
parent f41cd5b8f1
commit 53df7353e5

View File

@ -18,6 +18,7 @@ class TimerListening {
public $deltaTime = null; public $deltaTime = null;
public $oneTime = null; public $oneTime = null;
public $lastTrigger = null; public $lastTrigger = null;
public $instantCall = null;
/** /**
* Construct a new Timer Listening * Construct a new Timer Listening
@ -25,13 +26,17 @@ class TimerListening {
* @param TimerListener $listener * @param TimerListener $listener
* @param string $method * @param string $method
* @param float $deltaTime * @param float $deltaTime
* @param bool $instantCall
*/ */
public function __construct(TimerListener $listener, $method, $deltaTime, $oneTime = false) { public function __construct(TimerListener $listener, $method, $deltaTime, $oneTime = false, $instantCall = true) {
$this->listener = $listener; $this->listener = $listener;
$this->method = $method; $this->method = $method;
$this->deltaTime = $deltaTime / 1000.; $this->deltaTime = $deltaTime / 1000.;
$this->lastTrigger = microtime(true);
$this->oneTime = (bool)$oneTime; $this->oneTime = (bool)$oneTime;
$this->instantCall = (bool)$instantCall;
if (!$this->instantCall) {
$this->lastTrigger = microtime(true);
}
} }
/** /**
@ -69,6 +74,9 @@ class TimerListening {
* @return bool * @return bool
*/ */
public function isTimeReached($time = null) { public function isTimeReached($time = null) {
if ($this->lastTrigger === null) {
return true;
}
if (!$time) { if (!$time) {
$time = microtime(true); $time = microtime(true);
} }