mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-15 02:09:42 +00:00
Improved heightmap generation
This commit is contained in:
parent
7754aa71a3
commit
d4b2e3d1b7
@ -2186,7 +2186,7 @@ class Server{
|
|||||||
private function tickProcessor(){
|
private function tickProcessor(){
|
||||||
while($this->isRunning){
|
while($this->isRunning){
|
||||||
$this->tick();
|
$this->tick();
|
||||||
usleep((int) max(1, ($this->nextTick - microtime(true)) * 1000000));
|
usleep((int) max(1, ($this->nextTick - microtime(true)) * 1000000 - 2000));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2369,7 +2369,7 @@ class Server{
|
|||||||
*/
|
*/
|
||||||
private function tick(){
|
private function tick(){
|
||||||
$tickTime = microtime(true);
|
$tickTime = microtime(true);
|
||||||
if($tickTime < $this->nextTick){
|
if(($tickTime - $this->nextTick) < -0.025){ //Allow half a tick of diff
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ class HandlerList{
|
|||||||
* @return RegisteredListener[]
|
* @return RegisteredListener[]
|
||||||
*/
|
*/
|
||||||
public function getRegisteredListeners($plugin = null){
|
public function getRegisteredListeners($plugin = null){
|
||||||
if($plugin instanceof Plugin){
|
if($plugin !== null){
|
||||||
$listeners = [];
|
$listeners = [];
|
||||||
foreach($this->getRegisteredListeners(null) as $hash => $listener){
|
foreach($this->getRegisteredListeners(null) as $hash => $listener){
|
||||||
if($listener->getPlugin() === $plugin){
|
if($listener->getPlugin() === $plugin){
|
||||||
|
@ -176,6 +176,8 @@ interface FullChunk{
|
|||||||
*/
|
*/
|
||||||
public function setHeightMap($x, $z, $value);
|
public function setHeightMap($x, $z, $value);
|
||||||
|
|
||||||
|
public function recalculateHeightMap();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $x 0-15
|
* @param int $x 0-15
|
||||||
* @param int $z 0-15
|
* @param int $z 0-15
|
||||||
|
@ -151,12 +151,6 @@ abstract class BaseFullChunk implements FullChunk{
|
|||||||
|
|
||||||
$this->getProvider()->getLevel()->timings->syncChunkLoadTileEntitiesTimer->stopTiming();
|
$this->getProvider()->getLevel()->timings->syncChunkLoadTileEntitiesTimer->stopTiming();
|
||||||
|
|
||||||
for($z = 0; $z < 16; ++$z){
|
|
||||||
for($x = 0; $x < 16; ++$x){
|
|
||||||
$this->setHeightMap($x, $z, $this->getHighestBlockAt($x, $z));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->NBTentities = null;
|
$this->NBTentities = null;
|
||||||
$this->NBTtiles = null;
|
$this->NBTtiles = null;
|
||||||
$this->hasChanged = false;
|
$this->hasChanged = false;
|
||||||
@ -228,10 +222,27 @@ abstract class BaseFullChunk implements FullChunk{
|
|||||||
$this->heightMap[($z << 4) + $x] = $value;
|
$this->heightMap[($z << 4) + $x] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getHighestBlockAt($x, $z){
|
public function recalculateHeightMap(){
|
||||||
|
for($z = 0; $z < 16; ++$z){
|
||||||
|
for($x = 0; $x < 16; ++$x){
|
||||||
|
$this->setHeightMap($x, $z, $this->getHighestBlockAt($x, $z, false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getHighestBlockAt($x, $z, $cache = true){
|
||||||
|
if($cache){
|
||||||
|
$h = $this->getHeightMap($x, $z);
|
||||||
|
|
||||||
|
if($h !== 0 and $h !== 127){
|
||||||
|
return $h;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$column = $this->getBlockIdColumn($x, $z);
|
$column = $this->getBlockIdColumn($x, $z);
|
||||||
for($y = 127; $y >= 0; --$y){
|
for($y = 127; $y >= 0; --$y){
|
||||||
if($column{$y} !== "\x00"){
|
if($column{$y} !== "\x00"){
|
||||||
|
$this->setHeightMap($x, $z, $y);
|
||||||
return $y;
|
return $y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -169,7 +169,7 @@ class RegionLoader{
|
|||||||
$full = $half . $half;
|
$full = $half . $half;
|
||||||
$nbt->Blocks = new ByteArray("Blocks", $full);
|
$nbt->Blocks = new ByteArray("Blocks", $full);
|
||||||
$nbt->Data = new ByteArray("Data", $half);
|
$nbt->Data = new ByteArray("Data", $half);
|
||||||
$nbt->SkyLight = new ByteArray("SkyLight", $half);
|
$nbt->SkyLight = new ByteArray("SkyLight", str_repeat("\xff", 16384));
|
||||||
$nbt->BlockLight = new ByteArray("BlockLight", $half);
|
$nbt->BlockLight = new ByteArray("BlockLight", $half);
|
||||||
|
|
||||||
$nbt->Entities = new Enum("Entities", []);
|
$nbt->Entities = new Enum("Entities", []);
|
||||||
|
@ -106,6 +106,7 @@ class PopulationTask extends AsyncTask{
|
|||||||
$generator->populateChunk($chunk->getX(), $chunk->getZ());
|
$generator->populateChunk($chunk->getX(), $chunk->getZ());
|
||||||
|
|
||||||
$chunk = $manager->getChunk($chunk->getX(), $chunk->getZ());
|
$chunk = $manager->getChunk($chunk->getX(), $chunk->getZ());
|
||||||
|
$chunk->recalculateHeightMap();
|
||||||
$chunk->setPopulated(true);
|
$chunk->setPopulated(true);
|
||||||
$this->chunk = $chunk->toFastBinary();
|
$this->chunk = $chunk->toFastBinary();
|
||||||
|
|
||||||
|
@ -251,7 +251,7 @@ class Normal extends Generator{
|
|||||||
|
|
||||||
if($noiseValue >= 0){
|
if($noiseValue >= 0){
|
||||||
$chunk->setBlockId($x, $y, $z, Block::STONE);
|
$chunk->setBlockId($x, $y, $z, Block::STONE);
|
||||||
}else{
|
}/*else{
|
||||||
if($y <= $this->waterHeight){
|
if($y <= $this->waterHeight){
|
||||||
$chunk->setBlockId($x, $y, $z, Block::STILL_WATER);
|
$chunk->setBlockId($x, $y, $z, Block::STILL_WATER);
|
||||||
$lightValue = 15 - ($this->waterHeight - $y) * 2;
|
$lightValue = 15 - ($this->waterHeight - $y) * 2;
|
||||||
@ -261,7 +261,7 @@ class Normal extends Generator{
|
|||||||
}else{
|
}else{
|
||||||
$chunk->setBlockSkyLight($x, $y, $z, 15);
|
$chunk->setBlockSkyLight($x, $y, $z, 15);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user