Added MemoryManager, new memory properties, improved performance, updated RakLib, fixed misc. bugs

This commit is contained in:
Shoghi Cervantes
2015-04-18 20:13:52 +02:00
parent ddc152ae0a
commit b2c25eaf36
32 changed files with 652 additions and 164 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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);
}
}

View File

@ -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){

View File

@ -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;
}