mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 18:32:55 +00:00
Drastically improved performance of basic chunk sky-light population
back 2 commits: 53ms per chunk back 1 commit: 27ms per chunk this commit: 3ms per chunk (on my machine, of course)
This commit is contained in:
@ -313,6 +313,17 @@ class Chunk{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $level
|
||||
*/
|
||||
public function setAllBlockSkyLight(int $level){
|
||||
$char = chr(($level & 0x0f) | ($level << 4));
|
||||
$data = str_repeat($char, 2048);
|
||||
for($y = $this->getHighestSubChunkIndex(); $y >= 0; --$y){
|
||||
$this->getSubChunk($y, true)->setBlockSkyLightArray($data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the block light level at the specified chunk block coordinates
|
||||
*
|
||||
@ -340,6 +351,17 @@ class Chunk{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $level
|
||||
*/
|
||||
public function setAllBlockLight(int $level){
|
||||
$char = chr(($level & 0x0f) | ($level << 4));
|
||||
$data = str_repeat($char, 2048);
|
||||
for($y = $this->getHighestSubChunkIndex(); $y >= 0; --$y){
|
||||
$this->getSubChunk($y, true)->setBlockLightArray($data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Y coordinate of the highest non-air block at the specified X/Z chunk block coordinates
|
||||
*
|
||||
@ -366,6 +388,10 @@ class Chunk{
|
||||
return -1;
|
||||
}
|
||||
|
||||
public function getMaxY() : int{
|
||||
return ($this->getHighestSubChunkIndex() << 4) | 0x0f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the heightmap value at the specified X/Z chunk block coordinates
|
||||
*
|
||||
@ -427,7 +453,10 @@ class Chunk{
|
||||
* TODO: fast adjacent light spread
|
||||
*/
|
||||
public function populateSkyLight(){
|
||||
$maxY = ($this->getHighestSubChunkIndex() + 1) << 4;
|
||||
$maxY = $this->getMaxY();
|
||||
|
||||
$this->setAllBlockSkyLight(0);
|
||||
|
||||
for($x = 0; $x < 16; ++$x){
|
||||
for($z = 0; $z < 16; ++$z){
|
||||
$heightMap = $this->getHeightMap($x, $z);
|
||||
@ -437,11 +466,11 @@ class Chunk{
|
||||
}
|
||||
|
||||
$light = 15;
|
||||
for(; $y > 0; --$y){
|
||||
for(; $y >= 0; --$y){
|
||||
if($light > 0){
|
||||
$light -= Block::$lightFilter[$this->getBlockId($x, $y, $z)];
|
||||
if($light < 0){
|
||||
$light = 0;
|
||||
if($light <= 0){
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->setBlockSkyLight($x, $y, $z, $light);
|
||||
|
Reference in New Issue
Block a user