Rename SubChunkIteratorManager -> SubChunkExplorer

This commit is contained in:
Dylan K. Taylor 2020-09-20 12:47:44 +01:00
parent 4879df626d
commit c9d2edcb4d
7 changed files with 38 additions and 38 deletions

View File

@ -39,7 +39,7 @@ use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\world\particle\HugeExplodeSeedParticle;
use pocketmine\world\sound\ExplodeSound;
use pocketmine\world\utils\SubChunkIteratorManager;
use pocketmine\world\utils\SubChunkExplorer;
use function ceil;
use function floor;
use function mt_rand;
@ -62,8 +62,8 @@ class Explosion{
/** @var Entity|Block|null */
private $what;
/** @var SubChunkIteratorManager */
private $subChunkHandler;
/** @var SubChunkExplorer */
private $subChunkExplorer;
/**
* @param Entity|Block|null $what
@ -81,7 +81,7 @@ class Explosion{
$this->size = $size;
$this->what = $what;
$this->subChunkHandler = new SubChunkIteratorManager($this->world);
$this->subChunkExplorer = new SubChunkExplorer($this->world);
}
/**
@ -123,11 +123,11 @@ class Explosion{
$pointerY += $shiftY;
$pointerZ += $shiftZ;
if(!$this->subChunkHandler->moveTo($vBlockX, $vBlockY, $vBlockZ, false)){
if(!$this->subChunkExplorer->moveTo($vBlockX, $vBlockY, $vBlockZ, false)){
continue;
}
$state = $this->subChunkHandler->currentSubChunk->getFullBlock($vBlockX & 0x0f, $vBlockY & 0x0f, $vBlockZ & 0x0f);
$state = $this->subChunkExplorer->currentSubChunk->getFullBlock($vBlockX & 0x0f, $vBlockY & 0x0f, $vBlockZ & 0x0f);
if($state !== 0){
$blastForce -= ($blockFactory->blastResistance[$state] / 5 + 0.3) * $this->stepLen;

View File

@ -28,7 +28,7 @@ use pocketmine\block\BlockFactory;
use pocketmine\block\VanillaBlocks;
use pocketmine\utils\Limits;
use pocketmine\world\format\Chunk;
use pocketmine\world\utils\SubChunkIteratorManager;
use pocketmine\world\utils\SubChunkExplorer;
class SimpleChunkManager implements ChunkManager{
@ -38,7 +38,7 @@ class SimpleChunkManager implements ChunkManager{
/** @var int */
protected $worldHeight;
/** @var SubChunkIteratorManager */
/** @var SubChunkExplorer */
protected $terrainPointer;
/**
@ -46,7 +46,7 @@ class SimpleChunkManager implements ChunkManager{
*/
public function __construct(int $worldHeight = World::Y_MAX){
$this->worldHeight = $worldHeight;
$this->terrainPointer = new SubChunkIteratorManager($this);
$this->terrainPointer = new SubChunkExplorer($this);
}
public function getBlockAt(int $x, int $y, int $z) : Block{

View File

@ -77,7 +77,7 @@ use pocketmine\world\particle\DestroyBlockParticle;
use pocketmine\world\particle\Particle;
use pocketmine\world\sound\BlockPlaceSound;
use pocketmine\world\sound\Sound;
use pocketmine\world\utils\SubChunkIteratorManager;
use pocketmine\world\utils\SubChunkExplorer;
use function abs;
use function array_fill_keys;
use function array_map;
@ -1166,14 +1166,14 @@ class World implements ChunkManager{
$blockFactory = BlockFactory::getInstance();
$this->timings->doBlockSkyLightUpdates->startTiming();
if($this->skyLightUpdate === null){
$this->skyLightUpdate = new SkyLightUpdate(new SubChunkIteratorManager($this), $blockFactory->lightFilter, $blockFactory->blocksDirectSkyLight);
$this->skyLightUpdate = new SkyLightUpdate(new SubChunkExplorer($this), $blockFactory->lightFilter, $blockFactory->blocksDirectSkyLight);
}
$this->skyLightUpdate->recalculateNode($x, $y, $z);
$this->timings->doBlockSkyLightUpdates->stopTiming();
$this->timings->doBlockLightUpdates->startTiming();
if($this->blockLightUpdate === null){
$this->blockLightUpdate = new BlockLightUpdate(new SubChunkIteratorManager($this), $blockFactory->lightFilter, $blockFactory->light);
$this->blockLightUpdate = new BlockLightUpdate(new SubChunkExplorer($this), $blockFactory->lightFilter, $blockFactory->light);
}
$this->blockLightUpdate->recalculateNode($x, $y, $z);
$this->timings->doBlockLightUpdates->stopTiming();

View File

@ -23,7 +23,7 @@ declare(strict_types=1);
namespace pocketmine\world\light;
use pocketmine\world\utils\SubChunkIteratorManager;
use pocketmine\world\utils\SubChunkExplorer;
use function max;
class BlockLightUpdate extends LightUpdate{
@ -40,18 +40,18 @@ class BlockLightUpdate extends LightUpdate{
* @phpstan-param \SplFixedArray<int> $lightFilters
* @phpstan-param \SplFixedArray<int> $lightEmitters
*/
public function __construct(SubChunkIteratorManager $subChunkHandler, \SplFixedArray $lightFilters, \SplFixedArray $lightEmitters){
parent::__construct($subChunkHandler, $lightFilters);
public function __construct(SubChunkExplorer $subChunkExplorer, \SplFixedArray $lightFilters, \SplFixedArray $lightEmitters){
parent::__construct($subChunkExplorer, $lightFilters);
$this->lightEmitters = $lightEmitters;
}
protected function updateLightArrayRef() : void{
$this->currentLightArray = $this->subChunkHandler->currentSubChunk->getBlockLightArray();
$this->currentLightArray = $this->subChunkExplorer->currentSubChunk->getBlockLightArray();
}
public function recalculateNode(int $x, int $y, int $z) : void{
if($this->subChunkHandler->moveTo($x, $y, $z, false)){
$block = $this->subChunkHandler->currentSubChunk->getFullBlock($x & 0xf, $y & 0xf, $z & 0xf);
if($this->subChunkExplorer->moveTo($x, $y, $z, false)){
$block = $this->subChunkExplorer->currentSubChunk->getFullBlock($x & 0xf, $y & 0xf, $z & 0xf);
$this->setAndUpdateLight($x, $y, $z, max($this->lightEmitters[$block], $this->getHighestAdjacentLight($x, $y, $z) - $this->lightFilters[$block]));
}
}

View File

@ -24,7 +24,7 @@ declare(strict_types=1);
namespace pocketmine\world\light;
use pocketmine\world\format\LightArray;
use pocketmine\world\utils\SubChunkIteratorManager;
use pocketmine\world\utils\SubChunkExplorer;
use pocketmine\world\World;
use function max;
@ -43,8 +43,8 @@ abstract class LightUpdate{
*/
protected $updateNodes = [];
/** @var SubChunkIteratorManager */
protected $subChunkHandler;
/** @var SubChunkExplorer */
protected $subChunkExplorer;
/** @var LightArray|null */
protected $currentLightArray = null;
@ -53,11 +53,11 @@ abstract class LightUpdate{
* @param \SplFixedArray|int[] $lightFilters
* @phpstan-param \SplFixedArray<int> $lightFilters
*/
public function __construct(SubChunkIteratorManager $subChunkHandler, \SplFixedArray $lightFilters){
public function __construct(SubChunkExplorer $subChunkExplorer, \SplFixedArray $lightFilters){
$this->lightFilters = $lightFilters;
$this->subChunkHandler = $subChunkHandler;
$this->subChunkHandler->onSubChunkChange(\Closure::fromCallable([$this, 'updateLightArrayRef']));
$this->subChunkExplorer = $subChunkExplorer;
$this->subChunkExplorer->onSubChunkChange(\Closure::fromCallable([$this, 'updateLightArrayRef']));
}
abstract protected function updateLightArrayRef() : void;
@ -65,7 +65,7 @@ abstract class LightUpdate{
abstract public function recalculateNode(int $x, int $y, int $z) : void;
protected function getEffectiveLight(int $x, int $y, int $z) : int{
if($this->subChunkHandler->moveTo($x, $y, $z, false)){
if($this->subChunkExplorer->moveTo($x, $y, $z, false)){
return $this->currentLightArray->get($x & 0xf, $y & 0xf, $z & 0xf);
}
return 0;
@ -95,7 +95,7 @@ abstract class LightUpdate{
private function prepareNodes() : LightPropagationContext{
$context = new LightPropagationContext();
foreach($this->updateNodes as $blockHash => [$x, $y, $z, $newLevel]){
if($this->subChunkHandler->moveTo($x, $y, $z, false)){
if($this->subChunkExplorer->moveTo($x, $y, $z, false)){
$oldLevel = $this->currentLightArray->get($x & 0xf, $y & 0xf, $z & 0xf);
if($oldLevel !== $newLevel){
@ -131,7 +131,7 @@ abstract class LightUpdate{
];
foreach($points as [$cx, $cy, $cz]){
if($this->subChunkHandler->moveTo($cx, $cy, $cz, false)){
if($this->subChunkExplorer->moveTo($cx, $cy, $cz, false)){
$this->computeRemoveLight($cx, $cy, $cz, $oldAdjacentLight, $context);
}elseif($this->getEffectiveLight($cx, $cy, $cz) > 0 and !isset($context->spreadVisited[$index = World::blockHash($cx, $cy, $cz)])){
$context->spreadVisited[$index] = true;
@ -161,7 +161,7 @@ abstract class LightUpdate{
];
foreach($points as [$cx, $cy, $cz]){
if($this->subChunkHandler->moveTo($cx, $cy, $cz, false)){
if($this->subChunkExplorer->moveTo($cx, $cy, $cz, false)){
$this->computeSpreadLight($cx, $cy, $cz, $newAdjacentLight, $context);
}
}
@ -192,7 +192,7 @@ abstract class LightUpdate{
protected function computeSpreadLight(int $x, int $y, int $z, int $newAdjacentLevel, LightPropagationContext $context) : void{
$current = $this->currentLightArray->get($x & 0xf, $y & 0xf, $z & 0xf);
$potentialLight = $newAdjacentLevel - $this->lightFilters[$this->subChunkHandler->currentSubChunk->getFullBlock($x & 0x0f, $y & 0x0f, $z & 0x0f)];
$potentialLight = $newAdjacentLevel - $this->lightFilters[$this->subChunkExplorer->currentSubChunk->getFullBlock($x & 0x0f, $y & 0x0f, $z & 0x0f)];
if($current < $potentialLight){
$this->currentLightArray->set($x & 0xf, $y & 0xf, $z & 0xf, $potentialLight);

View File

@ -23,7 +23,7 @@ declare(strict_types=1);
namespace pocketmine\world\light;
use pocketmine\world\utils\SubChunkIteratorManager;
use pocketmine\world\utils\SubChunkExplorer;
use pocketmine\world\World;
use function max;
@ -41,31 +41,31 @@ class SkyLightUpdate extends LightUpdate{
* @phpstan-param \SplFixedArray<int> $lightFilters
* @phpstan-param \SplFixedArray<bool> $directSkyLightBlockers
*/
public function __construct(SubChunkIteratorManager $subChunkHandler, \SplFixedArray $lightFilters, \SplFixedArray $directSkyLightBlockers){
parent::__construct($subChunkHandler, $lightFilters);
public function __construct(SubChunkExplorer $subChunkExplorer, \SplFixedArray $lightFilters, \SplFixedArray $directSkyLightBlockers){
parent::__construct($subChunkExplorer, $lightFilters);
$this->directSkyLightBlockers = $directSkyLightBlockers;
}
protected function updateLightArrayRef() : void{
$this->currentLightArray = $this->subChunkHandler->currentSubChunk->getBlockSkyLightArray();
$this->currentLightArray = $this->subChunkExplorer->currentSubChunk->getBlockSkyLightArray();
}
protected function getEffectiveLight(int $x, int $y, int $z) : int{
if($y >= World::Y_MAX){
$this->subChunkHandler->invalidate();
$this->subChunkExplorer->invalidate();
return 15;
}
return parent::getEffectiveLight($x, $y, $z);
}
public function recalculateNode(int $x, int $y, int $z) : void{
if(!$this->subChunkHandler->moveTo($x, $y, $z, false)){
if(!$this->subChunkExplorer->moveTo($x, $y, $z, false)){
return;
}
$chunk = $this->subChunkHandler->currentChunk;
$chunk = $this->subChunkExplorer->currentChunk;
$oldHeightMap = $chunk->getHeightMap($x & 0xf, $z & 0xf);
$source = $this->subChunkHandler->currentSubChunk->getFullBlock($x & 0xf, $y & 0xf, $z & 0xf);
$source = $this->subChunkExplorer->currentSubChunk->getFullBlock($x & 0xf, $y & 0xf, $z & 0xf);
$yPlusOne = $y + 1;

View File

@ -29,7 +29,7 @@ use pocketmine\world\format\Chunk;
use pocketmine\world\format\SubChunk;
use function assert;
class SubChunkIteratorManager{
class SubChunkExplorer{
/** @var ChunkManager */
public $world;