mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-06 11:57:10 +00:00
Chunk: simplify heightmap calculation
This commit is contained in:
parent
c7070788f9
commit
03de2bcc67
@ -260,12 +260,10 @@ class Chunk{
|
||||
/**
|
||||
* Recalculates the heightmap for the whole chunk.
|
||||
*
|
||||
* @param \SplFixedArray|int[] $lightFilters
|
||||
* @param \SplFixedArray|bool[] $lightDiffusers
|
||||
* @phpstan-param \SplFixedArray<int> $lightFilters
|
||||
* @phpstan-param \SplFixedArray<bool> $lightDiffusers
|
||||
* @param \SplFixedArray|bool[] $directSkyLightBlockers
|
||||
* @phpstan-param \SplFixedArray<bool> $directSkyLightBlockers
|
||||
*/
|
||||
public function recalculateHeightMap(\SplFixedArray $lightFilters, \SplFixedArray $lightDiffusers) : void{
|
||||
public function recalculateHeightMap(\SplFixedArray $directSkyLightBlockers) : void{
|
||||
$maxSubChunkY = $this->subChunks->count() - 1;
|
||||
for(; $maxSubChunkY >= 0; $maxSubChunkY--){
|
||||
if(!$this->getSubChunk($maxSubChunkY)->isEmptyFast()){
|
||||
@ -292,7 +290,7 @@ class Chunk{
|
||||
$this->setHeightMap($x, $z, 0);
|
||||
}else{
|
||||
for(; $y >= 0; --$y){
|
||||
if($lightFilters[$state = $this->getFullBlock($x, $y, $z)] > 1 or $lightDiffusers[$state]){
|
||||
if($directSkyLightBlockers[$this->getFullBlock($x, $y, $z)]){
|
||||
$this->setHeightMap($x, $z, $y + 1);
|
||||
break;
|
||||
}
|
||||
@ -307,17 +305,15 @@ class Chunk{
|
||||
*
|
||||
* @param int $x 0-15
|
||||
* @param int $z 0-15
|
||||
* @param \SplFixedArray|int[] $lightFilters
|
||||
* @param \SplFixedArray|bool[] $lightDiffusers
|
||||
* @phpstan-param \SplFixedArray<int> $lightFilters
|
||||
* @phpstan-param \SplFixedArray<bool> $lightDiffusers
|
||||
* @param \SplFixedArray|bool[] $directSkyLightBlockers
|
||||
* @phpstan-param \SplFixedArray<bool> $directSkyLightBlockers
|
||||
*
|
||||
* @return int New calculated heightmap value (0-256 inclusive)
|
||||
*/
|
||||
public function recalculateHeightMapColumn(int $x, int $z, \SplFixedArray $lightFilters, \SplFixedArray $lightDiffusers) : int{
|
||||
public function recalculateHeightMapColumn(int $x, int $z, \SplFixedArray $directSkyLightBlockers) : int{
|
||||
$y = $this->getHighestBlockAt($x, $z);
|
||||
for(; $y >= 0; --$y){
|
||||
if($lightFilters[$state = $this->getFullBlock($x, $y, $z)] > 1 or $lightDiffusers[$state]){
|
||||
if($directSkyLightBlockers[$this->getFullBlock($x, $y, $z)]){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ class PopulationTask extends AsyncTask{
|
||||
$chunk->setPopulated();
|
||||
|
||||
$blockFactory = BlockFactory::getInstance();
|
||||
$chunk->recalculateHeightMap($blockFactory->lightFilter, $blockFactory->blocksDirectSkyLight);
|
||||
$chunk->recalculateHeightMap($blockFactory->blocksDirectSkyLight);
|
||||
$chunk->populateSkyLight($blockFactory->lightFilter);
|
||||
$chunk->setLightPopulated();
|
||||
|
||||
|
@ -61,7 +61,7 @@ class LightPopulationTask extends AsyncTask{
|
||||
$chunk = FastChunkSerializer::deserialize($this->chunk);
|
||||
|
||||
$blockFactory = BlockFactory::getInstance();
|
||||
$chunk->recalculateHeightMap($blockFactory->lightFilter, $blockFactory->blocksDirectSkyLight);
|
||||
$chunk->recalculateHeightMap($blockFactory->blocksDirectSkyLight);
|
||||
$chunk->populateSkyLight($blockFactory->lightFilter);
|
||||
$chunk->setLightPopulated();
|
||||
|
||||
|
@ -70,7 +70,7 @@ class SkyLightUpdate extends LightUpdate{
|
||||
$yPlusOne = $y + 1;
|
||||
|
||||
if($yPlusOne === $oldHeightMap){ //Block changed directly beneath the heightmap. Check if a block was removed or changed to a different light-filter.
|
||||
$newHeightMap = $chunk->recalculateHeightMapColumn($x & 0x0f, $z & 0x0f, $this->lightFilters, $this->directSkyLightBlockers);
|
||||
$newHeightMap = $chunk->recalculateHeightMapColumn($x & 0x0f, $z & 0x0f, $this->directSkyLightBlockers);
|
||||
}elseif($yPlusOne > $oldHeightMap){ //Block changed above the heightmap.
|
||||
if($this->directSkyLightBlockers[$source]){
|
||||
$chunk->setHeightMap($x & 0xf, $z & 0xf, $yPlusOne);
|
||||
|
@ -755,6 +755,11 @@ parameters:
|
||||
count: 1
|
||||
path: ../../../src/world/biome/BiomeRegistry.php
|
||||
|
||||
-
|
||||
message: "#^Only booleans are allowed in an if condition, bool\\|null given\\.$#"
|
||||
count: 2
|
||||
path: ../../../src/world/format/Chunk.php
|
||||
|
||||
-
|
||||
message: "#^Method pocketmine\\\\world\\\\format\\\\Chunk\\:\\:getSubChunk\\(\\) should return pocketmine\\\\world\\\\format\\\\SubChunkInterface but returns pocketmine\\\\world\\\\format\\\\SubChunk\\|null\\.$#"
|
||||
count: 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user