Fixed Server::getTicksPerSecond()

This commit is contained in:
Shoghi Cervantes 2014-09-04 12:22:16 +02:00
parent 352497d88c
commit 9980a0780a

View File

@ -127,7 +127,7 @@ class Server{
*/ */
private $tickCounter; private $tickCounter;
private $nextTick = 0; private $nextTick = 0;
private $tickMeasure = 20; private $tickAverage = [20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20];
private $tickTime = 0; private $tickTime = 0;
private $inTick = false; private $inTick = false;
@ -536,7 +536,7 @@ class Server{
* @return float * @return float
*/ */
public function getTicksPerSecond(){ public function getTicksPerSecond(){
return round((0.05 / $this->tickMeasure) * 20, 2); return round(array_sum($this->tickAverage) / count($this->tickAverage), 2);
} }
/** /**
@ -2061,10 +2061,17 @@ class Server{
TimingsHandler::tick(); TimingsHandler::tick();
$time = microtime(true); $updateTime = $tickTime - $this->tickTime;
$this->tickMeasure = ($tickTime - $this->tickTime);
$this->tickTime = $time; array_shift($this->tickAverage);
$this->nextTick = $tickTime + 0.05; $this->tickAverage[] = 1 / $updateTime;
$this->tickTime = $tickTime;
if(($this->nextTick - $tickTime) < -1){
$this->nextTick = $tickTime;
}
$this->nextTick += 0.05;
$this->inTick = false; $this->inTick = false;
return true; return true;