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

This reverts commit 3bb450244f.

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

@@ -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){