Chunk: Use an SplFixedArray for heightmap

this goes on 3.1 because it changes the behaviour of chunk cloning, which might possibly break some plugins, and this isn't a bug fix.

This should see no change in behaviour other than a minor performance improvement and slight reduction in memory usage.
This commit is contained in:
Dylan K. Taylor 2018-07-05 11:58:20 +01:00
parent 0f0d12bebc
commit 28a72a93b4

View File

@ -75,8 +75,8 @@ class Chunk{
/** @var Entity[] */
protected $entities = [];
/** @var int[] */
protected $heightMap = [];
/** @var \SplFixedArray|int[] */
protected $heightMap;
/** @var string */
protected $biomeIds;
@ -110,11 +110,11 @@ class Chunk{
}
if(count($heightMap) === 256){
$this->heightMap = $heightMap;
$this->heightMap = \SplFixedArray::fromArray($heightMap);
}else{
assert(count($heightMap) === 0, "Wrong HeightMap value count, expected 256, got " . count($heightMap));
$val = ($this->height * 16);
$this->heightMap = array_fill(0, 256, $val);
$this->heightMap = \SplFixedArray::fromArray(array_fill(0, 256, $val));
}
if(strlen($biomeIds) === 256){
@ -739,7 +739,7 @@ class Chunk{
* @return int[]
*/
public function getHeightMapArray() : array{
return $this->heightMap;
return $this->heightMap->toArray();
}
/**