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();
|
$this->timings->doChunkGC->stopTiming();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,6 +218,8 @@ interface LevelProvider{
|
|||||||
*/
|
*/
|
||||||
public function getLoadedChunks();
|
public function getLoadedChunks();
|
||||||
|
|
||||||
|
public function doGarbageCollection();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Level
|
* @return Level
|
||||||
*/
|
*/
|
||||||
|
@ -50,6 +50,8 @@ class RegionLoader extends \pocketmine\level\format\mcregion\RegionLoader{
|
|||||||
}else{
|
}else{
|
||||||
$this->loadLocationTable();
|
$this->loadLocationTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->lastUsed = time();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function readChunk($x, $z, $generate = true, $forward = false){
|
public function readChunk($x, $z, $generate = true, $forward = false){
|
||||||
@ -58,6 +60,8 @@ class RegionLoader extends \pocketmine\level\format\mcregion\RegionLoader{
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->lastUsed = time();
|
||||||
|
|
||||||
if(!$this->isChunkGenerated($index)){
|
if(!$this->isChunkGenerated($index)){
|
||||||
if($generate === true){
|
if($generate === true){
|
||||||
//Allocate space
|
//Allocate space
|
||||||
|
@ -105,6 +105,10 @@ abstract class BaseLevelProvider implements LevelProvider{
|
|||||||
$this->levelData->SpawnZ = new Int("SpawnZ", (int) $pos->z);
|
$this->levelData->SpawnZ = new Int("SpawnZ", (int) $pos->z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function doGarbageCollection(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Compound
|
* @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){
|
public function loadChunk($chunkX, $chunkZ, $create = false){
|
||||||
$index = Level::chunkHash($chunkX, $chunkZ);
|
$index = Level::chunkHash($chunkX, $chunkZ);
|
||||||
if(isset($this->chunks[$index])){
|
if(isset($this->chunks[$index])){
|
||||||
|
@ -50,6 +50,8 @@ class RegionLoader{
|
|||||||
protected $levelProvider;
|
protected $levelProvider;
|
||||||
protected $locationTable = [];
|
protected $locationTable = [];
|
||||||
|
|
||||||
|
public $lastUsed;
|
||||||
|
|
||||||
public function __construct(LevelProvider $level, $regionX, $regionZ){
|
public function __construct(LevelProvider $level, $regionX, $regionZ){
|
||||||
$this->x = $regionX;
|
$this->x = $regionX;
|
||||||
$this->z = $regionZ;
|
$this->z = $regionZ;
|
||||||
@ -65,6 +67,8 @@ class RegionLoader{
|
|||||||
}else{
|
}else{
|
||||||
$this->loadLocationTable();
|
$this->loadLocationTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->lastUsed = time();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __destruct(){
|
public function __destruct(){
|
||||||
@ -84,6 +88,8 @@ class RegionLoader{
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->lastUsed = time();
|
||||||
|
|
||||||
if(!$this->isChunkGenerated($index)){
|
if(!$this->isChunkGenerated($index)){
|
||||||
if($generate === true){
|
if($generate === true){
|
||||||
//Allocate space
|
//Allocate space
|
||||||
@ -197,6 +203,7 @@ class RegionLoader{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function writeChunk(FullChunk $chunk){
|
public function writeChunk(FullChunk $chunk){
|
||||||
|
$this->lastUsed = time();
|
||||||
$chunkData = $chunk->toBinary();
|
$chunkData = $chunk->toBinary();
|
||||||
if($chunkData !== false){
|
if($chunkData !== false){
|
||||||
$this->saveChunk($chunk->getX() - ($this->getX() * 32), $chunk->getZ() - ($this->getZ() * 32), $chunkData);
|
$this->saveChunk($chunk->getX() - ($this->getX() * 32), $chunk->getZ() - ($this->getZ() * 32), $chunkData);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user