ChunkLoader: remove getLoaderId() (take 2)

This commit is contained in:
Dylan K. Taylor
2019-01-25 18:58:01 +00:00
parent bb27c76d13
commit 6ee484e401
4 changed files with 13 additions and 33 deletions

View File

@ -106,6 +106,7 @@ use function max;
use function microtime;
use function min;
use function mt_rand;
use function spl_object_id;
use function strtolower;
use function trim;
use const INT32_MAX;
@ -117,7 +118,6 @@ use const M_PI;
class Level implements ChunkManager, Metadatable{
private static $levelIdCounter = 1;
private static $chunkLoaderCounter = 1;
public const Y_MASK = 0xFF;
public const Y_MAX = 0x100; //256
@ -321,14 +321,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
*
@ -642,7 +634,7 @@ class Level implements ChunkManager, Metadatable{
}
public function registerChunkLoader(ChunkLoader $loader, int $chunkX, int $chunkZ, bool $autoLoad = true){
$loaderId = $loader->getLoaderId();
$loaderId = spl_object_id($loader);
if(!isset($this->chunkLoaders[$chunkHash = Level::chunkHash($chunkX, $chunkZ)])){
$this->chunkLoaders[$chunkHash] = [];
@ -672,7 +664,7 @@ class Level implements ChunkManager, Metadatable{
public function unregisterChunkLoader(ChunkLoader $loader, int $chunkX, int $chunkZ){
$chunkHash = Level::chunkHash($chunkX, $chunkZ);
$loaderId = $loader->getLoaderId();
$loaderId = spl_object_id($loader);
if(isset($this->chunkLoaders[$chunkHash][$loaderId])){
unset($this->chunkLoaders[$chunkHash][$loaderId]);
unset($this->playerLoaders[$chunkHash][$loaderId]);
@ -2401,7 +2393,7 @@ class Level implements ChunkManager, Metadatable{
$this->chunkSendQueue[$index] = [];
}
$this->chunkSendQueue[$index][$player->getLoaderId()] = $player;
$this->chunkSendQueue[$index][spl_object_id($player)] = $player;
}
private function sendCachedChunk(int $x, int $z){