mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-03 16:49:53 +00:00
SubChunk: Lazily allocate LightArrays as needed
this is slightly slower, but saves a significant amount of memory (~80 KB per chunk). Since ext-chunkutils2 doesn't do copy-on-write trickery like the PHP impl did, we need this to get the memory advantages back.
This commit is contained in:
parent
e6ecacbb2b
commit
e8dd4de5c8
@ -33,9 +33,9 @@ class SubChunk{
|
|||||||
/** @var PalettedBlockArray[] */
|
/** @var PalettedBlockArray[] */
|
||||||
private $blockLayers;
|
private $blockLayers;
|
||||||
|
|
||||||
/** @var LightArray */
|
/** @var LightArray|null */
|
||||||
private $blockLight;
|
private $blockLight;
|
||||||
/** @var LightArray */
|
/** @var LightArray|null */
|
||||||
private $skyLight;
|
private $skyLight;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -47,8 +47,8 @@ class SubChunk{
|
|||||||
$this->emptyBlockId = $emptyBlockId;
|
$this->emptyBlockId = $emptyBlockId;
|
||||||
$this->blockLayers = $blocks;
|
$this->blockLayers = $blocks;
|
||||||
|
|
||||||
$this->skyLight = $skyLight ?? LightArray::fill(15);
|
$this->skyLight = $skyLight;
|
||||||
$this->blockLight = $blockLight ?? LightArray::fill(0);
|
$this->blockLight = $blockLight;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -110,7 +110,7 @@ class SubChunk{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getBlockSkyLightArray() : LightArray{
|
public function getBlockSkyLightArray() : LightArray{
|
||||||
return $this->skyLight;
|
return $this->skyLight ??= LightArray::fill(15);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setBlockSkyLightArray(LightArray $data) : void{
|
public function setBlockSkyLightArray(LightArray $data) : void{
|
||||||
@ -118,7 +118,7 @@ class SubChunk{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getBlockLightArray() : LightArray{
|
public function getBlockLightArray() : LightArray{
|
||||||
return $this->blockLight;
|
return $this->blockLight ??= LightArray::fill(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setBlockLightArray(LightArray $data) : void{
|
public function setBlockLightArray(LightArray $data) : void{
|
||||||
@ -145,8 +145,12 @@ class SubChunk{
|
|||||||
}
|
}
|
||||||
$this->blockLayers = array_values($this->blockLayers);
|
$this->blockLayers = array_values($this->blockLayers);
|
||||||
|
|
||||||
$this->skyLight->collectGarbage();
|
if($this->skyLight !== null){
|
||||||
$this->blockLight->collectGarbage();
|
$this->skyLight->collectGarbage();
|
||||||
|
}
|
||||||
|
if($this->blockLight !== null){
|
||||||
|
$this->blockLight->collectGarbage();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __clone(){
|
public function __clone(){
|
||||||
@ -154,7 +158,11 @@ class SubChunk{
|
|||||||
return clone $array;
|
return clone $array;
|
||||||
}, $this->blockLayers);
|
}, $this->blockLayers);
|
||||||
|
|
||||||
$this->skyLight = clone $this->skyLight;
|
if($this->skyLight !== null){
|
||||||
$this->blockLight = clone $this->blockLight;
|
$this->skyLight = clone $this->skyLight;
|
||||||
|
}
|
||||||
|
if($this->blockLight !== null){
|
||||||
|
$this->blockLight = clone $this->blockLight;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user