From 5def864acaee89d2737e2366fe587653800ddca9 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 5 Jun 2013 12:58:58 +0200 Subject: [PATCH] Removed server.tick event --- src/API/ConsoleAPI.php | 2 +- src/API/EntityAPI.php | 8 +++++++- src/Player.php | 2 +- src/PocketMinecraftServer.php | 1 - src/world/Entity.php | 5 ++++- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/API/ConsoleAPI.php b/src/API/ConsoleAPI.php index 9a32769e..b9c29777 100644 --- a/src/API/ConsoleAPI.php +++ b/src/API/ConsoleAPI.php @@ -36,7 +36,7 @@ class ConsoleAPI{ } public function init(){ - $this->event = $this->server->event("server.tick", array($this, "handle")); + $this->server->schedule(2, array($this, "handle"), array(), true); $this->loop = new ConsoleLoop(); $this->register("help", "[page|command name]", array($this, "defaultCommands")); $this->register("status", "", array($this, "defaultCommands")); diff --git a/src/API/EntityAPI.php b/src/API/EntityAPI.php index c3c15ed5..988be032 100644 --- a/src/API/EntityAPI.php +++ b/src/API/EntityAPI.php @@ -48,14 +48,20 @@ class EntityAPI{ public function updateEntities(){ $l = $this->server->query("SELECT EID FROM entities WHERE hasUpdate = 1;"); - $this->server->query("UPDATE entities SET hasUpdate = 0;"); + if($l !== false and $l !== true){ + $q = ""; while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){ $e = $this->get($e["EID"]); if($e instanceof Entity){ + console($e->eid); $e->update(); + $q .= "UPDATE entities SET hasUpdate = 0 WHERE EID = ".$e->eid.";"; } } + if($q !== ""){ + $this->server->query("BEGIN TRANSACTION;".$q.";COMMIT;"); + } } } diff --git a/src/Player.php b/src/Player.php index 18ce20cb..2a9e43fc 100644 --- a/src/Player.php +++ b/src/Player.php @@ -191,7 +191,7 @@ class Player{ public function onTick(){ if($this->connected === false){ - return; + return false; } $time = microtime(true); if($time > $this->timeout){ diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index 2bc45c22..9a3af7bc 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -377,7 +377,6 @@ class PocketMinecraftServer{ unset($this->tickMeasure[key($this->tickMeasure)]); ++$this->ticks; $this->tickerFunction($time); - $this->trigger("server.tick", $time); } } diff --git a/src/world/Entity.php b/src/world/Entity.php index 239fc841..3986821a 100644 --- a/src/world/Entity.php +++ b/src/world/Entity.php @@ -337,6 +337,7 @@ class Entity extends Position{ if($this->closed === true){ return false; } + $hasUpdate = false; $now = microtime(true); if($this->check === false){ @@ -415,7 +416,7 @@ class Entity extends Position{ } $this->server->api->handle("entity.motion", $this); $this->close(); - return; + return false; } break; } @@ -493,6 +494,8 @@ class Entity extends Position{ } $this->lastUpdate = $now; if($this->class !== ENTITY_PLAYER and $hasUpdate === true){ + console($this->eid); + var_dump($this->speedX, $this->speedY, $this->speedZ); $this->server->schedule(5, array($this, "update")); } }