From 9aab97578b01b550e8571cd82a23e973fd45b775 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 23 Oct 2019 21:52:39 +0100 Subject: [PATCH] World: clean up lighting update API --- src/world/Explosion.php | 2 +- src/world/World.php | 43 +++++++++++++++-------------------------- 2 files changed, 17 insertions(+), 28 deletions(-) diff --git a/src/world/Explosion.php b/src/world/Explosion.php index 3e3a95a68..47eb6475f 100644 --- a/src/world/Explosion.php +++ b/src/world/Explosion.php @@ -228,7 +228,7 @@ class Explosion{ $t->onBlockDestroyed(); //needed to create drops for inventories } $this->world->setBlockAt($pos->x, $pos->y, $pos->z, $airBlock, false); //TODO: should updating really be disabled here? - $this->world->updateAllLight($pos); + $this->world->updateAllLight($pos->x, $pos->y, $pos->z); } foreach(Facing::ALL as $side){ diff --git a/src/world/World.php b/src/world/World.php index b4555ef05..f88fd4c5f 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -1245,9 +1245,20 @@ class World implements ChunkManager{ return $light < 0 ? 0 : $light; } - public function updateAllLight(Vector3 $pos){ - $this->updateBlockSkyLight($pos->x, $pos->y, $pos->z); - $this->updateBlockLight($pos->x, $pos->y, $pos->z); + public function updateAllLight(int $x, int $y, int $z) : void{ + $this->timings->doBlockSkyLightUpdates->startTiming(); + if($this->skyLightUpdate === null){ + $this->skyLightUpdate = new SkyLightUpdate($this); + } + $this->skyLightUpdate->recalculateNode($x, $y, $z); + $this->timings->doBlockSkyLightUpdates->stopTiming(); + + $this->timings->doBlockLightUpdates->startTiming(); + if($this->blockLightUpdate === null){ + $this->blockLightUpdate = new BlockLightUpdate($this); + } + $this->blockLightUpdate->recalculateNode($x, $y, $z); + $this->timings->doBlockLightUpdates->stopTiming(); } /** @@ -1277,17 +1288,6 @@ class World implements ChunkManager{ return $max; } - public function updateBlockSkyLight(int $x, int $y, int $z){ - $this->timings->doBlockSkyLightUpdates->startTiming(); - - if($this->skyLightUpdate === null){ - $this->skyLightUpdate = new SkyLightUpdate($this); - } - $this->skyLightUpdate->recalculateNode($x, $y, $z); - - $this->timings->doBlockSkyLightUpdates->stopTiming(); - } - /** * Returns the highest block light level available in the positions adjacent to the specified block coordinates. * @@ -1315,18 +1315,7 @@ class World implements ChunkManager{ return $max; } - public function updateBlockLight(int $x, int $y, int $z){ - $this->timings->doBlockLightUpdates->startTiming(); - - if($this->blockLightUpdate === null){ - $this->blockLightUpdate = new BlockLightUpdate($this); - } - $this->blockLightUpdate->recalculateNode($x, $y, $z); - - $this->timings->doBlockLightUpdates->stopTiming(); - } - - public function executeQueuedLightUpdates() : void{ + private function executeQueuedLightUpdates() : void{ if($this->blockLightUpdate !== null){ $this->timings->doBlockLightUpdates->startTiming(); $this->blockLightUpdate->execute(); @@ -1493,7 +1482,7 @@ class World implements ChunkManager{ if($update){ if($oldBlock->getLightFilter() !== $block->getLightFilter() or $oldBlock->getLightLevel() !== $block->getLightLevel()){ - $this->updateAllLight($pos); + $this->updateAllLight($x, $y, $z); } $this->tryAddToNeighbourUpdateQueue($pos); foreach($pos->sides() as $side){