Added preprocessor optimizations

This commit is contained in:
Shoghi Cervantes 2014-10-30 07:58:53 +01:00
parent 8cb9dd9a14
commit d8f9def7f4
63 changed files with 163 additions and 35 deletions

View File

@ -126,7 +126,7 @@ class LevelFormat extends PMF{
return false; return false;
} }
$this->levelData["name"] = $this->read(Binary::readShort($this->read(2), false)); $this->levelData["name"] = $this->read(Binary::readShort($this->read(2)));
$this->levelData["seed"] = Binary::readInt($this->read(4)); $this->levelData["seed"] = Binary::readInt($this->read(4));
$this->levelData["time"] = Binary::readInt($this->read(4)); $this->levelData["time"] = Binary::readInt($this->read(4));
$this->levelData["spawnX"] = Binary::readFloat($this->read(4)); $this->levelData["spawnX"] = Binary::readFloat($this->read(4));
@ -140,11 +140,11 @@ class LevelFormat extends PMF{
if($this->levelData["height"] !== 8){ if($this->levelData["height"] !== 8){
return false; return false;
} }
$this->levelData["generator"] = $this->read(Binary::readShort($this->read(2), false)); $this->levelData["generator"] = $this->read(Binary::readShort($this->read(2)));
$this->levelData["generatorSettings"] = unserialize($this->read(Binary::readShort($this->read(2), false))); $this->levelData["generatorSettings"] = unserialize($this->read(Binary::readShort($this->read(2))));
} }
$this->levelData["extra"] = @zlib_decode($this->read(Binary::readShort($this->read(2), false))); $this->levelData["extra"] = @zlib_decode($this->read(Binary::readShort($this->read(2))));
$upgrade = false; $upgrade = false;
if($this->levelData["version"] === 0){ if($this->levelData["version"] === 0){

View File

@ -41,6 +41,8 @@ use pocketmine\nbt\tag\Tag;
use pocketmine\utils\Binary; use pocketmine\utils\Binary;
use pocketmine\utils\Utils; use pocketmine\utils\Utils;
#include <rules/NBT.h>
/** /**
* Named Binary Tag encoder/decoder * Named Binary Tag encoder/decoder
*/ */
@ -61,7 +63,7 @@ class NBT{
const TAG_Compound = 10; const TAG_Compound = 10;
const TAG_IntArray = 11; const TAG_IntArray = 11;
private $buffer; public $buffer;
private $offset; private $offset;
public $endianness; public $endianness;
private $data; private $data;
@ -191,8 +193,8 @@ class NBT{
$tag->write($this); $tag->write($this);
} }
public function getByte($signed = false){ public function getByte(){
return Binary::readByte($this->get(1), $signed); return Binary::readByte($this->get(1));
} }
public function putByte($v){ public function putByte($v){

View File

@ -23,6 +23,8 @@ namespace pocketmine\nbt\tag;
use pocketmine\nbt\NBT; use pocketmine\nbt\NBT;
#include <rules/NBT.h>
class Byte extends NamedTag{ class Byte extends NamedTag{
public function getType(){ public function getType(){
@ -30,7 +32,7 @@ class Byte extends NamedTag{
} }
public function read(NBT $nbt){ public function read(NBT $nbt){
$this->value = $nbt->getByte(true); $this->value = $nbt->getByte();
} }
public function write(NBT $nbt){ public function write(NBT $nbt){

View File

@ -23,6 +23,8 @@ namespace pocketmine\nbt\tag;
use pocketmine\nbt\NBT; use pocketmine\nbt\NBT;
#include <rules/NBT.h>
class ByteArray extends NamedTag{ class ByteArray extends NamedTag{
public function getType(){ public function getType(){

View File

@ -23,6 +23,8 @@ namespace pocketmine\nbt\tag;
use pocketmine\nbt\NBT; use pocketmine\nbt\NBT;
#include <rules/NBT.h>
class Compound extends NamedTag implements \ArrayAccess{ class Compound extends NamedTag implements \ArrayAccess{
public function __construct($name = "", $value = []){ public function __construct($name = "", $value = []){

View File

@ -23,6 +23,8 @@ namespace pocketmine\nbt\tag;
use pocketmine\nbt\NBT; use pocketmine\nbt\NBT;
#include <rules/NBT.h>
class Double extends NamedTag{ class Double extends NamedTag{
public function getType(){ public function getType(){

View File

@ -24,6 +24,8 @@ namespace pocketmine\nbt\tag;
use pocketmine\nbt\NBT; use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\Enum as TagEnum; use pocketmine\nbt\tag\Enum as TagEnum;
#include <rules/NBT.h>
class Enum extends NamedTag implements \ArrayAccess, \Countable{ class Enum extends NamedTag implements \ArrayAccess, \Countable{
private $tagType; private $tagType;

View File

@ -23,6 +23,8 @@ namespace pocketmine\nbt\tag;
use pocketmine\nbt\NBT; use pocketmine\nbt\NBT;
#include <rules/NBT.h>
class Float extends NamedTag{ class Float extends NamedTag{
public function getType(){ public function getType(){

View File

@ -23,6 +23,8 @@ namespace pocketmine\nbt\tag;
use pocketmine\nbt\NBT; use pocketmine\nbt\NBT;
#include <rules/NBT.h>
class Int extends NamedTag{ class Int extends NamedTag{
public function getType(){ public function getType(){

View File

@ -23,6 +23,8 @@ namespace pocketmine\nbt\tag;
use pocketmine\nbt\NBT; use pocketmine\nbt\NBT;
#include <rules/NBT.h>
class IntArray extends NamedTag{ class IntArray extends NamedTag{
public function getType(){ public function getType(){

View File

@ -23,6 +23,8 @@ namespace pocketmine\nbt\tag;
use pocketmine\nbt\NBT; use pocketmine\nbt\NBT;
#include <rules/NBT.h>
class Long extends NamedTag{ class Long extends NamedTag{
public function getType(){ public function getType(){

View File

@ -23,6 +23,8 @@ namespace pocketmine\nbt\tag;
use pocketmine\nbt\NBT; use pocketmine\nbt\NBT;
#include <rules/NBT.h>
class Short extends NamedTag{ class Short extends NamedTag{
public function getType(){ public function getType(){

View File

@ -23,6 +23,8 @@ namespace pocketmine\nbt\tag;
use pocketmine\nbt\NBT; use pocketmine\nbt\NBT;
#include <rules/NBT.h>
class String extends NamedTag{ class String extends NamedTag{
public function getType(){ public function getType(){

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class AddEntityPacket extends DataPacket{ class AddEntityPacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class AddItemEntityPacket extends DataPacket{ class AddItemEntityPacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
use pocketmine\utils\Binary; use pocketmine\utils\Binary;
class AddMobPacket extends DataPacket{ class AddMobPacket extends DataPacket{

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class AddPaintingPacket extends DataPacket{ class AddPaintingPacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
use pocketmine\utils\Binary; use pocketmine\utils\Binary;
class AddPlayerPacket extends DataPacket{ class AddPlayerPacket extends DataPacket{

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class AdventureSettingsPacket extends DataPacket{ class AdventureSettingsPacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class AnimatePacket extends DataPacket{ class AnimatePacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class ChatPacket extends DataPacket{ class ChatPacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class ContainerClosePacket extends DataPacket{ class ContainerClosePacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class ContainerOpenPacket extends DataPacket{ class ContainerOpenPacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class ContainerSetContentPacket extends DataPacket{ class ContainerSetContentPacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class ContainerSetDataPacket extends DataPacket{ class ContainerSetDataPacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
use pocketmine\item\Item; use pocketmine\item\Item;
class ContainerSetSlotPacket extends DataPacket{ class ContainerSetSlotPacket extends DataPacket{

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\utils\Binary; use pocketmine\utils\Binary;
@ -106,7 +108,7 @@ abstract class DataPacket extends \stdClass{
} }
protected function getShort($signed = true){ protected function getShort($signed = true){
return Binary::readShort($this->get(2), $signed); return $signed ? Binary::readSignedShort($this->get(2)) : Binary::readShort($this->get(2));
} }
protected function putShort($v){ protected function putShort($v){
@ -180,7 +182,7 @@ abstract class DataPacket extends \stdClass{
} }
protected function getString(){ protected function getString(){
return $this->get($this->getShort(false)); return $this->get($this->getShort());
} }
protected function putString($v){ protected function putString($v){

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class DropItemPacket extends DataPacket{ class DropItemPacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class EntityDataPacket extends DataPacket{ class EntityDataPacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class EntityEventPacket extends DataPacket{ class EntityEventPacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class ExplodePacket extends DataPacket{ class ExplodePacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class FullChunkDataPacket extends DataPacket{ class FullChunkDataPacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class HurtArmorPacket extends DataPacket{ class HurtArmorPacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class InteractPacket extends DataPacket{ class InteractPacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class LevelEventPacket extends DataPacket{ class LevelEventPacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class LoginPacket extends DataPacket{ class LoginPacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class LoginStatusPacket extends DataPacket{ class LoginStatusPacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class MessagePacket extends DataPacket{ class MessagePacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class MoveEntityPacket extends DataPacket{ class MoveEntityPacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class MovePlayerPacket extends DataPacket{ class MovePlayerPacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class PlayerActionPacket extends DataPacket{ class PlayerActionPacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class PlayerArmorEquipmentPacket extends DataPacket{ class PlayerArmorEquipmentPacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class PlayerEquipmentPacket extends DataPacket{ class PlayerEquipmentPacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class RemoveBlockPacket extends DataPacket{ class RemoveBlockPacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class RemoveEntityPacket extends DataPacket{ class RemoveEntityPacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class RemovePlayerPacket extends DataPacket{ class RemovePlayerPacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class RespawnPacket extends DataPacket{ class RespawnPacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class RotateHeadPacket extends DataPacket{ class RotateHeadPacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class SendInventoryPacket extends DataPacket{ class SendInventoryPacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
use pocketmine\utils\Binary; use pocketmine\utils\Binary;
class SetEntityDataPacket extends DataPacket{ class SetEntityDataPacket extends DataPacket{

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class SetEntityMotionPacket extends DataPacket{ class SetEntityMotionPacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class SetHealthPacket extends DataPacket{ class SetHealthPacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class SetSpawnPositionPacket extends DataPacket{ class SetSpawnPositionPacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
use pocketmine\level\Level; use pocketmine\level\Level;

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class StartGamePacket extends DataPacket{ class StartGamePacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class TakeItemEntityPacket extends DataPacket{ class TakeItemEntityPacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class TileEventPacket extends DataPacket{ class TileEventPacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -22,6 +22,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class UnknownPacket extends DataPacket{ class UnknownPacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class UnloadChunkPacket extends DataPacket{ class UnloadChunkPacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class UpdateBlockPacket extends DataPacket{ class UpdateBlockPacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol; namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class UseItemPacket extends DataPacket{ class UseItemPacket extends DataPacket{
public static $pool = []; public static $pool = [];

View File

@ -228,24 +228,28 @@ class Binary{
} }
/** /**
* Reads a 16-bit signed/unsigned big-endian number * Reads a 16-bit unsigned big-endian number
* *
* @param $str * @param $str
* @param bool $signed
* *
* @return int * @return int
*/ */
public static function readShort($str, $signed = true){ public static function readShort($str){
$unpacked = unpack("n", $str)[1]; return unpack("n", $str)[1];
if($signed){
if(PHP_INT_SIZE === 8){
return $unpacked << 48 >> 48;
}else{
return $unpacked << 16 >> 16;
} }
/**
* Reads a 16-bit signed big-endian number
*
* @param $str
*
* @return int
*/
public static function readSignedShort($str){
if(PHP_INT_SIZE === 8){
return unpack("n", $str)[1] << 48 >> 48;
}else{ }else{
return $unpacked; return unpack("n", $str)[1] << 16 >> 16;
} }
} }
@ -261,24 +265,28 @@ class Binary{
} }
/** /**
* Reads a 16-bit signed/unsigned little-endian number * Reads a 16-bit unsigned little-endian number
* *
* @param $str * @param $str
* @param bool $signed
* *
* @return int * @return int
*/ */
public static function readLShort($str, $signed = true){ public static function readLShort($str){
$unpacked = unpack("v", $str)[1]; return unpack("v", $str)[1];
if($signed){
if(PHP_INT_SIZE === 8){
return $unpacked << 48 >> 48;
}else{
return $unpacked << 16 >> 16;
} }
/**
* Reads a 16-bit signed little-endian number
*
* @param $str
*
* @return int
*/
public static function readSignedLShort($str){
if(PHP_INT_SIZE === 8){
return unpack("v", $str)[1] << 48 >> 48;
}else{ }else{
return $unpacked; return unpack("v", $str)[1] << 16 >> 16;
} }
} }
@ -361,7 +369,7 @@ class Binary{
$value = "0"; $value = "0";
for($i = 0; $i < 8; $i += 2){ for($i = 0; $i < 8; $i += 2){
$value = bcmul($value, "65536", 0); $value = bcmul($value, "65536", 0);
$value = bcadd($value, self::readShort(substr($x, $i, 2), false), 0); $value = bcadd($value, self::readShort(substr($x, $i, 2)), 0);
} }
if(bccomp($value, "9223372036854775807") == 1){ if(bccomp($value, "9223372036854775807") == 1){

@ -1 +1 @@
Subproject commit a15d851daa87698499a1485e37e76422cfb3f0c4 Subproject commit 1eba2267876ba8e9a00380f2ae9e05dff9eb0ec8