Level: Identify chunk loaders by their object ID

chunkloader ID is completely unnecessary extra complication. spl_object_hash() would be fine for this as well, but a number is better. Since it's unique for the object lifetime (and the Level keeps a ref to loaders) this system should work just fine.
This commit is contained in:
Dylan K. Taylor 2018-10-09 16:32:34 +01:00
parent a653289c40
commit 3bb450244f
3 changed files with 2 additions and 26 deletions

View File

@ -214,8 +214,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
/** @var int */
protected $gamemode;
/** @var int */
private $loaderId = 0;
/** @var bool[] chunkHash => bool (true = sent, false = needs sending) */
public $usedChunks = [];
/** @var bool[] chunkHash => dummy */
@ -664,7 +662,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$this->networkSession = $session;
$this->perm = new PermissibleBase($this);
$this->loaderId = Level::generateChunkLoaderId($this);
$this->chunksPerTick = (int) $this->server->getProperty("chunk-sending.per-tick", 4);
$this->spawnThreshold = (int) (($this->server->getProperty("chunk-sending.spawn-radius", 4) ** 2) * M_PI);
@ -3382,8 +3379,4 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
public function onBlockChanged(Vector3 $block){
}
public function getLoaderId() : int{
return $this->loaderId;
}
}

View File

@ -39,14 +39,6 @@ use pocketmine\math\Vector3;
*/
interface ChunkLoader{
/**
* Returns the ChunkLoader id.
* Call Level::generateChunkLoaderId($this) to generate and save it
*
* @return int
*/
public function getLoaderId() : int;
/**
* @return float
*/

View File

@ -91,7 +91,6 @@ use pocketmine\utils\ReversePriorityQueue;
class Level implements ChunkManager, Metadatable{
private static $levelIdCounter = 1;
private static $chunkLoaderCounter = 1;
public const Y_MASK = 0xFF;
public const Y_MAX = 0x100; //256
@ -280,14 +279,6 @@ class Level implements ChunkManager, Metadatable{
$z = ($hash & 0xFFFFFFFF) << 32 >> 32;
}
public static function generateChunkLoaderId(ChunkLoader $loader) : int{
if($loader->getLoaderId() === 0){
return self::$chunkLoaderCounter++;
}else{
throw new \InvalidStateException("ChunkLoader has a loader id already assigned: " . $loader->getLoaderId());
}
}
/**
* @param string $str
* @return int
@ -624,7 +615,7 @@ class Level implements ChunkManager, Metadatable{
}
public function registerChunkLoader(ChunkLoader $loader, int $chunkX, int $chunkZ, bool $autoLoad = true){
$hash = $loader->getLoaderId();
$hash = spl_object_id($loader);
if(!isset($this->chunkLoaders[$index = Level::chunkHash($chunkX, $chunkZ)])){
$this->chunkLoaders[$index] = [];
@ -653,7 +644,7 @@ class Level implements ChunkManager, Metadatable{
}
public function unregisterChunkLoader(ChunkLoader $loader, int $chunkX, int $chunkZ){
if(isset($this->chunkLoaders[$index = Level::chunkHash($chunkX, $chunkZ)][$hash = $loader->getLoaderId()])){
if(isset($this->chunkLoaders[$index = Level::chunkHash($chunkX, $chunkZ)][$hash = spl_object_id($loader)])){
unset($this->chunkLoaders[$index][$hash]);
unset($this->playerLoaders[$index][$hash]);
if(count($this->chunkLoaders[$index]) === 0){