mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-01 07:39:57 +00:00
Improved Level->getTile() to a direct lookup instead of linear search
This commit is contained in:
parent
3b9a9bcd5d
commit
f1519e6d13
@ -1366,13 +1366,10 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
if($pos instanceof Position and $pos->getLevel() !== $this){
|
if($pos instanceof Position and $pos->getLevel() !== $this){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$tiles = $this->getChunkTiles($pos->x >> 4, $pos->z >> 4);
|
$chunk = $this->getChunk($pos->x >> 4, $pos->z >> 4);
|
||||||
if(count($tiles) > 0){
|
|
||||||
foreach($tiles as $tile){
|
if($chunk instanceof FullChunk){
|
||||||
if($tile->x === (int) $pos->x and $tile->y === (int) $pos->y and $tile->z === (int) $pos->z){
|
return $chunk->getTile($pos->x & 0x0f, $pos->y & 0x7f, $pos->z & 0x0f);
|
||||||
return $tile;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -226,6 +226,13 @@ interface FullChunk{
|
|||||||
*/
|
*/
|
||||||
public function getTiles();
|
public function getTiles();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $x 0-15
|
||||||
|
* @param int $y 0-127
|
||||||
|
* @param int $z 0-15
|
||||||
|
*/
|
||||||
|
public function getTile($x, $y, $z);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
|
@ -37,6 +37,9 @@ abstract class BaseFullChunk implements FullChunk{
|
|||||||
/** @var Tile[] */
|
/** @var Tile[] */
|
||||||
protected $tiles = [];
|
protected $tiles = [];
|
||||||
|
|
||||||
|
/** @var Tile[] */
|
||||||
|
protected $tileList = [];
|
||||||
|
|
||||||
/** @var string */
|
/** @var string */
|
||||||
protected $biomeIds;
|
protected $biomeIds;
|
||||||
|
|
||||||
@ -234,11 +237,13 @@ abstract class BaseFullChunk implements FullChunk{
|
|||||||
|
|
||||||
public function addTile(Tile $tile){
|
public function addTile(Tile $tile){
|
||||||
$this->tiles[$tile->getID()] = $tile;
|
$this->tiles[$tile->getID()] = $tile;
|
||||||
|
$this->tiles[(($tile->z & 0x0f) << 8) | (($tile->x & 0x0f) << 4) | ($tile->y & 0x7f)] = $tile;
|
||||||
$this->hasChanged = true;
|
$this->hasChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function removeTile(Tile $tile){
|
public function removeTile(Tile $tile){
|
||||||
unset($this->tiles[$tile->getID()]);
|
unset($this->tiles[$tile->getID()]);
|
||||||
|
unset($this->tiles[(($tile->z & 0x0f) << 8) | (($tile->x & 0x0f) << 4) | ($tile->y & 0x7f)]);
|
||||||
$this->hasChanged = true;
|
$this->hasChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,6 +255,11 @@ abstract class BaseFullChunk implements FullChunk{
|
|||||||
return $this->tiles;
|
return $this->tiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getTile($x, $y, $z){
|
||||||
|
$index = ($z << 8) | ($x << 4) | $y;
|
||||||
|
return isset($this->tileList[$index]) ? $this->tileList[$index] : null;
|
||||||
|
}
|
||||||
|
|
||||||
public function isLoaded(){
|
public function isLoaded(){
|
||||||
return $this->getProvider() === null ? false : $this->getProvider()->isChunkLoaded($this->getX(), $this->getZ());
|
return $this->getProvider() === null ? false : $this->getProvider()->isChunkLoaded($this->getX(), $this->getZ());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user