From 03de2bcc670528219044138013da4404871a5ca7 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 8 Sep 2020 23:03:52 +0100 Subject: [PATCH] Chunk: simplify heightmap calculation --- src/world/format/Chunk.php | 20 ++++++++------------ src/world/generator/PopulationTask.php | 2 +- src/world/light/LightPopulationTask.php | 2 +- src/world/light/SkyLightUpdate.php | 2 +- tests/phpstan/configs/l8-baseline.neon | 5 +++++ 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/world/format/Chunk.php b/src/world/format/Chunk.php index e842fef96..0b76f0076 100644 --- a/src/world/format/Chunk.php +++ b/src/world/format/Chunk.php @@ -260,12 +260,10 @@ class Chunk{ /** * Recalculates the heightmap for the whole chunk. * - * @param \SplFixedArray|int[] $lightFilters - * @param \SplFixedArray|bool[] $lightDiffusers - * @phpstan-param \SplFixedArray $lightFilters - * @phpstan-param \SplFixedArray $lightDiffusers + * @param \SplFixedArray|bool[] $directSkyLightBlockers + * @phpstan-param \SplFixedArray $directSkyLightBlockers */ - public function recalculateHeightMap(\SplFixedArray $lightFilters, \SplFixedArray $lightDiffusers) : void{ + public function recalculateHeightMap(\SplFixedArray $directSkyLightBlockers) : void{ $maxSubChunkY = $this->subChunks->count() - 1; for(; $maxSubChunkY >= 0; $maxSubChunkY--){ if(!$this->getSubChunk($maxSubChunkY)->isEmptyFast()){ @@ -292,7 +290,7 @@ class Chunk{ $this->setHeightMap($x, $z, 0); }else{ for(; $y >= 0; --$y){ - if($lightFilters[$state = $this->getFullBlock($x, $y, $z)] > 1 or $lightDiffusers[$state]){ + if($directSkyLightBlockers[$this->getFullBlock($x, $y, $z)]){ $this->setHeightMap($x, $z, $y + 1); break; } @@ -307,17 +305,15 @@ class Chunk{ * * @param int $x 0-15 * @param int $z 0-15 - * @param \SplFixedArray|int[] $lightFilters - * @param \SplFixedArray|bool[] $lightDiffusers - * @phpstan-param \SplFixedArray $lightFilters - * @phpstan-param \SplFixedArray $lightDiffusers + * @param \SplFixedArray|bool[] $directSkyLightBlockers + * @phpstan-param \SplFixedArray $directSkyLightBlockers * * @return int New calculated heightmap value (0-256 inclusive) */ - public function recalculateHeightMapColumn(int $x, int $z, \SplFixedArray $lightFilters, \SplFixedArray $lightDiffusers) : int{ + public function recalculateHeightMapColumn(int $x, int $z, \SplFixedArray $directSkyLightBlockers) : int{ $y = $this->getHighestBlockAt($x, $z); for(; $y >= 0; --$y){ - if($lightFilters[$state = $this->getFullBlock($x, $y, $z)] > 1 or $lightDiffusers[$state]){ + if($directSkyLightBlockers[$this->getFullBlock($x, $y, $z)]){ break; } } diff --git a/src/world/generator/PopulationTask.php b/src/world/generator/PopulationTask.php index 979909119..f4f3df3ac 100644 --- a/src/world/generator/PopulationTask.php +++ b/src/world/generator/PopulationTask.php @@ -119,7 +119,7 @@ class PopulationTask extends AsyncTask{ $chunk->setPopulated(); $blockFactory = BlockFactory::getInstance(); - $chunk->recalculateHeightMap($blockFactory->lightFilter, $blockFactory->blocksDirectSkyLight); + $chunk->recalculateHeightMap($blockFactory->blocksDirectSkyLight); $chunk->populateSkyLight($blockFactory->lightFilter); $chunk->setLightPopulated(); diff --git a/src/world/light/LightPopulationTask.php b/src/world/light/LightPopulationTask.php index e066c2f2a..bd734202f 100644 --- a/src/world/light/LightPopulationTask.php +++ b/src/world/light/LightPopulationTask.php @@ -61,7 +61,7 @@ class LightPopulationTask extends AsyncTask{ $chunk = FastChunkSerializer::deserialize($this->chunk); $blockFactory = BlockFactory::getInstance(); - $chunk->recalculateHeightMap($blockFactory->lightFilter, $blockFactory->blocksDirectSkyLight); + $chunk->recalculateHeightMap($blockFactory->blocksDirectSkyLight); $chunk->populateSkyLight($blockFactory->lightFilter); $chunk->setLightPopulated(); diff --git a/src/world/light/SkyLightUpdate.php b/src/world/light/SkyLightUpdate.php index ac2054339..4c63bbc2d 100644 --- a/src/world/light/SkyLightUpdate.php +++ b/src/world/light/SkyLightUpdate.php @@ -70,7 +70,7 @@ class SkyLightUpdate extends LightUpdate{ $yPlusOne = $y + 1; if($yPlusOne === $oldHeightMap){ //Block changed directly beneath the heightmap. Check if a block was removed or changed to a different light-filter. - $newHeightMap = $chunk->recalculateHeightMapColumn($x & 0x0f, $z & 0x0f, $this->lightFilters, $this->directSkyLightBlockers); + $newHeightMap = $chunk->recalculateHeightMapColumn($x & 0x0f, $z & 0x0f, $this->directSkyLightBlockers); }elseif($yPlusOne > $oldHeightMap){ //Block changed above the heightmap. if($this->directSkyLightBlockers[$source]){ $chunk->setHeightMap($x & 0xf, $z & 0xf, $yPlusOne); diff --git a/tests/phpstan/configs/l8-baseline.neon b/tests/phpstan/configs/l8-baseline.neon index 8550477db..37b22a9de 100644 --- a/tests/phpstan/configs/l8-baseline.neon +++ b/tests/phpstan/configs/l8-baseline.neon @@ -755,6 +755,11 @@ parameters: count: 1 path: ../../../src/world/biome/BiomeRegistry.php + - + message: "#^Only booleans are allowed in an if condition, bool\\|null given\\.$#" + count: 2 + path: ../../../src/world/format/Chunk.php + - message: "#^Method pocketmine\\\\world\\\\format\\\\Chunk\\:\\:getSubChunk\\(\\) should return pocketmine\\\\world\\\\format\\\\SubChunkInterface but returns pocketmine\\\\world\\\\format\\\\SubChunk\\|null\\.$#" count: 1