mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-28 06:16:37 -04:00
Discrete rendering (#1612)
* Named threads for debugging/profiling * Proposal: Discrete rendering, remove black spinning circle
This commit is contained in:
parent
23cfab6001
commit
e61c4f5f1c
@ -51,6 +51,7 @@ class UncivGame(
|
|||||||
val translations = Translations()
|
val translations = Translations()
|
||||||
|
|
||||||
override fun create() {
|
override fun create() {
|
||||||
|
Gdx.graphics.setContinuousRendering(false)
|
||||||
Gdx.input.setCatchKey(Input.Keys.BACK, true)
|
Gdx.input.setCatchKey(Input.Keys.BACK, true)
|
||||||
if (Gdx.app.type != Application.ApplicationType.Desktop) {
|
if (Gdx.app.type != Application.ApplicationType.Desktop) {
|
||||||
viewEntireMapForDebug = false
|
viewEntireMapForDebug = false
|
||||||
@ -65,7 +66,7 @@ class UncivGame(
|
|||||||
settings = GameSaver().getGeneralSettings() // needed for the screen
|
settings = GameSaver().getGeneralSettings() // needed for the screen
|
||||||
screen = LoadingScreen()
|
screen = LoadingScreen()
|
||||||
|
|
||||||
thread {
|
thread(name="LoadJSON") {
|
||||||
ruleset = Ruleset(true)
|
ruleset = Ruleset(true)
|
||||||
|
|
||||||
if (rewriteTranslationFiles) { // Yes, also when running from the Jar. Sue me.
|
if (rewriteTranslationFiles) { // Yes, also when running from the Jar. Sue me.
|
||||||
|
@ -6,6 +6,7 @@ import com.badlogic.gdx.utils.Json
|
|||||||
import com.unciv.models.metadata.GameSettings
|
import com.unciv.models.metadata.GameSettings
|
||||||
import com.unciv.ui.utils.ImageGetter
|
import com.unciv.ui.utils.ImageGetter
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import kotlin.concurrent.thread
|
||||||
|
|
||||||
class GameSaver {
|
class GameSaver {
|
||||||
private val saveFilesFolder = "SaveFiles"
|
private val saveFilesFolder = "SaveFiles"
|
||||||
@ -69,7 +70,7 @@ class GameSaver {
|
|||||||
// On the other hand if we alter the game data while it's being serialized we could get a concurrent modification exception.
|
// On the other hand if we alter the game data while it's being serialized we could get a concurrent modification exception.
|
||||||
// So what we do is we clone all the game data and serialize the clone.
|
// So what we do is we clone all the game data and serialize the clone.
|
||||||
val gameInfoClone = gameInfo.clone()
|
val gameInfoClone = gameInfo.clone()
|
||||||
kotlin.concurrent.thread {
|
thread(name="Autosave") {
|
||||||
saveGame(gameInfoClone, "Autosave")
|
saveGame(gameInfoClone, "Autosave")
|
||||||
|
|
||||||
// keep auto-saves for the last 10 turns for debugging purposes
|
// keep auto-saves for the last 10 turns for debugging purposes
|
||||||
|
@ -22,7 +22,7 @@ class MapDownloadTable(loadMapScreen: LoadMapScreen): PopupTable(loadMapScreen)
|
|||||||
for (downloadableMap in folderList.entries) {
|
for (downloadableMap in folderList.entries) {
|
||||||
val downloadMapButton = TextButton(downloadableMap.name, CameraStageBaseScreen.skin)
|
val downloadMapButton = TextButton(downloadableMap.name, CameraStageBaseScreen.skin)
|
||||||
downloadMapButton.onClick {
|
downloadMapButton.onClick {
|
||||||
thread {
|
thread(name="MapDownload") {
|
||||||
try {
|
try {
|
||||||
val mapJsonGzipped = DropBox().downloadFileAsString(downloadableMap.path_display)
|
val mapJsonGzipped = DropBox().downloadFileAsString(downloadableMap.path_display)
|
||||||
val decodedMapJson = Gzip.unzip(mapJsonGzipped)
|
val decodedMapJson = Gzip.unzip(mapJsonGzipped)
|
||||||
|
@ -66,7 +66,7 @@ class MapEditorMenuPopup(mapEditorScreen: MapEditorScreen): PopupTable(mapEditor
|
|||||||
|
|
||||||
val uploadMapButton = TextButton("Upload map".tr(), skin)
|
val uploadMapButton = TextButton("Upload map".tr(), skin)
|
||||||
uploadMapButton.onClick {
|
uploadMapButton.onClick {
|
||||||
thread {
|
thread(name="MapUpload") {
|
||||||
try {
|
try {
|
||||||
val gzippedMap = Gzip.zip(Json().toJson(mapEditorScreen.tileMap))
|
val gzippedMap = Gzip.zip(Json().toJson(mapEditorScreen.tileMap))
|
||||||
DropBox().uploadFile("/Maps/" + mapEditorScreen.mapName, gzippedMap)
|
DropBox().uploadFile("/Maps/" + mapEditorScreen.mapName, gzippedMap)
|
||||||
|
@ -66,7 +66,7 @@ class NewGameScreen: PickerScreen(){
|
|||||||
rightSideButton.disable()
|
rightSideButton.disable()
|
||||||
rightSideButton.setText("Working...".tr())
|
rightSideButton.setText("Working...".tr())
|
||||||
|
|
||||||
thread {
|
thread(name="NewGame") {
|
||||||
// Creating a new game can take a while and we don't want ANRs
|
// Creating a new game can take a while and we don't want ANRs
|
||||||
try {
|
try {
|
||||||
newGame = GameStarter().startNewGame(newGameParameters,mapParameters)
|
newGame = GameStarter().startNewGame(newGameParameters,mapParameters)
|
||||||
|
@ -57,7 +57,7 @@ class SaveGameScreen : PickerScreen() {
|
|||||||
rightSideButton.setText("Save game".tr())
|
rightSideButton.setText("Save game".tr())
|
||||||
rightSideButton.onClick {
|
rightSideButton.onClick {
|
||||||
rightSideButton.setText("Saving...".tr())
|
rightSideButton.setText("Saving...".tr())
|
||||||
thread{
|
thread(name="SaveGame"){
|
||||||
GameSaver().saveGame(UncivGame.Current.gameInfo, textField.text)
|
GameSaver().saveGame(UncivGame.Current.gameInfo, textField.text)
|
||||||
UncivGame.Current.setWorldScreen()
|
UncivGame.Current.setWorldScreen()
|
||||||
}
|
}
|
||||||
|
@ -148,7 +148,7 @@ fun Actor.center(parent:Stage){ centerX(parent); centerY(parent)}
|
|||||||
fun Actor.onClickEvent(sound: UncivSound = UncivSound.Click, function: (event: InputEvent?, x: Float, y: Float) -> Unit) {
|
fun Actor.onClickEvent(sound: UncivSound = UncivSound.Click, function: (event: InputEvent?, x: Float, y: Float) -> Unit) {
|
||||||
this.addListener(object : ClickListener() {
|
this.addListener(object : ClickListener() {
|
||||||
override fun clicked(event: InputEvent?, x: Float, y: Float) {
|
override fun clicked(event: InputEvent?, x: Float, y: Float) {
|
||||||
thread { Sounds.play(sound) }
|
thread(name="Sound") { Sounds.play(sound) }
|
||||||
function(event, x, y)
|
function(event, x, y)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -57,8 +57,8 @@ class UnitGroup(val unit: MapUnit, val size: Float): Group() {
|
|||||||
spinningCircle.center(this)
|
spinningCircle.center(this)
|
||||||
spinningCircle.x += whiteHaloSize / 2 // to edge of white halo
|
spinningCircle.x += whiteHaloSize / 2 // to edge of white halo
|
||||||
spinningCircle.setOrigin(spinningCircle.width / 2 - whiteHaloSize / 2, spinningCircle.height / 2)
|
spinningCircle.setOrigin(spinningCircle.width / 2 - whiteHaloSize / 2, spinningCircle.height / 2)
|
||||||
addActor(spinningCircle)
|
//addActor(spinningCircle)
|
||||||
spinningCircle.addAction(Actions.repeat(RepeatAction.FOREVER, Actions.rotateBy(90f, 1f)))
|
//spinningCircle.addAction(Actions.repeat(RepeatAction.FOREVER, Actions.rotateBy(90f, 1f)))
|
||||||
blackSpinningCircle = spinningCircle
|
blackSpinningCircle = spinningCircle
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -92,7 +92,7 @@ class WorldMapHolder(internal val worldScreen: WorldScreen, internal val tileMap
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun addTileOverlaysWithUnitMovement(selectedUnit: MapUnit, tileInfo: TileInfo) {
|
private fun addTileOverlaysWithUnitMovement(selectedUnit: MapUnit, tileInfo: TileInfo) {
|
||||||
thread {
|
thread(name="TurnsToGetThere") {
|
||||||
/** LibGdx sometimes has these weird errors when you try to edit the UI layout from 2 separate threads.
|
/** LibGdx sometimes has these weird errors when you try to edit the UI layout from 2 separate threads.
|
||||||
* And so, all UI editing will be done on the main thread.
|
* And so, all UI editing will be done on the main thread.
|
||||||
* The only "heavy lifting" that needs to be done is getting the turns to get there,
|
* The only "heavy lifting" that needs to be done is getting the turns to get there,
|
||||||
|
@ -143,7 +143,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
|
|||||||
val loadingGamePopup = PopupTable(this)
|
val loadingGamePopup = PopupTable(this)
|
||||||
loadingGamePopup.add("Loading latest game state...")
|
loadingGamePopup.add("Loading latest game state...")
|
||||||
loadingGamePopup.open()
|
loadingGamePopup.open()
|
||||||
thread {
|
thread(name="MultiplayerLoad") {
|
||||||
try {
|
try {
|
||||||
val latestGame = OnlineMultiplayer().tryDownloadGame(gameInfo.gameId)
|
val latestGame = OnlineMultiplayer().tryDownloadGame(gameInfo.gameId)
|
||||||
if(gameInfo.isUpToDate && gameInfo.currentPlayer==latestGame.currentPlayer) { // we were trying to download this to see when it's our turn...nothing changed
|
if(gameInfo.isUpToDate && gameInfo.currentPlayer==latestGame.currentPlayer) { // we were trying to download this to see when it's our turn...nothing changed
|
||||||
@ -379,7 +379,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
|
|||||||
shouldUpdate = true
|
shouldUpdate = true
|
||||||
|
|
||||||
|
|
||||||
thread { // on a separate thread so the user can explore their world while we're passing the turn
|
thread(name="NextTurn") { // on a separate thread so the user can explore their world while we're passing the turn
|
||||||
val gameInfoClone = gameInfo.clone()
|
val gameInfoClone = gameInfo.clone()
|
||||||
gameInfoClone.setTransients()
|
gameInfoClone.setTransients()
|
||||||
try {
|
try {
|
||||||
|
@ -118,7 +118,7 @@ class WorldScreenMenuTable(val worldScreen: WorldScreen) : PopupTable(worldScree
|
|||||||
badGameIdLabel.isVisible = true
|
badGameIdLabel.isVisible = true
|
||||||
return@addButton
|
return@addButton
|
||||||
}
|
}
|
||||||
thread {
|
thread(name="MultiplayerDownload") {
|
||||||
try {
|
try {
|
||||||
// The tryDownload can take more than 500ms. Therefore, to avoid ANRs,
|
// The tryDownload can take more than 500ms. Therefore, to avoid ANRs,
|
||||||
// we need to run it in a different thread.
|
// we need to run it in a different thread.
|
||||||
|
@ -182,7 +182,7 @@ class WorldScreenOptionsTable(val worldScreen:WorldScreen) : PopupTable(worldScr
|
|||||||
|
|
||||||
downloadMusicButton.onClick {
|
downloadMusicButton.onClick {
|
||||||
// So the whole game doesn't get stuck while downloading the file
|
// So the whole game doesn't get stuck while downloading the file
|
||||||
thread {
|
thread(name="Music") {
|
||||||
try {
|
try {
|
||||||
downloadMusicButton.disable()
|
downloadMusicButton.disable()
|
||||||
errorTable.clear()
|
errorTable.clear()
|
||||||
|
@ -58,7 +58,7 @@ class UnitContextMenu(val tileMapHolder: WorldMapHolder, val selectedUnit: MapUn
|
|||||||
|
|
||||||
fun onMoveButtonClick() {
|
fun onMoveButtonClick() {
|
||||||
// this can take a long time, because of the unit-to-tile calculation needed, so we put it in a different thread
|
// this can take a long time, because of the unit-to-tile calculation needed, so we put it in a different thread
|
||||||
thread {
|
thread(name="TileToMoveTo") {
|
||||||
// these are the heavy parts, finding where we want to go
|
// these are the heavy parts, finding where we want to go
|
||||||
// Since this runs in a different thread, even if we check movement.canReach()
|
// Since this runs in a different thread, even if we check movement.canReach()
|
||||||
// then it might change until we get to the getTileToMoveTo, so we just try/catch it
|
// then it might change until we get to the getTileToMoveTo, so we just try/catch it
|
||||||
|
Loading…
x
Reference in New Issue
Block a user