Store world height in the Level for faster access

this might look like a micro optimization, but it shows up big-time on profiler snapshots.
This commit is contained in:
Dylan K. Taylor 2017-11-23 17:24:37 +00:00
parent b22b493abb
commit 667a54fd00

View File

@ -145,6 +145,8 @@ class Level implements ChunkManager, Metadatable{
/** @var LevelProvider */
private $provider;
private $worldHeight;
/** @var ChunkLoader[] */
private $loaders = [];
/** @var int[] */
@ -335,6 +337,9 @@ class Level implements ChunkManager, Metadatable{
}else{
throw new LevelException("Provider is not a subclass of LevelProvider");
}
$this->worldHeight = $this->provider->getWorldHeight();
$this->server->getLogger()->info($this->server->getLanguage()->translateString("pocketmine.level.preparing", [$this->provider->getName()]));
$this->generator = Generator::getGenerator($this->provider->getGenerator());
@ -1308,7 +1313,7 @@ class Level implements ChunkManager, Metadatable{
public function isInWorld(float $x, float $y, float $z) : bool{
return (
$x <= INT32_MAX and $x >= INT32_MIN and
$y < $this->getWorldHeight() and $y >= 0 and
$y < $this->worldHeight and $y >= 0 and
$z <= INT32_MAX and $z >= INT32_MIN
);
}
@ -1735,7 +1740,7 @@ class Level implements ChunkManager, Metadatable{
$clickVector = new Vector3(0.0, 0.0, 0.0);
}
if($blockReplace->y >= $this->provider->getWorldHeight() or $blockReplace->y < 0){
if($blockReplace->y >= $this->worldHeight or $blockReplace->y < 0){
//TODO: build height limit messages for custom world heights and mcregion cap
return false;
}
@ -2692,7 +2697,7 @@ class Level implements ChunkManager, Metadatable{
$spawn = $this->getSpawnLocation();
}
if($spawn instanceof Vector3){
$max = $this->provider->getWorldHeight();
$max = $this->worldHeight;
$v = $spawn->floor();
$chunk = $this->getChunk($v->x >> 4, $v->z >> 4, false);
$x = (int) $v->x;
@ -2802,7 +2807,7 @@ class Level implements ChunkManager, Metadatable{
}
public function getWorldHeight() : int{
return $this->provider->getWorldHeight();
return $this->worldHeight;
}
/**