FastChunkSerializer: expose a method to disable lighting serialization

this is useful for copies which don't care about lighting, such as chunk sending.
This commit is contained in:
Dylan K. Taylor 2020-02-09 17:48:30 +00:00
parent ce42ca958e
commit d360439c92

View File

@ -45,15 +45,21 @@ final class FastChunkSerializer{
//NOOP //NOOP
} }
public static function serializeWithoutLight(Chunk $chunk) : string{
return self::serialize($chunk, false);
}
/** /**
* Fast-serializes the chunk for passing between threads * Fast-serializes the chunk for passing between threads
* TODO: tiles and entities * TODO: tiles and entities
*/ */
public static function serialize(Chunk $chunk) : string{ public static function serialize(Chunk $chunk, bool $includeLight = true) : string{
$includeLight = $includeLight && $chunk->isLightPopulated();
$stream = new BinaryStream(); $stream = new BinaryStream();
$stream->putInt($chunk->getX()); $stream->putInt($chunk->getX());
$stream->putInt($chunk->getZ()); $stream->putInt($chunk->getZ());
$stream->putByte(($chunk->isLightPopulated() ? 4 : 0) | ($chunk->isPopulated() ? 2 : 0) | ($chunk->isGenerated() ? 1 : 0)); $stream->putByte(($includeLight ? 4 : 0) | ($chunk->isPopulated() ? 2 : 0) | ($chunk->isGenerated() ? 1 : 0));
if($chunk->isGenerated()){ if($chunk->isGenerated()){
//subchunks //subchunks
$subChunks = $chunk->getSubChunks(); $subChunks = $chunk->getSubChunks();
@ -75,7 +81,7 @@ final class FastChunkSerializer{
$stream->put($serialPalette); $stream->put($serialPalette);
} }
if($chunk->isLightPopulated()){ if($includeLight){
$stream->put($subChunk->getBlockSkyLightArray()->getData()); $stream->put($subChunk->getBlockSkyLightArray()->getData());
$stream->put($subChunk->getBlockLightArray()->getData()); $stream->put($subChunk->getBlockLightArray()->getData());
} }
@ -83,7 +89,7 @@ final class FastChunkSerializer{
//biomes //biomes
$stream->put($chunk->getBiomeIdArray()); $stream->put($chunk->getBiomeIdArray());
if($chunk->isLightPopulated()){ if($includeLight){
$stream->put(pack("v*", ...$chunk->getHeightMapArray())); $stream->put(pack("v*", ...$chunk->getHeightMapArray()));
} }
} }