From ae9f57ac285e3fb588a95e649f5113676b70a8d4 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 10 Mar 2019 19:46:23 +0000 Subject: [PATCH] Revert "Remove hacks for triggering adjacent light refill" This reverts commit 1dca9074d5f087d15f8d30d2941150fe51617489. This change introduced performance issues with transparent blocks. --- src/pocketmine/level/Level.php | 8 +++++--- src/pocketmine/level/light/LightUpdate.php | 14 +++++++------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index f5c51f9c1..b20e4b9d1 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -1492,8 +1492,8 @@ class Level implements ChunkManager, Metadatable{ for($i = $y; $i >= $newHeightMap; --$i){ $this->skyLightUpdate->setAndUpdateLight($x, $i, $z, 15); } - }else{ //No heightmap change, block changed "underground" - trigger recalculation from surroundings - $this->skyLightUpdate->setAndUpdateLight($x, $y, $z, 0); + }else{ //No heightmap change, block changed "underground" + $this->skyLightUpdate->setAndUpdateLight($x, $y, $z, max(0, $this->getHighestAdjacentBlockSkyLight($x, $y, $z) - BlockFactory::$lightFilter[($source->getId() << 4) | $source->getMeta()])); } $this->timings->doBlockSkyLightUpdates->stopTiming(); @@ -1523,10 +1523,12 @@ class Level implements ChunkManager, Metadatable{ $this->timings->doBlockLightUpdates->startTiming(); $block = $this->getBlockAt($x, $y, $z); + $newLevel = max($block->getLightLevel(), $this->getHighestAdjacentBlockLight($x, $y, $z) - BlockFactory::$lightFilter[($block->getId() << 4) | $block->getMeta()]); + if($this->blockLightUpdate === null){ $this->blockLightUpdate = new BlockLightUpdate($this); } - $this->blockLightUpdate->setAndUpdateLight($x, $y, $z, $block->getLightLevel()); + $this->blockLightUpdate->setAndUpdateLight($x, $y, $z, $newLevel); $this->timings->doBlockLightUpdates->stopTiming(); } diff --git a/src/pocketmine/level/light/LightUpdate.php b/src/pocketmine/level/light/LightUpdate.php index cf360acab..c141b2ee3 100644 --- a/src/pocketmine/level/light/LightUpdate.php +++ b/src/pocketmine/level/light/LightUpdate.php @@ -72,13 +72,13 @@ abstract class LightUpdate{ if($oldLevel !== $newLevel){ $this->setLight($x, $y, $z, $newLevel); - } - if($newLevel > $oldLevel){ //light increased - $this->spreadVisited[$blockHash] = true; - $this->spreadQueue->enqueue([$x, $y, $z]); - }elseif($newLevel < 15){ //light removed or stayed the same, force recheck nearby environment - $this->removalVisited[$blockHash] = true; - $this->removalQueue->enqueue([$x, $y, $z, $oldLevel]); + if($oldLevel < $newLevel){ //light increased + $this->spreadVisited[$blockHash] = true; + $this->spreadQueue->enqueue([$x, $y, $z]); + }else{ //light removed + $this->removalVisited[$blockHash] = true; + $this->removalQueue->enqueue([$x, $y, $z, $oldLevel]); + } } } }