mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-01 07:39:57 +00:00
Use single Perlin noise
This commit is contained in:
parent
1bc54dbc44
commit
4e820ab89f
@ -38,28 +38,24 @@ class NormalGenerator implements LevelGenerator{
|
|||||||
private $noiseGen5;
|
private $noiseGen5;
|
||||||
private $noiseGen6;
|
private $noiseGen6;
|
||||||
private $noiseArray = array();
|
private $noiseArray = array();
|
||||||
|
private $noise;
|
||||||
|
|
||||||
public function __construct(array $options = array()){
|
public function __construct(array $options = array()){
|
||||||
$this->noiseGen1 = new PerlinOctaveGenerator($rand, 16);
|
|
||||||
$this->noiseGen2 = new PerlinOctaveGenerator($rand, 16);
|
|
||||||
$this->noiseGen3 = new PerlinOctaveGenerator($rand, 8);
|
|
||||||
$this->noiseGen4 = new PerlinOctaveGenerator($rand, 4);
|
|
||||||
$this->noiseGen5 = new PerlinOctaveGenerator($rand, 10);
|
|
||||||
$this->noiseGen6 = new PerlinOctaveGenerator($rand, 16);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function init(Level $level, Random $random){
|
public function init(Level $level, Random $random){
|
||||||
$this->level = $level;
|
$this->level = $level;
|
||||||
$this->random = $random;
|
$this->random = $random;
|
||||||
$this->random->setSeed($this->level->getSeed());
|
$this->random->setSeed($this->level->getSeed());
|
||||||
$perlin = new PerlinNoiseGenerator($this->random, array(
|
$this->noise = new NoiseGeneratorPerlin($this->random);
|
||||||
"frequency" => 1,
|
$this->noiseGen1 = new PerlinOctaveGenerator($this->random, 16);
|
||||||
"octaves" => 8,
|
$this->noiseGen2 = new PerlinOctaveGenerator($this->random, 16);
|
||||||
"persistence" => 0.3,
|
$this->noiseGen3 = new PerlinOctaveGenerator($this->random, 8);
|
||||||
"scale" => 1,
|
$this->noiseGen4 = new PerlinOctaveGenerator($this->random, 4);
|
||||||
));
|
$this->noiseGen5 = new PerlinOctaveGenerator($this->random, 10);
|
||||||
$this->deviations = $perlin->fillNoiseArray(256, 256);
|
$this->noiseGen6 = new PerlinOctaveGenerator($this->random, 16);
|
||||||
|
|
||||||
$ores = new OrePopulator();
|
$ores = new OrePopulator();
|
||||||
$ores->setOreTypes(array(
|
$ores->setOreTypes(array(
|
||||||
new OreType(new CoalOreBlock(), 20, 16, 0, 128),
|
new OreType(new CoalOreBlock(), 20, 16, 0, 128),
|
||||||
@ -75,9 +71,10 @@ class NormalGenerator implements LevelGenerator{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function generateChunk($chunkX, $chunkZ){
|
public function generateChunk($chunkX, $chunkZ){
|
||||||
//$this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed());
|
$this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed());
|
||||||
$byte0 = 4;
|
|
||||||
$this->noiseArray = $this->initializeNoiseArray($chunkX * $byte0, 0, $chunkZ * $byte0, $byte0 + 1, ($this->worldHeight / 8) + 1, $byte0 + 1);
|
//$this->noiseArray = $this->initializeNoiseArray($chunkX * $byte0, 0, $chunkZ * $byte0, $byte0 + 1, ($this->worldHeight / 8) + 1, $byte0 + 1);
|
||||||
|
|
||||||
|
|
||||||
$chunks = array();
|
$chunks = array();
|
||||||
for($chunkY = 0; $chunkY < 8; ++$chunkY){
|
for($chunkY = 0; $chunkY < 8; ++$chunkY){
|
||||||
@ -86,7 +83,7 @@ class NormalGenerator implements LevelGenerator{
|
|||||||
$endY = $startY + 16;
|
$endY = $startY + 16;
|
||||||
for($z = 0; $z < 16; ++$z){
|
for($z = 0; $z < 16; ++$z){
|
||||||
for($x = 0; $x < 16; ++$x){
|
for($x = 0; $x < 16; ++$x){
|
||||||
$height = (int) ($this->baseHeight + $this->deviations[$z + ($chunkZ << 4)][$x + ($chunkX << 4)]);
|
$height = (int) ($this->worldHeight + $this->noise->noise3D($x + ($chunkX << 4), 0, $z + ($chunkZ << 4), 4, 0.5, 24));
|
||||||
for($y = $startY; $y < $endY; ++$y){
|
for($y = $startY; $y < $endY; ++$y){
|
||||||
$diff = $height - $y;
|
$diff = $height - $y;
|
||||||
if($y <= 4 and ($y === 0 or $this->random->nextFloat() < 0.75)){
|
if($y <= 4 and ($y === 0 or $this->random->nextFloat() < 0.75)){
|
||||||
|
@ -22,12 +22,12 @@
|
|||||||
|
|
||||||
abstract class NoiseGenerator{
|
abstract class NoiseGenerator{
|
||||||
protected $perm = array();
|
protected $perm = array();
|
||||||
protected $offsetX;
|
protected $offsetX = 0;
|
||||||
protected $offsetY;
|
protected $offsetY = 0;
|
||||||
protected $offsetZ;
|
protected $offsetZ = 0;
|
||||||
|
|
||||||
public static function floor($x){
|
public static function floor($x){
|
||||||
return $x >= 0 ? (int) $x : (int) $x - 1;
|
return $x >= 0 ? (int) $x : (int) ($x - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function fade($x){
|
public static function fade($x){
|
||||||
@ -64,4 +64,11 @@ abstract class NoiseGenerator{
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setOffset($x, $y, $z){
|
||||||
|
$this->offsetX = $x;
|
||||||
|
$this->offsetY = $y;
|
||||||
|
$this->offsetZ = $z;
|
||||||
|
}
|
||||||
}
|
}
|
@ -23,7 +23,7 @@
|
|||||||
require_once("NoiseGenerator.php");
|
require_once("NoiseGenerator.php");
|
||||||
/***REM_END***/
|
/***REM_END***/
|
||||||
|
|
||||||
class NoiseGeneratorPerlin extends NoiseGenerator[
|
class NoiseGeneratorPerlin extends NoiseGenerator{
|
||||||
public static $grad3 = [
|
public static $grad3 = [
|
||||||
[1, 1, 0], [-1, 1, 0], [1, -1, 0], [-1, -1, 0],
|
[1, 1, 0], [-1, 1, 0], [1, -1, 0], [-1, -1, 0],
|
||||||
[1, 0, 1], [-1, 0, 1], [1, 0, -1], [-1, 0, -1],
|
[1, 0, 1], [-1, 0, 1], [1, 0, -1], [-1, 0, -1],
|
||||||
@ -37,19 +37,20 @@ class NoiseGeneratorPerlin extends NoiseGenerator[
|
|||||||
$this->offsetZ = $random->nextFloat() * 256;
|
$this->offsetZ = $random->nextFloat() * 256;
|
||||||
|
|
||||||
for($i = 0; $i < 512; ++$i){
|
for($i = 0; $i < 512; ++$i){
|
||||||
$this->perm[$i} = 0;
|
$this->perm[$i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for($i = 0; $i < 256; ++$i){
|
for($i = 0; $i < 256; ++$i){
|
||||||
$this->perm[$i} = $random->nextRange(0, 255);
|
$this->perm[$i] = $random->nextRange(0, 255);
|
||||||
}
|
}
|
||||||
for($i = 0; $i < 256; ++$i)[
|
|
||||||
|
for($i = 0; $i < 256; ++$i){
|
||||||
$pos = $random->nextRange(0, 255 - $i) + $i;
|
$pos = $random->nextRange(0, 255 - $i) + $i;
|
||||||
$old = $this->perm[$i};
|
$old = $this->perm[$i];
|
||||||
|
|
||||||
$this->perm[$i} = $this->perm[$pos};
|
$this->perm[$i] = $this->perm[$pos];
|
||||||
$this->perm[$pos} = $old;
|
$this->perm[$pos] = $old;
|
||||||
$this->perm[$i + 256} = $this->perm[$i};
|
$this->perm[$i + 256] = $this->perm[$i];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -84,8 +85,8 @@ class NoiseGeneratorPerlin extends NoiseGenerator[
|
|||||||
$BA = $this->perm[$B] + $Z;
|
$BA = $this->perm[$B] + $Z;
|
||||||
$BB = $this->perm[$B + 1] + $Z;
|
$BB = $this->perm[$B + 1] + $Z;
|
||||||
|
|
||||||
return self::lerp($fZ, self::lerp($fY, self::lerp($fX, self::grad($this->perm[$AA]), $x, $y, $z),
|
return self::lerp($fZ, self::lerp($fY, self::lerp($fX, self::grad($this->perm[$AA], $x, $y, $z),
|
||||||
self::grad($this->perm[$BA], $x - 1, $y, $z),
|
self::grad($this->perm[$BA], $x - 1, $y, $z)),
|
||||||
self::lerp($fX, self::grad($this->perm[$AB], $x, $y - 1, $z),
|
self::lerp($fX, self::grad($this->perm[$AB], $x, $y - 1, $z),
|
||||||
self::grad($this->perm[$BB], $x - 1, $y - 1, $z))),
|
self::grad($this->perm[$BB], $x - 1, $y - 1, $z))),
|
||||||
self::lerp($fY, self::lerp($fX, self::grad($this->perm[$AA + 1], $x, $y, $z - 1),
|
self::lerp($fY, self::lerp($fX, self::grad($this->perm[$AA + 1], $x, $y, $z - 1),
|
@ -102,7 +102,7 @@ abstract class OctaveGenerator{
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generateNoiseOctaves($x, $y, $z, $frequency, $amplitude){
|
/*public function generateNoiseOctaves($x, $y, $z, $frequency, $amplitude){
|
||||||
|
|
||||||
}
|
}*/
|
||||||
}
|
}
|
@ -31,5 +31,33 @@ class PerlinOctaveGenerator extends OctaveGenerator{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function
|
/*public function generateNoiseOctaves($x, $y, $z, $sizeX, $sizeY, $sizeZ, $fX, $fY, $fZ){
|
||||||
|
$adouble = array_fill(0, $sizeX * $sizeY * $sizeZ, 0.0);
|
||||||
|
|
||||||
|
$d3 = 1.0;
|
||||||
|
|
||||||
|
foreach($this->octaves as $octave){
|
||||||
|
$dX = $x * $d3 * $fX;
|
||||||
|
$dY = $y * $d3 * $fY;
|
||||||
|
$dZ = $x * $d3 * $fZ;
|
||||||
|
|
||||||
|
$x1 = NoiseGenerator::floor($dX);
|
||||||
|
$z1 = NoiseGenerator::floor($dZ);
|
||||||
|
|
||||||
|
$dX -= $x1;
|
||||||
|
$dZ -= $z1;
|
||||||
|
|
||||||
|
$x1 %= 16777216;
|
||||||
|
$z1 %= 16777216;
|
||||||
|
//$x1 &= 0xFFFFFF;
|
||||||
|
//$z1 &= 0xFFFFFF;
|
||||||
|
|
||||||
|
$dX += $x1;
|
||||||
|
$dZ += $z1;
|
||||||
|
$octave->populateNoiseArray($adouble, $dX, $dY, $dZ, $sizeX, $sizeY, $sizeZ, $fX * $d3, $fY * $d3, $fZ * $d3, $d3);
|
||||||
|
$d3 *= 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $adouble;
|
||||||
|
}*/
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user