Added cache for tile spawn compounds

avoids expensive repetetive NBT writes on chunk sends when the tile hasn't been changed
This commit is contained in:
Dylan K. Taylor
2017-10-27 10:23:37 +01:00
parent 52d0ad8a61
commit 48fefae920
3 changed files with 33 additions and 17 deletions

View File

@ -29,7 +29,6 @@ namespace pocketmine\level\format;
use pocketmine\block\BlockFactory;
use pocketmine\entity\Entity;
use pocketmine\level\Level;
use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\Player;
use pocketmine\tile\Spawnable;
@ -939,16 +938,10 @@ class Chunk{
}
$result .= $extraData->getBuffer();
if(count($this->tiles) > 0){
$nbt = new NBT(NBT::LITTLE_ENDIAN);
$list = [];
foreach($this->tiles as $tile){
if($tile instanceof Spawnable){
$list[] = $tile->getSpawnCompound();
}
foreach($this->tiles as $tile){
if($tile instanceof Spawnable){
$result .= $tile->getSerializedSpawnCompound();
}
$nbt->setData($list);
$result .= $nbt->write(true);
}
return $result;

View File

@ -25,7 +25,6 @@ namespace pocketmine\level\format\io;
use pocketmine\level\format\Chunk;
use pocketmine\level\Level;
use pocketmine\nbt\NBT;
use pocketmine\network\mcpe\protocol\BatchPacket;
use pocketmine\network\mcpe\protocol\FullChunkDataPacket;
use pocketmine\scheduler\AsyncTask;
@ -54,11 +53,9 @@ class ChunkRequestTask extends AsyncTask{
//TODO: serialize tiles with chunks
$tiles = "";
$nbt = new NBT(NBT::LITTLE_ENDIAN);
foreach($chunk->getTiles() as $tile){
if($tile instanceof Spawnable){
$nbt->setData($tile->getSpawnCompound());
$tiles .= $nbt->write(true);
$tiles .= $tile->getSerializedSpawnCompound();
}
}