mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 09:56:06 +00:00
Added encode packet timings
these changes required some new APIs in BedrockProtocol.
This commit is contained in:
@ -120,6 +120,7 @@ use pocketmine\player\XboxLivePlayerInfo;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\timings\Timings;
|
||||
use pocketmine\utils\AssumptionFailedError;
|
||||
use pocketmine\utils\BinaryStream;
|
||||
use pocketmine\utils\ObjectSet;
|
||||
use pocketmine\utils\TextFormat;
|
||||
use pocketmine\utils\Utils;
|
||||
@ -176,7 +177,7 @@ class NetworkSession{
|
||||
|
||||
private ?EncryptionContext $cipher = null;
|
||||
|
||||
/** @var Packet[] */
|
||||
/** @var ClientboundPacket[] */
|
||||
private array $sendBuffer = [];
|
||||
|
||||
/**
|
||||
@ -263,6 +264,23 @@ class NetworkSession{
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClientboundPacket[] $packets
|
||||
*/
|
||||
public static function encodePacketBatchTimed(BinaryStream $stream, PacketSerializerContext $context, array $packets) : void{
|
||||
PacketBatch::encodeRaw($stream, array_map(function(ClientboundPacket $packet) use ($context) : string{
|
||||
$timings = Timings::getEncodeDataPacketTimings($packet);
|
||||
$timings->startTiming();
|
||||
try{
|
||||
$stream = PacketSerializer::encoder($this->packetSerializerContext);
|
||||
$packet->encode($stream);
|
||||
return $stream->getBuffer();
|
||||
}finally{
|
||||
$timings->stopTiming();
|
||||
}
|
||||
}, $packets));
|
||||
}
|
||||
|
||||
private function onPlayerCreated(Player $player) : void{
|
||||
if(!$this->isConnected()){
|
||||
//the remote player might have disconnected before spawn terrain generation was finished
|
||||
@ -502,12 +520,14 @@ class NetworkSession{
|
||||
$syncMode = false;
|
||||
}
|
||||
|
||||
$batch = PacketBatch::fromPackets($this->packetSerializerContext, ...$this->sendBuffer);
|
||||
$stream = new BinaryStream();
|
||||
self::encodePacketBatchTimed($stream, $this->packetSerializerContext, $this->sendBuffer);
|
||||
|
||||
if($this->enableCompression){
|
||||
$promise = $this->server->prepareBatch($batch, $this->compressor, $syncMode);
|
||||
$promise = $this->server->prepareBatch(new PacketBatch($stream->getBuffer()), $this->compressor, $syncMode);
|
||||
}else{
|
||||
$promise = new CompressBatchPromise();
|
||||
$promise->resolve($batch->getBuffer());
|
||||
$promise->resolve($stream->getBuffer());
|
||||
}
|
||||
$this->sendBuffer = [];
|
||||
$this->queueCompressedNoBufferFlush($promise, $immediate);
|
||||
|
Reference in New Issue
Block a user