mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-11 04:17:48 +00:00
NetworkSession: Remove parameters from startUsingChunk() callback
these can easily be use()d into the closure (which also has slightly better performance, because no type checks - not that anyone will notice).
This commit is contained in:
parent
49cf009017
commit
de49a361c0
@ -903,23 +903,23 @@ class NetworkSession{
|
|||||||
/**
|
/**
|
||||||
* Instructs the networksession to start using the chunk at the given coordinates. This may occur asynchronously.
|
* Instructs the networksession to start using the chunk at the given coordinates. This may occur asynchronously.
|
||||||
* @param \Closure $onCompletion To be called when chunk sending has completed.
|
* @param \Closure $onCompletion To be called when chunk sending has completed.
|
||||||
* @phpstan-param \Closure(int $chunkX, int $chunkZ) : void $onCompletion
|
* @phpstan-param \Closure() : void $onCompletion
|
||||||
*/
|
*/
|
||||||
public function startUsingChunk(int $chunkX, int $chunkZ, \Closure $onCompletion) : void{
|
public function startUsingChunk(int $chunkX, int $chunkZ, \Closure $onCompletion) : void{
|
||||||
Utils::validateCallableSignature(function(int $chunkX, int $chunkZ) : void{}, $onCompletion);
|
Utils::validateCallableSignature(function() : void{}, $onCompletion);
|
||||||
|
|
||||||
$world = $this->player->getLocation()->getWorld();
|
$world = $this->player->getLocation()->getWorld();
|
||||||
ChunkCache::getInstance($world, $this->compressor)->request($chunkX, $chunkZ)->onResolve(
|
ChunkCache::getInstance($world, $this->compressor)->request($chunkX, $chunkZ)->onResolve(
|
||||||
|
|
||||||
//this callback may be called synchronously or asynchronously, depending on whether the promise is resolved yet
|
//this callback may be called synchronously or asynchronously, depending on whether the promise is resolved yet
|
||||||
function(CompressBatchPromise $promise) use ($chunkX, $chunkZ, $onCompletion) : void{
|
function(CompressBatchPromise $promise) use ($onCompletion) : void{
|
||||||
if(!$this->isConnected()){
|
if(!$this->isConnected()){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$currentWorld->timings->syncChunkSend->startTiming();
|
$currentWorld->timings->syncChunkSend->startTiming();
|
||||||
try{
|
try{
|
||||||
$this->queueCompressed($promise);
|
$this->queueCompressed($promise);
|
||||||
$onCompletion($chunkX, $chunkZ);
|
$onCompletion();
|
||||||
}finally{
|
}finally{
|
||||||
$currentWorld->timings->syncChunkSend->stopTiming();
|
$currentWorld->timings->syncChunkSend->stopTiming();
|
||||||
}
|
}
|
||||||
|
@ -727,14 +727,14 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
|||||||
unset($this->loadQueue[$index]);
|
unset($this->loadQueue[$index]);
|
||||||
$this->usedChunks[$index] = UsedChunkStatus::REQUESTED();
|
$this->usedChunks[$index] = UsedChunkStatus::REQUESTED();
|
||||||
|
|
||||||
$this->getNetworkSession()->startUsingChunk($X, $Z, function(int $chunkX, int $chunkZ) use ($index, $world) : void{
|
$this->getNetworkSession()->startUsingChunk($X, $Z, function() use ($X, $Z, $index, $world) : void{
|
||||||
if(!isset($this->usedChunks[$index]) || $world !== $this->getWorld()){
|
if(!isset($this->usedChunks[$index]) || $world !== $this->getWorld()){
|
||||||
$this->logger->debug("Tried to send no-longer-active chunk $chunkX $chunkZ in world " . $world->getFolderName());
|
$this->logger->debug("Tried to send no-longer-active chunk $X $Z in world " . $world->getFolderName());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->usedChunks[$index] = UsedChunkStatus::SENT();
|
$this->usedChunks[$index] = UsedChunkStatus::SENT();
|
||||||
if($this->spawnChunkLoadCount === -1){
|
if($this->spawnChunkLoadCount === -1){
|
||||||
$this->spawnEntitiesOnChunk($chunkX, $chunkZ);
|
$this->spawnEntitiesOnChunk($X, $Z);
|
||||||
}elseif($this->spawnChunkLoadCount++ === $this->spawnThreshold){
|
}elseif($this->spawnChunkLoadCount++ === $this->spawnThreshold){
|
||||||
$this->spawnChunkLoadCount = -1;
|
$this->spawnChunkLoadCount = -1;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user