From d0470a80ab662601b6fbee48ae674b71b9d80a15 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 31 Oct 2020 22:02:36 +0000 Subject: [PATCH] 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. --- src/world/SimpleChunkManager.php | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/world/SimpleChunkManager.php b/src/world/SimpleChunkManager.php index 7911158b0..17325ad0f 100644 --- a/src/world/SimpleChunkManager.php +++ b/src/world/SimpleChunkManager.php @@ -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"); }