storeLocal(self::TLS_KEY_WORLD, $world); [$this->chunkX, $this->chunkZ] = [$chunk->getX(), $chunk->getZ()]; $chunk->setLightPopulated(null); $this->chunk = FastChunkSerializer::serialize($chunk); } public function onRun() : void{ $chunk = FastChunkSerializer::deserialize($this->chunk); $manager = new SimpleChunkManager(); $manager->setChunk($this->chunkX, $this->chunkZ, $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($this->chunkX, $this->chunkZ); $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 World $world */ $world = $this->fetchLocal(self::TLS_KEY_WORLD); if(!$world->isClosed() and ($chunk = $world->getChunk($this->chunkX, $this->chunkZ)) !== null){ //TODO: calculated light information might not be valid if the terrain changed during light calculation /** @var int[] $heightMapArray */ $heightMapArray = igbinary_unserialize($this->resultHeightMap); $chunk->setHeightMapArray($heightMapArray); /** @var LightArray[] $skyLightArrays */ $skyLightArrays = igbinary_unserialize($this->resultSkyLightArrays); /** @var LightArray[] $blockLightArrays */ $blockLightArrays = igbinary_unserialize($this->resultBlockLightArrays); foreach($skyLightArrays as $y => $array){ $chunk->getSubChunk($y)->setBlockSkyLightArray($array); } foreach($blockLightArrays as $y => $array){ $chunk->getSubChunk($y)->setBlockLightArray($array); } $chunk->setLightPopulated(); } } }