PocketMine-MP 5.33.2 git-919492bdcad8510eb6606439eb77e1c604f1d1ea
Loading...
Searching...
No Matches
RuntimeDataSizeCalculator.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\data\runtime;
25
28use function count;
29use function log;
30
32 private int $bits = 0;
33
34 protected function addBits(int $bits) : void{
35 $this->bits += $bits;
36 }
37
38 public function getBitsUsed() : int{
39 return $this->bits;
40 }
41
42 public function int(int $bits, int &$value) : void{
43 $this->addBits($bits);
44 }
45
46 public function boundedIntAuto(int $min, int $max, int &$value) : void{
47 $this->addBits(((int) log($max - $min, 2)) + 1);
48 }
49
50 public function bool(bool &$value) : void{
51 $this->addBits(1);
52 }
53
54 public function facingExcept(Facing &$facing, Facing $except) : void{
55 $this->enum($facing);
56 }
57
58 public function horizontalAxis(Axis &$axis) : void{
59 $this->addBits(1);
60 }
61
62 public function wallConnections(array &$connections) : void{
63 $this->addBits(7);
64 }
65
66 public function enum(\UnitEnum &$case) : void{
67 $metadata = RuntimeEnumMetadata::from($case);
68 $this->addBits($metadata->bits);
69 }
70
71 public function enumSet(array &$set, array $allCases) : void{
72 $this->addBits(count($allCases));
73 }
74}