requestChunkTask() public method

Requests a MC: PE network chunk to be sent
public requestChunkTask ( integer $x, integer $z ) : AsyncTask | null
$x integer
$z integer
return pocketmine\scheduler\AsyncTask | null
Exemplo n.º 1
0
 protected function processChunkRequest()
 {
     if (count($this->chunkSendQueue) > 0) {
         $this->timings->syncChunkSendTimer->startTiming();
         $x = null;
         $z = null;
         foreach ($this->chunkSendQueue as $index => $players) {
             if (isset($this->chunkSendTasks[$index])) {
                 continue;
             }
             if (PHP_INT_SIZE === 8) {
                 $x = $index >> 32 << 32 >> 32;
                 $z = ($index & 4294967295.0) << 32 >> 32;
             } else {
                 list($x, $z) = explode(":", $index);
                 $x = (int) $x;
                 $z = (int) $z;
             }
             if (ADVANCED_CACHE == true and ($cache = Cache::get("world:" . $this->getId() . ":" . $index)) !== false) {
                 /** @var Player[] $players */
                 foreach ($players as $player) {
                     if ($player->isConnected() and isset($player->usedChunks[$index])) {
                         $player->sendChunk($x, $z, $cache);
                     }
                 }
                 unset($this->chunkSendQueue[$index]);
             } else {
                 $this->chunkSendTasks[$index] = true;
                 $this->timings->syncChunkSendPrepareTimer->startTiming();
                 $task = $this->provider->requestChunkTask($x, $z);
                 if ($task instanceof AsyncTask) {
                     $this->server->getScheduler()->scheduleAsyncTask($task);
                 }
                 $this->timings->syncChunkSendPrepareTimer->stopTiming();
             }
         }
         $this->timings->syncChunkSendTimer->stopTiming();
     }
 }
Exemplo n.º 2
0
 private function processChunkRequest()
 {
     if (count($this->chunkSendQueue) > 0) {
         $this->timings->syncChunkSendTimer->startTiming();
         $x = null;
         $z = null;
         foreach ($this->chunkSendQueue as $index => $players) {
             if (isset($this->chunkSendTasks[$index])) {
                 continue;
             }
             Level::getXZ($index, $x, $z);
             $this->chunkSendTasks[$index] = true;
             if (isset($this->chunkCache[$index])) {
                 $this->sendChunkFromCache($x, $z);
                 continue;
             }
             $this->timings->syncChunkSendPrepareTimer->startTiming();
             $task = $this->provider->requestChunkTask($x, $z);
             if ($task !== null) {
                 $this->server->getScheduler()->scheduleAsyncTask($task);
             }
             $this->timings->syncChunkSendPrepareTimer->stopTiming();
         }
         $this->timings->syncChunkSendTimer->stopTiming();
     }
 }
Exemplo n.º 3
0
 private function processChunkRequest()
 {
     if (\count($this->chunkSendQueue) > 0) {
         $this->timings->syncChunkSendTimer->startTiming();
         $x = \null;
         $z = \null;
         foreach ($this->chunkSendQueue as $index => $players) {
             if (isset($this->chunkSendTasks[$index])) {
                 continue;
             }
             if (\PHP_INT_SIZE === 8) {
                 $x = $index >> 32 << 32 >> 32;
                 $z = ($index & 0xffffffff) << 32 >> 32;
             } else {
                 list($x, $z) = \explode(":", $index);
                 $x = (int) $x;
                 $z = (int) $z;
             }
             $this->chunkSendTasks[$index] = \true;
             if (isset($this->chunkCache[$index])) {
                 $this->sendChunkFromCache($x, $z);
                 continue;
             }
             $this->timings->syncChunkSendPrepareTimer->startTiming();
             $task = $this->provider->requestChunkTask($x, $z);
             if ($task !== \null) {
                 $this->server->getScheduler()->scheduleAsyncTask($task);
             }
             $this->timings->syncChunkSendPrepareTimer->stopTiming();
         }
         $this->timings->syncChunkSendTimer->stopTiming();
     }
 }
Exemplo n.º 4
0
 protected function processChunkRequest()
 {
     if (count($this->chunkSendQueue) > 0) {
         $x = null;
         $z = null;
         foreach ($this->chunkSendQueue as $index => $players) {
             if (isset($this->chunkSendTasks[$index])) {
                 continue;
             }
             Level::getXZ($index, $x, $z);
             if (ADVANCED_CACHE == true and ($cache = Cache::get("world:" . $this->getID() . ":" . $index)) !== false) {
                 /** @var Player[] $players */
                 foreach ($players as $player) {
                     if (isset($player->usedChunks[$index])) {
                         $player->sendChunk($x, $z, $cache);
                     }
                 }
                 unset($this->chunkSendQueue[$index]);
             } else {
                 $this->chunkSendTasks[$index] = true;
                 $task = $this->provider->requestChunkTask($x, $z);
                 if ($task instanceof AsyncTask) {
                     $this->server->getScheduler()->scheduleAsyncTask($task);
                 }
             }
         }
     }
 }
Exemplo n.º 5
0
 private function processChunkRequest()
 {
     if (count($this->chunkSendQueue) > 0) {
         $this->timings->syncChunkSendTimer->startTiming();
         $x = null;
         $z = null;
         foreach ($this->chunkSendQueue as $index => $players) {
             if (isset($this->chunkSendTasks[$index])) {
                 continue;
             }
             Level::getXZ($index, $x, $z);
             $this->chunkSendTasks[$index] = true;
             // Gets chunks from disk or cache if it can
             if (isset($this->chunkCache[$x . ":" . $z]) or $this->loadChunkFromDisk($x, $z)) {
                 foreach ($players as $player) {
                     // Found chunk? Call special function to send just the payload
                     $player->sendBatchedChunk($x, $z, $this->chunkCache[$x . ":" . $z]);
                 }
                 unset($this->chunkSendQueue[$index]);
                 unset($this->chunkSendTasks[$index]);
                 $this->server->chunkUsedTimes[$this->getName()][$x . ":" . $z] = time();
                 continue;
             }
             $this->timings->syncChunkSendPrepareTimer->startTiming();
             $task = $this->provider->requestChunkTask($x, $z);
             if ($task !== null) {
                 $this->server->getScheduler()->scheduleAsyncTask($task);
             }
             $this->timings->syncChunkSendPrepareTimer->stopTiming();
         }
         $this->timings->syncChunkSendTimer->stopTiming();
     }
 }