FastChunkSerializer: remove legacy code, simplify encoding

this is also faster than the old technique (theoretically).
This commit is contained in:
Dylan K. Taylor 2019-10-22 21:55:18 +01:00
parent 02ff8d671b
commit dddc3e8407

View File

@ -60,32 +60,30 @@ final class FastChunkSerializer{
$stream->putByte(($chunk->isLightPopulated() ? 4 : 0) | ($chunk->isPopulated() ? 2 : 0) | ($chunk->isGenerated() ? 1 : 0)); $stream->putByte(($chunk->isLightPopulated() ? 4 : 0) | ($chunk->isPopulated() ? 2 : 0) | ($chunk->isGenerated() ? 1 : 0));
if($chunk->isGenerated()){ if($chunk->isGenerated()){
//subchunks //subchunks
$count = 0; $subChunks = $chunk->getSubChunks();
$subStream = new BinaryStream(); $count = $subChunks->count();
foreach($chunk->getSubChunks() as $y => $subChunk){ $stream->putByte($count);
++$count;
$subStream->putByte($y); foreach($subChunks as $y => $subChunk){
$stream->putByte($y);
$layers = $subChunk->getBlockLayers(); $layers = $subChunk->getBlockLayers();
$subStream->putByte(count($subChunk->getBlockLayers())); $stream->putByte(count($layers));
foreach($layers as $blocks){ foreach($layers as $blocks){
$wordArray = $blocks->getWordArray(); $wordArray = $blocks->getWordArray();
$palette = $blocks->getPalette(); $palette = $blocks->getPalette();
$subStream->putByte($blocks->getBitsPerBlock()); $stream->putByte($blocks->getBitsPerBlock());
$subStream->put($wordArray); $stream->put($wordArray);
$serialPalette = pack("N*", ...$palette); $serialPalette = pack("N*", ...$palette);
$subStream->putInt(strlen($serialPalette)); $stream->putInt(strlen($serialPalette));
$subStream->put($serialPalette); $stream->put($serialPalette);
} }
if($chunk->isLightPopulated()){ if($chunk->isLightPopulated()){
$subStream->put($subChunk->getBlockSkyLightArray()->getData()); $stream->put($subChunk->getBlockSkyLightArray()->getData());
$subStream->put($subChunk->getBlockLightArray()->getData()); $stream->put($subChunk->getBlockLightArray()->getData());
} }
} }
$stream->putByte($count);
$stream->put($subStream->getBuffer());
//biomes //biomes
$stream->put($chunk->getBiomeIdArray()); $stream->put($chunk->getBiomeIdArray());