mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-11 00:09:39 +00:00
Reduce complexity of chunk sending system
This commit is contained in:
parent
51548d1a27
commit
78bb6f4a0c
@ -969,30 +969,6 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
unset($this->loadQueue[$index]);
|
unset($this->loadQueue[$index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onChunkReady(int $x, int $z){
|
|
||||||
if(!$this->isConnected()){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(isset($this->usedChunks[World::chunkHash($x, $z)]));
|
|
||||||
$this->usedChunks[World::chunkHash($x, $z)] = true;
|
|
||||||
|
|
||||||
$this->networkSession->startUsingChunk($x, $z, function(int $chunkX, int $chunkZ) : void{
|
|
||||||
if($this->spawned){
|
|
||||||
$this->spawnEntitiesOnChunk($chunkX, $chunkZ);
|
|
||||||
}elseif($this->spawnChunkLoadCount++ === $this->spawnThreshold){
|
|
||||||
$this->spawned = true;
|
|
||||||
|
|
||||||
foreach($this->usedChunks as $chunkHash => $_){
|
|
||||||
World::getXZ($chunkHash, $_x, $_z);
|
|
||||||
$this->spawnEntitiesOnChunk($_x, $_z);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->networkSession->onTerrainReady();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function spawnEntitiesOnChunk(int $chunkX, int $chunkZ) : void{
|
protected function spawnEntitiesOnChunk(int $chunkX, int $chunkZ) : void{
|
||||||
foreach($this->world->getChunkEntities($chunkX, $chunkZ) as $entity){
|
foreach($this->world->getChunkEntities($chunkX, $chunkZ) as $entity){
|
||||||
if($entity !== $this and !$entity->isClosed() and !$entity->isFlaggedForDespawn()){
|
if($entity !== $this and !$entity->isClosed() and !$entity->isFlaggedForDespawn()){
|
||||||
@ -1030,7 +1006,22 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
}
|
}
|
||||||
|
|
||||||
unset($this->loadQueue[$index]);
|
unset($this->loadQueue[$index]);
|
||||||
$this->world->requestChunk($X, $Z, $this);
|
$this->usedChunks[$index] = true;
|
||||||
|
|
||||||
|
$this->networkSession->startUsingChunk($X, $Z, function(int $chunkX, int $chunkZ) : void{
|
||||||
|
if($this->spawned){
|
||||||
|
$this->spawnEntitiesOnChunk($chunkX, $chunkZ);
|
||||||
|
}elseif($this->spawnChunkLoadCount++ === $this->spawnThreshold){
|
||||||
|
$this->spawned = true;
|
||||||
|
|
||||||
|
foreach($this->usedChunks as $chunkHash => $_){
|
||||||
|
World::getXZ($chunkHash, $_x, $_z);
|
||||||
|
$this->spawnEntitiesOnChunk($_x, $_z);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->networkSession->onTerrainReady();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Timings::$playerChunkSendTimer->stopTiming();
|
Timings::$playerChunkSendTimer->stopTiming();
|
||||||
|
@ -70,7 +70,6 @@ use pocketmine\timings\Timings;
|
|||||||
use pocketmine\utils\ReversePriorityQueue;
|
use pocketmine\utils\ReversePriorityQueue;
|
||||||
use pocketmine\world\biome\Biome;
|
use pocketmine\world\biome\Biome;
|
||||||
use pocketmine\world\format\Chunk;
|
use pocketmine\world\format\Chunk;
|
||||||
use pocketmine\world\format\ChunkException;
|
|
||||||
use pocketmine\world\format\EmptySubChunk;
|
use pocketmine\world\format\EmptySubChunk;
|
||||||
use pocketmine\world\format\io\exception\CorruptedChunkException;
|
use pocketmine\world\format\io\exception\CorruptedChunkException;
|
||||||
use pocketmine\world\format\io\exception\UnsupportedChunkFormatException;
|
use pocketmine\world\format\io\exception\UnsupportedChunkFormatException;
|
||||||
@ -217,9 +216,6 @@ class World implements ChunkManager, Metadatable{
|
|||||||
/** @var bool[] blockhash => dummy */
|
/** @var bool[] blockhash => dummy */
|
||||||
private $neighbourBlockUpdateQueueIndex = [];
|
private $neighbourBlockUpdateQueueIndex = [];
|
||||||
|
|
||||||
/** @var Player[][] */
|
|
||||||
private $chunkSendQueue = [];
|
|
||||||
|
|
||||||
/** @var bool[] */
|
/** @var bool[] */
|
||||||
private $chunkPopulationQueue = [];
|
private $chunkPopulationQueue = [];
|
||||||
/** @var bool[] */
|
/** @var bool[] */
|
||||||
@ -865,7 +861,6 @@ class World implements ChunkManager, Metadatable{
|
|||||||
foreach($this->players as $p){
|
foreach($this->players as $p){
|
||||||
$p->doChunkRequests();
|
$p->doChunkRequests();
|
||||||
}
|
}
|
||||||
$this->processChunkRequests();
|
|
||||||
|
|
||||||
if($this->sleepTicks > 0 and --$this->sleepTicks <= 0){
|
if($this->sleepTicks > 0 and --$this->sleepTicks <= 0){
|
||||||
$this->checkSleep();
|
$this->checkSleep();
|
||||||
@ -2407,42 +2402,6 @@ class World implements ChunkManager, Metadatable{
|
|||||||
(new SpawnChangeEvent($this, $previousSpawn))->call();
|
(new SpawnChangeEvent($this, $previousSpawn))->call();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function requestChunk(int $x, int $z, Player $player){
|
|
||||||
$index = World::chunkHash($x, $z);
|
|
||||||
if(!isset($this->chunkSendQueue[$index])){
|
|
||||||
$this->chunkSendQueue[$index] = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->chunkSendQueue[$index][spl_object_id($player)] = $player;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function processChunkRequests(){
|
|
||||||
if(count($this->chunkSendQueue) > 0){
|
|
||||||
$this->timings->syncChunkSendTimer->startTiming();
|
|
||||||
|
|
||||||
foreach($this->chunkSendQueue as $index => $players){
|
|
||||||
World::getXZ($index, $x, $z);
|
|
||||||
|
|
||||||
$this->timings->syncChunkSendPrepareTimer->startTiming();
|
|
||||||
|
|
||||||
$chunk = $this->chunks[$index] ?? null;
|
|
||||||
if($chunk === null or !$chunk->isGenerated() or !$chunk->isPopulated()){
|
|
||||||
throw new ChunkException("Invalid Chunk sent");
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($players as $player){
|
|
||||||
$player->onChunkReady($x, $z);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->timings->syncChunkSendPrepareTimer->stopTiming();
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->chunkSendQueue = [];
|
|
||||||
|
|
||||||
$this->timings->syncChunkSendTimer->stopTiming();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Entity $entity
|
* @param Entity $entity
|
||||||
*
|
*
|
||||||
@ -2670,7 +2629,6 @@ class World implements ChunkManager, Metadatable{
|
|||||||
unset($this->chunks[$chunkHash]);
|
unset($this->chunks[$chunkHash]);
|
||||||
unset($this->blockCache[$chunkHash]);
|
unset($this->blockCache[$chunkHash]);
|
||||||
unset($this->changedBlocks[$chunkHash]);
|
unset($this->changedBlocks[$chunkHash]);
|
||||||
unset($this->chunkSendQueue[$chunkHash]);
|
|
||||||
|
|
||||||
$this->timings->doChunkUnload->stopTiming();
|
$this->timings->doChunkUnload->stopTiming();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user