RuntimeBlockMapping is now a singleton instead of static class

this prepares for a fully dynamic block mapper, as well as allowing a small performance improvement to chunk encoding by eliding the constant lazy-init checks.
This commit is contained in:
Dylan K. Taylor
2020-04-23 21:09:58 +01:00
parent f3fed60d57
commit aa1828aa98
4 changed files with 34 additions and 36 deletions

View File

@ -53,6 +53,7 @@ final class ChunkSerializer{
public static function serialize(Chunk $chunk, ?string $tiles = null) : string{
$stream = new NetworkBinaryStream();
$subChunkCount = self::getSubChunkCount($chunk);
$blockMapper = RuntimeBlockMapping::getInstance();
for($y = 0; $y < $subChunkCount; ++$y){
$layers = $chunk->getSubChunk($y)->getBlockLayers();
$stream->putByte(8); //version
@ -69,7 +70,7 @@ final class ChunkSerializer{
//zigzag and just shift directly.
$stream->putUnsignedVarInt(count($palette) << 1); //yes, this is intentionally zigzag
foreach($palette as $p){
$stream->putUnsignedVarInt(RuntimeBlockMapping::toStaticRuntimeId($p >> 4, $p & 0xf) << 1);
$stream->putUnsignedVarInt($blockMapper->toStaticRuntimeId($p >> 4, $p & 0xf) << 1);
}
}
}