$blockLight, array $skyLight, array $heightMap) : void $onCompletion */ public function __construct(Chunk $chunk, \Closure $onCompletion){ $this->chunk = FastChunkSerializer::serializeTerrain($chunk); $this->storeLocal(self::TLS_KEY_COMPLETION_CALLBACK, $onCompletion); } public function onRun() : void{ $chunk = FastChunkSerializer::deserializeTerrain($this->chunk); $manager = new SimpleChunkManager(World::Y_MIN, World::Y_MAX); $manager->setChunk(0, 0, $chunk); $blockFactory = BlockFactory::getInstance(); foreach([ "Block" => new BlockLightUpdate(new SubChunkExplorer($manager), $blockFactory->lightFilter, $blockFactory->light), "Sky" => new SkyLightUpdate(new SubChunkExplorer($manager), $blockFactory->lightFilter, $blockFactory->blocksDirectSkyLight), ] as $name => $update){ $update->recalculateChunk(0, 0); $update->execute(); } $chunk->setLightPopulated(); $this->resultHeightMap = igbinary_serialize($chunk->getHeightMapArray()); $skyLightArrays = []; $blockLightArrays = []; foreach($chunk->getSubChunks() as $y => $subChunk){ $skyLightArrays[$y] = $subChunk->getBlockSkyLightArray(); $blockLightArrays[$y] = $subChunk->getBlockLightArray(); } $this->resultSkyLightArrays = igbinary_serialize($skyLightArrays); $this->resultBlockLightArrays = igbinary_serialize($blockLightArrays); } public function onCompletion() : void{ /** @var int[] $heightMapArray */ $heightMapArray = igbinary_unserialize($this->resultHeightMap); /** @var LightArray[] $skyLightArrays */ $skyLightArrays = igbinary_unserialize($this->resultSkyLightArrays); /** @var LightArray[] $blockLightArrays */ $blockLightArrays = igbinary_unserialize($this->resultBlockLightArrays); /** * @var \Closure * @phpstan-var \Closure(array $blockLight, array $skyLight, array $heightMap>) : void */ $callback = $this->fetchLocal(self::TLS_KEY_COMPLETION_CALLBACK); $callback($blockLightArrays, $skyLightArrays, $heightMapArray); } }