Added better Entity/Tile scheduled updates

This commit is contained in:
Shoghi Cervantes 2014-09-01 11:59:46 +02:00
parent e047b6a870
commit ff48eb3d4d
6 changed files with 23 additions and 33 deletions

View File

@ -162,8 +162,7 @@ class Arrow extends Projectile{
}
$this->updateMovement();
//TODO: handle scheduled updates
return true;
return !$this->onGround or ($this->motionX == 0 and $this->motionY == 0 and $this->motionZ == 0);
}
public function attack($damage, $source = EntityDamageEvent::CAUSE_MAGIC){

View File

@ -107,8 +107,7 @@ class DroppedItem extends Entity{
}
$this->updateMovement();
//TODO: handle scheduled updates
return true;
return !$this->onGround or ($this->motionX == 0 and $this->motionY == 0 and $this->motionZ == 0);
}
public function attack($damage, $source = EntityDamageEvent::CAUSE_MAGIC){

View File

@ -64,11 +64,6 @@ abstract class Entity extends Position implements Metadatable{
public static $entityCount = 1;
/**
* @var Entity[]
*/
public static $needUpdate = [];
/**
* @var Player[]
*/
@ -584,8 +579,7 @@ abstract class Entity extends Position implements Metadatable{
}
public final function scheduleUpdate(){
//TODO!
Entity::$needUpdate[$this->id] = $this;
$this->level->updateEntities[$this->id] = $this;
}
public function setOnFire($seconds){
@ -1106,7 +1100,7 @@ abstract class Entity extends Position implements Metadatable{
if($this->closed === false){
$this->server->getPluginManager()->callEvent(new EntityDespawnEvent($this));
$this->closed = true;
unset(Entity::$needUpdate[$this->id]);
unset($this->level->updateEntities[$this->id]);
if($this->chunk instanceof FullChunk){
$this->chunk->removeEntity($this);
}

View File

@ -24,13 +24,12 @@ namespace pocketmine\event\entity;
use pocketmine\entity\Living;
use pocketmine\entity\Projectile;
use pocketmine\event\Cancellable;
use pocketmine\item\Bow;
use pocketmine\item\Item;
class EntityShootBowEvent extends EntityEvent implements Cancellable{
public static $handlerList = null;
/** @var Bow */
/** @var Item */
private $bow;
/** @var Projectile */
private $projectile;
@ -39,11 +38,11 @@ class EntityShootBowEvent extends EntityEvent implements Cancellable{
/**
* @param Living $shooter
* @param Bow $bow
* @param Item $bow
* @param Projectile $projectile
* @param float $force
*/
public function __construct(Living $shooter, Bow $bow, Projectile $projectile, $force){
public function __construct(Living $shooter, Item $bow, Projectile $projectile, $force){
$this->entity = $shooter;
$this->bow = $bow;
$this->projectile = $projectile;
@ -58,7 +57,7 @@ class EntityShootBowEvent extends EntityEvent implements Cancellable{
}
/**
* @return Bow
* @return Item
*/
public function getBow(){
return $this->bow;

View File

@ -121,6 +121,11 @@ class Level implements ChunkManager, Metadatable{
/** @var Entity[] */
protected $entities = [];
/** @var Entity[] */
public $updateEntities = [];
/** @var Tile[] */
public $updateTiles = [];
/** @var Server */
protected $server;
@ -505,11 +510,11 @@ class Level implements ChunkManager, Metadatable{
$this->timings->entityTick->startTiming();
//Update entities that need update
if(count(Entity::$needUpdate) > 0){
if(count($this->updateEntities) > 0){
//Timings::$tickEntityTimer->startTiming();
foreach($this->entities as $id => $entity){
if($entity->onUpdate() === false){
//unset(Entity::$needUpdate[$id]);
foreach($this->updateEntities as $id => $entity){
if($entity->onUpdate() !== true){
unset($this->updateEntities[$id]);
}
}
//Timings::$tickEntityTimer->stopTiming();
@ -518,11 +523,11 @@ class Level implements ChunkManager, Metadatable{
$this->timings->tileEntityTick->startTiming();
//Update tiles that need update
if(count(Tile::$needUpdate) > 0){
if(count($this->updateTiles) > 0){
//Timings::$tickTileEntityTimer->startTiming();
foreach($this->tiles as $id => $tile){
if($tile->onUpdate() === false){
//unset(Tile::$needUpdate[$id]);
foreach($this->updateTiles as $id => $tile){
if($tile->onUpdate() !== true){
unset($this->updateTiles[$id]);
}
}
//Timings::$tickTileEntityTimer->stopTiming();

View File

@ -41,11 +41,6 @@ abstract class Tile extends Position{
public static $tileCount = 1;
/**
* @var Tile[]
*/
public static $needUpdate = [];
/** @var Chunk */
public $chunk;
public $name;
@ -100,8 +95,7 @@ abstract class Tile extends Position{
}
public final function scheduleUpdate(){
//TODO!
Tile::$needUpdate[$this->id] = $this;
$this->level->updateTiles[$this->id] = $this;
}
public function __destruct(){
@ -111,7 +105,7 @@ abstract class Tile extends Position{
public function close(){
if($this->closed === false){
$this->closed = true;
unset(Tile::$needUpdate[$this->id]);
unset($this->level->updateTiles[$this->id]);
if($this->chunk instanceof FullChunk){
$this->chunk->removeTile($this);
}