From 9dec82cdbc168a900fd860d9b5739bb9cf1df88c Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 31 Oct 2021 23:40:34 +0000 Subject: [PATCH] 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. --- src/world/World.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/world/World.php b/src/world/World.php index 2cd4fab2c7..f58b3ca29d 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -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);