TPS measurement improvement, moved interface handling to tick

This commit is contained in:
Shoghi Cervantes 2014-09-09 18:07:27 +02:00
parent 317c6788a6
commit 57373b8c5e
2 changed files with 13 additions and 20 deletions

View File

@ -127,8 +127,7 @@ class Server{
*/ */
private $tickCounter; private $tickCounter;
private $nextTick = 0; private $nextTick = 0;
private $tickAverage = [20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20]; private $tickAverage = [20,20,20,20,20,20,20,20,20,20];
private $tickTime = 0;
private $inTick = false; private $inTick = false;
/** @var \AttachableThreadedLogger */ /** @var \AttachableThreadedLogger */
@ -1928,19 +1927,7 @@ class Server{
private function tickProcessor(){ private function tickProcessor(){
$lastLoop = 0; $lastLoop = 0;
$connectionTimer = Timings::$connectionTimer;
while($this->isRunning){ while($this->isRunning){
//TODO: move this to tick
$connectionTimer->startTiming();
foreach($this->interfaces as $interface){
if($interface->process()){
$lastLoop = 0;
}
}
$connectionTimer->stopTiming();
$this->generationManager->handlePackets();
++$lastLoop; ++$lastLoop;
if(($ticks = $this->tick()) !== true){ if(($ticks = $this->tick()) !== true){
@ -2045,6 +2032,14 @@ class Server{
++$this->tickCounter; ++$this->tickCounter;
$this->checkConsole(); $this->checkConsole();
//TODO: move this to tick
Timings::$connectionTimer->startTiming();
foreach($this->interfaces as $interface){
$interface->process();
}
Timings::$connectionTimer->stopTiming();
Timings::$schedulerTimer->startTiming(); Timings::$schedulerTimer->startTiming();
$this->scheduler->mainThreadHeartbeat($this->tickCounter); $this->scheduler->mainThreadHeartbeat($this->tickCounter);
Timings::$schedulerTimer->stopTiming(); Timings::$schedulerTimer->stopTiming();
@ -2057,17 +2052,15 @@ class Server{
} }
} }
$this->generationManager->handlePackets();
Timings::$serverTickTimer->stopTiming(); Timings::$serverTickTimer->stopTiming();
TimingsHandler::tick(); TimingsHandler::tick();
$now = microtime(true); $now = microtime(true);
$updateTime = max(0.01, $tickTime - $this->tickTime);
array_shift($this->tickAverage); array_shift($this->tickAverage);
$this->tickAverage[] = 1 / $updateTime; $this->tickAverage[] = min(20, 1 / ($now - $tickTime));
$this->tickTime = $tickTime;
if(($this->nextTick - $tickTime) < -1){ if(($this->nextTick - $tickTime) < -1){
$this->nextTick = $tickTime; $this->nextTick = $tickTime;

View File

@ -934,7 +934,7 @@ class Level implements ChunkManager, Metadatable{
new Double("", $source->getY()), new Double("", $source->getY()),
new Double("", $source->getZ()) new Double("", $source->getZ())
]), ]),
//TODO: add random motion with physics
"Motion" => new Enum("Motion", [ "Motion" => new Enum("Motion", [
new Double("", $motion->x), new Double("", $motion->x),
new Double("", $motion->y), new Double("", $motion->y),