mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-08 02:42:58 +00:00
DataPacket: inject buffer via parameter instead of class field (packet & stream separation, step 2)
this is not complete yet, but the final change (having the binarystream actually come from outside) is a little more disruptive, and some extra changes need to be made. This will grant some sanity in the meantime without breaking too much stuff.
This commit is contained in:
@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol;
|
||||
#include <rules/DataPacket.h>
|
||||
|
||||
use pocketmine\network\mcpe\handler\PacketHandler;
|
||||
use pocketmine\network\mcpe\serializer\NetworkBinaryStream;
|
||||
use pocketmine\utils\BinaryDataException;
|
||||
|
||||
class MoveActorDeltaPacket extends DataPacket implements ClientboundPacket{
|
||||
@ -58,9 +59,9 @@ class MoveActorDeltaPacket extends DataPacket implements ClientboundPacket{
|
||||
/**
|
||||
* @throws BinaryDataException
|
||||
*/
|
||||
private function maybeReadCoord(int $flag) : int{
|
||||
private function maybeReadCoord(int $flag, NetworkBinaryStream $in) : int{
|
||||
if(($this->flags & $flag) !== 0){
|
||||
return $this->buf->getVarInt();
|
||||
return $in->getVarInt();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -68,45 +69,45 @@ class MoveActorDeltaPacket extends DataPacket implements ClientboundPacket{
|
||||
/**
|
||||
* @throws BinaryDataException
|
||||
*/
|
||||
private function maybeReadRotation(int $flag) : float{
|
||||
private function maybeReadRotation(int $flag, NetworkBinaryStream $in) : float{
|
||||
if(($this->flags & $flag) !== 0){
|
||||
return $this->buf->getByteRotation();
|
||||
return $in->getByteRotation();
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
protected function decodePayload() : void{
|
||||
$this->entityRuntimeId = $this->buf->getEntityRuntimeId();
|
||||
$this->flags = $this->buf->getLShort();
|
||||
$this->xDiff = $this->maybeReadCoord(self::FLAG_HAS_X);
|
||||
$this->yDiff = $this->maybeReadCoord(self::FLAG_HAS_Y);
|
||||
$this->zDiff = $this->maybeReadCoord(self::FLAG_HAS_Z);
|
||||
$this->xRot = $this->maybeReadRotation(self::FLAG_HAS_ROT_X);
|
||||
$this->yRot = $this->maybeReadRotation(self::FLAG_HAS_ROT_Y);
|
||||
$this->zRot = $this->maybeReadRotation(self::FLAG_HAS_ROT_Z);
|
||||
protected function decodePayload(NetworkBinaryStream $in) : void{
|
||||
$this->entityRuntimeId = $in->getEntityRuntimeId();
|
||||
$this->flags = $in->getLShort();
|
||||
$this->xDiff = $this->maybeReadCoord(self::FLAG_HAS_X, $in);
|
||||
$this->yDiff = $this->maybeReadCoord(self::FLAG_HAS_Y, $in);
|
||||
$this->zDiff = $this->maybeReadCoord(self::FLAG_HAS_Z, $in);
|
||||
$this->xRot = $this->maybeReadRotation(self::FLAG_HAS_ROT_X, $in);
|
||||
$this->yRot = $this->maybeReadRotation(self::FLAG_HAS_ROT_Y, $in);
|
||||
$this->zRot = $this->maybeReadRotation(self::FLAG_HAS_ROT_Z, $in);
|
||||
}
|
||||
|
||||
private function maybeWriteCoord(int $flag, int $val) : void{
|
||||
private function maybeWriteCoord(int $flag, int $val, NetworkBinaryStream $out) : void{
|
||||
if(($this->flags & $flag) !== 0){
|
||||
$this->buf->putVarInt($val);
|
||||
$out->putVarInt($val);
|
||||
}
|
||||
}
|
||||
|
||||
private function maybeWriteRotation(int $flag, float $val) : void{
|
||||
private function maybeWriteRotation(int $flag, float $val, NetworkBinaryStream $out) : void{
|
||||
if(($this->flags & $flag) !== 0){
|
||||
$this->buf->putByteRotation($val);
|
||||
$out->putByteRotation($val);
|
||||
}
|
||||
}
|
||||
|
||||
protected function encodePayload() : void{
|
||||
$this->buf->putEntityRuntimeId($this->entityRuntimeId);
|
||||
$this->buf->putLShort($this->flags);
|
||||
$this->maybeWriteCoord(self::FLAG_HAS_X, $this->xDiff);
|
||||
$this->maybeWriteCoord(self::FLAG_HAS_Y, $this->yDiff);
|
||||
$this->maybeWriteCoord(self::FLAG_HAS_Z, $this->zDiff);
|
||||
$this->maybeWriteRotation(self::FLAG_HAS_ROT_X, $this->xRot);
|
||||
$this->maybeWriteRotation(self::FLAG_HAS_ROT_Y, $this->yRot);
|
||||
$this->maybeWriteRotation(self::FLAG_HAS_ROT_Z, $this->zRot);
|
||||
protected function encodePayload(NetworkBinaryStream $out) : void{
|
||||
$out->putEntityRuntimeId($this->entityRuntimeId);
|
||||
$out->putLShort($this->flags);
|
||||
$this->maybeWriteCoord(self::FLAG_HAS_X, $this->xDiff, $out);
|
||||
$this->maybeWriteCoord(self::FLAG_HAS_Y, $this->yDiff, $out);
|
||||
$this->maybeWriteCoord(self::FLAG_HAS_Z, $this->zDiff, $out);
|
||||
$this->maybeWriteRotation(self::FLAG_HAS_ROT_X, $this->xRot, $out);
|
||||
$this->maybeWriteRotation(self::FLAG_HAS_ROT_Y, $this->yRot, $out);
|
||||
$this->maybeWriteRotation(self::FLAG_HAS_ROT_Z, $this->zRot, $out);
|
||||
}
|
||||
|
||||
public function handle(PacketHandler $handler) : bool{
|
||||
|
Reference in New Issue
Block a user