Do not sleep on main Thread, when actions are being done.

This commit is contained in:
kotyaralih 2021-12-13 06:41:51 -08:00
parent a1764f0de7
commit 0664e1ae03

View file

@ -468,8 +468,9 @@ class PocketMinecraftServer{
$this->tickMeasure[] = $this->lastTick = $time; $this->tickMeasure[] = $this->lastTick = $time;
unset($this->tickMeasure[key($this->tickMeasure)]); unset($this->tickMeasure[key($this->tickMeasure)]);
++$this->ticks; ++$this->ticks;
$this->tickerFunction($time); return $this->tickerFunction($time);
} }
return 0;
} }
public static function clientID($ip, $port){ public static function clientID($ip, $port){
@ -567,6 +568,8 @@ class PocketMinecraftServer{
if($packet !== false){ if($packet !== false){
$this->packetHandler($packet); $this->packetHandler($packet);
$lastLoop = 0; $lastLoop = 0;
}elseif($this->tick() > 0){
$lastLoop = 0;
}else{ }else{
++$lastLoop; ++$lastLoop;
if($lastLoop < 16){ if($lastLoop < 16){
@ -622,6 +625,7 @@ class PocketMinecraftServer{
$this->preparedSQL->selectActions->bindValue(":time", $time, SQLITE3_FLOAT); $this->preparedSQL->selectActions->bindValue(":time", $time, SQLITE3_FLOAT);
$actions = $this->preparedSQL->selectActions->execute(); $actions = $this->preparedSQL->selectActions->execute();
$actionCount = 0;
if($actions instanceof SQLite3Result){ if($actions instanceof SQLite3Result){
while(($action = $actions->fetchArray(SQLITE3_ASSOC)) !== false){ while(($action = $actions->fetchArray(SQLITE3_ASSOC)) !== false){
$cid = $action["ID"]; $cid = $action["ID"];
@ -632,6 +636,7 @@ class PocketMinecraftServer{
if(!@is_callable($this->schedule[$cid][0])){ if(!@is_callable($this->schedule[$cid][0])){
$return = false; $return = false;
}else{ }else{
++$actionCount;
$return = call_user_func($this->schedule[$cid][0], $this->schedule[$cid][1], $this->schedule[$cid][2]); $return = call_user_func($this->schedule[$cid][0], $this->schedule[$cid][1], $this->schedule[$cid][2]);
} }
@ -643,6 +648,7 @@ class PocketMinecraftServer{
} }
$actions->finalize(); $actions->finalize();
} }
return $actionCount;
} }
public function event($event,callable $func){ public function event($event,callable $func){