FastChunkSerializer: use machine endianness for pack() (thanks @Frago9876543210)

this is faster due to not having to reverse bytes. Since we don't use this format for persistence, it's OK to use machine byte order for this.
This commit is contained in:
Dylan K. Taylor 2020-02-25 15:08:53 +00:00
parent bd00ee5038
commit a633e415ef

View File

@ -76,7 +76,7 @@ final class FastChunkSerializer{
$stream->putByte($blocks->getBitsPerBlock());
$stream->put($wordArray);
$serialPalette = pack("N*", ...$palette);
$serialPalette = pack("L*", ...$palette);
$stream->putInt(strlen($serialPalette));
$stream->put($serialPalette);
}
@ -90,7 +90,7 @@ final class FastChunkSerializer{
//biomes
$stream->put($chunk->getBiomeIdArray());
if($includeLight){
$stream->put(pack("v*", ...$chunk->getHeightMapArray()));
$stream->put(pack("S*", ...$chunk->getHeightMapArray()));
}
}
@ -123,7 +123,7 @@ final class FastChunkSerializer{
for($i = 0, $layerCount = $stream->getByte(); $i < $layerCount; ++$i){
$bitsPerBlock = $stream->getByte();
$words = $stream->get(PalettedBlockArray::getExpectedWordArraySize($bitsPerBlock));
$palette = array_values(unpack("N*", $stream->get($stream->getInt())));
$palette = array_values(unpack("L*", $stream->get($stream->getInt())));
$layers[] = PalettedBlockArray::fromData($bitsPerBlock, $words, $palette);
}
@ -134,7 +134,7 @@ final class FastChunkSerializer{
$biomeIds = $stream->get(256);
if($lightPopulated){
$heightMap = array_values(unpack("v*", $stream->get(512)));
$heightMap = array_values(unpack("S*", $stream->get(512)));
}
}