mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-08 04:38:35 +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){
|
if($this->connected === false){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$this->server->getPluginManager()->callEvent($ev = DataPacketSendEvent::createEvent($this, $packet));
|
$this->server->getPluginManager()->callEvent($ev = $packet->getSendEvent($this));
|
||||||
if($ev->isCancelled()){
|
if($ev->isCancelled()){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1288,7 +1288,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->server->getPluginManager()->callEvent($ev = DataPacketReceiveEvent::createEvent($this, $packet));
|
$this->server->getPluginManager()->callEvent($ev = $packet->getReceiveEvent($this));
|
||||||
if($ev->isCancelled()){
|
if($ev->isCancelled()){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ class Fence extends Transparent{
|
|||||||
$this->y,
|
$this->y,
|
||||||
$this->z + $f2,
|
$this->z + $f2,
|
||||||
$this->x + $f1,
|
$this->x + $f1,
|
||||||
$this->y + 1, //TODO: check this, add extra bounding box
|
$this->y + 1,
|
||||||
$this->z + $f3
|
$this->z + $f3
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -776,8 +776,7 @@ abstract class Entity extends Location implements Metadatable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function isInsideOfWater(){
|
public function isInsideOfWater(){
|
||||||
$pos = Vector3::createVector($this->x, $y = ($this->y + $this->getEyeHeight()), $this->z);
|
$block = $this->level->getBlock(Vector3::createVector(Math::floorFloat($this->x), Math::floorFloat($y = ($this->y + $this->getEyeHeight())), Math::floorFloat($this->z)));
|
||||||
$block = $this->level->getBlock($pos->floor());
|
|
||||||
|
|
||||||
if($block instanceof Water){
|
if($block instanceof Water){
|
||||||
$f = ($block->y + 1) - ($block->getFluidHeightPercent() - 0.1111111);
|
$f = ($block->y + 1) - ($block->getFluidHeightPercent() - 0.1111111);
|
||||||
@ -788,8 +787,7 @@ abstract class Entity extends Location implements Metadatable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function isInsideOfSolid(){
|
public function isInsideOfSolid(){
|
||||||
$pos = Vector3::createVector($this->x, $y = ($this->y + $this->getEyeHeight()), $this->z);
|
$block = $this->level->getBlock(Vector3::createVector(Math::floorFloat($this->x), Math::floorFloat($y = ($this->y + $this->getEyeHeight())), Math::floorFloat($this->z)));
|
||||||
$block = $this->level->getBlock($pos->floor());
|
|
||||||
|
|
||||||
$bb = $block->getBoundingBox();
|
$bb = $block->getBoundingBox();
|
||||||
|
|
||||||
|
@ -26,8 +26,8 @@ class AxisAlignedBB{
|
|||||||
|
|
||||||
|
|
||||||
/** @var AxisAlignedBB[] */
|
/** @var AxisAlignedBB[] */
|
||||||
private static $boundingBoxes = [];
|
public static $boundingBoxes = [];
|
||||||
private static $nextBoundingBox = 0;
|
public static $nextBoundingBox = 0;
|
||||||
|
|
||||||
public $minX;
|
public $minX;
|
||||||
public $minY;
|
public $minY;
|
||||||
@ -126,11 +126,11 @@ class AxisAlignedBB{
|
|||||||
$maxZ += $z;
|
$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){
|
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){
|
public function expand($x, $y, $z){
|
||||||
@ -156,7 +156,7 @@ class AxisAlignedBB{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function shrink($x, $y, $z){
|
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){
|
public function contract($x, $y, $z){
|
||||||
@ -181,7 +181,7 @@ class AxisAlignedBB{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getOffsetBoundingBox($x, $y, $z){
|
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){
|
public function calculateXOffset(AxisAlignedBB $bb, $x){
|
||||||
|
@ -23,17 +23,27 @@ namespace pocketmine\network\protocol;
|
|||||||
|
|
||||||
#include <rules/DataPacket.h>
|
#include <rules/DataPacket.h>
|
||||||
|
|
||||||
use pocketmine\item\Item;
|
|
||||||
#ifndef COMPILE
|
#ifndef COMPILE
|
||||||
use pocketmine\utils\Binary;
|
use pocketmine\utils\Binary;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
use pocketmine\event\server\DataPacketSendEvent;
|
||||||
|
use pocketmine\event\server\DataPacketReceiveEvent;
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
use pocketmine\Player;
|
||||||
|
|
||||||
|
|
||||||
abstract class DataPacket extends \stdClass{
|
abstract class DataPacket extends \stdClass{
|
||||||
|
|
||||||
/** @var DataPacket[] */
|
/** @var DataPacket[] */
|
||||||
public static $pool = [];
|
public static $pool = [];
|
||||||
public static $next = 0;
|
public static $next = 0;
|
||||||
|
|
||||||
|
/** @var DataPacketSendEvent */
|
||||||
|
private $sendEvent = null;
|
||||||
|
/** @var DataPacketReceiveEvent */
|
||||||
|
private $receiveEvent = null;
|
||||||
|
|
||||||
public static function getFromPool(){
|
public static function getFromPool(){
|
||||||
if(static::$next >= count(static::$pool)){
|
if(static::$next >= count(static::$pool)){
|
||||||
static::$pool[] = new static;
|
static::$pool[] = new static;
|
||||||
@ -48,6 +58,38 @@ abstract class DataPacket extends \stdClass{
|
|||||||
static::$next = 0;
|
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;
|
private $offset = 0;
|
||||||
public $buffer = "";
|
public $buffer = "";
|
||||||
public $isEncoded = false;
|
public $isEncoded = false;
|
||||||
|
@ -74,7 +74,7 @@ class Binary{
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function writeLTriad($value){
|
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