perf: Only attempt to get game ID for multiplayer game if current game is actually multiplayer

This commit is contained in:
Yair Morgenstern
2024-03-09 23:45:09 +02:00
parent 55aa3d56e6
commit d6ac736d6e

View File

@ -67,11 +67,12 @@ class OnlineMultiplayer {
while (true) {
delay(500)
if (!currentCoroutineContext().isActive) return@flow
val currentGame = getCurrentGame()
val multiplayerSettings: GameSettings.GameSettingsMultiplayer
try { // Fails in unknown cases - cannot debug :/ This is just so it doesn't appear in GP analytics
multiplayerSettings = UncivGame.Current.settings.multiplayer
} catch (ex:Exception){ continue }
val currentGame = getCurrentGame()
val preview = currentGame?.preview
if (currentGame != null && (usesCustomServer() || preview == null || !preview.isUsersTurn())) {
throttle(lastCurGameRefresh, multiplayerSettings.currentGameRefreshDelay, {}) { currentGame.requestUpdate() }
@ -85,7 +86,7 @@ class OnlineMultiplayer {
private fun getCurrentGame(): OnlineMultiplayerGame? {
val gameInfo = UncivGame.Current.gameInfo
return if (gameInfo != null) {
return if (gameInfo != null && gameInfo.gameParameters.isOnlineMultiplayer) {
getGameByGameId(gameInfo.gameId)
} else null
}