Entity: don't rebuild metadata every tick unless an associated property changed

this should improve performance back to PM3 levels.
This commit is contained in:
Dylan K. Taylor
2021-05-17 20:05:52 +01:00
parent bdce781c6d
commit 5a14c1cb89
8 changed files with 42 additions and 3 deletions

View File

@ -184,6 +184,8 @@ abstract class Entity{
/** @var TimingsHandler */
protected $timings;
protected bool $networkPropertiesDirty = false;
/** @var string */
protected $nameTag = "";
/** @var bool */
@ -269,6 +271,7 @@ abstract class Entity{
public function setNameTag(string $name) : void{
$this->nameTag = $name;
$this->networkPropertiesDirty = true;
}
public function setNameTagVisible(bool $value = true) : void{
@ -277,6 +280,7 @@ abstract class Entity{
public function setNameTagAlwaysVisible(bool $value = true) : void{
$this->alwaysShowNameTag = $value;
$this->networkPropertiesDirty = true;
}
public function getScoreTag() : ?string{
@ -285,6 +289,7 @@ abstract class Entity{
public function setScoreTag(string $score) : void{
$this->scoreTag = $score;
$this->networkPropertiesDirty = true;
}
public function getScale() : float{
@ -300,6 +305,7 @@ abstract class Entity{
$this->scale = $value;
$this->recalculateBoundingBox();
$this->networkPropertiesDirty = true;
}
public function getBoundingBox() : AxisAlignedBB{
@ -325,6 +331,7 @@ abstract class Entity{
public function setImmobile(bool $value = true) : void{
$this->immobile = $value;
$this->networkPropertiesDirty = true;
}
public function isInvisible() : bool{
@ -333,6 +340,7 @@ abstract class Entity{
public function setInvisible(bool $value = true) : void{
$this->invisible = $value;
$this->networkPropertiesDirty = true;
}
public function isSilent() : bool{
@ -341,6 +349,7 @@ abstract class Entity{
public function setSilent(bool $value = true) : void{
$this->silent = $value;
$this->networkPropertiesDirty = true;
}
/**
@ -355,6 +364,7 @@ abstract class Entity{
*/
public function setCanClimb(bool $value = true) : void{
$this->canClimb = $value;
$this->networkPropertiesDirty = true;
}
/**
@ -369,6 +379,7 @@ abstract class Entity{
*/
public function setCanClimbWalls(bool $value = true) : void{
$this->canClimbWalls = $value;
$this->networkPropertiesDirty = true;
}
/**
@ -398,6 +409,7 @@ abstract class Entity{
}else{
$this->ownerId = $owner->getId();
}
$this->networkPropertiesDirty = true;
}
/**
@ -428,6 +440,7 @@ abstract class Entity{
}else{
$this->targetId = $target->getId();
}
$this->networkPropertiesDirty = true;
}
/**
@ -635,6 +648,7 @@ abstract class Entity{
if($ticks > $this->getFireTicks()){
$this->setFireTicks($ticks);
}
$this->networkPropertiesDirty = true;
}
public function getFireTicks() : int{
@ -1580,7 +1594,10 @@ abstract class Entity{
* @phpstan-return array<int, MetadataProperty>
*/
final protected function getDirtyNetworkData() : array{
$this->syncNetworkData($this->networkProperties);
if($this->networkPropertiesDirty){
$this->syncNetworkData($this->networkProperties);
$this->networkPropertiesDirty = false;
}
return $this->networkProperties->getDirty();
}
@ -1589,7 +1606,10 @@ abstract class Entity{
* @phpstan-return array<int, MetadataProperty>
*/
final protected function getAllNetworkData() : array{
$this->syncNetworkData($this->networkProperties);
if($this->networkPropertiesDirty){
$this->syncNetworkData($this->networkProperties);
$this->networkPropertiesDirty = false;
}
return $this->networkProperties->getAll();
}