PocketMine-MP 5.23.3 git-976fc63567edab7a6fb6aeae739f43cf9fe57de4
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
27use function count;
28use function log;
29
31 private int $bits = 0;
32
33 protected function addBits(int $bits) : void{
34 $this->bits += $bits;
35 }
36
37 public function getBitsUsed() : int{
38 return $this->bits;
39 }
40
41 public function int(int $bits, int &$value) : void{
42 $this->addBits($bits);
43 }
44
45 public function boundedIntAuto(int $min, int $max, int &$value) : void{
46 $this->addBits(((int) log($max - $min, 2)) + 1);
47 }
48
49 public function bool(bool &$value) : void{
50 $this->addBits(1);
51 }
52
53 public function horizontalFacing(int &$facing) : void{
54 $this->addBits(2);
55 }
56
57 public function facingFlags(array &$faces) : void{
58 $this->addBits(count(Facing::ALL));
59 }
60
61 public function horizontalFacingFlags(array &$faces) : void{
62 $this->addBits(count(Facing::HORIZONTAL));
63 }
64
65 public function facing(int &$facing) : void{
66 $this->addBits(3);
67 }
68
69 public function facingExcept(int &$facing, int $except) : void{
70 $this->facing($facing);
71 }
72
73 public function axis(int &$axis) : void{
74 $this->addBits(2);
75 }
76
77 public function horizontalAxis(int &$axis) : void{
78 $this->addBits(1);
79 }
80
81 public function wallConnections(array &$connections) : void{
82 $this->addBits(7);
83 }
84
85 public function railShape(int &$railShape) : void{
86 $this->addBits(4);
87 }
88
89 public function straightOnlyRailShape(int &$railShape) : void{
90 $this->addBits(3);
91 }
92
93 public function enum(\UnitEnum &$case) : void{
94 $metadata = RuntimeEnumMetadata::from($case);
95 $this->addBits($metadata->bits);
96 }
97
98 public function enumSet(array &$set, array $allCases) : void{
99 $this->addBits(count($allCases));
100 }
101}