mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-18 11:45:30 +00:00
Make sure generator gets preemptively registered when a worker restart is detected
if a PopulationTask took place after the target worker was garbage collected, the population would fail and the chunks it used would be copied for nothing. This change marks workers as having unregistered generators when detecting that a worker that previously had a generator registered is restarted.
This commit is contained in:
parent
e056456dd1
commit
bacdb7bde5
@ -87,6 +87,7 @@ use pocketmine\world\sound\Sound;
|
||||
use pocketmine\world\utils\SubChunkExplorer;
|
||||
use function abs;
|
||||
use function array_fill_keys;
|
||||
use function array_key_exists;
|
||||
use function array_map;
|
||||
use function array_merge;
|
||||
use function array_sum;
|
||||
@ -405,6 +406,16 @@ class World implements ChunkManager{
|
||||
}
|
||||
|
||||
$this->timings = new WorldTimings($this);
|
||||
|
||||
$this->workerPool->addWorkerStartHook($workerStartHook = function(int $workerId) : void{
|
||||
if(array_key_exists($workerId, $this->generatorRegisteredWorkers)){
|
||||
$this->logger->debug("Worker $workerId with previously registered generator restarted, flagging as unregistered");
|
||||
unset($this->generatorRegisteredWorkers[$workerId]);
|
||||
}
|
||||
});
|
||||
$this->addOnUnloadCallback(function() use ($workerStartHook) : void{
|
||||
$this->workerPool->removeWorkerStartHook($workerStartHook);
|
||||
});
|
||||
}
|
||||
|
||||
public function getTickRateTime() : float{
|
||||
@ -412,8 +423,9 @@ class World implements ChunkManager{
|
||||
}
|
||||
|
||||
public function registerGeneratorToWorker(int $worker) : void{
|
||||
$this->generatorRegisteredWorkers[$worker] = true;
|
||||
$this->logger->debug("Registering generator on worker $worker");
|
||||
$this->workerPool->submitTaskToWorker(new GeneratorRegisterTask($this, $this->generator, $this->provider->getWorldData()->getGeneratorOptions()), $worker);
|
||||
$this->generatorRegisteredWorkers[$worker] = true;
|
||||
}
|
||||
|
||||
public function unregisterGenerator() : void{
|
||||
|
Loading…
x
Reference in New Issue
Block a user