Better, faster world generation. Needs more things

This commit is contained in:
Shoghi Cervantes 2014-02-13 20:44:15 +01:00
parent 4eebbba5bf
commit 5929b510d5
4 changed files with 48 additions and 26 deletions

View File

@ -147,7 +147,7 @@ class ServerAPI{
//Load advanced properties
define("DEBUG", $this->getProperty("debug", 1));
define("ADVANCED_CACHE", $this->getProperty("enable-advanced-cache", false));
define("MAX_CHUNK_RATE", 20 / $this->getProperty("max-chunks-per-second", 8)); //Default rate ~512 kB/s
define("MAX_CHUNK_RATE", 20 / $this->getProperty("max-chunks-per-second", 6)); //Default rate ~384 kB/s
if(ADVANCED_CACHE == true){
console("[INFO] Advanced cache enabled");
}

View File

@ -233,7 +233,7 @@ class PMFLevel extends PMF{
if(($this->chunkInfo[$index][0] & $t) === $t){
// 4096 + 2048 + 2048, Block Data, Meta, Light
if(strlen($this->chunks[$index][$Y] = gzread($chunk, 8192)) < 8192){
console("[NOTICE] Empty corrupt chunk detected [$X,$Z,:$Y], recovering contents");
console("[NOTICE] Empty corrupt chunk detected [$X,$Z,:$Y], recovering contents", true, true, 2);
$this->fillMiniChunk($X, $Z, $Y);
}
}else{

View File

@ -30,13 +30,9 @@ class NormalGenerator implements LevelGenerator{
private $random;
private $worldHeight = 65;
private $waterHeight = 63;
private $noiseHills;
private $noisePatches;
private $noiseBase;
private $noiseGen1;
private $noiseGen2;
private $noiseGen3;
private $noiseGen4;
private $noiseGen5;
private $noiseGen6;
public function __construct(array $options = array()){
@ -50,9 +46,9 @@ class NormalGenerator implements LevelGenerator{
$this->level = $level;
$this->random = $random;
$this->random->setSeed($this->level->getSeed());
$this->noiseBase = new NoiseGeneratorSimplex($this->random, 4);
$this->noiseGen1 = new NoiseGeneratorPerlin($this->random, 4);
$this->noiseGen2 = new NoiseGeneratorPerlin($this->random, 4);
$this->noiseHills = new NoiseGeneratorSimplex($this->random, 3);
$this->noisePatches = new NoiseGeneratorSimplex($this->random, 2);
$this->noiseBase = new NoiseGeneratorSimplex($this->random, 8);
$ores = new OrePopulator();
@ -71,34 +67,59 @@ class NormalGenerator implements LevelGenerator{
public function generateChunk($chunkX, $chunkZ){
$this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed());
$hills = array();
$patches = array();
$base = array();
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);
$base[$i] = $this->noiseBase->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.5, 4, true);
if($base[$i] < 0){
$base[$i] *= 0.5;
}
}
}
for($chunkY = 0; $chunkY < 8; ++$chunkY){
$chunk = "";
$startY = $chunkY << 4;
$endY = $startY + 16;
$endY = $startY + 16;
for($z = 0; $z < 16; ++$z){
for($x = 0; $x < 16; ++$x){
$noise1 = $this->noiseGen1->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.6, 32, true) * 2;
$noise2 = $this->noiseGen2->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.35, 64, true) * 15;
$noiseBase = $this->noiseBase->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 1/5, 16, true) * 3;
$height = (int) ($this->worldHeight + $noise1 + $noise2 + $noiseBase);
$i = ($z << 4) + $x;
$height = $this->worldHeight + $hills[$i] * 14 + $base[$i] * 4;
$height = (int) $height;
for($y = $startY; $y < $endY; ++$y){
$diff = $height - $y;
if($y <= 4 and ($y === 0 or $this->random->nextFloat() < 0.75)){
$chunk .= "\x07"; //bedrock
}elseif($diff > 3){
}elseif($diff > 2){
$chunk .= "\x01"; //stone
}elseif($diff > 0){
$chunk .= "\x03"; //dirt
if($patches[$i] > 0.7){
$chunk .= "\x01"; //stone
}elseif($patches[$i] < -0.8){
$chunk .= "\x0d"; //gravel
}else{
$chunk .= "\x03"; //dirt
}
}elseif($y <= $this->waterHeight){
if($y === $this->waterHeight and $diff === 0){
if(($this->waterHeight - $y) <= 1 and $diff === 0){
$chunk .= "\x0c"; //sand
}else{
$chunk .= "\x09"; //still_water
}
}elseif($diff === 0){
$chunk .= "\x02"; //grass
if($patches[$i] > 0.7){
$chunk .= "\x01"; //stone
}elseif($patches[$i] < -0.8){
$chunk .= "\x0d"; //gravel
}else{
$chunk .= "\x02"; //grass
}
}else{
$chunk .= "\x00";
}

View File

@ -45,18 +45,19 @@ class WorldGenerator{
$this->level = new Level($level, $entities, $tiles, $blockUpdates, $name);
}
public function generate(){
public function generate(){
++$this->level->level->isGenerating;
$this->generator->init($this->level, $this->random);
for($Z = 7; $Z <= 9; ++$Z){
for($X = 7; $X <= 9; ++$X){
//Generate 4 chunks for spawning players
for($Z = 7; $Z <= 8; ++$Z){
for($X = 7; $X <= 8; ++$X){
$this->generator->generateChunk($X, $Z);
}
}
for($Z = 7; $Z <= 9; ++$Z){
for($X = 7; $X <= 9; ++$X){
for($Z = 7; $Z <= 8; ++$Z){
for($X = 7; $X <= 8; ++$X){
$this->generator->populateChunk($X, $Z);
}
}