mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +00:00
Micro-optimizations
This commit is contained in:
parent
7b7b91ea0d
commit
9b85abd75e
@ -1145,9 +1145,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$this->lastPitch = $to->pitch;
|
||||
|
||||
$ev = new PlayerMoveEvent($this, $from, $to);
|
||||
if($revert){
|
||||
$ev->setCancelled();
|
||||
}
|
||||
|
||||
$this->server->getPluginManager()->callEvent($ev);
|
||||
|
||||
|
@ -54,7 +54,7 @@ class DroppedItem extends Entity{
|
||||
protected function initEntity(){
|
||||
$this->namedtag->id = new String("id", "Item");
|
||||
$this->setMaxHealth(5);
|
||||
$this->setHealth(@$this->namedtag["Health"]);
|
||||
$this->setHealth($this->namedtag["Health"]);
|
||||
if(isset($this->namedtag->Age)){
|
||||
$this->age = $this->namedtag["Age"];
|
||||
}
|
||||
|
@ -211,7 +211,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
$this->invulnerable = $this->namedtag["Invulnerable"] > 0 ? true : false;
|
||||
|
||||
$this->chunk->addEntity($this);
|
||||
$this->getLevel()->addEntity($this);
|
||||
$this->level->addEntity($this);
|
||||
$this->initEntity();
|
||||
$this->lastUpdate = $this->server->getTick();
|
||||
$this->server->getPluginManager()->callEvent(new EntitySpawnEvent($this));
|
||||
@ -384,17 +384,17 @@ abstract class Entity extends Location implements Metadatable{
|
||||
$diffY = $y - $j;
|
||||
$diffZ = $z - $k;
|
||||
|
||||
$list = $this->getLevel()->getCollisionBlocks($this->boundingBox);
|
||||
$list = $this->level->getCollisionBlocks($this->boundingBox);
|
||||
|
||||
if(count($list) === 0 and !$this->getLevel()->isFullBlock(new Vector3($i, $j, $k))){
|
||||
if(count($list) === 0 and !$this->level->isFullBlock(new Vector3($i, $j, $k))){
|
||||
return false;
|
||||
}else{
|
||||
$flag = !$this->getLevel()->isFullBlock(new Vector3($i - 1, $j, $k));
|
||||
$flag1 = !$this->getLevel()->isFullBlock(new Vector3($i + 1, $j, $k));
|
||||
//$flag2 = !$this->getLevel()->isFullBlock(new Vector3($i, $j - 1, $k));
|
||||
$flag3 = !$this->getLevel()->isFullBlock(new Vector3($i, $j + 1, $k));
|
||||
$flag4 = !$this->getLevel()->isFullBlock(new Vector3($i, $j, $k - 1));
|
||||
$flag5 = !$this->getLevel()->isFullBlock(new Vector3($i, $j, $k + 1));
|
||||
$flag = !$this->level->isFullBlock(new Vector3($i - 1, $j, $k));
|
||||
$flag1 = !$this->level->isFullBlock(new Vector3($i + 1, $j, $k));
|
||||
//$flag2 = !$this->level->isFullBlock(new Vector3($i, $j - 1, $k));
|
||||
$flag3 = !$this->level->isFullBlock(new Vector3($i, $j + 1, $k));
|
||||
$flag4 = !$this->level->isFullBlock(new Vector3($i, $j, $k - 1));
|
||||
$flag5 = !$this->level->isFullBlock(new Vector3($i, $j, $k + 1));
|
||||
|
||||
$direction = 3; //UP!
|
||||
$limit = 9999;
|
||||
@ -703,12 +703,12 @@ abstract class Entity extends Location implements Metadatable{
|
||||
|
||||
protected function switchLevel(Level $targetLevel){
|
||||
if($this->isValid()){
|
||||
$this->server->getPluginManager()->callEvent($ev = new EntityLevelChangeEvent($this, $this->getLevel(), $targetLevel));
|
||||
$this->server->getPluginManager()->callEvent($ev = new EntityLevelChangeEvent($this, $this->level, $targetLevel));
|
||||
if($ev->isCancelled()){
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->getLevel()->removeEntity($this);
|
||||
$this->level->removeEntity($this);
|
||||
$this->chunk->removeEntity($this);
|
||||
$this->despawnFromAll();
|
||||
if($this instanceof Player){
|
||||
@ -716,21 +716,21 @@ abstract class Entity extends Location implements Metadatable{
|
||||
$X = null;
|
||||
$Z = null;
|
||||
Level::getXZ($index, $X, $Z);
|
||||
foreach($this->getLevel()->getChunkEntities($X, $Z) as $entity){
|
||||
foreach($this->level->getChunkEntities($X, $Z) as $entity){
|
||||
$entity->despawnFrom($this);
|
||||
}
|
||||
|
||||
}
|
||||
$this->getLevel()->freeAllChunks($this);
|
||||
$this->level->freeAllChunks($this);
|
||||
}
|
||||
}
|
||||
$this->setLevel($targetLevel, $this instanceof Player ? true : false); //Hard reference
|
||||
$this->getLevel()->addEntity($this);
|
||||
$this->level->addEntity($this);
|
||||
if($this instanceof Player){
|
||||
$this->usedChunks = [];
|
||||
$pk = new SetTimePacket();
|
||||
$pk->time = $this->getLevel()->getTime();
|
||||
$pk->started = $this->getLevel()->stopTime == false;
|
||||
$pk->time = $this->level->getTime();
|
||||
$pk->started = $this->level->stopTime == false;
|
||||
$this->dataPacket($pk);
|
||||
}
|
||||
$this->chunk = null;
|
||||
@ -739,15 +739,15 @@ abstract class Entity extends Location implements Metadatable{
|
||||
}
|
||||
|
||||
public function getPosition(){
|
||||
return new Position($this->x, $this->y, $this->z, $this->getLevel());
|
||||
return new Position($this->x, $this->y, $this->z, $this->level);
|
||||
}
|
||||
|
||||
public function getLocation(){
|
||||
return new Location($this->x, $this->y, $this->z, $this->yaw, $this->pitch, $this->getLevel());
|
||||
return new Location($this->x, $this->y, $this->z, $this->yaw, $this->pitch, $this->level);
|
||||
}
|
||||
|
||||
public function isInsideOfWater(){
|
||||
$block = $this->getLevel()->getBlock($pos = (new Vector3($this->x, $y = ($this->y + $this->getEyeHeight()), $this->z))->floor());
|
||||
$block = $this->level->getBlock($pos = (new Vector3($this->x, $y = ($this->y + $this->getEyeHeight()), $this->z))->floor());
|
||||
|
||||
if($block instanceof Water){
|
||||
$f = ($pos->y + 1) - ($block->getFluidHeightPercent() - 0.1111111);
|
||||
@ -758,7 +758,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
}
|
||||
|
||||
public function isInsideOfSolid(){
|
||||
$block = $this->getLevel()->getBlock($pos = (new Vector3($this->x, $y = ($this->y + $this->getEyeHeight()), $this->z))->floor());
|
||||
$block = $this->level->getBlock($pos = (new Vector3($this->x, $y = ($this->y + $this->getEyeHeight()), $this->z))->floor());
|
||||
|
||||
$bb = $block->getBoundingBox();
|
||||
|
||||
@ -811,7 +811,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
/*$sneakFlag = $this->onGround and $this instanceof Player;
|
||||
|
||||
if($sneakFlag){
|
||||
for($mov = 0.05; $dx != 0.0 and count($this->getLevel()->getCollisionCubes($this, $this->boundingBox->getOffsetBoundingBox($dx, -1, 0))) === 0; $movX = $dx){
|
||||
for($mov = 0.05; $dx != 0.0 and count($this->level->getCollisionCubes($this, $this->boundingBox->getOffsetBoundingBox($dx, -1, 0))) === 0; $movX = $dx){
|
||||
if($dx < $mov and $dx >= -$mov){
|
||||
$dx = 0;
|
||||
}elseif($dx > 0){
|
||||
@ -821,7 +821,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
}
|
||||
}
|
||||
|
||||
for(; $dz != 0.0 and count($this->getLevel()->getCollisionCubes($this, $this->boundingBox->getOffsetBoundingBox(0, -1, $dz))) === 0; $movZ = $dz){
|
||||
for(; $dz != 0.0 and count($this->level->getCollisionCubes($this, $this->boundingBox->getOffsetBoundingBox(0, -1, $dz))) === 0; $movZ = $dz){
|
||||
if($dz < $mov and $dz >= -$mov){
|
||||
$dz = 0;
|
||||
}elseif($dz > 0){
|
||||
@ -834,7 +834,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
//TODO: big messy loop
|
||||
}*/
|
||||
|
||||
$list = $this->getLevel()->getCollisionCubes($this, $this->boundingBox->getOffsetBoundingBox($dx, $dy, $dz), false);
|
||||
$list = $this->level->getCollisionCubes($this, $this->boundingBox->getOffsetBoundingBox($dx, $dy, $dz), false);
|
||||
|
||||
|
||||
foreach($list as $bb){
|
||||
@ -1063,11 +1063,11 @@ abstract class Entity extends Location implements Metadatable{
|
||||
if($this->chunk instanceof FullChunk){
|
||||
$this->chunk->removeEntity($this);
|
||||
}
|
||||
$this->getLevel()->loadChunk($this->x >> 4, $this->z >> 4);
|
||||
$this->chunk = $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4);
|
||||
$this->level->loadChunk($this->x >> 4, $this->z >> 4);
|
||||
$this->chunk = $this->level->getChunk($this->x >> 4, $this->z >> 4);
|
||||
|
||||
if(!$this->justCreated){
|
||||
$newChunk = $this->getLevel()->getUsingChunk($this->x >> 4, $this->z >> 4);
|
||||
$newChunk = $this->level->getUsingChunk($this->x >> 4, $this->z >> 4);
|
||||
foreach($this->hasSpawned as $player){
|
||||
if(!isset($newChunk[$player->getID()])){
|
||||
$this->despawnFrom($player);
|
||||
@ -1141,8 +1141,8 @@ abstract class Entity extends Location implements Metadatable{
|
||||
$yaw = $pos->yaw;
|
||||
$pitch = $pos->pitch;
|
||||
}
|
||||
$from = Position::fromObject($this, $this->getLevel());
|
||||
$to = Position::fromObject($pos, $pos instanceof Position ? $pos->getLevel() : $this->getLevel());
|
||||
$from = Position::fromObject($this, $this->level);
|
||||
$to = Position::fromObject($pos, $pos instanceof Position ? $pos->getLevel() : $this->level);
|
||||
$this->server->getPluginManager()->callEvent($ev = new EntityTeleportEvent($this, $from, $to));
|
||||
if($ev->isCancelled()){
|
||||
return false;
|
||||
@ -1166,7 +1166,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
}
|
||||
|
||||
public function spawnToAll(){
|
||||
foreach($this->getLevel()->getUsingChunk($this->x >> 4, $this->z >> 4) as $player){
|
||||
foreach($this->level->getUsingChunk($this->x >> 4, $this->z >> 4) as $player){
|
||||
if(isset($player->id) and $player->spawned === true){
|
||||
$this->spawnTo($player);
|
||||
}
|
||||
@ -1187,7 +1187,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
if($this->chunk instanceof FullChunk){
|
||||
$this->chunk->removeEntity($this);
|
||||
}
|
||||
if(($level = $this->getLevel()) instanceof Level){
|
||||
if(($level = $this->level) instanceof Level){
|
||||
$level->removeEntity($this);
|
||||
}
|
||||
$this->despawnFromAll();
|
||||
|
@ -370,9 +370,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
* @return Player[]
|
||||
*/
|
||||
public function getUsingChunk($X, $Z){
|
||||
$index = Level::chunkHash($X, $Z);
|
||||
|
||||
return isset($this->usedChunks[$index]) ? $this->usedChunks[$index] : [];
|
||||
return isset($this->usedChunks[$index = "$X:$Z"]) ? $this->usedChunks[$index] : [];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1839,7 +1837,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
}
|
||||
|
||||
public function cancelUnloadChunkRequest($x, $z){
|
||||
unset($this->unloadQueue[static::chunkHash($x, $z)]);
|
||||
unset($this->unloadQueue[Level::chunkHash($x, $z)]);
|
||||
}
|
||||
|
||||
public function unloadChunk($x, $z, $safe = true){
|
||||
|
@ -105,7 +105,7 @@ abstract class BaseLevelProvider implements LevelProvider{
|
||||
"Data" => $this->levelData
|
||||
]));
|
||||
$buffer = $nbt->writeCompressed();
|
||||
@file_put_contents($this->getPath() . "level.dat", $buffer);
|
||||
file_put_contents($this->getPath() . "level.dat", $buffer);
|
||||
}
|
||||
|
||||
|
||||
|
@ -98,7 +98,7 @@ class McRegion extends BaseLevelProvider{
|
||||
"Data" => $levelData
|
||||
]));
|
||||
$buffer = $nbt->writeCompressed();
|
||||
@file_put_contents($path . "level.dat", $buffer);
|
||||
file_put_contents($path . "level.dat", $buffer);
|
||||
}
|
||||
|
||||
public static function getRegionIndex($chunkX, $chunkZ, &$x, &$z){
|
||||
|
@ -168,6 +168,7 @@ class Enum extends NamedTag implements \ArrayAccess, \Countable{
|
||||
|
||||
public function write(NBT $nbt){
|
||||
if(!isset($this->tagType)){
|
||||
$id = null;
|
||||
foreach($this as $tag){
|
||||
if($tag instanceof Tag){
|
||||
if(!isset($id)){
|
||||
@ -177,7 +178,7 @@ class Enum extends NamedTag implements \ArrayAccess, \Countable{
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->tagType = @$id;
|
||||
$this->tagType = $id;
|
||||
}
|
||||
|
||||
$nbt->putByte($this->tagType);
|
||||
|
@ -58,7 +58,7 @@ abstract class DataPacket extends \stdClass{
|
||||
|
||||
$buffer = "";
|
||||
for(; $len > 0; --$len, ++$this->offset){
|
||||
$buffer .= @$this->buffer{$this->offset};
|
||||
$buffer .= $this->buffer{$this->offset};
|
||||
}
|
||||
|
||||
return $buffer;
|
||||
|
@ -43,8 +43,8 @@ class ExplodePacket extends DataPacket{
|
||||
$this->putFloat($this->y);
|
||||
$this->putFloat($this->z);
|
||||
$this->putFloat($this->radius);
|
||||
$this->putInt(@count($this->records));
|
||||
if(@count($this->records) > 0){
|
||||
$this->putInt(count($this->records));
|
||||
if(count($this->records) > 0){
|
||||
foreach($this->records as $record){
|
||||
$this->putByte($record->x);
|
||||
$this->putByte($record->y);
|
||||
|
@ -59,12 +59,12 @@ class RCON{
|
||||
|
||||
return;
|
||||
}
|
||||
@socket_set_block($this->socket);
|
||||
socket_set_block($this->socket);
|
||||
|
||||
for($n = 0; $n < $this->threads; ++$n){
|
||||
$this->workers[$n] = new RCONInstance($this->socket, $this->password, $this->clientsPerThread);
|
||||
}
|
||||
@socket_getsockname($this->socket, $addr, $port);
|
||||
socket_getsockname($this->socket, $addr, $port);
|
||||
$this->server->getLogger()->info("RCON running on $addr:$port");
|
||||
$this->server->getScheduler()->scheduleRepeatingTask(new CallbackTask([$this, "check"]), 3);
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ class RCONInstance extends \Thread{
|
||||
}
|
||||
|
||||
private function readPacket($client, &$size, &$requestID, &$packetType, &$payload){
|
||||
@socket_set_nonblock($client);
|
||||
socket_set_nonblock($client);
|
||||
$d = socket_read($client, 4);
|
||||
if($this->stop === true){
|
||||
return false;
|
||||
@ -66,7 +66,7 @@ class RCONInstance extends \Thread{
|
||||
}elseif($d === "" or strlen($d) < 4){
|
||||
return false;
|
||||
}
|
||||
@socket_set_block($client);
|
||||
socket_set_block($client);
|
||||
$size = Binary::readLInt($d);
|
||||
if($size < 0 or $size > 65535){
|
||||
return false;
|
||||
@ -131,7 +131,7 @@ class RCONInstance extends \Thread{
|
||||
continue;
|
||||
}
|
||||
if($payload === $this->password){
|
||||
@socket_getpeername($client, $addr, $port);
|
||||
socket_getpeername($client, $addr, $port);
|
||||
$this->response = "[INFO] Successful Rcon connection from: /$addr:$port";
|
||||
$this->synchronized(function (){
|
||||
$this->wait();
|
||||
|
@ -53,7 +53,7 @@ abstract class AsyncTask extends \Collectable{
|
||||
* @return mixed
|
||||
*/
|
||||
public function getResult(){
|
||||
return @unserialize($this->result);
|
||||
return unserialize($this->result);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -67,7 +67,7 @@ abstract class AsyncTask extends \Collectable{
|
||||
* @param mixed $result
|
||||
*/
|
||||
public function setResult($result){
|
||||
$this->result = @serialize($result);
|
||||
$this->result = serialize($result);
|
||||
}
|
||||
|
||||
public function setTaskId($taskId){
|
||||
|
@ -58,7 +58,7 @@ class AutoUpdater{
|
||||
|
||||
protected function check(){
|
||||
$response = Utils::getURL($this->endpoint . "?channel=" . $this->getChannel(), 4);
|
||||
$response = @json_decode($response, true);
|
||||
$response = json_decode($response, true);
|
||||
if(!is_array($response)){
|
||||
return;
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ class Binary{
|
||||
* @return mixed
|
||||
*/
|
||||
public static function readTriad($str){
|
||||
return @unpack("N", "\x00" . $str)[1];
|
||||
return unpack("N", "\x00" . $str)[1];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -236,7 +236,7 @@ class Binary{
|
||||
* @return int
|
||||
*/
|
||||
public static function readShort($str, $signed = true){
|
||||
$unpacked = @unpack("n", $str)[1];
|
||||
$unpacked = unpack("n", $str)[1];
|
||||
|
||||
if($signed){
|
||||
if(PHP_INT_SIZE === 8){
|
||||
@ -269,7 +269,7 @@ class Binary{
|
||||
* @return int
|
||||
*/
|
||||
public static function readLShort($str, $signed = true){
|
||||
$unpacked = @unpack("v", $str)[1];
|
||||
$unpacked = unpack("v", $str)[1];
|
||||
|
||||
if($signed){
|
||||
if(PHP_INT_SIZE === 8){
|
||||
@ -295,9 +295,9 @@ class Binary{
|
||||
|
||||
public static function readInt($str){
|
||||
if(PHP_INT_SIZE === 8){
|
||||
return @unpack("N", $str)[1] << 32 >> 32;
|
||||
return unpack("N", $str)[1] << 32 >> 32;
|
||||
}else{
|
||||
return @unpack("N", $str)[1];
|
||||
return unpack("N", $str)[1];
|
||||
}
|
||||
}
|
||||
|
||||
@ -307,9 +307,9 @@ class Binary{
|
||||
|
||||
public static function readLInt($str){
|
||||
if(PHP_INT_SIZE === 8){
|
||||
return @unpack("V", $str)[1] << 32 >> 32;
|
||||
return unpack("V", $str)[1] << 32 >> 32;
|
||||
}else{
|
||||
return @unpack("V", $str)[1];
|
||||
return unpack("V", $str)[1];
|
||||
}
|
||||
}
|
||||
|
||||
@ -318,7 +318,7 @@ class Binary{
|
||||
}
|
||||
|
||||
public static function readFloat($str){
|
||||
return ENDIANNESS === self::BIG_ENDIAN ? @unpack("f", $str)[1] : @unpack("f", strrev($str))[1];
|
||||
return ENDIANNESS === self::BIG_ENDIAN ? unpack("f", $str)[1] : unpack("f", strrev($str))[1];
|
||||
}
|
||||
|
||||
public static function writeFloat($value){
|
||||
@ -326,7 +326,7 @@ class Binary{
|
||||
}
|
||||
|
||||
public static function readLFloat($str){
|
||||
return ENDIANNESS === self::BIG_ENDIAN ? @unpack("f", strrev($str))[1] : @unpack("f", $str)[1];
|
||||
return ENDIANNESS === self::BIG_ENDIAN ? unpack("f", strrev($str))[1] : unpack("f", $str)[1];
|
||||
}
|
||||
|
||||
public static function writeLFloat($value){
|
||||
@ -338,7 +338,7 @@ class Binary{
|
||||
}
|
||||
|
||||
public static function readDouble($str){
|
||||
return ENDIANNESS === self::BIG_ENDIAN ? @unpack("d", $str)[1] : @unpack("d", strrev($str))[1];
|
||||
return ENDIANNESS === self::BIG_ENDIAN ? unpack("d", $str)[1] : unpack("d", strrev($str))[1];
|
||||
}
|
||||
|
||||
public static function writeDouble($value){
|
||||
@ -346,7 +346,7 @@ class Binary{
|
||||
}
|
||||
|
||||
public static function readLDouble($str){
|
||||
return ENDIANNESS === self::BIG_ENDIAN ? @unpack("d", strrev($str))[1] : @unpack("d", $str)[1];
|
||||
return ENDIANNESS === self::BIG_ENDIAN ? unpack("d", strrev($str))[1] : unpack("d", $str)[1];
|
||||
}
|
||||
|
||||
public static function writeLDouble($value){
|
||||
@ -355,7 +355,7 @@ class Binary{
|
||||
|
||||
public static function readLong($x){
|
||||
if(PHP_INT_SIZE === 8){
|
||||
list(, $int1, $int2) = @unpack("N*", $x);
|
||||
list(, $int1, $int2) = unpack("N*", $x);
|
||||
return ($int1 << 32) | $int2;
|
||||
}else{
|
||||
$value = "0";
|
||||
|
@ -231,7 +231,6 @@ class Utils{
|
||||
//some entropy, but works ^^
|
||||
$weakEntropy = [
|
||||
is_array($startEntropy) ? implode($startEntropy) : $startEntropy,
|
||||
serialize(@stat(__FILE__)),
|
||||
__DIR__,
|
||||
PHP_OS,
|
||||
microtime(),
|
||||
@ -253,8 +252,8 @@ class Utils{
|
||||
(string) getmygid(),
|
||||
(string) rand(),
|
||||
function_exists("zend_thread_id") ? ((string) zend_thread_id()) : microtime(),
|
||||
function_exists("getrusage") ? @implode(getrusage()) : microtime(),
|
||||
function_exists("sys_getloadavg") ? @implode(sys_getloadavg()) : microtime(),
|
||||
function_exists("getrusage") ? implode(getrusage()) : microtime(),
|
||||
function_exists("sys_getloadavg") ? implode(sys_getloadavg()) : microtime(),
|
||||
serialize(get_loaded_extensions()),
|
||||
sys_get_temp_dir(),
|
||||
(string) disk_free_space("."),
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit cc1bb88794ec46782853a86beed0a61ee18f2c90
|
||||
Subproject commit d5a195a742b2872d5edac82a7dafc00bbe28ee6a
|
Loading…
x
Reference in New Issue
Block a user