mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-05 01:16:15 +00:00
FastChunkSerializer no longer serializes light by default
the core doesn't use this anywhere. serializeWithoutLight() has been renamed to serializeTerrain() to more accurately describe what it does.
This commit is contained in:
@ -26,8 +26,6 @@ namespace pocketmine\world\format\io;
|
||||
use pocketmine\utils\BinaryStream;
|
||||
use pocketmine\world\format\BiomeArray;
|
||||
use pocketmine\world\format\Chunk;
|
||||
use pocketmine\world\format\HeightArray;
|
||||
use pocketmine\world\format\LightArray;
|
||||
use pocketmine\world\format\PalettedBlockArray;
|
||||
use pocketmine\world\format\SubChunk;
|
||||
use function array_values;
|
||||
@ -42,26 +40,18 @@ use function unpack;
|
||||
*/
|
||||
final class FastChunkSerializer{
|
||||
private const FLAG_POPULATED = 1 << 1;
|
||||
private const FLAG_HAS_LIGHT = 1 << 2;
|
||||
|
||||
private function __construct(){
|
||||
//NOOP
|
||||
}
|
||||
|
||||
public static function serializeWithoutLight(Chunk $chunk) : string{
|
||||
return self::serialize($chunk, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fast-serializes the chunk for passing between threads
|
||||
* TODO: tiles and entities
|
||||
*/
|
||||
public static function serialize(Chunk $chunk, bool $includeLight = true) : string{
|
||||
$includeLight = $includeLight && $chunk->isLightPopulated() === true;
|
||||
|
||||
public static function serializeTerrain(Chunk $chunk) : string{
|
||||
$stream = new BinaryStream();
|
||||
$stream->putByte(
|
||||
($includeLight ? self::FLAG_HAS_LIGHT : 0) |
|
||||
($chunk->isPopulated() ? self::FLAG_POPULATED : 0)
|
||||
);
|
||||
|
||||
@ -85,18 +75,10 @@ final class FastChunkSerializer{
|
||||
$stream->putInt(strlen($serialPalette));
|
||||
$stream->put($serialPalette);
|
||||
}
|
||||
|
||||
if($includeLight){
|
||||
$stream->put($subChunk->getBlockSkyLightArray()->getData());
|
||||
$stream->put($subChunk->getBlockLightArray()->getData());
|
||||
}
|
||||
}
|
||||
|
||||
//biomes
|
||||
$stream->put($chunk->getBiomeIdArray());
|
||||
if($includeLight){
|
||||
$stream->put(pack("S*", ...$chunk->getHeightMapArray()));
|
||||
}
|
||||
|
||||
return $stream->getBuffer();
|
||||
}
|
||||
@ -104,15 +86,13 @@ final class FastChunkSerializer{
|
||||
/**
|
||||
* Deserializes a fast-serialized chunk
|
||||
*/
|
||||
public static function deserialize(string $data) : Chunk{
|
||||
public static function deserializeTerrain(string $data) : Chunk{
|
||||
$stream = new BinaryStream($data);
|
||||
|
||||
$flags = $stream->getByte();
|
||||
$lightPopulated = (bool) ($flags & self::FLAG_HAS_LIGHT);
|
||||
$terrainPopulated = (bool) ($flags & self::FLAG_POPULATED);
|
||||
|
||||
$subChunks = [];
|
||||
$heightMap = null;
|
||||
|
||||
$count = $stream->getByte();
|
||||
for($subCount = 0; $subCount < $count; ++$subCount){
|
||||
@ -130,21 +110,13 @@ final class FastChunkSerializer{
|
||||
|
||||
$layers[] = PalettedBlockArray::fromData($bitsPerBlock, $words, $palette);
|
||||
}
|
||||
$subChunks[$y] = new SubChunk(
|
||||
$airBlockId, $layers, $lightPopulated ? new LightArray($stream->get(2048)) : null, $lightPopulated ? new LightArray($stream->get(2048)) : null
|
||||
);
|
||||
$subChunks[$y] = new SubChunk($airBlockId, $layers);
|
||||
}
|
||||
|
||||
$biomeIds = new BiomeArray($stream->get(256));
|
||||
if($lightPopulated){
|
||||
/** @var int[] $unpackedHeightMap */
|
||||
$unpackedHeightMap = unpack("S*", $stream->get(512)); //unpack() will never fail here
|
||||
$heightMap = new HeightArray(array_values($unpackedHeightMap));
|
||||
}
|
||||
|
||||
$chunk = new Chunk($subChunks, $biomeIds, $heightMap);
|
||||
$chunk = new Chunk($subChunks, $biomeIds);
|
||||
$chunk->setPopulated($terrainPopulated);
|
||||
$chunk->setLightPopulated($lightPopulated);
|
||||
$chunk->clearTerrainDirtyFlags();
|
||||
|
||||
return $chunk;
|
||||
|
Reference in New Issue
Block a user