mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 08:17:34 +00:00
Pack wall connections into 7 bits for runtime data encoding
This commit is contained in:
parent
95c18ef99a
commit
b9d62de29d
@ -54,7 +54,7 @@ use function get_class;
|
||||
use const PHP_INT_MAX;
|
||||
|
||||
class Block{
|
||||
public const INTERNAL_STATE_DATA_BITS = 9;
|
||||
public const INTERNAL_STATE_DATA_BITS = 8;
|
||||
public const INTERNAL_STATE_DATA_MASK = ~(~0 << self::INTERNAL_STATE_DATA_BITS);
|
||||
|
||||
protected BlockIdentifier $idInfo;
|
||||
|
@ -144,9 +144,10 @@ final class RuntimeDataReader implements RuntimeDataDescriber{
|
||||
*/
|
||||
public function wallConnections(array &$connections) : void{
|
||||
$result = [];
|
||||
//TODO: we can pack this into 7 bits instead of 8
|
||||
$offset = 0;
|
||||
$packed = $this->readBoundedInt(7, 0, (3 ** 4) - 1);
|
||||
foreach(Facing::HORIZONTAL as $facing){
|
||||
$type = $this->readBoundedInt(2, 0, 2);
|
||||
$type = intdiv($packed, (3 ** $offset)) % 3;
|
||||
if($type !== 0){
|
||||
$result[$facing] = match($type){
|
||||
1 => WallConnectionType::SHORT(),
|
||||
@ -154,6 +155,7 @@ final class RuntimeDataReader implements RuntimeDataDescriber{
|
||||
default => throw new AssumptionFailedError("Unreachable")
|
||||
};
|
||||
}
|
||||
$offset++;
|
||||
}
|
||||
|
||||
$connections = $result;
|
||||
|
@ -81,8 +81,7 @@ final class RuntimeDataSizeCalculator implements RuntimeDataDescriber{
|
||||
}
|
||||
|
||||
public function wallConnections(array &$connections) : void{
|
||||
//TODO: this can be reduced to 7 if we pack the trinary values
|
||||
$this->addBits(8);
|
||||
$this->addBits(7);
|
||||
}
|
||||
|
||||
public function brewingStandSlots(array &$slots) : void{
|
||||
|
@ -133,15 +133,18 @@ final class RuntimeDataWriter implements RuntimeDataDescriber{
|
||||
* @phpstan-param array<Facing::NORTH|Facing::EAST|Facing::SOUTH|Facing::WEST, WallConnectionType> $connections
|
||||
*/
|
||||
public function wallConnections(array &$connections) : void{
|
||||
//TODO: we can pack this into 7 bits instead of 8
|
||||
$packed = 0;
|
||||
$offset = 0;
|
||||
foreach(Facing::HORIZONTAL as $facing){
|
||||
$this->writeBoundedInt(2, 0, 2, match($connections[$facing] ?? null){
|
||||
$packed += match($connections[$facing] ?? null){
|
||||
null => 0,
|
||||
WallConnectionType::SHORT() => 1,
|
||||
WallConnectionType::TALL() => 2,
|
||||
default => throw new AssumptionFailedError("Unreachable")
|
||||
});
|
||||
} * (3 ** $offset);
|
||||
$offset++;
|
||||
}
|
||||
$this->writeBoundedInt(7, 0, (3 ** 4) - 1, $packed);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user