From cb2b08b248d980534bc1742b06c53a45774bb372 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sun, 23 Mar 2014 00:19:11 +0100 Subject: [PATCH] Fixed Level generators --- src/PocketMine/level/generator/Normal.php | 16 ++++++++-------- .../level/generator/noise/Generator.php | 14 ++++++++------ src/PocketMine/level/generator/noise/Perlin.php | 4 +++- src/PocketMine/level/generator/noise/Simplex.php | 5 +++-- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/PocketMine/level/generator/Normal.php b/src/PocketMine/level/generator/Normal.php index 030ce6355..b89b2b145 100644 --- a/src/PocketMine/level/generator/Normal.php +++ b/src/PocketMine/level/generator/Normal.php @@ -67,10 +67,10 @@ class Normal extends Generator{ $this->level = $level; $this->random = $random; $this->random->setSeed($this->level->getSeed()); - $this->noiseHills = new Simplex($this->random, 3); - $this->noisePatches = new Simplex($this->random, 2); - $this->noisePatchesSmall = new Simplex($this->random, 2); - $this->noiseBase = new Simplex($this->random, 16); + $this->noiseHills = new Simplex($this->random, 3, 0.11, 12); + $this->noisePatches = new Simplex($this->random, 2, 0.03, 16); + $this->noisePatchesSmall = new Simplex($this->random, 2, 0.5, 4); + $this->noiseBase = new Simplex($this->random, 16, 0.7, 16); $ores = new Ore(); @@ -106,10 +106,10 @@ class Normal extends Generator{ for($z = 0; $z < 16; ++$z){ for($x = 0; $x < 16; ++$x){ $i = ($z << 4) + $x; - $hills[$i] = $this->noiseHills->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.11, 12, true); - $patches[$i] = $this->noisePatches->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.03, 16, true); - $patchesSmall[$i] = $this->noisePatchesSmall->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.5, 4, true); - $base[$i] = $this->noiseBase->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.7, 16, true); + $hills[$i] = $this->noiseHills->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), true); + $patches[$i] = $this->noisePatches->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), true); + $patchesSmall[$i] = $this->noisePatchesSmall->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), true); + $base[$i] = $this->noiseBase->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), true); if($base[$i] < 0){ $base[$i] *= 0.5; diff --git a/src/PocketMine/level/generator/noise/Generator.php b/src/PocketMine/level/generator/noise/Generator.php index 656c2b604..40f3ac475 100644 --- a/src/PocketMine/level/generator/noise/Generator.php +++ b/src/PocketMine/level/generator/noise/Generator.php @@ -33,6 +33,8 @@ abstract class Generator{ protected $offsetY = 0; protected $offsetZ = 0; protected $octaves = 8; + protected $frequency; + protected $amplitude; public static function floor($x){ return $x >= 0 ? (int) $x : (int) ($x - 1); @@ -58,7 +60,7 @@ abstract class Generator{ abstract public function getNoise3D($x, $y, $z); - public function noise2D($x, $z, $frequency, $amplitude, $normalized = false){ + public function noise2D($x, $z, $normalized = false){ $result = 0; $amp = 1; $freq = 1; @@ -67,8 +69,8 @@ abstract class Generator{ for($i = 0; $i < $this->octaves; ++$i){ $result += $this->getNoise2D($x * $freq, $z * $freq) * $amp; $max += $amp; - $freq *= $frequency; - $amp *= $amplitude; + $freq *= $this->frequency; + $amp *= $this->amplitude; } if($normalized === true){ $result /= $max; @@ -77,7 +79,7 @@ abstract class Generator{ return $result; } - public function noise3D($x, $y, $z, $frequency, $amplitude, $normalized = false){ + public function noise3D($x, $y, $z, $normalized = false){ $result = 0; $amp = 1; $freq = 1; @@ -86,8 +88,8 @@ abstract class Generator{ for($i = 0; $i < $this->octaves; ++$i){ $result += $this->getNoise3D($x * $freq, $y * $freq, $z * $freq) * $amp; $max += $amp; - $freq *= $frequency; - $amp *= $amplitude; + $freq *= $this->frequency; + $amp *= $this->amplitude; } if($normalized === true){ $result /= $max; diff --git a/src/PocketMine/level/generator/noise/Perlin.php b/src/PocketMine/level/generator/noise/Perlin.php index 7be1404fc..096888a58 100644 --- a/src/PocketMine/level/generator/noise/Perlin.php +++ b/src/PocketMine/level/generator/noise/Perlin.php @@ -32,8 +32,10 @@ class Perlin extends Generator{ ]; - public function __construct(Random $random, $octaves){ + public function __construct(Random $random, $octaves, $frequency, $amplitude){ $this->octaves = $octaves; + $this->frequency = $frequency; + $this->amplitude = $amplitude; $this->offsetX = $random->nextFloat() * 256; $this->offsetY = $random->nextFloat() * 256; $this->offsetZ = $random->nextFloat() * 256; diff --git a/src/PocketMine/level/generator/noise/Simplex.php b/src/PocketMine/level/generator/noise/Simplex.php index 9168d5421..cd8263920 100644 --- a/src/PocketMine/level/generator/noise/Simplex.php +++ b/src/PocketMine/level/generator/noise/Simplex.php @@ -64,8 +64,9 @@ class Simplex extends Perlin{ [2, 1, 0, 3], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [3, 1, 0, 2], [0, 0, 0, 0], [3, 2, 0, 1], [3, 2, 1, 0]]; protected $offsetW; - public function __construct(Random $random, $octaves){ - parent::__construct($random, $octaves); + + public function __construct(Random $random, $octaves, $frequency, $amplitude){ + parent::__construct($random, $octaves, $frequency, $amplitude); $this->offsetW = $random->nextFloat() * 256; self::$SQRT_3 = sqrt(3); self::$SQRT_5 = sqrt(5);