From dddc3e8407f021a37220c3f8076b75624c0c3e76 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 22 Oct 2019 21:55:18 +0100 Subject: [PATCH] FastChunkSerializer: remove legacy code, simplify encoding this is also faster than the old technique (theoretically). --- src/world/format/io/FastChunkSerializer.php | 26 ++++++++++----------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/world/format/io/FastChunkSerializer.php b/src/world/format/io/FastChunkSerializer.php index 66de12c80..0ab45ff76 100644 --- a/src/world/format/io/FastChunkSerializer.php +++ b/src/world/format/io/FastChunkSerializer.php @@ -60,32 +60,30 @@ final class FastChunkSerializer{ $stream->putByte(($chunk->isLightPopulated() ? 4 : 0) | ($chunk->isPopulated() ? 2 : 0) | ($chunk->isGenerated() ? 1 : 0)); if($chunk->isGenerated()){ //subchunks - $count = 0; - $subStream = new BinaryStream(); - foreach($chunk->getSubChunks() as $y => $subChunk){ - ++$count; + $subChunks = $chunk->getSubChunks(); + $count = $subChunks->count(); + $stream->putByte($count); - $subStream->putByte($y); + foreach($subChunks as $y => $subChunk){ + $stream->putByte($y); $layers = $subChunk->getBlockLayers(); - $subStream->putByte(count($subChunk->getBlockLayers())); + $stream->putByte(count($layers)); foreach($layers as $blocks){ $wordArray = $blocks->getWordArray(); $palette = $blocks->getPalette(); - $subStream->putByte($blocks->getBitsPerBlock()); - $subStream->put($wordArray); + $stream->putByte($blocks->getBitsPerBlock()); + $stream->put($wordArray); $serialPalette = pack("N*", ...$palette); - $subStream->putInt(strlen($serialPalette)); - $subStream->put($serialPalette); + $stream->putInt(strlen($serialPalette)); + $stream->put($serialPalette); } if($chunk->isLightPopulated()){ - $subStream->put($subChunk->getBlockSkyLightArray()->getData()); - $subStream->put($subChunk->getBlockLightArray()->getData()); + $stream->put($subChunk->getBlockSkyLightArray()->getData()); + $stream->put($subChunk->getBlockLightArray()->getData()); } } - $stream->putByte($count); - $stream->put($subStream->getBuffer()); //biomes $stream->put($chunk->getBiomeIdArray());