mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-11 22:15:30 +00:00
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:
parent
2c6381632c
commit
a6cd9ae029
@ -798,6 +798,12 @@ class Level implements ChunkManager, Metadatable{
|
||||
if(!$tile->onUpdate()){
|
||||
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();
|
||||
$this->timings->tileEntityTick->stopTiming();
|
||||
@ -2587,10 +2593,6 @@ class Level implements ChunkManager, Metadatable{
|
||||
|
||||
$this->tiles[Level::blockHash($tile->x, $tile->y, $tile->z)] = $tile;
|
||||
$tile->scheduleUpdate();
|
||||
if($tile instanceof Spawnable){
|
||||
$this->clearChunkCache($chunkX, $chunkZ);
|
||||
$tile->spawnToAll();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -88,17 +88,14 @@ class Sign extends Spawnable{
|
||||
/**
|
||||
* @param int $index 0-3
|
||||
* @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){
|
||||
throw new \InvalidArgumentException("Index must be in the range 0-3!");
|
||||
}
|
||||
|
||||
$this->text[$index] = $line;
|
||||
if($update){
|
||||
$this->onChanged();
|
||||
}
|
||||
$this->onChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -33,6 +33,9 @@ use pocketmine\Player;
|
||||
abstract class Spawnable extends Tile{
|
||||
/** @var string|null */
|
||||
private $spawnCompoundCache = null;
|
||||
/** @var bool */
|
||||
private $dirty = true; //default dirty, until it's been spawned appropriately on the level
|
||||
|
||||
/** @var NetworkLittleEndianNBTStream|null */
|
||||
private static $nbtWriter = null;
|
||||
|
||||
@ -56,23 +59,30 @@ abstract class Spawnable extends Tile{
|
||||
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.
|
||||
* WARNING: This MUST be called to clear spawn-compound and chunk caches when the tile's spawn compound has changed!
|
||||
* Flags the tile as modified, so that updates will be broadcasted at the next available opportunity.
|
||||
* This MUST be called any time a change is made that players must be able to see.
|
||||
*/
|
||||
protected function onChanged() : void{
|
||||
$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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user