mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-29 14:49:59 +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){
|
for($Z = -$side; $Z <= $side; ++$Z){
|
||||||
$chunkX = $X + $centerX;
|
$chunkX = $X + $centerX;
|
||||||
$chunkZ = $Z + $centerZ;
|
$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);
|
$newOrder[$index] = abs($X) + abs($Z);
|
||||||
}else{
|
}else{
|
||||||
$currentQueue[$index] = abs($X) + abs($Z);
|
$currentQueue[$index] = abs($X) + abs($Z);
|
||||||
|
@ -48,7 +48,7 @@ class GarbageCollectorCommand extends VanillaCommand{
|
|||||||
foreach($sender->getServer()->getLevels() as $level){
|
foreach($sender->getServer()->getLevels() as $level){
|
||||||
$diff = [count($level->getChunks()), count($level->getEntities()), count($level->getTiles())];
|
$diff = [count($level->getChunks()), count($level->getEntities()), count($level->getTiles())];
|
||||||
$level->doChunkGarbageCollection();
|
$level->doChunkGarbageCollection();
|
||||||
$level->unloadChunks();
|
$level->unloadChunks(true);
|
||||||
$chunksCollected += $diff[0] - count($level->getChunks());
|
$chunksCollected += $diff[0] - count($level->getChunks());
|
||||||
$entitiesCollected += $diff[1] - count($level->getEntities());
|
$entitiesCollected += $diff[1] - count($level->getEntities());
|
||||||
$tilesCollected += $diff[2] - count($level->getTiles());
|
$tilesCollected += $diff[2] - count($level->getTiles());
|
||||||
|
@ -167,7 +167,7 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
/** @var Player[][] */
|
/** @var Player[][] */
|
||||||
private $playerLoaders = [];
|
private $playerLoaders = [];
|
||||||
|
|
||||||
/** @var FullChunk[]|Chunk[] */
|
/** @var float[] */
|
||||||
private $unloadQueue;
|
private $unloadQueue;
|
||||||
|
|
||||||
private $time;
|
private $time;
|
||||||
@ -2629,16 +2629,25 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
$this->timings->doChunkGC->stopTiming();
|
$this->timings->doChunkGC->stopTiming();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function unloadChunks(){
|
public function unloadChunks($force = false){
|
||||||
if(count($this->unloadQueue) > 0){
|
if(count($this->unloadQueue) > 0){
|
||||||
$X = null;
|
$maxUnload = 96;
|
||||||
$Z = null;
|
$now = microtime(true);
|
||||||
foreach($this->unloadQueue as $index => $time){
|
foreach($this->unloadQueue as $index => $time){
|
||||||
Level::getXZ($index, $X, $Z);
|
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 the chunk can't be unloaded, it stays on the queue
|
||||||
if($this->unloadChunk($X, $Z, true)){
|
if($this->unloadChunk($X, $Z, true)){
|
||||||
unset($this->unloadQueue[$index]);
|
unset($this->unloadQueue[$index]);
|
||||||
|
--$maxUnload;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,10 +158,10 @@ abstract class BaseFullChunk implements FullChunk{
|
|||||||
|
|
||||||
$this->NBTentities = null;
|
$this->NBTentities = null;
|
||||||
$this->NBTtiles = null;
|
$this->NBTtiles = null;
|
||||||
|
|
||||||
$this->setChanged($changed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->setChanged($changed);
|
||||||
|
|
||||||
$this->isInit = true;
|
$this->isInit = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user