World: clean up lighting update API

This commit is contained in:
Dylan K. Taylor 2019-10-23 21:52:39 +01:00
parent 3768f3008e
commit 9aab97578b
2 changed files with 17 additions and 28 deletions

View File

@ -228,7 +228,7 @@ class Explosion{
$t->onBlockDestroyed(); //needed to create drops for inventories $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->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){ foreach(Facing::ALL as $side){

View File

@ -1245,9 +1245,20 @@ class World implements ChunkManager{
return $light < 0 ? 0 : $light; return $light < 0 ? 0 : $light;
} }
public function updateAllLight(Vector3 $pos){ public function updateAllLight(int $x, int $y, int $z) : void{
$this->updateBlockSkyLight($pos->x, $pos->y, $pos->z); $this->timings->doBlockSkyLightUpdates->startTiming();
$this->updateBlockLight($pos->x, $pos->y, $pos->z); 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; 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. * 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; return $max;
} }
public function updateBlockLight(int $x, int $y, int $z){ private function executeQueuedLightUpdates() : void{
$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{
if($this->blockLightUpdate !== null){ if($this->blockLightUpdate !== null){
$this->timings->doBlockLightUpdates->startTiming(); $this->timings->doBlockLightUpdates->startTiming();
$this->blockLightUpdate->execute(); $this->blockLightUpdate->execute();
@ -1493,7 +1482,7 @@ class World implements ChunkManager{
if($update){ if($update){
if($oldBlock->getLightFilter() !== $block->getLightFilter() or $oldBlock->getLightLevel() !== $block->getLightLevel()){ if($oldBlock->getLightFilter() !== $block->getLightFilter() or $oldBlock->getLightLevel() !== $block->getLightLevel()){
$this->updateAllLight($pos); $this->updateAllLight($x, $y, $z);
} }
$this->tryAddToNeighbourUpdateQueue($pos); $this->tryAddToNeighbourUpdateQueue($pos);
foreach($pos->sides() as $side){ foreach($pos->sides() as $side){