mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 09:56:06 +00:00
Merge branch 'minor-next' into major-next
This commit is contained in:
@ -121,6 +121,8 @@ use pocketmine\utils\AssumptionFailedError;
|
||||
use pocketmine\utils\TextFormat;
|
||||
use pocketmine\world\ChunkListener;
|
||||
use pocketmine\world\ChunkListenerNoOpTrait;
|
||||
use pocketmine\world\ChunkLoader;
|
||||
use pocketmine\world\ChunkTicker;
|
||||
use pocketmine\world\format\Chunk;
|
||||
use pocketmine\world\Position;
|
||||
use pocketmine\world\sound\EntityAttackNoDamageSound;
|
||||
@ -239,12 +241,16 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
||||
protected array $loadQueue = [];
|
||||
protected int $nextChunkOrderRun = 5;
|
||||
|
||||
/** @var true[] */
|
||||
private array $tickingChunks = [];
|
||||
|
||||
protected int $viewDistance = -1;
|
||||
protected int $spawnThreshold;
|
||||
protected int $spawnChunkLoadCount = 0;
|
||||
protected int $chunksPerTick;
|
||||
protected ChunkSelector $chunkSelector;
|
||||
protected PlayerChunkLoader $chunkLoader;
|
||||
protected ChunkLoader $chunkLoader;
|
||||
protected ChunkTicker $chunkTicker;
|
||||
|
||||
/** @var bool[] map: raw UUID (string) => bool */
|
||||
protected array $hiddenPlayers = [];
|
||||
@ -310,8 +316,8 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
||||
$this->spawnThreshold = (int) (($this->server->getConfigGroup()->getPropertyInt("chunk-sending.spawn-radius", 4) ** 2) * M_PI);
|
||||
$this->chunkSelector = new ChunkSelector();
|
||||
|
||||
$this->chunkLoader = new PlayerChunkLoader($spawnLocation);
|
||||
|
||||
$this->chunkLoader = new class implements ChunkLoader{};
|
||||
$this->chunkTicker = new ChunkTicker();
|
||||
$world = $spawnLocation->getWorld();
|
||||
//load the spawn chunk so we can see the terrain
|
||||
$xSpawnChunk = $spawnLocation->getFloorX() >> Chunk::COORD_BIT_SIZE;
|
||||
@ -749,6 +755,8 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
||||
$world->unregisterChunkLoader($this->chunkLoader, $x, $z);
|
||||
$world->unregisterChunkListener($this, $x, $z);
|
||||
unset($this->loadQueue[$index]);
|
||||
$world->unregisterTickingChunk($this->chunkTicker, $x, $z);
|
||||
unset($this->tickingChunks[$index]);
|
||||
}
|
||||
|
||||
protected function spawnEntitiesOnAllChunks() : void{
|
||||
@ -800,6 +808,9 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
||||
unset($this->loadQueue[$index]);
|
||||
$this->getWorld()->registerChunkLoader($this->chunkLoader, $X, $Z, true);
|
||||
$this->getWorld()->registerChunkListener($this, $X, $Z);
|
||||
if(isset($this->tickingChunks[$index])){
|
||||
$this->getWorld()->registerTickingChunk($this->chunkTicker, $X, $Z);
|
||||
}
|
||||
|
||||
$this->getWorld()->requestChunkPopulation($X, $Z, $this->chunkLoader)->onCompletion(
|
||||
function() use ($X, $Z, $index, $world) : void{
|
||||
@ -897,16 +908,23 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
||||
Timings::$playerChunkOrder->startTiming();
|
||||
|
||||
$newOrder = [];
|
||||
$tickingChunks = [];
|
||||
$unloadChunks = $this->usedChunks;
|
||||
|
||||
$world = $this->getWorld();
|
||||
$tickingChunkRadius = $world->getChunkTickRadius();
|
||||
|
||||
foreach($this->chunkSelector->selectChunks(
|
||||
$this->server->getAllowedViewDistance($this->viewDistance),
|
||||
$this->location->getFloorX() >> Chunk::COORD_BIT_SIZE,
|
||||
$this->location->getFloorZ() >> Chunk::COORD_BIT_SIZE
|
||||
) as $hash){
|
||||
) as $radius => $hash){
|
||||
if(!isset($this->usedChunks[$hash]) || $this->usedChunks[$hash]->equals(UsedChunkStatus::NEEDED())){
|
||||
$newOrder[$hash] = true;
|
||||
}
|
||||
if($radius < $tickingChunkRadius){
|
||||
$tickingChunks[$hash] = true;
|
||||
}
|
||||
unset($unloadChunks[$hash]);
|
||||
}
|
||||
|
||||
@ -914,10 +932,18 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
||||
World::getXZ($index, $X, $Z);
|
||||
$this->unloadChunk($X, $Z);
|
||||
}
|
||||
foreach($this->tickingChunks as $hash => $_){
|
||||
//any chunks we encounter here are still used by the player, but may no longer be within ticking range
|
||||
if(!isset($tickingChunks[$hash]) && !isset($newOrder[$hash])){
|
||||
World::getXZ($hash, $tickingChunkX, $tickingChunkZ);
|
||||
$world->unregisterTickingChunk($this->chunkTicker, $tickingChunkX, $tickingChunkZ);
|
||||
}
|
||||
}
|
||||
|
||||
$this->loadQueue = $newOrder;
|
||||
$this->tickingChunks = $tickingChunks;
|
||||
|
||||
if(count($this->loadQueue) > 0 || count($unloadChunks) > 0){
|
||||
$this->chunkLoader->setCurrentLocation($this->location);
|
||||
$this->getNetworkSession()->syncViewAreaCenterPoint($this->location, $this->viewDistance);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user