mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-26 23:58:43 +07:00
Small bug fixes (#1968)
* Fixed access to unitialized variable Fixed possible concurrency issue (long has visibility issues) https://github.com/yairm210/Unciv/issues/1680 * Added comments https://github.com/yairm210/Unciv/issues/1680
This commit is contained in:
@ -56,7 +56,8 @@ class AndroidLauncher : AndroidApplication() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
if (UncivGame.Current.settings.multiplayerTurnCheckerEnabled
|
if (UncivGame.Companion.isCurrentInitialized()
|
||||||
|
&& UncivGame.Current.settings.multiplayerTurnCheckerEnabled
|
||||||
&& UncivGame.Current.isGameInfoInitialized()
|
&& UncivGame.Current.isGameInfoInitialized()
|
||||||
&& UncivGame.Current.gameInfo.gameParameters.isOnlineMultiplayer) {
|
&& UncivGame.Current.gameInfo.gameParameters.isOnlineMultiplayer) {
|
||||||
MultiplayerTurnCheckWorker.startTurnChecker(applicationContext, UncivGame.Current.gameInfo, UncivGame.Current.settings)
|
MultiplayerTurnCheckWorker.startTurnChecker(applicationContext, UncivGame.Current.gameInfo, UncivGame.Current.settings)
|
||||||
|
@ -30,13 +30,17 @@ class MultiplayerTurnCheckWorker(appContext: Context, workerParams: WorkerParame
|
|||||||
private const val NOTIFICATION_CHANNEL_ID_INFO = "UNCIV_NOTIFICATION_CHANNEL_INFO"
|
private const val NOTIFICATION_CHANNEL_ID_INFO = "UNCIV_NOTIFICATION_CHANNEL_INFO"
|
||||||
private const val NOTIFICATION_CHANNEL_ID_SERVICE = "UNCIV_NOTIFICATION_CHANNEL_SERVICE"
|
private const val NOTIFICATION_CHANNEL_ID_SERVICE = "UNCIV_NOTIFICATION_CHANNEL_SERVICE"
|
||||||
|
|
||||||
|
|
||||||
|
// These fields need to be volatile because they are set by main thread but later accessed by worker thread.
|
||||||
|
// Classes used here need to be primitive or internally synchronized to avoid visibility issues.
|
||||||
|
// Long and double must not be used here because they have visibility issues: https://stackoverflow.com/a/9278798
|
||||||
@Volatile private var failCount = 0
|
@Volatile private var failCount = 0
|
||||||
@Volatile private var gameId = ""
|
@Volatile private var gameId = ""
|
||||||
@Volatile private var userId = ""
|
@Volatile private var userId = ""
|
||||||
@Volatile private var configuredDelay = 5L
|
@Volatile private var configuredDelay = 5
|
||||||
@Volatile private var persistentNotificationEnabled = true
|
@Volatile private var persistentNotificationEnabled = true
|
||||||
|
|
||||||
fun enqueue(appContext: Context, delayInMinutes: Long) {
|
fun enqueue(appContext: Context, delayInMinutes: Int) {
|
||||||
val constraints = Constraints.Builder()
|
val constraints = Constraints.Builder()
|
||||||
// If no internet is available, worker waits before becoming active.
|
// If no internet is available, worker waits before becoming active.
|
||||||
.setRequiredNetworkType(NetworkType.CONNECTED)
|
.setRequiredNetworkType(NetworkType.CONNECTED)
|
||||||
@ -44,7 +48,7 @@ class MultiplayerTurnCheckWorker(appContext: Context, workerParams: WorkerParame
|
|||||||
|
|
||||||
val checkTurnWork = OneTimeWorkRequestBuilder<MultiplayerTurnCheckWorker>()
|
val checkTurnWork = OneTimeWorkRequestBuilder<MultiplayerTurnCheckWorker>()
|
||||||
.setConstraints(constraints)
|
.setConstraints(constraints)
|
||||||
.setInitialDelay(delayInMinutes, TimeUnit.MINUTES)
|
.setInitialDelay(delayInMinutes.toLong(), TimeUnit.MINUTES)
|
||||||
.addTag(WORK_TAG)
|
.addTag(WORK_TAG)
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ class UncivGame(
|
|||||||
constructor(version: String) : this(version, null)
|
constructor(version: String) : this(version, null)
|
||||||
|
|
||||||
lateinit var gameInfo: GameInfo
|
lateinit var gameInfo: GameInfo
|
||||||
fun isGameInfoInitialized() = ::gameInfo.isInitialized
|
fun isGameInfoInitialized() = this::gameInfo.isInitialized
|
||||||
lateinit var settings : GameSettings
|
lateinit var settings : GameSettings
|
||||||
lateinit var crashController: CrashController
|
lateinit var crashController: CrashController
|
||||||
/**
|
/**
|
||||||
@ -181,6 +181,7 @@ class UncivGame(
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
lateinit var Current: UncivGame
|
lateinit var Current: UncivGame
|
||||||
|
fun isCurrentInitialized() = this::Current.isInitialized
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,10 +30,10 @@ class GameSettings {
|
|||||||
var userId = ""
|
var userId = ""
|
||||||
var multiplayerTurnCheckerEnabled = true
|
var multiplayerTurnCheckerEnabled = true
|
||||||
var multiplayerTurnCheckerPersistentNotificationEnabled = true
|
var multiplayerTurnCheckerPersistentNotificationEnabled = true
|
||||||
var multiplayerTurnCheckerDelayInMinutes = 5L
|
var multiplayerTurnCheckerDelayInMinutes = 5
|
||||||
|
|
||||||
init {
|
init {
|
||||||
// 26 = Android Oreo. Version below may display permanent icon in notification bar.
|
// 26 = Android Oreo. Versions below may display permanent icon in notification bar.
|
||||||
if (Gdx.app.type == Application.ApplicationType.Android && Gdx.app.version < 26) {
|
if (Gdx.app.type == Application.ApplicationType.Android && Gdx.app.version < 26) {
|
||||||
multiplayerTurnCheckerPersistentNotificationEnabled = false
|
multiplayerTurnCheckerPersistentNotificationEnabled = false
|
||||||
}
|
}
|
||||||
|
@ -300,9 +300,9 @@ class WorldScreenOptionsPopup(val worldScreen:WorldScreen) : Popup(worldScreen){
|
|||||||
private fun addMultiplayerTurnCheckerDelayBox(innerTable: Table) {
|
private fun addMultiplayerTurnCheckerDelayBox(innerTable: Table) {
|
||||||
innerTable.add("Time between turn checks out-of-game (in minutes)".toLabel())
|
innerTable.add("Time between turn checks out-of-game (in minutes)".toLabel())
|
||||||
|
|
||||||
val checkDelaySelectBox = SelectBox<Long>(skin)
|
val checkDelaySelectBox = SelectBox<Int>(skin)
|
||||||
val possibleDelaysArray = Array<Long>()
|
val possibleDelaysArray = Array<Int>()
|
||||||
possibleDelaysArray.addAll(1L, 2L, 5L, 15L)
|
possibleDelaysArray.addAll(1, 2, 5, 15)
|
||||||
checkDelaySelectBox.items = possibleDelaysArray
|
checkDelaySelectBox.items = possibleDelaysArray
|
||||||
checkDelaySelectBox.selected = UncivGame.Current.settings.multiplayerTurnCheckerDelayInMinutes
|
checkDelaySelectBox.selected = UncivGame.Current.settings.multiplayerTurnCheckerDelayInMinutes
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user