Implemented #2556: don't send tile NBT updates until the end of tick

this eliminates spam when tile spawn NBT changes a lot during a tick, for example the lines of a sign being updated.

closes #2556
This commit is contained in:
Dylan K. Taylor 2018-12-26 22:18:47 +00:00
parent 2c6381632c
commit a6cd9ae029
3 changed files with 30 additions and 21 deletions

View File

@ -798,6 +798,12 @@ class Level implements ChunkManager, Metadatable{
if(!$tile->onUpdate()){ if(!$tile->onUpdate()){
unset($this->updateTiles[$blockHash]); unset($this->updateTiles[$blockHash]);
} }
if(!$tile->isClosed() and $tile instanceof Spawnable and $tile->isDirty()){
$this->clearChunkCache($tile->getFloorX() >> 4, $tile->getFloorZ() >> 4);
//TODO: merge this with block-updating (it'll send useless data if a full-chunk resend happens)
$this->broadcastPacketToViewers($tile, $tile->createSpawnPacket());
$tile->setDirty(false);
}
} }
Timings::$tickTileEntityTimer->stopTiming(); Timings::$tickTileEntityTimer->stopTiming();
$this->timings->tileEntityTick->stopTiming(); $this->timings->tileEntityTick->stopTiming();
@ -2587,10 +2593,6 @@ class Level implements ChunkManager, Metadatable{
$this->tiles[Level::blockHash($tile->x, $tile->y, $tile->z)] = $tile; $this->tiles[Level::blockHash($tile->x, $tile->y, $tile->z)] = $tile;
$tile->scheduleUpdate(); $tile->scheduleUpdate();
if($tile instanceof Spawnable){
$this->clearChunkCache($chunkX, $chunkZ);
$tile->spawnToAll();
}
} }
/** /**

View File

@ -88,17 +88,14 @@ class Sign extends Spawnable{
/** /**
* @param int $index 0-3 * @param int $index 0-3
* @param string $line * @param string $line
* @param bool $update
*/ */
public function setLine(int $index, string $line, bool $update = true) : void{ public function setLine(int $index, string $line) : void{
if($index < 0 or $index > 3){ if($index < 0 or $index > 3){
throw new \InvalidArgumentException("Index must be in the range 0-3!"); throw new \InvalidArgumentException("Index must be in the range 0-3!");
} }
$this->text[$index] = $line; $this->text[$index] = $line;
if($update){ $this->onChanged();
$this->onChanged();
}
} }
/** /**

View File

@ -33,6 +33,9 @@ use pocketmine\Player;
abstract class Spawnable extends Tile{ abstract class Spawnable extends Tile{
/** @var string|null */ /** @var string|null */
private $spawnCompoundCache = null; private $spawnCompoundCache = null;
/** @var bool */
private $dirty = true; //default dirty, until it's been spawned appropriately on the level
/** @var NetworkLittleEndianNBTStream|null */ /** @var NetworkLittleEndianNBTStream|null */
private static $nbtWriter = null; private static $nbtWriter = null;
@ -56,23 +59,30 @@ abstract class Spawnable extends Tile{
return true; return true;
} }
public function spawnToAll(){
if($this->closed){
return;
}
$this->level->broadcastPacketToViewers($this, $this->createSpawnPacket());
}
/** /**
* Performs actions needed when the tile is modified, such as clearing caches and respawning the tile to players. * Flags the tile as modified, so that updates will be broadcasted at the next available opportunity.
* WARNING: This MUST be called to clear spawn-compound and chunk caches when the tile's spawn compound has changed! * This MUST be called any time a change is made that players must be able to see.
*/ */
protected function onChanged() : void{ protected function onChanged() : void{
$this->spawnCompoundCache = null; $this->spawnCompoundCache = null;
$this->spawnToAll(); $this->dirty = true;
$this->scheduleUpdate();
}
$this->level->clearChunkCache($this->getFloorX() >> 4, $this->getFloorZ() >> 4); /**
* Returns whether the tile needs to be respawned to viewers.
*
* @return bool
*/
public function isDirty() : bool{
return $this->dirty;
}
/**
* @param bool $dirty
*/
public function setDirty(bool $dirty = true) : void{
$this->dirty = $dirty;
} }
/** /**