FastChunkSerializer no longer encodes chunk coordinates

in cases like PopulationTask it makes more sense to store the coordinates separately where they can be stored more efficiently (once instead of 9 times)
In addition, PopulationTask shouldn't need to serialize an empty chunk just to copy coordinates.

I've made changes like this in other areas already in preparation for the day when chunks no longer contain their coordinates, so this brings us one step closer to that goal.
This commit is contained in:
Dylan K. Taylor
2020-12-03 20:52:33 +00:00
parent 5b1fa25dff
commit 1f5998d24c
4 changed files with 22 additions and 15 deletions

View File

@ -61,8 +61,6 @@ final class FastChunkSerializer{
$includeLight = $includeLight && $chunk->isLightPopulated() === true;
$stream = new BinaryStream();
$stream->putInt($chunk->getX());
$stream->putInt($chunk->getZ());
$stream->putByte(
($includeLight ? self::FLAG_HAS_LIGHT : 0) |
($chunk->isPopulated() ? self::FLAG_POPULATED : 0) |
@ -109,11 +107,9 @@ final class FastChunkSerializer{
/**
* Deserializes a fast-serialized chunk
*/
public static function deserialize(string $data) : Chunk{
public static function deserialize(string $data, int $chunkX, int $chunkZ) : Chunk{
$stream = new BinaryStream($data);
$x = $stream->getInt();
$z = $stream->getInt();
$flags = $stream->getByte();
$lightPopulated = (bool) ($flags & self::FLAG_HAS_LIGHT);
$terrainPopulated = (bool) ($flags & self::FLAG_POPULATED);
@ -148,7 +144,7 @@ final class FastChunkSerializer{
}
}
$chunk = new Chunk($x, $z, $subChunks, null, null, $biomeIds, $heightMap);
$chunk = new Chunk($chunkX, $chunkZ, $subChunks, null, null, $biomeIds, $heightMap);
$chunk->setGenerated($terrainGenerated);
$chunk->setPopulated($terrainPopulated);
$chunk->setLightPopulated($lightPopulated);