mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-13 01:09:44 +00:00
Level: reduce complexity of populateChunk()
This commit is contained in:
parent
a2a6286e1c
commit
20b87b7875
@ -2903,35 +2903,31 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
if(isset($this->chunkPopulationQueue[$index = Level::chunkHash($x, $z)]) or (count($this->chunkPopulationQueue) >= $this->chunkPopulationQueueSize and !$force)){
|
if(isset($this->chunkPopulationQueue[$index = Level::chunkHash($x, $z)]) or (count($this->chunkPopulationQueue) >= $this->chunkPopulationQueueSize and !$force)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
for($xx = -1; $xx <= 1; ++$xx){
|
||||||
|
for($zz = -1; $zz <= 1; ++$zz){
|
||||||
|
if(isset($this->chunkPopulationLock[Level::chunkHash($x + $xx, $z + $zz)])){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$chunk = $this->getChunk($x, $z, true);
|
$chunk = $this->getChunk($x, $z, true);
|
||||||
if(!$chunk->isPopulated()){
|
if(!$chunk->isPopulated()){
|
||||||
Timings::$populationTimer->startTiming();
|
Timings::$populationTimer->startTiming();
|
||||||
$populate = true;
|
|
||||||
|
$this->chunkPopulationQueue[$index] = true;
|
||||||
for($xx = -1; $xx <= 1; ++$xx){
|
for($xx = -1; $xx <= 1; ++$xx){
|
||||||
for($zz = -1; $zz <= 1; ++$zz){
|
for($zz = -1; $zz <= 1; ++$zz){
|
||||||
if(isset($this->chunkPopulationLock[Level::chunkHash($x + $xx, $z + $zz)])){
|
$this->chunkPopulationLock[Level::chunkHash($x + $xx, $z + $zz)] = true;
|
||||||
$populate = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($populate){
|
$task = new PopulationTask($this, $chunk);
|
||||||
$this->chunkPopulationQueue[$index] = true;
|
$workerId = $this->server->getAsyncPool()->selectWorker();
|
||||||
for($xx = -1; $xx <= 1; ++$xx){
|
if(!isset($this->generatorRegisteredWorkers[$workerId])){
|
||||||
for($zz = -1; $zz <= 1; ++$zz){
|
$this->registerGeneratorToWorker($workerId);
|
||||||
$this->chunkPopulationLock[Level::chunkHash($x + $xx, $z + $zz)] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$task = new PopulationTask($this, $chunk);
|
|
||||||
$workerId = $this->server->getAsyncPool()->selectWorker();
|
|
||||||
if(!isset($this->generatorRegisteredWorkers[$workerId])){
|
|
||||||
$this->registerGeneratorToWorker($workerId);
|
|
||||||
}
|
|
||||||
$this->server->getAsyncPool()->submitTaskToWorker($task, $workerId);
|
|
||||||
}
|
}
|
||||||
|
$this->server->getAsyncPool()->submitTaskToWorker($task, $workerId);
|
||||||
|
|
||||||
Timings::$populationTimer->stopTiming();
|
Timings::$populationTimer->stopTiming();
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user