Minor improvements to Batch encoding

This commit is contained in:
Dylan K. Taylor
2017-04-15 19:40:06 +01:00
parent b55929b382
commit c5eccc8e1c
3 changed files with 39 additions and 18 deletions

View File

@ -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;