Faster generation, ticks catch up when slower

This commit is contained in:
Shoghi Cervantes
2014-06-15 16:54:28 +02:00
parent ed5325c069
commit e6224be46f
3 changed files with 5 additions and 4 deletions

View File

@ -63,7 +63,7 @@ class TickScheduler extends \Thread{
public function run(){
$tickTime = microtime(true);
$this->hasTick = true;
$this->tickMeasure = $this->sleepTime;
while(true){
$this->synchronized(function (){
$this->hasTick = true;
@ -73,7 +73,8 @@ class TickScheduler extends \Thread{
$this->tickMeasure = (int) ((($time = microtime(true)) - $tickTime) * 1000000);
$tickTime = $time;
usleep($this->sleepTime - 100); //Remove a few ms for processing
$sleepTime = $this->sleepTime * ($this->sleepTime / max($this->sleepTime, $this->tickMeasure));
usleep($sleepTime - 100); //Remove a few ms for processing
}
}
}