mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-17 11:18:52 +00:00
Better, faster world generation. Needs more things
This commit is contained in:
parent
4eebbba5bf
commit
5929b510d5
@ -147,7 +147,7 @@ class ServerAPI{
|
|||||||
//Load advanced properties
|
//Load advanced properties
|
||||||
define("DEBUG", $this->getProperty("debug", 1));
|
define("DEBUG", $this->getProperty("debug", 1));
|
||||||
define("ADVANCED_CACHE", $this->getProperty("enable-advanced-cache", false));
|
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){
|
if(ADVANCED_CACHE == true){
|
||||||
console("[INFO] Advanced cache enabled");
|
console("[INFO] Advanced cache enabled");
|
||||||
}
|
}
|
||||||
|
@ -233,7 +233,7 @@ class PMFLevel extends PMF{
|
|||||||
if(($this->chunkInfo[$index][0] & $t) === $t){
|
if(($this->chunkInfo[$index][0] & $t) === $t){
|
||||||
// 4096 + 2048 + 2048, Block Data, Meta, Light
|
// 4096 + 2048 + 2048, Block Data, Meta, Light
|
||||||
if(strlen($this->chunks[$index][$Y] = gzread($chunk, 8192)) < 8192){
|
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);
|
$this->fillMiniChunk($X, $Z, $Y);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
|
@ -30,13 +30,9 @@ class NormalGenerator implements LevelGenerator{
|
|||||||
private $random;
|
private $random;
|
||||||
private $worldHeight = 65;
|
private $worldHeight = 65;
|
||||||
private $waterHeight = 63;
|
private $waterHeight = 63;
|
||||||
|
private $noiseHills;
|
||||||
|
private $noisePatches;
|
||||||
private $noiseBase;
|
private $noiseBase;
|
||||||
private $noiseGen1;
|
|
||||||
private $noiseGen2;
|
|
||||||
private $noiseGen3;
|
|
||||||
private $noiseGen4;
|
|
||||||
private $noiseGen5;
|
|
||||||
private $noiseGen6;
|
|
||||||
|
|
||||||
public function __construct(array $options = array()){
|
public function __construct(array $options = array()){
|
||||||
|
|
||||||
@ -50,9 +46,9 @@ class NormalGenerator implements LevelGenerator{
|
|||||||
$this->level = $level;
|
$this->level = $level;
|
||||||
$this->random = $random;
|
$this->random = $random;
|
||||||
$this->random->setSeed($this->level->getSeed());
|
$this->random->setSeed($this->level->getSeed());
|
||||||
$this->noiseBase = new NoiseGeneratorSimplex($this->random, 4);
|
$this->noiseHills = new NoiseGeneratorSimplex($this->random, 3);
|
||||||
$this->noiseGen1 = new NoiseGeneratorPerlin($this->random, 4);
|
$this->noisePatches = new NoiseGeneratorSimplex($this->random, 2);
|
||||||
$this->noiseGen2 = new NoiseGeneratorPerlin($this->random, 4);
|
$this->noiseBase = new NoiseGeneratorSimplex($this->random, 8);
|
||||||
|
|
||||||
|
|
||||||
$ores = new OrePopulator();
|
$ores = new OrePopulator();
|
||||||
@ -71,6 +67,20 @@ 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());
|
||||||
|
$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){
|
for($chunkY = 0; $chunkY < 8; ++$chunkY){
|
||||||
$chunk = "";
|
$chunk = "";
|
||||||
@ -78,27 +88,38 @@ 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){
|
||||||
$noise1 = $this->noiseGen1->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.6, 32, true) * 2;
|
$i = ($z << 4) + $x;
|
||||||
$noise2 = $this->noiseGen2->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.35, 64, true) * 15;
|
$height = $this->worldHeight + $hills[$i] * 14 + $base[$i] * 4;
|
||||||
$noiseBase = $this->noiseBase->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 1/5, 16, true) * 3;
|
$height = (int) $height;
|
||||||
$height = (int) ($this->worldHeight + $noise1 + $noise2 + $noiseBase);
|
|
||||||
|
|
||||||
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)){
|
||||||
$chunk .= "\x07"; //bedrock
|
$chunk .= "\x07"; //bedrock
|
||||||
}elseif($diff > 3){
|
}elseif($diff > 2){
|
||||||
$chunk .= "\x01"; //stone
|
$chunk .= "\x01"; //stone
|
||||||
}elseif($diff > 0){
|
}elseif($diff > 0){
|
||||||
|
if($patches[$i] > 0.7){
|
||||||
|
$chunk .= "\x01"; //stone
|
||||||
|
}elseif($patches[$i] < -0.8){
|
||||||
|
$chunk .= "\x0d"; //gravel
|
||||||
|
}else{
|
||||||
$chunk .= "\x03"; //dirt
|
$chunk .= "\x03"; //dirt
|
||||||
|
}
|
||||||
}elseif($y <= $this->waterHeight){
|
}elseif($y <= $this->waterHeight){
|
||||||
if($y === $this->waterHeight and $diff === 0){
|
if(($this->waterHeight - $y) <= 1 and $diff === 0){
|
||||||
$chunk .= "\x0c"; //sand
|
$chunk .= "\x0c"; //sand
|
||||||
}else{
|
}else{
|
||||||
$chunk .= "\x09"; //still_water
|
$chunk .= "\x09"; //still_water
|
||||||
}
|
}
|
||||||
}elseif($diff === 0){
|
}elseif($diff === 0){
|
||||||
|
if($patches[$i] > 0.7){
|
||||||
|
$chunk .= "\x01"; //stone
|
||||||
|
}elseif($patches[$i] < -0.8){
|
||||||
|
$chunk .= "\x0d"; //gravel
|
||||||
|
}else{
|
||||||
$chunk .= "\x02"; //grass
|
$chunk .= "\x02"; //grass
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
$chunk .= "\x00";
|
$chunk .= "\x00";
|
||||||
}
|
}
|
||||||
|
@ -49,14 +49,15 @@ class WorldGenerator{
|
|||||||
++$this->level->level->isGenerating;
|
++$this->level->level->isGenerating;
|
||||||
$this->generator->init($this->level, $this->random);
|
$this->generator->init($this->level, $this->random);
|
||||||
|
|
||||||
for($Z = 7; $Z <= 9; ++$Z){
|
//Generate 4 chunks for spawning players
|
||||||
for($X = 7; $X <= 9; ++$X){
|
for($Z = 7; $Z <= 8; ++$Z){
|
||||||
|
for($X = 7; $X <= 8; ++$X){
|
||||||
$this->generator->generateChunk($X, $Z);
|
$this->generator->generateChunk($X, $Z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for($Z = 7; $Z <= 9; ++$Z){
|
for($Z = 7; $Z <= 8; ++$Z){
|
||||||
for($X = 7; $X <= 9; ++$X){
|
for($X = 7; $X <= 8; ++$X){
|
||||||
$this->generator->populateChunk($X, $Z);
|
$this->generator->populateChunk($X, $Z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user