mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-11 04:17:48 +00:00
Chunk no longer depends on BlockFactory
really this light population crap shouldn't be in the chunk to begin with, but that's a bit more complicated.
This commit is contained in:
parent
aa1828aa98
commit
accc0da0cb
@ -26,7 +26,6 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\world\format;
|
namespace pocketmine\world\format;
|
||||||
|
|
||||||
use pocketmine\block\BlockFactory;
|
|
||||||
use pocketmine\block\BlockLegacyIds;
|
use pocketmine\block\BlockLegacyIds;
|
||||||
use pocketmine\block\tile\Tile;
|
use pocketmine\block\tile\Tile;
|
||||||
use pocketmine\block\tile\TileFactory;
|
use pocketmine\block\tile\TileFactory;
|
||||||
@ -279,11 +278,16 @@ class Chunk{
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Recalculates the heightmap for the whole 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
|
||||||
*/
|
*/
|
||||||
public function recalculateHeightMap() : void{
|
public function recalculateHeightMap(\SplFixedArray $lightFilters, \SplFixedArray $lightDiffusers) : void{
|
||||||
for($z = 0; $z < 16; ++$z){
|
for($z = 0; $z < 16; ++$z){
|
||||||
for($x = 0; $x < 16; ++$x){
|
for($x = 0; $x < 16; ++$x){
|
||||||
$this->recalculateHeightMapColumn($x, $z);
|
$this->recalculateHeightMapColumn($x, $z, $lightFilters, $lightDiffusers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -293,13 +297,17 @@ class Chunk{
|
|||||||
*
|
*
|
||||||
* @param int $x 0-15
|
* @param int $x 0-15
|
||||||
* @param int $z 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
|
||||||
*
|
*
|
||||||
* @return int New calculated heightmap value (0-256 inclusive)
|
* @return int New calculated heightmap value (0-256 inclusive)
|
||||||
*/
|
*/
|
||||||
public function recalculateHeightMapColumn(int $x, int $z) : int{
|
public function recalculateHeightMapColumn(int $x, int $z, \SplFixedArray $lightFilters, \SplFixedArray $lightDiffusers) : int{
|
||||||
$y = $this->getHighestBlockAt($x, $z);
|
$y = $this->getHighestBlockAt($x, $z);
|
||||||
for(; $y >= 0; --$y){
|
for(; $y >= 0; --$y){
|
||||||
if(BlockFactory::$lightFilter[$state = $this->getFullBlock($x, $y, $z)] > 1 or BlockFactory::$diffusesSkyLight[$state]){
|
if($lightFilters[$state = $this->getFullBlock($x, $y, $z)] > 1 or $lightDiffusers[$state]){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -313,9 +321,12 @@ class Chunk{
|
|||||||
* This does not cater for adjacent sky light, this performs direct sky light population only. This may cause some strange visual artifacts
|
* This does not cater for adjacent sky light, this performs direct sky light population only. This may cause some strange visual artifacts
|
||||||
* if the chunk is light-populated after being terrain-populated.
|
* if the chunk is light-populated after being terrain-populated.
|
||||||
*
|
*
|
||||||
|
* @param \SplFixedArray|int[] $lightFilters
|
||||||
|
* @phpstan-param \SplFixedArray<int> $lightFilters
|
||||||
|
*
|
||||||
* TODO: fast adjacent light spread
|
* TODO: fast adjacent light spread
|
||||||
*/
|
*/
|
||||||
public function populateSkyLight() : void{
|
public function populateSkyLight(\SplFixedArray $lightFilters) : void{
|
||||||
$this->setAllBlockSkyLight(0);
|
$this->setAllBlockSkyLight(0);
|
||||||
|
|
||||||
for($x = 0; $x < 16; ++$x){
|
for($x = 0; $x < 16; ++$x){
|
||||||
@ -329,7 +340,7 @@ class Chunk{
|
|||||||
|
|
||||||
$light = 15;
|
$light = 15;
|
||||||
for(; $y >= 0; --$y){
|
for(; $y >= 0; --$y){
|
||||||
$light -= BlockFactory::$lightFilter[$this->getFullBlock($x, $y, $z)];
|
$light -= $lightFilters[$this->getFullBlock($x, $y, $z)];
|
||||||
if($light <= 0){
|
if($light <= 0){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\world\generator;
|
namespace pocketmine\world\generator;
|
||||||
|
|
||||||
|
use pocketmine\block\BlockFactory;
|
||||||
use pocketmine\scheduler\AsyncTask;
|
use pocketmine\scheduler\AsyncTask;
|
||||||
use pocketmine\world\format\Chunk;
|
use pocketmine\world\format\Chunk;
|
||||||
use pocketmine\world\format\io\FastChunkSerializer;
|
use pocketmine\world\format\io\FastChunkSerializer;
|
||||||
@ -118,8 +119,8 @@ class PopulationTask extends AsyncTask{
|
|||||||
$chunk = $manager->getChunk($chunk->getX(), $chunk->getZ());
|
$chunk = $manager->getChunk($chunk->getX(), $chunk->getZ());
|
||||||
$chunk->setPopulated();
|
$chunk->setPopulated();
|
||||||
|
|
||||||
$chunk->recalculateHeightMap();
|
$chunk->recalculateHeightMap(BlockFactory::$lightFilter, BlockFactory::$diffusesSkyLight);
|
||||||
$chunk->populateSkyLight();
|
$chunk->populateSkyLight(BlockFactory::$lightFilter);
|
||||||
$chunk->setLightPopulated();
|
$chunk->setLightPopulated();
|
||||||
|
|
||||||
$this->chunk = FastChunkSerializer::serialize($chunk);
|
$this->chunk = FastChunkSerializer::serialize($chunk);
|
||||||
|
@ -63,8 +63,8 @@ class LightPopulationTask extends AsyncTask{
|
|||||||
/** @var Chunk $chunk */
|
/** @var Chunk $chunk */
|
||||||
$chunk = FastChunkSerializer::deserialize($this->chunk);
|
$chunk = FastChunkSerializer::deserialize($this->chunk);
|
||||||
|
|
||||||
$chunk->recalculateHeightMap();
|
$chunk->recalculateHeightMap(BlockFactory::$lightFilter, BlockFactory::$diffusesSkyLight);
|
||||||
$chunk->populateSkyLight();
|
$chunk->populateSkyLight(BlockFactory::$lightFilter);
|
||||||
$chunk->setLightPopulated();
|
$chunk->setLightPopulated();
|
||||||
|
|
||||||
$this->resultHeightMap = igbinary_serialize($chunk->getHeightMapArray());
|
$this->resultHeightMap = igbinary_serialize($chunk->getHeightMapArray());
|
||||||
|
@ -51,7 +51,7 @@ class SkyLightUpdate extends LightUpdate{
|
|||||||
$yPlusOne = $y + 1;
|
$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.
|
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);
|
$newHeightMap = $chunk->recalculateHeightMapColumn($x & 0x0f, $z & 0x0f, BlockFactory::$lightFilter, BlockFactory::$diffusesSkyLight);
|
||||||
}elseif($yPlusOne > $oldHeightMap){ //Block changed above the heightmap.
|
}elseif($yPlusOne > $oldHeightMap){ //Block changed above the heightmap.
|
||||||
if($source->getLightFilter() > 0 or $source->diffusesSkyLight()){
|
if($source->getLightFilter() > 0 or $source->diffusesSkyLight()){
|
||||||
$chunk->setHeightMap($x & 0xf, $z & 0xf, $yPlusOne);
|
$chunk->setHeightMap($x & 0xf, $z & 0xf, $yPlusOne);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user