SimpleChunkManager: remove post-mature optimisation

these methods are not used in hot paths and are inherently slow anyway, not to mention the introduction of morton codes eliminating the hashtable indexing problem.
This commit is contained in:
Dylan K. Taylor 2020-10-31 22:02:36 +00:00
parent ddda2d1e64
commit d0470a80ab

View File

@ -28,8 +28,6 @@ use pocketmine\block\BlockFactory;
use pocketmine\block\VanillaBlocks;
use pocketmine\utils\Limits;
use pocketmine\world\format\Chunk;
use pocketmine\world\utils\SubChunkExplorer;
use pocketmine\world\utils\SubChunkExplorerStatus;
class SimpleChunkManager implements ChunkManager{
@ -39,28 +37,23 @@ class SimpleChunkManager implements ChunkManager{
/** @var int */
protected $worldHeight;
/** @var SubChunkExplorer */
protected $terrainPointer;
/**
* SimpleChunkManager constructor.
*/
public function __construct(int $worldHeight = World::Y_MAX){
$this->worldHeight = $worldHeight;
$this->terrainPointer = new SubChunkExplorer($this);
}
public function getBlockAt(int $x, int $y, int $z) : Block{
if($this->terrainPointer->moveTo($x, $y, $z) !== SubChunkExplorerStatus::INVALID){
return BlockFactory::getInstance()->fromFullBlock($this->terrainPointer->currentSubChunk->getFullBlock($x & 0xf, $y & 0xf, $z & 0xf));
if(($chunk = $this->getChunk($x >> 4, $z >> 4)) !== null){
return BlockFactory::getInstance()->fromFullBlock($chunk->getFullBlock($x & 0xf, $y, $z));
}
return VanillaBlocks::AIR();
}
public function setBlockAt(int $x, int $y, int $z, Block $block) : void{
if($this->terrainPointer->moveTo($x, $y, $z) !== SubChunkExplorerStatus::INVALID){
$this->terrainPointer->currentSubChunk->setFullBlock($x & 0xf, $y & 0xf, $z & 0xf, $block->getFullId());
$this->terrainPointer->currentChunk->setDirtyFlag(Chunk::DIRTY_FLAG_TERRAIN, true);
if(($chunk = $this->getChunk($x >> 4, $z >> 4)) !== null){
$chunk->setFullBlock($x & 0xf, $y, $z & 0xf, $block->getFullId());
}else{
throw new \InvalidArgumentException("Cannot set block at coordinates x=$x,y=$y,z=$z, terrain is not loaded or out of bounds");
}