From a633e415ef713d5a256aa8ab48fa01149e40ac18 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 25 Feb 2020 15:08:53 +0000 Subject: [PATCH] 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. --- src/world/format/io/FastChunkSerializer.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/world/format/io/FastChunkSerializer.php b/src/world/format/io/FastChunkSerializer.php index cbdefee35..76aa5b77e 100644 --- a/src/world/format/io/FastChunkSerializer.php +++ b/src/world/format/io/FastChunkSerializer.php @@ -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))); } }