mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 09:56:06 +00:00
Minor improvements to Batch encoding
This commit is contained in:
@ -1771,17 +1771,11 @@ class Server{
|
||||
*/
|
||||
public function batchPackets(array $players, array $packets, $forceSync = false){
|
||||
Timings::$playerNetworkTimer->startTiming();
|
||||
$str = "";
|
||||
|
||||
$pk = new BatchPacket();
|
||||
|
||||
foreach($packets as $p){
|
||||
if($p instanceof DataPacket){
|
||||
if(!$p->isEncoded){
|
||||
$p->encode();
|
||||
}
|
||||
$str .= Binary::writeUnsignedVarInt(strlen($p->buffer)) . $p->buffer;
|
||||
}else{
|
||||
$str .= Binary::writeUnsignedVarInt(strlen($p)) . $p;
|
||||
}
|
||||
$pk->addPacket($p);
|
||||
}
|
||||
|
||||
$targets = [];
|
||||
@ -1792,18 +1786,17 @@ class Server{
|
||||
}
|
||||
|
||||
if(!$forceSync and $this->networkCompressionAsync){
|
||||
$task = new CompressBatchedTask($str, $targets, $this->networkCompressionLevel);
|
||||
$task = new CompressBatchedTask($pk, $targets, $this->networkCompressionLevel);
|
||||
$this->getScheduler()->scheduleAsyncTask($task);
|
||||
}else{
|
||||
$this->broadcastPacketsCallback(zlib_encode($str, ZLIB_ENCODING_DEFLATE, $this->networkCompressionLevel), $targets);
|
||||
$pk->compress($this->networkCompressionLevel);
|
||||
$this->broadcastPacketsCallback($pk, $targets);
|
||||
}
|
||||
|
||||
Timings::$playerNetworkTimer->stopTiming();
|
||||
}
|
||||
|
||||
public function broadcastPacketsCallback($data, array $identifiers){
|
||||
$pk = new BatchPacket();
|
||||
$pk->payload = $data;
|
||||
public function broadcastPacketsCallback(BatchPacket $pk, array $identifiers){
|
||||
$pk->encode();
|
||||
$pk->isEncoded = true;
|
||||
|
||||
|
Reference in New Issue
Block a user