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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
use pocketmine\item\Item;
use pocketmine\utils\Binary;
@ -106,7 +108,7 @@ abstract class DataPacket extends \stdClass{
}
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){
@ -180,7 +182,7 @@ abstract class DataPacket extends \stdClass{
}
protected function getString(){
return $this->get($this->getShort(false));
return $this->get($this->getShort());
}
protected function putString($v){

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -21,6 +21,8 @@
namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class UseItemPacket extends DataPacket{
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 bool $signed
* @param $str
*
* @return int
*/
public static function readShort($str, $signed = true){
$unpacked = unpack("n", $str)[1];
public static function readShort($str){
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{
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 bool $signed
*
* @return int
*/
public static function readLShort($str, $signed = true){
$unpacked = unpack("v", $str)[1];
public static function readLShort($str){
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{
return $unpacked;
return unpack("v", $str)[1] << 16 >> 16;
}
}
@ -361,7 +369,7 @@ class Binary{
$value = "0";
for($i = 0; $i < 8; $i += 2){
$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){

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