Merge network refactors

This commit is contained in:
Dylan K. Taylor
2017-07-14 13:04:02 +01:00
23 changed files with 1213 additions and 650 deletions

View File

@ -257,6 +257,7 @@ class Server{
/** @var Player[] */
private $playerList = [];
/** @var string[] */
private $identifiers = [];
/** @var Level[] */
@ -1816,7 +1817,6 @@ class Server{
*/
public function broadcastPacket(array $players, DataPacket $packet){
$packet->encode();
$packet->isEncoded = true;
$this->batchPackets($players, [$packet], false);
}
@ -1846,17 +1846,16 @@ class Server{
}
if(Network::$BATCH_THRESHOLD >= 0 and strlen($pk->payload) >= Network::$BATCH_THRESHOLD){
$compressionLevel = $this->networkCompressionLevel;
$pk->setCompressionLevel($this->networkCompressionLevel);
}else{
$compressionLevel = 0; //Do not compress packets under the threshold
$pk->setCompressionLevel(0); //Do not compress packets under the threshold
$forceSync = true;
}
if(!$forceSync and !$immediate and $this->networkCompressionAsync){
$task = new CompressBatchedTask($pk, $targets, $compressionLevel);
$task = new CompressBatchedTask($pk, $targets);
$this->getScheduler()->scheduleAsyncTask($task);
}else{
$pk->compress($compressionLevel);
$this->broadcastPacketsCallback($pk, $targets, $immediate);
}
}
@ -1867,7 +1866,6 @@ class Server{
public function broadcastPacketsCallback(BatchPacket $pk, array $identifiers, bool $immediate = false){
if(!$pk->isEncoded){
$pk->encode();
$pk->isEncoded = true;
}
if($immediate){