Generator no longer requires a ChunkManager to construct

this allows injection of arbitrary ChunkManagers into a single Generator instance.
The objective here was to remove the requirement to cache a SimpleChunkManager instance in worker-local storage, because that requires that the chunks it stores be manually removed to avoid memory leaks. However, there are some other obstacles, primarily the worldHeight which is not retained anywhere else.
This commit is contained in:
Dylan K. Taylor
2020-11-01 16:34:56 +00:00
parent 315962c12c
commit f991961d9a
6 changed files with 31 additions and 36 deletions

View File

@ -57,8 +57,8 @@ class Flat extends Generator{
*
* @throws InvalidGeneratorOptionsException
*/
public function __construct(ChunkManager $world, int $seed, array $options = []){
parent::__construct($world, $seed, $options);
public function __construct(int $seed, array $options = []){
parent::__construct($seed, $options);
if(isset($this->options["preset"]) and $this->options["preset"] != ""){
$this->preset = $this->options["preset"];
@ -169,17 +169,17 @@ class Flat extends Generator{
}
}
public function generateChunk(int $chunkX, int $chunkZ) : void{
public function generateChunk(ChunkManager $world, int $chunkX, int $chunkZ) : void{
$chunk = clone $this->chunk;
$chunk->setX($chunkX);
$chunk->setZ($chunkZ);
$this->world->setChunk($chunkX, $chunkZ, $chunk);
$world->setChunk($chunkX, $chunkZ, $chunk);
}
public function populateChunk(int $chunkX, int $chunkZ) : void{
public function populateChunk(ChunkManager $world, int $chunkX, int $chunkZ) : void{
$this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->seed);
foreach($this->populators as $populator){
$populator->populate($this->world, $chunkX, $chunkZ, $this->random);
$populator->populate($world, $chunkX, $chunkZ, $this->random);
}
}