main loop in own method

This commit is contained in:
Steffen Schröder 2014-05-09 13:46:04 +02:00
parent d58e468492
commit 36531b9227

View File

@ -358,13 +358,23 @@ class ManiaControl implements CommandListener, TimerListener {
// Main loop
while (!$this->shutdownRequested) {
$this->loop();
}
// Shutdown
$this->quit();
}
/**
* Perform the Main Loop
*/
private function loop() {
$loopStart = microtime(true);
// Disable script timeout
set_time_limit(self::SCRIPT_TIMEOUT);
try {
// Manager callbacks
$this->callbackManager->manageCallbacks();
} catch (TransportException $e) {
$this->log("Connection interrupted!");
@ -378,16 +388,13 @@ class ManiaControl implements CommandListener, TimerListener {
// Yield for next tick
$loopEnd = microtime(true);
$sleepTime = (int)(2500 - ($loopEnd - $loopStart) * 1000000);
$loopDuration = $loopEnd - $loopStart;
$sleepTime = (int)(2500 - $loopDuration * 1000000);
if ($sleepTime > 0) {
usleep($sleepTime);
}
}
// Shutdown
$this->quit();
}
/**
* Connect to ManiaPlanet server
*/