mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-01 15:49:54 +00:00
Better parameters ^^
This commit is contained in:
parent
2d88739005
commit
f91e2a5cfe
@ -30,15 +30,12 @@ class NormalGenerator implements LevelGenerator{
|
||||
private $random;
|
||||
private $worldHeight = 64;
|
||||
private $waterHeight = 60;
|
||||
private $blockLevels = array();
|
||||
private $noiseGen1;
|
||||
private $noiseGen2;
|
||||
private $noiseGen3;
|
||||
private $noiseGen4;
|
||||
private $noiseGen5;
|
||||
private $noiseGen6;
|
||||
private $noiseArray = array();
|
||||
private $noise;
|
||||
|
||||
public function __construct(array $options = array()){
|
||||
|
||||
@ -48,13 +45,8 @@ class NormalGenerator implements LevelGenerator{
|
||||
$this->level = $level;
|
||||
$this->random = $random;
|
||||
$this->random->setSeed($this->level->getSeed());
|
||||
$this->noise = new NoiseGeneratorPerlin($this->random);
|
||||
$this->noiseGen1 = new PerlinOctaveGenerator($this->random, 16);
|
||||
$this->noiseGen2 = new PerlinOctaveGenerator($this->random, 16);
|
||||
$this->noiseGen3 = new PerlinOctaveGenerator($this->random, 8);
|
||||
$this->noiseGen4 = new PerlinOctaveGenerator($this->random, 4);
|
||||
$this->noiseGen5 = new PerlinOctaveGenerator($this->random, 10);
|
||||
$this->noiseGen6 = new PerlinOctaveGenerator($this->random, 16);
|
||||
$this->noiseGen1 = new NoiseGeneratorPerlin($this->random, 16);
|
||||
$this->noiseGen2 = new NoiseGeneratorPerlin($this->random, 4);
|
||||
|
||||
$ores = new OrePopulator();
|
||||
$ores->setOreTypes(array(
|
||||
@ -73,17 +65,14 @@ class NormalGenerator implements LevelGenerator{
|
||||
public function generateChunk($chunkX, $chunkZ){
|
||||
$this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed());
|
||||
|
||||
//$this->noiseArray = $this->initializeNoiseArray($chunkX * $byte0, 0, $chunkZ * $byte0, $byte0 + 1, ($this->worldHeight / 8) + 1, $byte0 + 1);
|
||||
|
||||
|
||||
$chunks = array();
|
||||
$baseHeight = $this->worldHeight;// + $this->noiseGen1->noise2D($chunkX, $chunkZ, 2, 1/4, true) * 35;
|
||||
for($chunkY = 0; $chunkY < 8; ++$chunkY){
|
||||
$chunk = "";
|
||||
$startY = $chunkY << 4;
|
||||
$endY = $startY + 16;
|
||||
for($z = 0; $z < 16; ++$z){
|
||||
for($x = 0; $x < 16; ++$x){
|
||||
$height = (int) ($this->worldHeight + $this->noise->noise3D($x + ($chunkX << 4), 0, $z + ($chunkZ << 4), 4, 0.5, 24, true));
|
||||
$height = (int) ($baseHeight + $this->noiseGen2->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.3, 32, true) * 15);
|
||||
for($y = $startY; $y < $endY; ++$y){
|
||||
$diff = $height - $y;
|
||||
if($y <= 4 and ($y === 0 or $this->random->nextFloat() < 0.75)){
|
||||
|
@ -25,6 +25,7 @@ abstract class NoiseGenerator{
|
||||
protected $offsetX = 0;
|
||||
protected $offsetY = 0;
|
||||
protected $offsetZ = 0;
|
||||
protected $octaves = 8;
|
||||
|
||||
public static function floor($x){
|
||||
return $x >= 0 ? (int) $x : (int) ($x - 1);
|
||||
@ -44,17 +45,38 @@ abstract class NoiseGenerator{
|
||||
$v = $hash < 4 ? $y : (($hash === 12 or $hash === 14) ? $x : $z);
|
||||
return (($hash & 1) === 0 ? $u : -$u) + (($hash & 2) === 0 ? $v : -$v);
|
||||
}
|
||||
|
||||
abstract public function getNoise2D($x, $z);
|
||||
|
||||
abstract public function noise($x, $y, $z);
|
||||
|
||||
public function noise3D($x, $y, $z, $octaves, $frequency, $amplitude, $normalized = false){
|
||||
abstract public function getNoise3D($x, $y, $z);
|
||||
|
||||
public function noise2D($x, $z, $frequency, $amplitude, $normalized = false){
|
||||
$result = 0;
|
||||
$amp = 1;
|
||||
$freq = 1;
|
||||
$max = 0;
|
||||
|
||||
for($i = 0; $i < $octaves; ++$i){
|
||||
$result += $this->noise($x * $freq, $y * $freq, $z * $freq) * $amp;
|
||||
for($i = 0; $i < $this->octaves; ++$i){
|
||||
$result += $this->getNoise2D($x * $freq, $z * $freq) * $amp;
|
||||
$max += $amp;
|
||||
$freq *= $frequency;
|
||||
$amp *= $amplitude;
|
||||
}
|
||||
if($normalized === true){
|
||||
$result /= $max;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function noise3D($x, $y, $z, $frequency, $amplitude, $normalized = false){
|
||||
$result = 0;
|
||||
$amp = 1;
|
||||
$freq = 1;
|
||||
$max = 0;
|
||||
|
||||
for($i = 0; $i < $this->octaves; ++$i){
|
||||
$result += $this->getNoise3D($x * $freq, $y * $freq, $z * $freq) * $amp;
|
||||
$max += $amp;
|
||||
$freq *= $frequency;
|
||||
$amp *= $amplitude;
|
||||
|
@ -31,7 +31,8 @@ class NoiseGeneratorPerlin extends NoiseGenerator{
|
||||
];
|
||||
|
||||
|
||||
public function __construct(Random $random){
|
||||
public function __construct(Random $random, $octaves){
|
||||
$this->octaves = $octaves;
|
||||
$this->offsetX = $random->nextFloat() * 256;
|
||||
$this->offsetY = $random->nextFloat() * 256;
|
||||
$this->offsetZ = $random->nextFloat() * 256;
|
||||
@ -55,7 +56,7 @@ class NoiseGeneratorPerlin extends NoiseGenerator{
|
||||
|
||||
}
|
||||
|
||||
public function noise($x, $y, $z){
|
||||
public function getNoise3D($x, $y, $z){
|
||||
$x += $this->offsetX;
|
||||
$y += $this->offsetY;
|
||||
$z += $this->offsetZ;
|
||||
@ -94,4 +95,8 @@ class NoiseGeneratorPerlin extends NoiseGenerator{
|
||||
self::lerp($fX, self::grad($this->perm[$AB + 1], $x, $y - 1, $z - 1),
|
||||
self::grad($this->perm[$BB + 1], $x - 1, $y - 1, $z - 1))));
|
||||
}
|
||||
|
||||
public function getNoise2D($x, $z){
|
||||
return $this->getNoise3D($x, 0, $z);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user