mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-15 02:09:42 +00:00
Improved world loading, added chunk queue delay, closes #3046
This commit is contained in:
parent
32722856ea
commit
8d4abe2f39
@ -771,7 +771,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
for($Z = -$side; $Z <= $side; ++$Z){
|
||||
$chunkX = $X + $centerX;
|
||||
$chunkZ = $Z + $centerZ;
|
||||
if(!isset($this->usedChunks[$index = Level::chunkHash($chunkX, $chunkZ)])){
|
||||
if(!isset($this->usedChunks[$index = Level::chunkHash($chunkX, $chunkZ)]) or $this->usedChunks[$index] === false){
|
||||
$newOrder[$index] = abs($X) + abs($Z);
|
||||
}else{
|
||||
$currentQueue[$index] = abs($X) + abs($Z);
|
||||
|
@ -48,7 +48,7 @@ class GarbageCollectorCommand extends VanillaCommand{
|
||||
foreach($sender->getServer()->getLevels() as $level){
|
||||
$diff = [count($level->getChunks()), count($level->getEntities()), count($level->getTiles())];
|
||||
$level->doChunkGarbageCollection();
|
||||
$level->unloadChunks();
|
||||
$level->unloadChunks(true);
|
||||
$chunksCollected += $diff[0] - count($level->getChunks());
|
||||
$entitiesCollected += $diff[1] - count($level->getEntities());
|
||||
$tilesCollected += $diff[2] - count($level->getTiles());
|
||||
|
@ -167,7 +167,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
/** @var Player[][] */
|
||||
private $playerLoaders = [];
|
||||
|
||||
/** @var FullChunk[]|Chunk[] */
|
||||
/** @var float[] */
|
||||
private $unloadQueue;
|
||||
|
||||
private $time;
|
||||
@ -2629,16 +2629,25 @@ class Level implements ChunkManager, Metadatable{
|
||||
$this->timings->doChunkGC->stopTiming();
|
||||
}
|
||||
|
||||
public function unloadChunks(){
|
||||
public function unloadChunks($force = false){
|
||||
if(count($this->unloadQueue) > 0){
|
||||
$X = null;
|
||||
$Z = null;
|
||||
$maxUnload = 96;
|
||||
$now = microtime(true);
|
||||
foreach($this->unloadQueue as $index => $time){
|
||||
Level::getXZ($index, $X, $Z);
|
||||
|
||||
if(!$force){
|
||||
if($maxUnload <= 0){
|
||||
break;
|
||||
}elseif($time > ($now - 30)){
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
//If the chunk can't be unloaded, it stays on the queue
|
||||
if($this->unloadChunk($X, $Z, true)){
|
||||
unset($this->unloadQueue[$index]);
|
||||
--$maxUnload;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -158,9 +158,9 @@ abstract class BaseFullChunk implements FullChunk{
|
||||
|
||||
$this->NBTentities = null;
|
||||
$this->NBTtiles = null;
|
||||
}
|
||||
|
||||
$this->setChanged($changed);
|
||||
}
|
||||
|
||||
$this->isInit = true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user