World: change 'closed' to 'unloaded'

this makes more sense overall from a reader's perspective.
and also provide a rug-jerk for any idiots using World->close() when they aren't supposed to? ....
This commit is contained in:
Dylan K. Taylor 2021-06-26 21:54:18 +01:00
parent b8ebf8936e
commit 02fab77e55
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
4 changed files with 14 additions and 14 deletions

View File

@ -39,7 +39,7 @@ class Position extends Vector3{
*/
public function __construct($x, $y, $z, ?World $world){
parent::__construct($x, $y, $z);
if($world !== null and $world->isClosed()){
if($world !== null and !$world->isLoaded()){
throw new \InvalidArgumentException("Specified world has been unloaded and cannot be used");
}
@ -66,7 +66,7 @@ class Position extends Vector3{
* @throws AssumptionFailedError
*/
public function getWorld() : World{
if($this->world === null || $this->world->isClosed()){
if($this->world === null || !$this->world->isLoaded()){
throw new AssumptionFailedError("Position world is null or has been unloaded");
}
@ -77,7 +77,7 @@ class Position extends Vector3{
* Checks if this object has a valid reference to a loaded world
*/
public function isValid() : bool{
if($this->world !== null and $this->world->isClosed()){
if($this->world !== null and !$this->world->isLoaded()){
$this->world = null;
return false;

View File

@ -285,7 +285,7 @@ class World implements ChunkManager{
private $generator;
/** @var bool */
private $closed = false;
private $unloaded = false;
/**
* @var \Closure[]
* @phpstan-var array<int, \Closure() : void>
@ -493,15 +493,15 @@ class World implements ChunkManager{
return $this->worldId;
}
public function isClosed() : bool{
return $this->closed;
public function isLoaded() : bool{
return !$this->unloaded;
}
/**
* @internal
*/
public function close() : void{
if($this->closed){
public function onUnload() : void{
if($this->unloaded){
throw new \InvalidStateException("Tried to close a world which is already closed");
}
@ -523,7 +523,7 @@ class World implements ChunkManager{
$this->provider = null;
$this->blockCache = [];
$this->closed = true;
$this->unloaded = true;
}
/** @phpstan-param \Closure() : void $callback */
@ -747,7 +747,7 @@ class World implements ChunkManager{
* @internal
*/
public function doTick(int $currentTick) : void{
if($this->closed){
if($this->unloaded){
throw new \InvalidStateException("Attempted to tick a world which has been closed");
}
@ -1046,7 +1046,7 @@ class World implements ChunkManager{
* @phpstan-var array<int, LightArray> $skyLight
* @phpstan-var array<int, int> $heightMap
*/
if($this->closed || ($chunk = $this->getChunk($chunkX, $chunkZ)) === null || $chunk->isLightPopulated() === true){
if($this->unloaded || ($chunk = $this->getChunk($chunkX, $chunkZ)) === null || $chunk->isLightPopulated() === true){
return;
}
//TODO: calculated light information might not be valid if the terrain changed during light calculation

View File

@ -168,7 +168,7 @@ class WorldManager{
}
unset($this->worlds[$world->getId()]);
$world->close();
$world->onUnload();
return true;
}
@ -321,7 +321,7 @@ class WorldManager{
*/
public function findEntity(int $entityId) : ?Entity{
foreach($this->worlds as $world){
assert(!$world->isClosed());
assert($world->isLoaded());
if(($entity = $world->getEntity($entityId)) instanceof Entity){
return $entity;
}

View File

@ -136,7 +136,7 @@ class PopulationTask extends AsyncTask{
public function onCompletion() : void{
/** @var World $world */
$world = $this->fetchLocal(self::TLS_KEY_WORLD);
if(!$world->isClosed()){
if($world->isLoaded()){
$chunk = $this->chunk !== null ? FastChunkSerializer::deserialize($this->chunk) : null;
for($i = 0; $i < 9; ++$i){