mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +00:00
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:
parent
bdce781c6d
commit
5a14c1cb89
@ -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();
|
||||
}
|
||||
|
||||
|
@ -123,6 +123,8 @@ abstract class Living extends Entity{
|
||||
parent::initEntity($nbt);
|
||||
|
||||
$this->effectManager = new EffectManager($this);
|
||||
$this->effectManager->getEffectAddHooks()->add(function() : void{ $this->networkPropertiesDirty = true; });
|
||||
$this->effectManager->getEffectRemoveHooks()->add(function() : void{ $this->networkPropertiesDirty = true; });
|
||||
|
||||
$this->armorInventory = new ArmorInventory($this);
|
||||
//TODO: load/save armor inventory contents
|
||||
@ -208,6 +210,7 @@ abstract class Living extends Entity{
|
||||
|
||||
public function setSneaking(bool $value = true) : void{
|
||||
$this->sneaking = $value;
|
||||
$this->networkPropertiesDirty = true;
|
||||
}
|
||||
|
||||
public function isSprinting() : bool{
|
||||
@ -217,6 +220,7 @@ abstract class Living extends Entity{
|
||||
public function setSprinting(bool $value = true) : void{
|
||||
if($value !== $this->isSprinting()){
|
||||
$this->sprinting = $value;
|
||||
$this->networkPropertiesDirty = true;
|
||||
$moveSpeed = $this->getMovementSpeed();
|
||||
$this->setMovementSpeed($value ? ($moveSpeed * 1.3) : ($moveSpeed / 1.3));
|
||||
$this->moveSpeedAttr->markSynchronized(false); //TODO: reevaluate this hack
|
||||
@ -643,6 +647,7 @@ abstract class Living extends Entity{
|
||||
*/
|
||||
public function setBreathing(bool $value = true) : void{
|
||||
$this->breathing = $value;
|
||||
$this->networkPropertiesDirty = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -658,6 +663,7 @@ abstract class Living extends Entity{
|
||||
*/
|
||||
public function setAirSupplyTicks(int $ticks) : void{
|
||||
$this->breathTicks = $ticks;
|
||||
$this->networkPropertiesDirty = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -672,6 +678,7 @@ abstract class Living extends Entity{
|
||||
*/
|
||||
public function setMaxAirSupplyTicks(int $ticks) : void{
|
||||
$this->maxBreathTicks = $ticks;
|
||||
$this->networkPropertiesDirty = true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -76,6 +76,7 @@ class Villager extends Living implements Ageable{
|
||||
*/
|
||||
public function setProfession(int $profession) : void{
|
||||
$this->profession = $profession; //TODO: validation
|
||||
$this->networkPropertiesDirty = true;
|
||||
}
|
||||
|
||||
public function getProfession() : int{
|
||||
|
@ -137,6 +137,7 @@ class ExperienceOrb extends Entity{
|
||||
throw new \InvalidArgumentException("XP amount must be greater than 0, got $amount");
|
||||
}
|
||||
$this->xpValue = $amount;
|
||||
$this->networkPropertiesDirty = true;
|
||||
}
|
||||
|
||||
public function hasTargetPlayer() : bool{
|
||||
|
@ -62,11 +62,15 @@ class PrimedTNT extends Entity implements Explosive{
|
||||
throw new \InvalidArgumentException("Fuse must be in the range 0-32767");
|
||||
}
|
||||
$this->fuse = $fuse;
|
||||
$this->networkPropertiesDirty = true;
|
||||
}
|
||||
|
||||
public function worksUnderwater() : bool{ return $this->worksUnderwater; }
|
||||
|
||||
public function setWorksUnderwater(bool $worksUnderwater) : void{ $this->worksUnderwater = $worksUnderwater; }
|
||||
public function setWorksUnderwater(bool $worksUnderwater) : void{
|
||||
$this->worksUnderwater = $worksUnderwater;
|
||||
$this->networkPropertiesDirty = true;
|
||||
}
|
||||
|
||||
public function attack(EntityDamageEvent $source) : void{
|
||||
if($source->getCause() === EntityDamageEvent::CAUSE_VOID){
|
||||
|
@ -96,6 +96,7 @@ class Arrow extends Projectile{
|
||||
|
||||
public function setCritical(bool $value = true) : void{
|
||||
$this->critical = $value;
|
||||
$this->networkPropertiesDirty = true;
|
||||
}
|
||||
|
||||
public function getResultDamage() : int{
|
||||
|
@ -150,6 +150,7 @@ class SplashPotion extends Throwable{
|
||||
|
||||
public function setPotionId(int $id) : void{
|
||||
$this->potionId = $id; //TODO: validation
|
||||
$this->networkPropertiesDirty = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -164,6 +165,7 @@ class SplashPotion extends Throwable{
|
||||
*/
|
||||
public function setLinger(bool $value = true) : void{
|
||||
$this->linger = $value;
|
||||
$this->networkPropertiesDirty = true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -594,6 +594,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
||||
|
||||
public function setUsingItem(bool $value) : void{
|
||||
$this->startAction = $value ? $this->server->getTick() : -1;
|
||||
$this->networkPropertiesDirty = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -956,6 +957,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
||||
}
|
||||
|
||||
$this->sleeping = $pos;
|
||||
$this->networkPropertiesDirty = true;
|
||||
|
||||
$this->setSpawn($pos);
|
||||
|
||||
@ -974,6 +976,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
||||
(new PlayerBedLeaveEvent($this, $b))->call();
|
||||
|
||||
$this->sleeping = null;
|
||||
$this->networkPropertiesDirty = true;
|
||||
|
||||
$this->getWorld()->setSleepTicks(0);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user