From 8a0c5e465545a678e5e828248ebde9813cddc46a Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Fri, 28 Dec 2012 16:33:16 +0100 Subject: [PATCH] Scheduled update for entities --- README.md | 2 +- src/classes/Entity.class.php | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6a20e55f8..a12a42027 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,6 @@ The entire server is done in PHP, and has been tested, profiled and optimized to * __[PHP Sockets](http://php.net/manual/en/book.sockets.php)__ * __[PHP SQLite3](http://php.net/manual/en/book.sqlite3.php)__ * __[PHP pthreads](https://github.com/krakjoe/pthreads)__ by _[krakjoe](https://github.com/krakjoe)_: Threading for PHP - Share Nothing, Do Everything -* __[PHP NBT](https://github.com/TheFrozenFire/PHP-NBT-Decoder-Encoder/blob/master/nbt.class.php)__ by _[TheFrozenFire](https://github.com/TheFrozenFire)_: Class for reading in NBT-format files +* __[PHP NBT](https://github.com/TheFrozenFire/PHP-NBT-Decoder-Encoder/blob/master/nbt.class.php)__ by _[TheFrozenFire](https://github.com/TheFrozenFire)_: Class for reading in NBT-format files (modified to handle Little-Endian files) * __[Math_BigInteger](http://phpseclib.sourceforge.net/math/intro.html)__ by _[phpseclib](http://phpseclib.sourceforge.net/)_: Pure-PHP arbitrary precission integer arithmetic library * __[Spyc](https://github.com/mustangostang/spyc/blob/master/Spyc.php)__ by _[Vlad Andersen](https://github.com/mustangostang)_: A simple YAML loader/dumper class for PHP \ No newline at end of file diff --git a/src/classes/Entity.class.php b/src/classes/Entity.class.php index 8c50069a7..6145a9996 100644 --- a/src/classes/Entity.class.php +++ b/src/classes/Entity.class.php @@ -33,8 +33,8 @@ define("ENTITY_ITEM", 3); define("ENTITY_PAINTING", 4); class Entity extends stdClass{ - var $eid, $type, $name, $x, $y, $z, $yaw, $pitch, $dead, $data, $class, $attach, $metadata, $closed, $player; - + var $eid, $type, $name, $x, $y, $z, $yaw, $pitch, $dead, $data, $class, $attach, $metadata, $closed, $player, $onTick; + private $ev, $server; function __construct($server, $eid, $class, $type = 0, $data = array()){ $this->server = $server; $this->eid = (int) $eid; @@ -49,6 +49,7 @@ class Entity extends stdClass{ $this->closed = false; $this->name = ""; $this->server->query("INSERT OR REPLACE INTO entities (EID, type, class, health) VALUES (".$this->eid.", ".$this->type.", ".$this->class.", ".$this->health.");"); + $this->ev = $this->server->event("server.tick", array($this, "update")); $this->metadata = array(); $this->x = isset($this->data["x"]) ? $this->data["x"]:0; $this->y = isset($this->data["y"]) ? $this->data["y"]:0; @@ -74,6 +75,10 @@ class Entity extends stdClass{ } } + public function update(){ + + } + public function getDirection(){ $rotation = ($this->yaw - 90) % 360; if ($rotation < 0) { @@ -147,6 +152,7 @@ class Entity extends stdClass{ if($this->closed === false){ $this->server->query("DELETE FROM entities WHERE EID = ".$this->eid.";"); $this->server->trigger("entity.remove", $this->eid); + $this->server->deleteEvent($this->ev); $this->closed = true; } }