mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 00:33:59 +00:00
Optimized networking code & AxisAlignedBB
This commit is contained in:
parent
673b867ee8
commit
7ab3c57b00
@ -748,7 +748,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
if($this->connected === false){
|
||||
return false;
|
||||
}
|
||||
$this->server->getPluginManager()->callEvent($ev = DataPacketSendEvent::createEvent($this, $packet));
|
||||
$this->server->getPluginManager()->callEvent($ev = $packet->getSendEvent($this));
|
||||
if($ev->isCancelled()){
|
||||
return false;
|
||||
}
|
||||
@ -1288,7 +1288,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
return;
|
||||
}
|
||||
|
||||
$this->server->getPluginManager()->callEvent($ev = DataPacketReceiveEvent::createEvent($this, $packet));
|
||||
$this->server->getPluginManager()->callEvent($ev = $packet->getReceiveEvent($this));
|
||||
if($ev->isCancelled()){
|
||||
return;
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ class Fence extends Transparent{
|
||||
$this->y,
|
||||
$this->z + $f2,
|
||||
$this->x + $f1,
|
||||
$this->y + 1, //TODO: check this, add extra bounding box
|
||||
$this->y + 1,
|
||||
$this->z + $f3
|
||||
);
|
||||
}
|
||||
|
@ -776,8 +776,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
}
|
||||
|
||||
public function isInsideOfWater(){
|
||||
$pos = Vector3::createVector($this->x, $y = ($this->y + $this->getEyeHeight()), $this->z);
|
||||
$block = $this->level->getBlock($pos->floor());
|
||||
$block = $this->level->getBlock(Vector3::createVector(Math::floorFloat($this->x), Math::floorFloat($y = ($this->y + $this->getEyeHeight())), Math::floorFloat($this->z)));
|
||||
|
||||
if($block instanceof Water){
|
||||
$f = ($block->y + 1) - ($block->getFluidHeightPercent() - 0.1111111);
|
||||
@ -788,8 +787,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
}
|
||||
|
||||
public function isInsideOfSolid(){
|
||||
$pos = Vector3::createVector($this->x, $y = ($this->y + $this->getEyeHeight()), $this->z);
|
||||
$block = $this->level->getBlock($pos->floor());
|
||||
$block = $this->level->getBlock(Vector3::createVector(Math::floorFloat($this->x), Math::floorFloat($y = ($this->y + $this->getEyeHeight())), Math::floorFloat($this->z)));
|
||||
|
||||
$bb = $block->getBoundingBox();
|
||||
|
||||
|
@ -26,8 +26,8 @@ class AxisAlignedBB{
|
||||
|
||||
|
||||
/** @var AxisAlignedBB[] */
|
||||
private static $boundingBoxes = [];
|
||||
private static $nextBoundingBox = 0;
|
||||
public static $boundingBoxes = [];
|
||||
public static $nextBoundingBox = 0;
|
||||
|
||||
public $minX;
|
||||
public $minY;
|
||||
@ -126,11 +126,11 @@ class AxisAlignedBB{
|
||||
$maxZ += $z;
|
||||
}
|
||||
|
||||
return self::getBoundingBoxFromPool($minX, $minY, $minZ, $maxX, $maxY, $maxZ);
|
||||
return AxisAlignedBB::getBoundingBoxFromPool($minX, $minY, $minZ, $maxX, $maxY, $maxZ);
|
||||
}
|
||||
|
||||
public function grow($x, $y, $z){
|
||||
return self::getBoundingBoxFromPool($this->minX - $x, $this->minY - $y, $this->minZ - $z, $this->maxX + $x, $this->maxY + $y, $this->maxZ + $z);
|
||||
return AxisAlignedBB::getBoundingBoxFromPool($this->minX - $x, $this->minY - $y, $this->minZ - $z, $this->maxX + $x, $this->maxY + $y, $this->maxZ + $z);
|
||||
}
|
||||
|
||||
public function expand($x, $y, $z){
|
||||
@ -156,7 +156,7 @@ class AxisAlignedBB{
|
||||
}
|
||||
|
||||
public function shrink($x, $y, $z){
|
||||
return self::getBoundingBoxFromPool($this->minX + $x, $this->minY + $y, $this->minZ + $z, $this->maxX - $x, $this->maxY - $y, $this->maxZ - $z);
|
||||
return AxisAlignedBB::getBoundingBoxFromPool($this->minX + $x, $this->minY + $y, $this->minZ + $z, $this->maxX - $x, $this->maxY - $y, $this->maxZ - $z);
|
||||
}
|
||||
|
||||
public function contract($x, $y, $z){
|
||||
@ -181,7 +181,7 @@ class AxisAlignedBB{
|
||||
}
|
||||
|
||||
public function getOffsetBoundingBox($x, $y, $z){
|
||||
return self::getBoundingBoxFromPool($this->minX + $x, $this->minY + $y, $this->minZ + $z, $this->maxX + $x, $this->maxY + $y, $this->maxZ + $z);
|
||||
return AxisAlignedBB::getBoundingBoxFromPool($this->minX + $x, $this->minY + $y, $this->minZ + $z, $this->maxX + $x, $this->maxY + $y, $this->maxZ + $z);
|
||||
}
|
||||
|
||||
public function calculateXOffset(AxisAlignedBB $bb, $x){
|
||||
|
@ -23,17 +23,27 @@ namespace pocketmine\network\protocol;
|
||||
|
||||
#include <rules/DataPacket.h>
|
||||
|
||||
use pocketmine\item\Item;
|
||||
#ifndef COMPILE
|
||||
use pocketmine\utils\Binary;
|
||||
#endif
|
||||
|
||||
use pocketmine\event\server\DataPacketSendEvent;
|
||||
use pocketmine\event\server\DataPacketReceiveEvent;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\Player;
|
||||
|
||||
|
||||
abstract class DataPacket extends \stdClass{
|
||||
|
||||
/** @var DataPacket[] */
|
||||
public static $pool = [];
|
||||
public static $next = 0;
|
||||
|
||||
/** @var DataPacketSendEvent */
|
||||
private $sendEvent = null;
|
||||
/** @var DataPacketReceiveEvent */
|
||||
private $receiveEvent = null;
|
||||
|
||||
public static function getFromPool(){
|
||||
if(static::$next >= count(static::$pool)){
|
||||
static::$pool[] = new static;
|
||||
@ -48,6 +58,38 @@ abstract class DataPacket extends \stdClass{
|
||||
static::$next = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Player $player
|
||||
*
|
||||
* @return DataPacketReceiveEvent
|
||||
*/
|
||||
public function getReceiveEvent(Player $player){
|
||||
if($this->receiveEvent === null){
|
||||
$this->receiveEvent = new DataPacketReceiveEvent($player, $this);
|
||||
}else{
|
||||
$this->receiveEvent->setCancelled(false);
|
||||
$this->receiveEvent->__construct($player, $this);
|
||||
}
|
||||
|
||||
return $this->receiveEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Player $player
|
||||
*
|
||||
* @return DataPacketSendEvent
|
||||
*/
|
||||
public function getSendEvent(Player $player){
|
||||
if($this->sendEvent === null){
|
||||
$this->sendEvent = new DataPacketSendEvent($player, $this);
|
||||
}else{
|
||||
$this->sendEvent->setCancelled(false);
|
||||
$this->sendEvent->__construct($player, $this);
|
||||
}
|
||||
|
||||
return $this->sendEvent;
|
||||
}
|
||||
|
||||
private $offset = 0;
|
||||
public $buffer = "";
|
||||
public $isEncoded = false;
|
||||
|
@ -74,7 +74,7 @@ class Binary{
|
||||
* @return string
|
||||
*/
|
||||
public static function writeLTriad($value){
|
||||
return substr(pack("N", $value), 0, -1);
|
||||
return substr(pack("V", $value), 0, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user