Chunk: Share EmptySubChunk instance with other chunks on the same thread

This commit is contained in:
Dylan K. Taylor 2018-06-04 11:44:18 +01:00
parent 0d177d5219
commit 857f6dd5df
2 changed files with 11 additions and 1 deletions

View File

@ -103,7 +103,7 @@ class Chunk{
$this->height = Chunk::MAX_SUBCHUNKS; //TODO: add a way of changing this
$this->subChunks = new \SplFixedArray($this->height);
$this->emptySubChunk = new EmptySubChunk();
$this->emptySubChunk = EmptySubChunk::getInstance();
foreach($this->subChunks as $y => $null){
$this->subChunks[$y] = $subChunks[$y] ?? $this->emptySubChunk;

View File

@ -24,6 +24,16 @@ declare(strict_types=1);
namespace pocketmine\level\format;
class EmptySubChunk implements SubChunkInterface{
/** @var EmptySubChunk */
private static $instance;
public static function getInstance() : self{
if(self::$instance === null){
self::$instance = new self();
}
return self::$instance;
}
public function isEmpty(bool $checkLight = true) : bool{
return true;