Added individual object timings to Entities / Tile Entities

This commit is contained in:
Shoghi Cervantes 2014-09-30 16:09:21 +02:00
parent f8378c09ba
commit 539fa232f8
8 changed files with 167 additions and 121 deletions

View File

@ -1167,6 +1167,8 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
return true; return true;
} }
$this->timings->startTiming();
$this->processMovement(); $this->processMovement();
$hasUpdate = $this->entityBaseTick(); $hasUpdate = $this->entityBaseTick();
@ -1232,6 +1234,8 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
} }
} }
$this->timings->stopTiming();
return true; return true;
} }

View File

@ -65,12 +65,16 @@ class Arrow extends Projectile{
} }
public function onUpdate(){ public function onUpdate(){
$this->entityBaseTick(); if($this->closed){
if($this->closed !== false){
return false; return false;
} }
$this->timings->startTiming();
$this->entityBaseTick();
if(!$this->dead){
$movingObjectPosition = null; $movingObjectPosition = null;
$this->motionY -= $this->gravity; $this->motionY -= $this->gravity;
@ -85,7 +89,9 @@ class Arrow extends Projectile{
$nearEntity = null; $nearEntity = null;
foreach($list as $entity){ foreach($list as $entity){
if(/*!$entity->canCollideWith($this) or */($entity === $this->shootingEntity and $this->ticksLived < 5)){ if(/*!$entity->canCollideWith($this) or */
($entity === $this->shootingEntity and $this->ticksLived < 5)
){
continue; continue;
} }
@ -147,6 +153,10 @@ class Arrow extends Projectile{
} }
$this->updateMovement(); $this->updateMovement();
}
$this->timings->stopTiming();
return !$this->onGround or ($this->motionX == 0 and $this->motionY == 0 and $this->motionZ == 0); return !$this->onGround or ($this->motionX == 0 and $this->motionY == 0 and $this->motionZ == 0);
} }

View File

@ -66,12 +66,16 @@ class DroppedItem extends Entity{
} }
public function onUpdate(){ public function onUpdate(){
$this->entityBaseTick();
if($this->closed !== false){ if($this->closed !== false){
return false; return false;
} }
$this->timings->startTiming();
$this->entityBaseTick();
if(!$this->dead){
if($this->pickupDelay > 0 and $this->pickupDelay < 32767){ //Infinite delay if($this->pickupDelay > 0 and $this->pickupDelay < 32767){ //Infinite delay
--$this->pickupDelay; --$this->pickupDelay;
} }
@ -100,6 +104,9 @@ class DroppedItem extends Entity{
} }
$this->updateMovement(); $this->updateMovement();
}
$this->timings->stopTiming();
return !$this->onGround or ($this->motionX == 0 and $this->motionY == 0 and $this->motionZ == 0); return !$this->onGround or ($this->motionX == 0 and $this->motionY == 0 and $this->motionZ == 0);
} }

View File

@ -152,12 +152,17 @@ abstract class Entity extends Position implements Metadatable{
public $closed = false; public $closed = false;
/** @var \pocketmine\event\TimingsHandler */
protected $timings;
public function __construct(FullChunk $chunk, Compound $nbt){ public function __construct(FullChunk $chunk, Compound $nbt){
if($chunk === null or $chunk->getProvider() === null){ if($chunk === null or $chunk->getProvider() === null){
throw new \Exception("Invalid garbage Chunk given to Entity"); throw new \Exception("Invalid garbage Chunk given to Entity");
} }
$this->timings = Timings::getEntityTimings($this);
if($this->eyeHeight === null){ if($this->eyeHeight === null){
$this->eyeHeight = $this->height; $this->eyeHeight = $this->height;
} }
@ -533,7 +538,7 @@ abstract class Entity extends Position implements Metadatable{
} }
foreach($this->hasSpawned as $player){ foreach($this->hasSpawned as $player){
$player->directDataPacket($pk); $player->dataPacket($pk);
} }
} }
@ -575,11 +580,14 @@ abstract class Entity extends Position implements Metadatable{
if($this->closed !== false){ if($this->closed !== false){
return false; return false;
} }
$this->timings->startTiming();
$hasUpdate = $this->entityBaseTick(); $hasUpdate = $this->entityBaseTick();
$this->updateMovement(); $this->updateMovement();
$this->timings->stopTiming();
//if($this->isStatic()) //if($this->isStatic())
return true; return true;
//return !($this instanceof Player); //return !($this instanceof Player);

View File

@ -63,12 +63,16 @@ class FallingBlock extends Entity{
} }
public function onUpdate(){ public function onUpdate(){
$this->entityBaseTick();
if($this->closed or $this->dead){ if($this->closed){
return false; return false;
} }
$this->timings->startTiming();
$this->entityBaseTick();
if(!$this->dead){
if($this->ticksLived === 1){ if($this->ticksLived === 1){
$block = $this->level->getBlock($this->floor()); $block = $this->level->getBlock($this->floor());
if($block->getID() != $this->blockId){ if($block->getID() != $this->blockId){
@ -102,6 +106,8 @@ class FallingBlock extends Entity{
} }
$this->updateMovement(); $this->updateMovement();
}
return !$this->onGround or ($this->motionX == 0 and $this->motionY == 0 and $this->motionZ == 0); return !$this->onGround or ($this->motionX == 0 and $this->motionY == 0 and $this->motionZ == 0);
} }

View File

@ -742,7 +742,11 @@ class Level implements ChunkManager, Metadatable{
* @return bool * @return bool
*/ */
public function isFullBlock(Vector3 $pos){ public function isFullBlock(Vector3 $pos){
if($pos instanceof Block){
$bb = $pos->getBoundingBox();
}else{
$bb = $this->getBlock($pos)->getBoundingBox(); $bb = $this->getBlock($pos)->getBoundingBox();
}
return $bb instanceof AxisAlignedBB and $bb->getAverageEdgeLength() >= 1; return $bb instanceof AxisAlignedBB and $bb->getAverageEdgeLength() >= 1;
} }

View File

@ -170,6 +170,8 @@ class Furnace extends Tile implements InventoryHolder, Container{
return false; return false;
} }
$this->timings->startTiming();
$ret = false; $ret = false;
$fuel = $this->inventory->getFuel(); $fuel = $this->inventory->getFuel();
@ -248,6 +250,8 @@ class Furnace extends Tile implements InventoryHolder, Container{
$this->lastUpdate = microtime(true); $this->lastUpdate = microtime(true);
$this->timings->stopTiming();
return $ret; return $ret;
} }
} }

View File

@ -54,6 +54,7 @@ abstract class Tile extends Position{
public $namedtag; public $namedtag;
protected $lastUpdate; protected $lastUpdate;
protected $server; protected $server;
protected $timings;
/** @var \pocketmine\event\TimingsHandler */ /** @var \pocketmine\event\TimingsHandler */
public $tickTimer; public $tickTimer;
@ -63,6 +64,8 @@ abstract class Tile extends Position{
throw new \Exception("Invalid garbage Chunk given to Tile"); throw new \Exception("Invalid garbage Chunk given to Tile");
} }
$this->timings = Timings::getTileEntityTimings($this);
$this->server = $chunk->getProvider()->getLevel()->getServer(); $this->server = $chunk->getProvider()->getLevel()->getServer();
$this->chunk = $chunk; $this->chunk = $chunk;
$this->setLevel($chunk->getProvider()->getLevel()); $this->setLevel($chunk->getProvider()->getLevel());