Improved batch handling

This commit is contained in:
Dylan K. Taylor
2017-07-13 12:04:47 +01:00
parent 5283975f20
commit 72d1948f30
4 changed files with 43 additions and 34 deletions

View File

@ -33,10 +33,14 @@ class CompressBatchedTask extends AsyncTask{
public $data;
public $targets;
public function __construct(BatchPacket $batch, array $targets, $level = 7){
/**
* @param BatchPacket $batch
* @param string[] $targets
*/
public function __construct(BatchPacket $batch, array $targets){
$this->data = $batch->payload;
$this->targets = serialize($targets);
$this->level = $level;
$this->level = $batch->getCompressionLevel();
}
public function onRun(){
@ -44,7 +48,7 @@ class CompressBatchedTask extends AsyncTask{
$batch->payload = $this->data;
$this->data = null;
$batch->compress($this->level);
$batch->setCompressionLevel($this->level);
$batch->encode();
$this->setResult($batch->buffer, false);
@ -53,7 +57,6 @@ class CompressBatchedTask extends AsyncTask{
public function onCompletion(Server $server){
$pk = new BatchPacket($this->getResult());
$pk->isEncoded = true;
$pk->compressed = true;
$server->broadcastPacketsCallback($pk, unserialize($this->targets));
}
}