performance: only calculate light for chunks inside ticking areas

this produces a major performance improvement for large render distances, and reduces the impact of lighting calculation to zero on servers which have random blockupdates turned off.
This commit is contained in:
Dylan K. Taylor
2020-09-26 13:13:12 +01:00
parent b727972c76
commit 89cce4c749
4 changed files with 12 additions and 9 deletions

View File

@@ -895,7 +895,13 @@ class World implements ChunkManager{
$dz = mt_rand(-$randRange, $randRange);
$hash = World::chunkHash($dx + $chunkX, $dz + $chunkZ);
if(!isset($chunkTickList[$hash]) and isset($this->chunks[$hash])){
if(!$this->chunks[$hash]->isLightPopulated()){
//TODO: this might need to be checked after adjacent chunks are loaded in future
$lightPopulatedState = $this->chunks[$hash]->isLightPopulated();
if($lightPopulatedState !== true){
if($lightPopulatedState === false){
$this->chunks[$hash]->setLightPopulated(null);
$this->server->getAsyncPool()->submitTask(new LightPopulationTask($this, $this->chunks[$hash]));
}
continue;
}
//check adjacent chunks are loaded
@@ -2143,10 +2149,6 @@ class World implements ChunkManager{
(new ChunkLoadEvent($this, $chunk, !$chunk->isGenerated()))->call();
if($chunk->isPopulated()){
$this->getServer()->getAsyncPool()->submitTask(new LightPopulationTask($this, $chunk));
}
if(!$this->isChunkInUse($x, $z)){
$this->logger->debug("Newly loaded chunk $x $z has no loaders registered, will be unloaded at next available opportunity");
$this->unloadChunkRequest($x, $z);