mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-23 03:16:35 +00:00
Improved chunk loading and order refresh times
This commit is contained in:
parent
163a37ee23
commit
7760559be1
@ -105,7 +105,6 @@ use pocketmine\scheduler\CallbackTask;
|
||||
use pocketmine\tile\Sign;
|
||||
use pocketmine\tile\Spawnable;
|
||||
use pocketmine\tile\Tile;
|
||||
use pocketmine\utils\ReversePriorityQueue;
|
||||
use pocketmine\utils\TextFormat;
|
||||
use pocketmine\utils\TextWrapper;
|
||||
|
||||
@ -168,8 +167,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
public $usedChunks = [];
|
||||
protected $loadQueue = [];
|
||||
protected $chunkACK = [];
|
||||
/** @var \pocketmine\scheduler\TaskHandler */
|
||||
protected $chunkLoadTask;
|
||||
protected $nextChunkOrderRun = 5;
|
||||
|
||||
/** @var Player[] */
|
||||
protected $hiddenPlayers = [];
|
||||
@ -594,22 +592,12 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$this->chunkACK[$cnt] = Level::chunkHash($x, $z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends, if available, the next ordered chunk to the client
|
||||
*
|
||||
* WARNING: Do not use this, it's only for internal use.
|
||||
* Changes to this function won't be recorded on the version.
|
||||
*
|
||||
*/
|
||||
public function sendNextChunk(){
|
||||
if($this->connected === false or !isset($this->chunkLoadTask)){
|
||||
return;
|
||||
protected function sendNextChunk(){
|
||||
if($this->connected === false){
|
||||
return false;
|
||||
}
|
||||
|
||||
if(count($this->loadQueue) === 0){
|
||||
$this->chunkLoadTask->setNextRun($this->chunkLoadTask->getNextRun() + 30);
|
||||
}else{
|
||||
$count = 0;;
|
||||
$count = 0;
|
||||
foreach($this->loadQueue as $index => $distance){
|
||||
if($count >= $this->chunksPerTick){
|
||||
break;
|
||||
@ -633,7 +621,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$this->level->useChunk($X, $Z, $this);
|
||||
$this->level->requestChunk($X, $Z, $this, LevelProvider::ORDER_ZXY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(count($this->usedChunks) < 16 and $this->spawned === true){
|
||||
$this->blocked = true;
|
||||
@ -650,7 +638,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
}
|
||||
|
||||
if($spawned < 56){
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->spawned = true;
|
||||
@ -686,18 +674,13 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* WARNING: Do not use this, it's only for internal use.
|
||||
* Changes to this function won't be recorded on the version.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function orderChunks(){
|
||||
protected function orderChunks(){
|
||||
if($this->connected === false){
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->nextChunkOrderRun = 100;
|
||||
|
||||
$radiusSquared = $this->viewDistance;
|
||||
$radius = ceil(sqrt($radiusSquared));
|
||||
$side = ceil($radius / 2);
|
||||
@ -1068,10 +1051,11 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
return -1;
|
||||
}
|
||||
|
||||
public function processMovement(){
|
||||
protected function processMovement($currentTick){
|
||||
if($this->dead or !$this->spawned or !($this->newPosition instanceof Vector3)){
|
||||
return;
|
||||
}
|
||||
|
||||
$oldPos = new Vector3($this->x, $this->y, $this->z);
|
||||
$distance = $oldPos->distance($this->newPosition);
|
||||
|
||||
@ -1171,6 +1155,9 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$this->forceMovement = new Vector3($from->x, $from->y, $from->z);
|
||||
}else{
|
||||
$this->forceMovement = null;
|
||||
if($this->nextChunkOrderRun > 4){
|
||||
$this->nextChunkOrderRun = 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1179,7 +1166,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
}
|
||||
|
||||
public function onUpdate($currentTick){
|
||||
if($this->spawned === false or $this->dead === true){
|
||||
if($this->dead === true){
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1187,7 +1174,8 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
|
||||
$this->lastUpdate = $currentTick;
|
||||
|
||||
$this->processMovement();
|
||||
if($this->spawned){
|
||||
$this->processMovement($currentTick);
|
||||
|
||||
$this->entityBaseTick(1);
|
||||
|
||||
@ -1267,6 +1255,15 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($this->nextChunkOrderRun-- <= 0){
|
||||
$this->orderChunks();
|
||||
}
|
||||
|
||||
if(count($this->loadQueue) > 0){
|
||||
$this->sendNextChunk();
|
||||
}
|
||||
|
||||
$this->timings->stopTiming();
|
||||
|
||||
@ -1463,10 +1460,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
|
||||
|
||||
$this->orderChunks();
|
||||
$this->tasks[] = $this->server->getScheduler()->scheduleDelayedRepeatingTask(new CallbackTask([$this, "orderChunks"]), 10, 40);
|
||||
$this->sendNextChunk();
|
||||
$this->tasks[] = $this->chunkLoadTask = $this->server->getScheduler()->scheduleRepeatingTask(new CallbackTask([$this, "sendNextChunk"]), 1);
|
||||
|
||||
break;
|
||||
case ProtocolInfo::ROTATE_HEAD_PACKET:
|
||||
if($this->spawned === false or $this->dead === true){
|
||||
@ -2525,7 +2519,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$this->airTicks = 300;
|
||||
$this->fallDistance = 0;
|
||||
$this->orderChunks();
|
||||
$this->chunkLoadTask->setNextRun(0);
|
||||
$this->forceMovement = $pos;
|
||||
$this->newPosition = $pos;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user