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

@ -48,8 +48,6 @@ abstract class Generator{
return $convertedSeed;
}
/** @var ChunkManager */
protected $world;
/** @var int */
protected $seed;
/**
@ -62,19 +60,16 @@ abstract class Generator{
protected $random;
/**
* @throws InvalidGeneratorOptionsException
*
* @param mixed[] $options
* @phpstan-param array<string, mixed> $options
*/
public function __construct(ChunkManager $world, int $seed, array $options = []){
$this->world = $world;
public function __construct(int $seed, array $options = []){
$this->seed = $seed;
$this->options = $options;
$this->random = new Random($seed);
}
abstract public function generateChunk(int $chunkX, int $chunkZ) : void;
abstract public function generateChunk(ChunkManager $world, int $chunkX, int $chunkZ) : void;
abstract public function populateChunk(int $chunkX, int $chunkZ) : void;
abstract public function populateChunk(ChunkManager $world, int $chunkX, int $chunkZ) : void;
}