Removed server.tick event

This commit is contained in:
Shoghi Cervantes 2013-06-05 12:58:58 +02:00
parent 911577e9b8
commit 5def864aca
5 changed files with 13 additions and 5 deletions

View File

@ -36,7 +36,7 @@ class ConsoleAPI{
} }
public function init(){ 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->loop = new ConsoleLoop();
$this->register("help", "[page|command name]", array($this, "defaultCommands")); $this->register("help", "[page|command name]", array($this, "defaultCommands"));
$this->register("status", "", array($this, "defaultCommands")); $this->register("status", "", array($this, "defaultCommands"));

View File

@ -48,14 +48,20 @@ class EntityAPI{
public function updateEntities(){ public function updateEntities(){
$l = $this->server->query("SELECT EID FROM entities WHERE hasUpdate = 1;"); $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){ if($l !== false and $l !== true){
$q = "";
while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){ while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){
$e = $this->get($e["EID"]); $e = $this->get($e["EID"]);
if($e instanceof Entity){ if($e instanceof Entity){
console($e->eid);
$e->update(); $e->update();
$q .= "UPDATE entities SET hasUpdate = 0 WHERE EID = ".$e->eid.";";
} }
} }
if($q !== ""){
$this->server->query("BEGIN TRANSACTION;".$q.";COMMIT;");
}
} }
} }

View File

@ -191,7 +191,7 @@ class Player{
public function onTick(){ public function onTick(){
if($this->connected === false){ if($this->connected === false){
return; return false;
} }
$time = microtime(true); $time = microtime(true);
if($time > $this->timeout){ if($time > $this->timeout){

View File

@ -377,7 +377,6 @@ class PocketMinecraftServer{
unset($this->tickMeasure[key($this->tickMeasure)]); unset($this->tickMeasure[key($this->tickMeasure)]);
++$this->ticks; ++$this->ticks;
$this->tickerFunction($time); $this->tickerFunction($time);
$this->trigger("server.tick", $time);
} }
} }

View File

@ -337,6 +337,7 @@ class Entity extends Position{
if($this->closed === true){ if($this->closed === true){
return false; return false;
} }
$hasUpdate = false; $hasUpdate = false;
$now = microtime(true); $now = microtime(true);
if($this->check === false){ if($this->check === false){
@ -415,7 +416,7 @@ class Entity extends Position{
} }
$this->server->api->handle("entity.motion", $this); $this->server->api->handle("entity.motion", $this);
$this->close(); $this->close();
return; return false;
} }
break; break;
} }
@ -493,6 +494,8 @@ class Entity extends Position{
} }
$this->lastUpdate = $now; $this->lastUpdate = $now;
if($this->class !== ENTITY_PLAYER and $hasUpdate === true){ 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")); $this->server->schedule(5, array($this, "update"));
} }
} }