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:
Dylan K. Taylor 2021-03-26 22:45:36 +00:00
parent 49cf009017
commit de49a361c0
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
2 changed files with 7 additions and 7 deletions

View File

@ -903,23 +903,23 @@ class NetworkSession{
/**
* 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.
* @phpstan-param \Closure(int $chunkX, int $chunkZ) : void $onCompletion
* @phpstan-param \Closure() : void $onCompletion
*/
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();
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
function(CompressBatchPromise $promise) use ($chunkX, $chunkZ, $onCompletion) : void{
function(CompressBatchPromise $promise) use ($onCompletion) : void{
if(!$this->isConnected()){
return;
}
$currentWorld->timings->syncChunkSend->startTiming();
try{
$this->queueCompressed($promise);
$onCompletion($chunkX, $chunkZ);
$onCompletion();
}finally{
$currentWorld->timings->syncChunkSend->stopTiming();
}

View File

@ -727,14 +727,14 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
unset($this->loadQueue[$index]);
$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()){
$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;
}
$this->usedChunks[$index] = UsedChunkStatus::SENT();
if($this->spawnChunkLoadCount === -1){
$this->spawnEntitiesOnChunk($chunkX, $chunkZ);
$this->spawnEntitiesOnChunk($X, $Z);
}elseif($this->spawnChunkLoadCount++ === $this->spawnThreshold){
$this->spawnChunkLoadCount = -1;