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