mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 02:08:21 +00:00
Added MemoryManager, new memory properties, improved performance, updated RakLib, fixed misc. bugs
This commit is contained in:
@ -84,7 +84,7 @@ class NBT{
|
||||
return $len === 1 ? $this->buffer{$this->offset++} : substr($this->buffer, ($this->offset += $len) - $len, $len);
|
||||
}
|
||||
|
||||
public function put($v){
|
||||
public function put(&$v){
|
||||
$this->buffer .= $v;
|
||||
}
|
||||
|
||||
@ -99,7 +99,7 @@ class NBT{
|
||||
|
||||
public function read($buffer, $doMultiple = false){
|
||||
$this->offset = 0;
|
||||
$this->buffer = $buffer;
|
||||
$this->buffer =& $buffer;
|
||||
$this->data = $this->readTag();
|
||||
if($doMultiple and $this->offset < strlen($this->buffer)){
|
||||
$this->data = [$this->data];
|
||||
@ -117,28 +117,30 @@ class NBT{
|
||||
/**
|
||||
* @return string|bool
|
||||
*/
|
||||
public function write(){
|
||||
public function &write(){
|
||||
$this->offset = 0;
|
||||
$data = false;
|
||||
if($this->data instanceof Compound){
|
||||
$this->writeTag($this->data);
|
||||
|
||||
return $this->buffer;
|
||||
$data =& $this->buffer;
|
||||
}elseif(is_array($this->data)){
|
||||
foreach($this->data as $tag){
|
||||
$this->writeTag($tag);
|
||||
}
|
||||
return $this->buffer;
|
||||
$data =& $this->buffer;
|
||||
}
|
||||
|
||||
return false;
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function writeCompressed($compression = ZLIB_ENCODING_GZIP, $level = 7){
|
||||
public function &writeCompressed($compression = ZLIB_ENCODING_GZIP, $level = 7){
|
||||
$data = false;
|
||||
if(($write = $this->write()) !== false){
|
||||
return zlib_encode($write, $compression, $level);
|
||||
$data = zlib_encode($write, $compression, $level);
|
||||
}
|
||||
|
||||
return false;
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function readTag(){
|
||||
@ -256,7 +258,7 @@ class NBT{
|
||||
return $this->get($this->getShort());
|
||||
}
|
||||
|
||||
public function putString($v){
|
||||
public function putString(&$v){
|
||||
$this->putShort(strlen($v));
|
||||
$this->buffer .= $v;
|
||||
}
|
||||
|
@ -27,6 +27,13 @@ use pocketmine\nbt\NBT;
|
||||
|
||||
class ByteArray extends NamedTag{
|
||||
|
||||
public function __construct($name = "", &$value = null){
|
||||
$this->name = $name;
|
||||
if($value !== null){
|
||||
$this->value =& $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function getType(){
|
||||
return NBT::TAG_ByteArray;
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ class IntArray extends NamedTag{
|
||||
|
||||
public function write(NBT $nbt){
|
||||
$nbt->putInt(count($this->value));
|
||||
$nbt->put(pack($nbt->endianness === NBT::LITTLE_ENDIAN ? "V*" : "N*", ...$this->value));
|
||||
$data = pack($nbt->endianness === NBT::LITTLE_ENDIAN ? "V*" : "N*", ...$this->value);
|
||||
$nbt->put($data);
|
||||
}
|
||||
}
|
@ -30,15 +30,15 @@ abstract class NamedTag extends Tag{
|
||||
* @param string $name
|
||||
* @param bool|float|double|int|byte|short|array|Compound|Enum|string $value
|
||||
*/
|
||||
public function __construct($name = "", $value = false){
|
||||
public function __construct($name = "", $value = null){
|
||||
$this->name = $name;
|
||||
if($value !== false){
|
||||
if($value !== null){
|
||||
$this->value = $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return $this->name === false ? "" : $this->name;
|
||||
public function &getName(){
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName($name){
|
||||
|
@ -27,6 +27,13 @@ use pocketmine\nbt\NBT;
|
||||
|
||||
class String extends NamedTag{
|
||||
|
||||
public function __construct($name = "", $value = null){
|
||||
$this->name = $name;
|
||||
if($value !== null){
|
||||
$this->value =& $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function getType(){
|
||||
return NBT::TAG_String;
|
||||
}
|
||||
|
Reference in New Issue
Block a user