Split player into more methods, added extra timings

This commit is contained in:
Shoghi Cervantes 2015-06-05 00:19:31 +02:00
parent 188f4d7778
commit d542dfc2ce
No known key found for this signature in database
GPG Key ID: 78464DB0A7837F89
4 changed files with 115 additions and 66 deletions

View File

@ -661,6 +661,8 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
return; return;
} }
Timings::$playerChunkSendTimer->startTiming();
$count = 0; $count = 0;
foreach($this->loadQueue as $index => $distance){ foreach($this->loadQueue as $index => $distance){
if($count >= $this->chunksPerTick){ if($count >= $this->chunksPerTick){
@ -674,7 +676,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
++$count; ++$count;
$this->usedChunks[$index] = false; $this->usedChunks[$index] = false;
$this->level->registerChunkLoader($this, $X, $Z); $this->level->registerChunkLoader($this, $X, $Z, false);
if(!$this->level->populateChunk($X, $Z)){ if(!$this->level->populateChunk($X, $Z)){
if($this->spawned and $this->teleportPosition === null){ if($this->spawned and $this->teleportPosition === null){
@ -689,6 +691,13 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
} }
if($this->chunkLoadCount >= $this->spawnThreshold and $this->spawned === false and $this->teleportPosition === null){ if($this->chunkLoadCount >= $this->spawnThreshold and $this->spawned === false and $this->teleportPosition === null){
$this->doFirstSpawn();
}
Timings::$playerChunkSendTimer->stopTiming();
}
protected function doFirstSpawn(){
$this->spawned = true; $this->spawned = true;
$this->sendSettings(); $this->sendSettings();
@ -755,13 +764,14 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$this->dataPacket($pk->setChannel(Network::CHANNEL_WORLD_EVENTS)); $this->dataPacket($pk->setChannel(Network::CHANNEL_WORLD_EVENTS));
} }
} }
}
protected function orderChunks(){ protected function orderChunks(){
if($this->connected === false){ if($this->connected === false){
return false; return false;
} }
Timings::$playerChunkOrderTimer->startTiming();
$this->nextChunkOrderRun = 200; $this->nextChunkOrderRun = 200;
$viewDistance = $this->server->getMemoryManager()->getViewDistance($this->viewDistance); $viewDistance = $this->server->getMemoryManager()->getViewDistance($this->viewDistance);
@ -823,6 +833,9 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$this->loadQueue = $newOrder; $this->loadQueue = $newOrder;
Timings::$playerChunkOrderTimer->stopTiming();
return true; return true;
} }
@ -837,8 +850,11 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
if($this->connected === false){ if($this->connected === false){
return false; return false;
} }
Timings::$playerNetworkTimer->startTiming();
$this->server->getPluginManager()->callEvent($ev = new DataPacketSendEvent($this, $packet)); $this->server->getPluginManager()->callEvent($ev = new DataPacketSendEvent($this, $packet));
if($ev->isCancelled()){ if($ev->isCancelled()){
Timings::$playerNetworkTimer->stopTiming();
return false; return false;
} }
@ -847,7 +863,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
} }
$this->batchedPackets[$packet->getChannel()][] = clone $packet; $this->batchedPackets[$packet->getChannel()][] = clone $packet;
Timings::$playerNetworkTimer->stopTiming();
return true; return true;
} }
@ -863,9 +879,11 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
if($this->connected === false){ if($this->connected === false){
return false; return false;
} }
Timings::$playerNetworkTimer->startTiming();
$this->server->getPluginManager()->callEvent($ev = new DataPacketSendEvent($this, $packet)); $this->server->getPluginManager()->callEvent($ev = new DataPacketSendEvent($this, $packet));
if($ev->isCancelled()){ if($ev->isCancelled()){
Timings::$playerNetworkTimer->stopTiming();
return false; return false;
} }
@ -874,9 +892,11 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
if($needACK and $identifier !== null){ if($needACK and $identifier !== null){
$this->needACK[$identifier] = false; $this->needACK[$identifier] = false;
Timings::$playerNetworkTimer->stopTiming();
return $identifier; return $identifier;
} }
Timings::$playerNetworkTimer->stopTiming();
return true; return true;
} }
@ -890,8 +910,11 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
if($this->connected === false){ if($this->connected === false){
return false; return false;
} }
Timings::$playerNetworkTimer->startTiming();
$this->server->getPluginManager()->callEvent($ev = new DataPacketSendEvent($this, $packet)); $this->server->getPluginManager()->callEvent($ev = new DataPacketSendEvent($this, $packet));
if($ev->isCancelled()){ if($ev->isCancelled()){
Timings::$playerNetworkTimer->stopTiming();
return false; return false;
} }
@ -900,9 +923,11 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
if($needACK and $identifier !== null){ if($needACK and $identifier !== null){
$this->needACK[$identifier] = false; $this->needACK[$identifier] = false;
Timings::$playerNetworkTimer->stopTiming();
return $identifier; return $identifier;
} }
Timings::$playerNetworkTimer->stopTiming();
return true; return true;
} }
@ -1283,12 +1308,12 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$revert = true; $revert = true;
}else{ }else{
if($this->chunk === null or !$this->chunk->isGenerated()){ if($this->chunk === null or !$this->chunk->isGenerated()){
$chunk = $this->level->getChunk($newPos->x >> 4, $newPos->z >> 4); $chunk = $this->level->getChunk($newPos->x >> 4, $newPos->z >> 4, false);
if(!($chunk instanceof FullChunk) or !$chunk->isGenerated()){ if($chunk === null or !$chunk->isGenerated()){
$revert = true; $revert = true;
$this->nextChunkOrderRun = 0; $this->nextChunkOrderRun = 0;
}else{ }else{
if($this->chunk instanceof FullChunk){ if($this->chunk !== null){
$this->chunk->removeEntity($this); $this->chunk->removeEntity($this);
} }
$this->chunk = $chunk; $this->chunk = $chunk;
@ -1458,6 +1483,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
if($this->inAirTicks < 100){ if($this->inAirTicks < 100){
$this->setMotion(new Vector3(0, $expectedVelocity, 0)); $this->setMotion(new Vector3(0, $expectedVelocity, 0));
}elseif($this->kick("Flying is not enabled on this server")){ }elseif($this->kick("Flying is not enabled on this server")){
$this->timings->stopTiming();
return false; return false;
} }
} }
@ -1468,6 +1494,18 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
} }
} }
$this->checkTeleportPosition();
$this->timings->stopTiming();
return true;
}
public function checkNetwork(){
if(!$this->isOnline()){
return;
}
if($this->nextChunkOrderRun-- <= 0 or $this->chunk === null){ if($this->nextChunkOrderRun-- <= 0 or $this->chunk === null){
$this->orderChunks(); $this->orderChunks();
} }
@ -1496,11 +1534,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$this->batchedPackets = []; $this->batchedPackets = [];
} }
$this->checkTeleportPosition();
$this->timings->stopTiming();
return true;
} }
public function canInteract(Vector3 $pos, $maxDistance, $maxDiff = 0.5){ public function canInteract(Vector3 $pos, $maxDistance, $maxDiff = 0.5){

View File

@ -1895,6 +1895,7 @@ class Server{
* @param int $channel * @param int $channel
*/ */
public function batchPackets(array $players, array $packets, $forceSync = false, $channel = 0){ public function batchPackets(array $players, array $packets, $forceSync = false, $channel = 0){
Timings::$playerNetworkTimer->startTiming();
$str = ""; $str = "";
foreach($packets as $p){ foreach($packets as $p){
@ -1921,6 +1922,8 @@ class Server{
}else{ }else{
$this->broadcastPacketsCallback(zlib_encode($str, ZLIB_ENCODING_DEFLATE, $this->networkCompressionLevel), $targets, $channel); $this->broadcastPacketsCallback(zlib_encode($str, ZLIB_ENCODING_DEFLATE, $this->networkCompressionLevel), $targets, $channel);
} }
Timings::$playerNetworkTimer->stopTiming();
} }
public function broadcastPacketsCallback($data, array $identifiers, $channel = 0){ public function broadcastPacketsCallback($data, array $identifiers, $channel = 0){

View File

@ -39,6 +39,12 @@ abstract class Timings{
/** @var TimingsHandler */ /** @var TimingsHandler */
public static $playerListTimer; public static $playerListTimer;
/** @var TimingsHandler */ /** @var TimingsHandler */
public static $playerNetworkTimer;
/** @var TimingsHandler */
public static $playerChunkOrderTimer;
/** @var TimingsHandler */
public static $playerChunkSendTimer;
/** @var TimingsHandler */
public static $connectionTimer; public static $connectionTimer;
/** @var TimingsHandler */ /** @var TimingsHandler */
public static $tickablesTimer; public static $tickablesTimer;
@ -109,6 +115,9 @@ abstract class Timings{
self::$memoryManagerTimer = new TimingsHandler("Memory Manager"); self::$memoryManagerTimer = new TimingsHandler("Memory Manager");
self::$garbageCollectorTimer = new TimingsHandler("Garbage Collector", self::$memoryManagerTimer); self::$garbageCollectorTimer = new TimingsHandler("Garbage Collector", self::$memoryManagerTimer);
self::$playerListTimer = new TimingsHandler("Player List"); self::$playerListTimer = new TimingsHandler("Player List");
self::$playerNetworkTimer = new TimingsHandler("Player Network");
self::$playerChunkOrderTimer = new TimingsHandler("Player Order Chunks");
self::$playerChunkSendTimer = new TimingsHandler("Player Send Chunks");
self::$connectionTimer = new TimingsHandler("Connection Handler"); self::$connectionTimer = new TimingsHandler("Connection Handler");
self::$tickablesTimer = new TimingsHandler("Tickables"); self::$tickablesTimer = new TimingsHandler("Tickables");
self::$schedulerTimer = new TimingsHandler("Scheduler"); self::$schedulerTimer = new TimingsHandler("Scheduler");

View File

@ -662,6 +662,10 @@ class Level implements ChunkManager, Metadatable{
Timings::$tickEntityTimer->stopTiming(); Timings::$tickEntityTimer->stopTiming();
$this->timings->entityTick->stopTiming(); $this->timings->entityTick->stopTiming();
foreach($this->players as $player){
$player->checkNetwork();
}
$this->timings->tileEntityTick->startTiming(); $this->timings->tileEntityTick->startTiming();
Timings::$tickTileEntityTimer->startTiming(); Timings::$tickTileEntityTimer->startTiming();
//Update tiles that need update //Update tiles that need update
@ -1697,7 +1701,7 @@ class Level implements ChunkManager, Metadatable{
for($x = $minX; $x <= $maxX; ++$x){ for($x = $minX; $x <= $maxX; ++$x){
for($z = $minZ; $z <= $maxZ; ++$z){ for($z = $minZ; $z <= $maxZ; ++$z){
foreach($this->getChunkEntities($x, $z) as $ent){ foreach($this->getChunkEntities($x, $z) as $ent){
if($ent !== $entity and ($entity === null or $entity->canCollideWith($ent)) and $ent->boundingBox->intersectsWith($bb)){ if(($entity === null or ($ent !== $entity and $ent->canCollideWith($entity))) and $ent->boundingBox->intersectsWith($bb)){
$nearby[] = $ent; $nearby[] = $ent;
} }
} }