Chunk: remove useless proxy field emptySubChunk

This commit is contained in:
Dylan K. Taylor 2019-10-22 20:24:26 +01:00
parent e1352668d1
commit 9d3637c999

View File

@ -74,9 +74,6 @@ class Chunk{
/** @var \SplFixedArray|SubChunkInterface[] */ /** @var \SplFixedArray|SubChunkInterface[] */
protected $subChunks; protected $subChunks;
/** @var EmptySubChunk */
protected $emptySubChunk;
/** @var Tile[] */ /** @var Tile[] */
protected $tiles = []; protected $tiles = [];
@ -111,10 +108,9 @@ class Chunk{
$this->height = Chunk::MAX_SUBCHUNKS; //TODO: add a way of changing this $this->height = Chunk::MAX_SUBCHUNKS; //TODO: add a way of changing this
$this->subChunks = new \SplFixedArray($this->height); $this->subChunks = new \SplFixedArray($this->height);
$this->emptySubChunk = EmptySubChunk::getInstance();
foreach($this->subChunks as $y => $null){ foreach($this->subChunks as $y => $null){
$this->subChunks[$y] = $subChunks[$y] ?? $this->emptySubChunk; $this->subChunks[$y] = $subChunks[$y] ?? EmptySubChunk::getInstance();
} }
if(count($heightMap) === 256){ if(count($heightMap) === 256){
@ -675,7 +671,7 @@ class Chunk{
*/ */
public function getSubChunk(int $y, bool $generateNew = false) : SubChunkInterface{ public function getSubChunk(int $y, bool $generateNew = false) : SubChunkInterface{
if($y < 0 or $y >= $this->height){ if($y < 0 or $y >= $this->height){
return $this->emptySubChunk; return EmptySubChunk::getInstance();
}elseif($generateNew and $this->subChunks[$y] instanceof EmptySubChunk){ }elseif($generateNew and $this->subChunks[$y] instanceof EmptySubChunk){
$this->subChunks[$y] = new SubChunk(BlockLegacyIds::AIR << 4, []); $this->subChunks[$y] = new SubChunk(BlockLegacyIds::AIR << 4, []);
} }
@ -697,7 +693,7 @@ class Chunk{
return false; return false;
} }
if($subChunk === null or ($subChunk->isEmpty() and !$allowEmpty)){ if($subChunk === null or ($subChunk->isEmpty() and !$allowEmpty)){
$this->subChunks[$y] = $this->emptySubChunk; $this->subChunks[$y] = EmptySubChunk::getInstance();
}else{ }else{
$this->subChunks[$y] = $subChunk; $this->subChunks[$y] = $subChunk;
} }
@ -746,7 +742,7 @@ class Chunk{
if($subChunk instanceof SubChunk){ if($subChunk instanceof SubChunk){
$subChunk->collectGarbage(); $subChunk->collectGarbage();
if($subChunk->isEmpty()){ if($subChunk->isEmpty()){
$this->subChunks[$y] = $this->emptySubChunk; $this->subChunks[$y] = EmptySubChunk::getInstance();
} }
} }
} }