Revert "Level: Identify chunk loaders by their object ID"

This reverts commit 3bb450244fda8c2e7050e44e8a392960ef63f02f.

PhpStorm you lying piece of shit... you only showed me the usages in Level!

This change should be revised and redone later.
This commit is contained in:
Dylan K. Taylor 2018-10-10 03:59:07 -04:00
parent 9b31484655
commit e2af394c81
3 changed files with 26 additions and 2 deletions

View File

@ -214,6 +214,8 @@ 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 */
@ -662,6 +664,7 @@ 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,4 +3385,8 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
public function onBlockChanged(Vector3 $block){
}
public function getLoaderId() : int{
return $this->loaderId;
}
}

View File

@ -39,6 +39,14 @@ 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,6 +91,7 @@ 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
@ -279,6 +280,14 @@ 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
@ -615,7 +624,7 @@ class Level implements ChunkManager, Metadatable{
}
public function registerChunkLoader(ChunkLoader $loader, int $chunkX, int $chunkZ, bool $autoLoad = true){
$hash = spl_object_id($loader);
$hash = $loader->getLoaderId();
if(!isset($this->chunkLoaders[$index = Level::chunkHash($chunkX, $chunkZ)])){
$this->chunkLoaders[$index] = [];
@ -644,7 +653,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 = spl_object_id($loader)])){
if(isset($this->chunkLoaders[$index = Level::chunkHash($chunkX, $chunkZ)][$hash = $loader->getLoaderId()])){
unset($this->chunkLoaders[$index][$hash]);
unset($this->playerLoaders[$index][$hash]);
if(count($this->chunkLoaders[$index]) === 0){