mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-01 23:59:53 +00:00
Added better Entity/Tile scheduled updates
This commit is contained in:
parent
e047b6a870
commit
ff48eb3d4d
@ -162,8 +162,7 @@ class Arrow extends Projectile{
|
|||||||
}
|
}
|
||||||
$this->updateMovement();
|
$this->updateMovement();
|
||||||
|
|
||||||
//TODO: handle scheduled updates
|
return !$this->onGround or ($this->motionX == 0 and $this->motionY == 0 and $this->motionZ == 0);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function attack($damage, $source = EntityDamageEvent::CAUSE_MAGIC){
|
public function attack($damage, $source = EntityDamageEvent::CAUSE_MAGIC){
|
||||||
|
@ -107,8 +107,7 @@ class DroppedItem extends Entity{
|
|||||||
}
|
}
|
||||||
$this->updateMovement();
|
$this->updateMovement();
|
||||||
|
|
||||||
//TODO: handle scheduled updates
|
return !$this->onGround or ($this->motionX == 0 and $this->motionY == 0 and $this->motionZ == 0);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function attack($damage, $source = EntityDamageEvent::CAUSE_MAGIC){
|
public function attack($damage, $source = EntityDamageEvent::CAUSE_MAGIC){
|
||||||
|
@ -64,11 +64,6 @@ abstract class Entity extends Position implements Metadatable{
|
|||||||
|
|
||||||
public static $entityCount = 1;
|
public static $entityCount = 1;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var Entity[]
|
|
||||||
*/
|
|
||||||
public static $needUpdate = [];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Player[]
|
* @var Player[]
|
||||||
*/
|
*/
|
||||||
@ -584,8 +579,7 @@ abstract class Entity extends Position implements Metadatable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public final function scheduleUpdate(){
|
public final function scheduleUpdate(){
|
||||||
//TODO!
|
$this->level->updateEntities[$this->id] = $this;
|
||||||
Entity::$needUpdate[$this->id] = $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setOnFire($seconds){
|
public function setOnFire($seconds){
|
||||||
@ -1106,7 +1100,7 @@ abstract class Entity extends Position implements Metadatable{
|
|||||||
if($this->closed === false){
|
if($this->closed === false){
|
||||||
$this->server->getPluginManager()->callEvent(new EntityDespawnEvent($this));
|
$this->server->getPluginManager()->callEvent(new EntityDespawnEvent($this));
|
||||||
$this->closed = true;
|
$this->closed = true;
|
||||||
unset(Entity::$needUpdate[$this->id]);
|
unset($this->level->updateEntities[$this->id]);
|
||||||
if($this->chunk instanceof FullChunk){
|
if($this->chunk instanceof FullChunk){
|
||||||
$this->chunk->removeEntity($this);
|
$this->chunk->removeEntity($this);
|
||||||
}
|
}
|
||||||
|
@ -24,13 +24,12 @@ namespace pocketmine\event\entity;
|
|||||||
use pocketmine\entity\Living;
|
use pocketmine\entity\Living;
|
||||||
use pocketmine\entity\Projectile;
|
use pocketmine\entity\Projectile;
|
||||||
use pocketmine\event\Cancellable;
|
use pocketmine\event\Cancellable;
|
||||||
use pocketmine\item\Bow;
|
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
|
|
||||||
class EntityShootBowEvent extends EntityEvent implements Cancellable{
|
class EntityShootBowEvent extends EntityEvent implements Cancellable{
|
||||||
public static $handlerList = null;
|
public static $handlerList = null;
|
||||||
|
|
||||||
/** @var Bow */
|
/** @var Item */
|
||||||
private $bow;
|
private $bow;
|
||||||
/** @var Projectile */
|
/** @var Projectile */
|
||||||
private $projectile;
|
private $projectile;
|
||||||
@ -39,11 +38,11 @@ class EntityShootBowEvent extends EntityEvent implements Cancellable{
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Living $shooter
|
* @param Living $shooter
|
||||||
* @param Bow $bow
|
* @param Item $bow
|
||||||
* @param Projectile $projectile
|
* @param Projectile $projectile
|
||||||
* @param float $force
|
* @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->entity = $shooter;
|
||||||
$this->bow = $bow;
|
$this->bow = $bow;
|
||||||
$this->projectile = $projectile;
|
$this->projectile = $projectile;
|
||||||
@ -58,7 +57,7 @@ class EntityShootBowEvent extends EntityEvent implements Cancellable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Bow
|
* @return Item
|
||||||
*/
|
*/
|
||||||
public function getBow(){
|
public function getBow(){
|
||||||
return $this->bow;
|
return $this->bow;
|
||||||
|
@ -121,6 +121,11 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
/** @var Entity[] */
|
/** @var Entity[] */
|
||||||
protected $entities = [];
|
protected $entities = [];
|
||||||
|
|
||||||
|
/** @var Entity[] */
|
||||||
|
public $updateEntities = [];
|
||||||
|
/** @var Tile[] */
|
||||||
|
public $updateTiles = [];
|
||||||
|
|
||||||
/** @var Server */
|
/** @var Server */
|
||||||
protected $server;
|
protected $server;
|
||||||
|
|
||||||
@ -505,11 +510,11 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
|
|
||||||
$this->timings->entityTick->startTiming();
|
$this->timings->entityTick->startTiming();
|
||||||
//Update entities that need update
|
//Update entities that need update
|
||||||
if(count(Entity::$needUpdate) > 0){
|
if(count($this->updateEntities) > 0){
|
||||||
//Timings::$tickEntityTimer->startTiming();
|
//Timings::$tickEntityTimer->startTiming();
|
||||||
foreach($this->entities as $id => $entity){
|
foreach($this->updateEntities as $id => $entity){
|
||||||
if($entity->onUpdate() === false){
|
if($entity->onUpdate() !== true){
|
||||||
//unset(Entity::$needUpdate[$id]);
|
unset($this->updateEntities[$id]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Timings::$tickEntityTimer->stopTiming();
|
//Timings::$tickEntityTimer->stopTiming();
|
||||||
@ -518,11 +523,11 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
|
|
||||||
$this->timings->tileEntityTick->startTiming();
|
$this->timings->tileEntityTick->startTiming();
|
||||||
//Update tiles that need update
|
//Update tiles that need update
|
||||||
if(count(Tile::$needUpdate) > 0){
|
if(count($this->updateTiles) > 0){
|
||||||
//Timings::$tickTileEntityTimer->startTiming();
|
//Timings::$tickTileEntityTimer->startTiming();
|
||||||
foreach($this->tiles as $id => $tile){
|
foreach($this->updateTiles as $id => $tile){
|
||||||
if($tile->onUpdate() === false){
|
if($tile->onUpdate() !== true){
|
||||||
//unset(Tile::$needUpdate[$id]);
|
unset($this->updateTiles[$id]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Timings::$tickTileEntityTimer->stopTiming();
|
//Timings::$tickTileEntityTimer->stopTiming();
|
||||||
|
@ -41,11 +41,6 @@ abstract class Tile extends Position{
|
|||||||
|
|
||||||
public static $tileCount = 1;
|
public static $tileCount = 1;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var Tile[]
|
|
||||||
*/
|
|
||||||
public static $needUpdate = [];
|
|
||||||
|
|
||||||
/** @var Chunk */
|
/** @var Chunk */
|
||||||
public $chunk;
|
public $chunk;
|
||||||
public $name;
|
public $name;
|
||||||
@ -100,8 +95,7 @@ abstract class Tile extends Position{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public final function scheduleUpdate(){
|
public final function scheduleUpdate(){
|
||||||
//TODO!
|
$this->level->updateTiles[$this->id] = $this;
|
||||||
Tile::$needUpdate[$this->id] = $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __destruct(){
|
public function __destruct(){
|
||||||
@ -111,7 +105,7 @@ abstract class Tile extends Position{
|
|||||||
public function close(){
|
public function close(){
|
||||||
if($this->closed === false){
|
if($this->closed === false){
|
||||||
$this->closed = true;
|
$this->closed = true;
|
||||||
unset(Tile::$needUpdate[$this->id]);
|
unset($this->level->updateTiles[$this->id]);
|
||||||
if($this->chunk instanceof FullChunk){
|
if($this->chunk instanceof FullChunk){
|
||||||
$this->chunk->removeTile($this);
|
$this->chunk->removeTile($this);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user