mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-13 09:19:42 +00:00
Unload unused regions after 5 minutes
This commit is contained in:
parent
4b73dbd9f8
commit
042a143dd6
@ -2269,6 +2269,8 @@ class Level implements ChunkManager, Metadatable{
|
||||
}
|
||||
}
|
||||
|
||||
$this->provider->doGarbageCollection();
|
||||
|
||||
$this->timings->doChunkGC->stopTiming();
|
||||
}
|
||||
|
||||
|
@ -218,6 +218,8 @@ interface LevelProvider{
|
||||
*/
|
||||
public function getLoadedChunks();
|
||||
|
||||
public function doGarbageCollection();
|
||||
|
||||
/**
|
||||
* @return Level
|
||||
*/
|
||||
|
@ -50,6 +50,8 @@ class RegionLoader extends \pocketmine\level\format\mcregion\RegionLoader{
|
||||
}else{
|
||||
$this->loadLocationTable();
|
||||
}
|
||||
|
||||
$this->lastUsed = time();
|
||||
}
|
||||
|
||||
public function readChunk($x, $z, $generate = true, $forward = false){
|
||||
@ -58,6 +60,8 @@ class RegionLoader extends \pocketmine\level\format\mcregion\RegionLoader{
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->lastUsed = time();
|
||||
|
||||
if(!$this->isChunkGenerated($index)){
|
||||
if($generate === true){
|
||||
//Allocate space
|
||||
|
@ -105,6 +105,10 @@ abstract class BaseLevelProvider implements LevelProvider{
|
||||
$this->levelData->SpawnZ = new Int("SpawnZ", (int) $pos->z);
|
||||
}
|
||||
|
||||
public function doGarbageCollection(){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Compound
|
||||
*/
|
||||
|
@ -174,6 +174,16 @@ class McRegion extends BaseLevelProvider{
|
||||
}
|
||||
}
|
||||
|
||||
public function doGarbageCollection(){
|
||||
$limit = time() - 300;
|
||||
foreach($this->regions as $index => $region){
|
||||
if($region->lastUsed <= $limit){
|
||||
$region->close();
|
||||
unset($this->regions[$index]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function loadChunk($chunkX, $chunkZ, $create = false){
|
||||
$index = Level::chunkHash($chunkX, $chunkZ);
|
||||
if(isset($this->chunks[$index])){
|
||||
|
@ -50,6 +50,8 @@ class RegionLoader{
|
||||
protected $levelProvider;
|
||||
protected $locationTable = [];
|
||||
|
||||
public $lastUsed;
|
||||
|
||||
public function __construct(LevelProvider $level, $regionX, $regionZ){
|
||||
$this->x = $regionX;
|
||||
$this->z = $regionZ;
|
||||
@ -65,6 +67,8 @@ class RegionLoader{
|
||||
}else{
|
||||
$this->loadLocationTable();
|
||||
}
|
||||
|
||||
$this->lastUsed = time();
|
||||
}
|
||||
|
||||
public function __destruct(){
|
||||
@ -84,6 +88,8 @@ class RegionLoader{
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->lastUsed = time();
|
||||
|
||||
if(!$this->isChunkGenerated($index)){
|
||||
if($generate === true){
|
||||
//Allocate space
|
||||
@ -197,6 +203,7 @@ class RegionLoader{
|
||||
}
|
||||
|
||||
public function writeChunk(FullChunk $chunk){
|
||||
$this->lastUsed = time();
|
||||
$chunkData = $chunk->toBinary();
|
||||
if($chunkData !== false){
|
||||
$this->saveChunk($chunk->getX() - ($this->getX() * 32), $chunk->getZ() - ($this->getZ() * 32), $chunkData);
|
||||
|
Loading…
x
Reference in New Issue
Block a user