Exemple #1
0
 public function __construct(LevelProvider $level, $regionX, $regionZ)
 {
     $this->x = $regionX;
     $this->z = $regionZ;
     $this->levelProvider = $level;
     $this->filePath = $this->levelProvider->getPath() . "region/r.{$regionX}.{$regionZ}.mcr";
     $exists = file_exists($this->filePath);
     if (!$exists) {
         touch($this->filePath);
     }
     $this->filePointer = fopen($this->filePath, "r+b");
     stream_set_read_buffer($this->filePointer, 1024 * 16);
     //16KB
     stream_set_write_buffer($this->filePointer, 1024 * 16);
     //16KB
     if (!$exists) {
         $this->createBlank();
     } else {
         $this->loadLocationTable();
     }
     $this->lastUsed = time();
 }
Exemple #2
0
 public function doChunkGarbageCollection()
 {
     $this->timings->doChunkGC->startTiming();
     $X = null;
     $Z = null;
     foreach ($this->chunks as $index => $chunk) {
         if (!isset($this->unloadQueue[$index]) and (!isset($this->usedChunks[$index]) or count($this->usedChunks[$index]) === 0)) {
             Level::getXZ($index, $X, $Z);
             if (!$this->isSpawnChunk($X, $Z)) {
                 $this->unloadChunkRequest($X, $Z, true);
             }
         }
     }
     foreach ($this->provider->getLoadedChunks() as $chunk) {
         if (!isset($this->chunks[Level::chunkHash($chunk->getX(), $chunk->getZ())])) {
             $this->provider->unloadChunk($chunk->getX(), $chunk->getZ(), false);
         }
     }
     $this->provider->doGarbageCollection();
     $this->timings->doChunkGC->stopTiming();
 }