World: fixed requestChunkPopulation() queuing requests for chunks which are already populated

this led to chunk sending getting bogged down if there were more than population-queue-size chunks waiting to be generated.
This commit is contained in:
Dylan K. Taylor 2021-10-31 23:40:34 +00:00
parent 74031d2fbe
commit 9dec82cdbc
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -2799,6 +2799,19 @@ class World implements ChunkManager{
//generation is already running
return $resolver->getPromise();
}
$temporaryChunkLoader = new class implements ChunkLoader{};
$this->registerChunkLoader($temporaryChunkLoader, $chunkX, $chunkZ);
$chunk = $this->loadChunk($chunkX, $chunkZ);
$this->unregisterChunkLoader($temporaryChunkLoader, $chunkX, $chunkZ);
if($chunk !== null && $chunk->isPopulated()){
//chunk is already populated; return a pre-resolved promise that will directly fire callbacks assigned
$resolver ??= new PromiseResolver();
unset($this->chunkPopulationRequestMap[$chunkHash]);
$resolver->resolve($chunk);
return $resolver->getPromise();
}
if(count($this->activeChunkPopulationTasks) >= $this->maxConcurrentChunkPopulationTasks){
//too many chunks are already generating; delay resolution of the request until later
return $resolver?->getPromise() ?? $this->enqueuePopulationRequest($chunkX, $chunkZ, $associatedChunkLoader);