Chunk: drop premature optimizations

This commit is contained in:
Dylan K. Taylor 2019-06-14 18:07:13 +01:00
parent 722da5e88d
commit 92035ac2ec

View File

@ -64,9 +64,6 @@ class Chunk{
/** @var bool */ /** @var bool */
protected $hasChanged = false; protected $hasChanged = false;
/** @var bool */
protected $isInit = false;
/** @var bool */ /** @var bool */
protected $lightPopulated = false; protected $lightPopulated = false;
/** @var bool */ /** @var bool */
@ -464,7 +461,7 @@ class Chunk{
throw new \InvalidArgumentException("Attempted to add a garbage closed Entity to a chunk"); throw new \InvalidArgumentException("Attempted to add a garbage closed Entity to a chunk");
} }
$this->entities[$entity->getId()] = $entity; $this->entities[$entity->getId()] = $entity;
if(!($entity instanceof Player) and $this->isInit){ if(!($entity instanceof Player)){
$this->hasChanged = true; $this->hasChanged = true;
} }
} }
@ -474,7 +471,7 @@ class Chunk{
*/ */
public function removeEntity(Entity $entity) : void{ public function removeEntity(Entity $entity) : void{
unset($this->entities[$entity->getId()]); unset($this->entities[$entity->getId()]);
if(!($entity instanceof Player) and $this->isInit){ if(!($entity instanceof Player)){
$this->hasChanged = true; $this->hasChanged = true;
} }
} }
@ -491,20 +488,16 @@ class Chunk{
$this->tiles[$index]->close(); $this->tiles[$index]->close();
} }
$this->tiles[$index] = $tile; $this->tiles[$index] = $tile;
if($this->isInit){
$this->hasChanged = true; $this->hasChanged = true;
} }
}
/** /**
* @param Tile $tile * @param Tile $tile
*/ */
public function removeTile(Tile $tile) : void{ public function removeTile(Tile $tile) : void{
unset($this->tiles[Chunk::blockHash($tile->x, $tile->y, $tile->z)]); unset($this->tiles[Chunk::blockHash($tile->x, $tile->y, $tile->z)]);
if($this->isInit){
$this->hasChanged = true; $this->hasChanged = true;
} }
}
/** /**
* Returns an array of entities currently using this chunk. * Returns an array of entities currently using this chunk.
@ -578,7 +571,6 @@ class Chunk{
* @param World $world * @param World $world
*/ */
public function initChunk(World $world) : void{ public function initChunk(World $world) : void{
if(!$this->isInit){
if($this->NBTentities !== null){ if($this->NBTentities !== null){
$this->hasChanged = true; $this->hasChanged = true;
$world->timings->syncChunkLoadEntitiesTimer->startTiming(); $world->timings->syncChunkLoadEntitiesTimer->startTiming();
@ -617,9 +609,6 @@ class Chunk{
$this->NBTtiles = null; $this->NBTtiles = null;
$world->timings->syncChunkLoadTileEntitiesTimer->stopTiming(); $world->timings->syncChunkLoadTileEntitiesTimer->stopTiming();
} }
$this->isInit = true;
}
} }
/** /**