Further cleanup to Simplex/Noise hierarchy

This commit is contained in:
Dylan K. Taylor 2018-10-28 16:19:20 +00:00
parent e1795dfd49
commit 1e8b153662
2 changed files with 26 additions and 11 deletions

View File

@ -28,13 +28,7 @@ namespace pocketmine\level\generator\noise;
abstract class Noise{
protected $perm = [];
protected $offsetX = 0;
protected $offsetY = 0;
protected $offsetZ = 0;
protected $octaves = 8;
protected $persistence;
protected $expansion;
public static function linearLerp($x, $x1, $x2, $q0, $q1){
return (($x2 - $x) / ($x2 - $x1)) * $q0 + (($x - $x1) / ($x2 - $x1)) * $q1;
@ -72,6 +66,19 @@ abstract class Noise{
);
}
/** @var float */
protected $persistence;
/** @var float */
protected $expansion;
/** @var int */
protected $octaves;
public function __construct(int $octaves, float $persistence, float $expansion){
$this->octaves = $octaves;
$this->persistence = $persistence;
$this->expansion = $expansion;
}
abstract public function getNoise2D($x, $z);
abstract public function getNoise3D($x, $y, $z);

View File

@ -45,10 +45,18 @@ class Simplex extends Noise{
protected const F3 = 1.0 / 3.0;
protected const G3 = 1.0 / 6.0;
public function __construct(Random $random, $octaves, $persistence, $expansion = 1){
$this->octaves = $octaves;
$this->persistence = $persistence;
$this->expansion = $expansion;
/** @var float */
protected $offsetX;
/** @var float */
protected $offsetZ;
/** @var float */
protected $offsetY;
/** @var int[] */
protected $perm = [];
public function __construct(Random $random, int $octaves, float $persistence, float $expansion){
parent::__construct($octaves, $persistence, $expansion);
$this->offsetX = $random->nextFloat() * 256;
$this->offsetY = $random->nextFloat() * 256;
$this->offsetZ = $random->nextFloat() * 256;