pocketmine\Player::orderChunks PHP Method

orderChunks() protected method

protected orderChunks ( )
    protected function orderChunks()
    {
        if ($this->connected === false) {
            return false;
        }
        Timings::$playerChunkOrderTimer->startTiming();
        $this->nextChunkOrderRun = 200;
        $viewDistance = $this->server->getMemoryManager()->getViewDistance($this->viewDistance);
        $newOrder = [];
        $lastChunk = $this->usedChunks;
        $centerX = $this->x >> 4;
        $centerZ = $this->z >> 4;
        $layer = 1;
        $leg = 0;
        $x = 0;
        $z = 0;
        for ($i = 0; $i < $viewDistance; ++$i) {
            $chunkX = $x + $centerX;
            $chunkZ = $z + $centerZ;
            if (!isset($this->usedChunks[$index = Level::chunkHash($chunkX, $chunkZ)]) or $this->usedChunks[$index] === false) {
                $newOrder[$index] = true;
            }
            unset($lastChunk[$index]);
            switch ($leg) {
                case 0:
                    ++$x;
                    if ($x === $layer) {
                        ++$leg;
                    }
                    break;
                case 1:
                    ++$z;
                    if ($z === $layer) {
                        ++$leg;
                    }
                    break;
                case 2:
                    --$x;
                    if (-$x === $layer) {
                        ++$leg;
                    }
                    break;
                case 3:
                    --$z;
                    if (-$z === $layer) {
                        $leg = 0;
                        ++$layer;
                    }
                    break;
            }
        }
        foreach ($lastChunk as $index => $bool) {
            Level::getXZ($index, $X, $Z);
            $this->unloadChunk($X, $Z);
        }
        $this->loadQueue = $newOrder;
        Timings::$playerChunkOrderTimer->stopTiming();
        return true;
    }
Player