mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-09 21:24:53 +00:00
Simplify NetworkSession ticking
we need to tick sessions every tick anyway, because other stuff is happening (e.g. sync attributes/entity metadata, batch buffer flush).
This commit is contained in:
parent
eb23d27004
commit
01b48a21d9
@ -31,15 +31,13 @@ class NetworkSessionManager{
|
|||||||
|
|
||||||
/** @var NetworkSession[] */
|
/** @var NetworkSession[] */
|
||||||
private $sessions = [];
|
private $sessions = [];
|
||||||
/** @var NetworkSession[] */
|
|
||||||
private $updateSessions = [];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a network session to the manager. This should only be called on session creation.
|
* Adds a network session to the manager. This should only be called on session creation.
|
||||||
*/
|
*/
|
||||||
public function add(NetworkSession $session) : void{
|
public function add(NetworkSession $session) : void{
|
||||||
$idx = spl_object_id($session);
|
$idx = spl_object_id($session);
|
||||||
$this->sessions[$idx] = $this->updateSessions[$idx] = $session;
|
$this->sessions[$idx] = $session;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -48,14 +46,7 @@ class NetworkSessionManager{
|
|||||||
*/
|
*/
|
||||||
public function remove(NetworkSession $session) : void{
|
public function remove(NetworkSession $session) : void{
|
||||||
$idx = spl_object_id($session);
|
$idx = spl_object_id($session);
|
||||||
unset($this->sessions[$idx], $this->updateSessions[$idx]);
|
unset($this->sessions[$idx]);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Requests an update to be scheduled on the given network session at the next tick.
|
|
||||||
*/
|
|
||||||
public function scheduleUpdate(NetworkSession $session) : void{
|
|
||||||
$this->updateSessions[spl_object_id($session)] = $session;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -72,9 +63,10 @@ class NetworkSessionManager{
|
|||||||
* Updates all sessions which need it.
|
* Updates all sessions which need it.
|
||||||
*/
|
*/
|
||||||
public function tick() : void{
|
public function tick() : void{
|
||||||
foreach($this->updateSessions as $k => $session){
|
foreach($this->sessions as $k => $session){
|
||||||
if(!$session->tick()){
|
$session->tick();
|
||||||
unset($this->updateSessions[$k]);
|
if(!$session->isConnected()){
|
||||||
|
unset($this->sessions[$k]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -87,6 +79,5 @@ class NetworkSessionManager{
|
|||||||
$session->disconnect($reason);
|
$session->disconnect($reason);
|
||||||
}
|
}
|
||||||
$this->sessions = [];
|
$this->sessions = [];
|
||||||
$this->updateSessions = [];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -421,7 +421,6 @@ class NetworkSession{
|
|||||||
$timings->startTiming();
|
$timings->startTiming();
|
||||||
try{
|
try{
|
||||||
$this->sendBuffer[] = $packet;
|
$this->sendBuffer[] = $packet;
|
||||||
$this->manager->scheduleUpdate($this); //schedule flush at end of tick
|
|
||||||
}finally{
|
}finally{
|
||||||
$timings->stopTiming();
|
$timings->stopTiming();
|
||||||
}
|
}
|
||||||
@ -1021,14 +1020,13 @@ class NetworkSession{
|
|||||||
$this->sendDataPacket(SetTitlePacket::setAnimationTimes($fadeIn, $stay, $fadeOut));
|
$this->sendDataPacket(SetTitlePacket::setAnimationTimes($fadeIn, $stay, $fadeOut));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tick() : bool{
|
public function tick() : void{
|
||||||
if($this->info === null){
|
if($this->info === null){
|
||||||
if(time() >= $this->connectTime + 10){
|
if(time() >= $this->connectTime + 10){
|
||||||
$this->disconnect("Login timeout");
|
$this->disconnect("Login timeout");
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true; //keep ticking until timeout
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->player !== null){
|
if($this->player !== null){
|
||||||
@ -1044,7 +1042,5 @@ class NetworkSession{
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->flushSendBuffer();
|
$this->flushSendBuffer();
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user