mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 12:18:46 +00:00
Improved chunk loading/unloading
This commit is contained in:
parent
c7f578f297
commit
525c8db779
@ -567,7 +567,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
$index = $this->chunkACK[$identifier];
|
$index = $this->chunkACK[$identifier];
|
||||||
unset($this->chunkACK[$identifier]);
|
unset($this->chunkACK[$identifier]);
|
||||||
if(isset($this->usedChunks[$index])){
|
if(isset($this->usedChunks[$index])){
|
||||||
$this->usedChunks[$index][0] = true;
|
$this->usedChunks[$index] = true;
|
||||||
$X = null;
|
$X = null;
|
||||||
$Z = null;
|
$Z = null;
|
||||||
Level::getXZ($index, $X, $Z);
|
Level::getXZ($index, $X, $Z);
|
||||||
@ -607,21 +607,23 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
if($count >= $this->chunksPerTick){
|
if($count >= $this->chunksPerTick){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
++$count;
|
|
||||||
$X = null;
|
$X = null;
|
||||||
$Z = null;
|
$Z = null;
|
||||||
Level::getXZ($index, $X, $Z);
|
Level::getXZ($index, $X, $Z);
|
||||||
if(!$this->level->isChunkPopulated($X, $Z)){
|
if(!$this->level->isChunkPopulated($X, $Z)){
|
||||||
$this->level->generateChunk($X, $Z);
|
$this->level->generateChunk($X, $Z);
|
||||||
if($this->spawned === true){
|
if($this->spawned){
|
||||||
continue;
|
continue;
|
||||||
}else{
|
}else{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
++$count;
|
||||||
|
|
||||||
unset($this->loadQueue[$index]);
|
unset($this->loadQueue[$index]);
|
||||||
$this->usedChunks[$index] = [false, 0];
|
$this->usedChunks[$index] = false;
|
||||||
|
|
||||||
$this->level->useChunk($X, $Z, $this);
|
$this->level->useChunk($X, $Z, $this);
|
||||||
$this->level->requestChunk($X, $Z, $this, LevelProvider::ORDER_ZXY);
|
$this->level->requestChunk($X, $Z, $this, LevelProvider::ORDER_ZXY);
|
||||||
@ -630,7 +632,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
if(count($this->usedChunks) >= 56 and $this->spawned === false){
|
if(count($this->usedChunks) >= 56 and $this->spawned === false){
|
||||||
$spawned = 0;
|
$spawned = 0;
|
||||||
foreach($this->usedChunks as $d){
|
foreach($this->usedChunks as $d){
|
||||||
if($d[0] === true){
|
if($d === true){
|
||||||
$spawned++;
|
$spawned++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -674,7 +676,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->nextChunkOrderRun = 100;
|
$this->nextChunkOrderRun = 200;
|
||||||
|
|
||||||
$radiusSquared = $this->viewDistance;
|
$radiusSquared = $this->viewDistance;
|
||||||
$radius = ceil(sqrt($radiusSquared));
|
$radius = ceil(sqrt($radiusSquared));
|
||||||
@ -682,23 +684,41 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
|
|
||||||
$newOrder = [];
|
$newOrder = [];
|
||||||
$lastChunk = $this->usedChunks;
|
$lastChunk = $this->usedChunks;
|
||||||
|
$currentQueue = [];
|
||||||
$centerX = $this->x >> 4;
|
$centerX = $this->x >> 4;
|
||||||
$centerZ = $this->z >> 4;
|
$centerZ = $this->z >> 4;
|
||||||
$count = 0;
|
|
||||||
for($X = -$side; $X <= $side; ++$X){
|
for($X = -$side; $X <= $side; ++$X){
|
||||||
for($Z = -$side; $Z <= $side; ++$Z){
|
for($Z = -$side; $Z <= $side; ++$Z){
|
||||||
++$count;
|
|
||||||
$chunkX = $X + $centerX;
|
$chunkX = $X + $centerX;
|
||||||
$chunkZ = $Z + $centerZ;
|
$chunkZ = $Z + $centerZ;
|
||||||
if(!isset($this->usedChunks[$index = "$chunkX:$chunkZ"])){
|
if(!isset($this->usedChunks[$index = "$chunkX:$chunkZ"])){
|
||||||
$newOrder[$index] = abs($X) + abs($Z);
|
$newOrder[$index] = abs($X) + abs($Z);
|
||||||
|
}else{
|
||||||
|
$currentQueue[$index] = abs($X) + abs($Z);
|
||||||
}
|
}
|
||||||
unset($lastChunk[$index]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$loadedChunks = max(0, count($this->usedChunks) - count($lastChunk));
|
|
||||||
asort($newOrder);
|
asort($newOrder);
|
||||||
|
asort($currentQueue);
|
||||||
|
|
||||||
|
|
||||||
|
$limit = $this->viewDistance;
|
||||||
|
foreach($currentQueue as $index => $distance){
|
||||||
|
if($limit-- <= 0){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
unset($lastChunk[$index]);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach($lastChunk as $index => $Yndex){
|
||||||
|
$X = null;
|
||||||
|
$Z = null;
|
||||||
|
Level::getXZ($index, $X, $Z);
|
||||||
|
$this->unloadChunk($X, $Z);
|
||||||
|
}
|
||||||
|
|
||||||
|
$loadedChunks = count($this->usedChunks);
|
||||||
|
|
||||||
if((count($newOrder) + $loadedChunks) > $this->viewDistance){
|
if((count($newOrder) + $loadedChunks) > $this->viewDistance){
|
||||||
$count = $loadedChunks;
|
$count = $loadedChunks;
|
||||||
$this->loadQueue = [];
|
$this->loadQueue = [];
|
||||||
@ -712,14 +732,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
$this->loadQueue = $newOrder;
|
$this->loadQueue = $newOrder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
foreach($lastChunk as $index => $Yndex){
|
|
||||||
$X = null;
|
|
||||||
$Z = null;
|
|
||||||
Level::getXZ($index, $X, $Z);
|
|
||||||
$this->unloadChunk($X, $Z);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1149,7 +1161,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
$this->newPosition = null;
|
$this->newPosition = null;
|
||||||
}else{
|
}else{
|
||||||
$this->forceMovement = null;
|
$this->forceMovement = null;
|
||||||
if($this->nextChunkOrderRun > 20){
|
if($distanceSquared != 0 and $this->nextChunkOrderRun > 20){
|
||||||
$this->nextChunkOrderRun = 20;
|
$this->nextChunkOrderRun = 20;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2324,6 +2336,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
foreach($this->usedChunks as $index => $d){
|
foreach($this->usedChunks as $index => $d){
|
||||||
Level::getXZ($index, $chunkX, $chunkZ);
|
Level::getXZ($index, $chunkX, $chunkZ);
|
||||||
$this->level->freeChunk($chunkX, $chunkZ, $this);
|
$this->level->freeChunk($chunkX, $chunkZ, $this);
|
||||||
|
unset($this->usedChunks[$index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
parent::close();
|
parent::close();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user