mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-26 05:14:32 -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()
|
||||
|
||||
override fun create() {
|
||||
Gdx.graphics.setContinuousRendering(false)
|
||||
Gdx.input.setCatchKey(Input.Keys.BACK, true)
|
||||
if (Gdx.app.type != Application.ApplicationType.Desktop) {
|
||||
viewEntireMapForDebug = false
|
||||
@ -65,7 +66,7 @@ class UncivGame(
|
||||
settings = GameSaver().getGeneralSettings() // needed for the screen
|
||||
screen = LoadingScreen()
|
||||
|
||||
thread {
|
||||
thread(name="LoadJSON") {
|
||||
ruleset = Ruleset(true)
|
||||
|
||||
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.ui.utils.ImageGetter
|
||||
import java.io.File
|
||||
import kotlin.concurrent.thread
|
||||
|
||||
class GameSaver {
|
||||
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.
|
||||
// So what we do is we clone all the game data and serialize the clone.
|
||||
val gameInfoClone = gameInfo.clone()
|
||||
kotlin.concurrent.thread {
|
||||
thread(name="Autosave") {
|
||||
saveGame(gameInfoClone, "Autosave")
|
||||
|
||||
// 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) {
|
||||
val downloadMapButton = TextButton(downloadableMap.name, CameraStageBaseScreen.skin)
|
||||
downloadMapButton.onClick {
|
||||
thread {
|
||||
thread(name="MapDownload") {
|
||||
try {
|
||||
val mapJsonGzipped = DropBox().downloadFileAsString(downloadableMap.path_display)
|
||||
val decodedMapJson = Gzip.unzip(mapJsonGzipped)
|
||||
|
@ -66,7 +66,7 @@ class MapEditorMenuPopup(mapEditorScreen: MapEditorScreen): PopupTable(mapEditor
|
||||
|
||||
val uploadMapButton = TextButton("Upload map".tr(), skin)
|
||||
uploadMapButton.onClick {
|
||||
thread {
|
||||
thread(name="MapUpload") {
|
||||
try {
|
||||
val gzippedMap = Gzip.zip(Json().toJson(mapEditorScreen.tileMap))
|
||||
DropBox().uploadFile("/Maps/" + mapEditorScreen.mapName, gzippedMap)
|
||||
|
@ -66,7 +66,7 @@ class NewGameScreen: PickerScreen(){
|
||||
rightSideButton.disable()
|
||||
rightSideButton.setText("Working...".tr())
|
||||
|
||||
thread {
|
||||
thread(name="NewGame") {
|
||||
// Creating a new game can take a while and we don't want ANRs
|
||||
try {
|
||||
newGame = GameStarter().startNewGame(newGameParameters,mapParameters)
|
||||
|
@ -57,7 +57,7 @@ class SaveGameScreen : PickerScreen() {
|
||||
rightSideButton.setText("Save game".tr())
|
||||
rightSideButton.onClick {
|
||||
rightSideButton.setText("Saving...".tr())
|
||||
thread{
|
||||
thread(name="SaveGame"){
|
||||
GameSaver().saveGame(UncivGame.Current.gameInfo, textField.text)
|
||||
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) {
|
||||
this.addListener(object : ClickListener() {
|
||||
override fun clicked(event: InputEvent?, x: Float, y: Float) {
|
||||
thread { Sounds.play(sound) }
|
||||
thread(name="Sound") { Sounds.play(sound) }
|
||||
function(event, x, y)
|
||||
}
|
||||
})
|
||||
|
@ -57,8 +57,8 @@ class UnitGroup(val unit: MapUnit, val size: Float): Group() {
|
||||
spinningCircle.center(this)
|
||||
spinningCircle.x += whiteHaloSize / 2 // to edge of white halo
|
||||
spinningCircle.setOrigin(spinningCircle.width / 2 - whiteHaloSize / 2, spinningCircle.height / 2)
|
||||
addActor(spinningCircle)
|
||||
spinningCircle.addAction(Actions.repeat(RepeatAction.FOREVER, Actions.rotateBy(90f, 1f)))
|
||||
//addActor(spinningCircle)
|
||||
//spinningCircle.addAction(Actions.repeat(RepeatAction.FOREVER, Actions.rotateBy(90f, 1f)))
|
||||
blackSpinningCircle = spinningCircle
|
||||
}
|
||||
}
|
@ -92,7 +92,7 @@ class WorldMapHolder(internal val worldScreen: WorldScreen, internal val tileMap
|
||||
}
|
||||
|
||||
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.
|
||||
* 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,
|
||||
|
@ -143,7 +143,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
|
||||
val loadingGamePopup = PopupTable(this)
|
||||
loadingGamePopup.add("Loading latest game state...")
|
||||
loadingGamePopup.open()
|
||||
thread {
|
||||
thread(name="MultiplayerLoad") {
|
||||
try {
|
||||
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
|
||||
@ -379,7 +379,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
|
||||
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()
|
||||
gameInfoClone.setTransients()
|
||||
try {
|
||||
|
@ -118,7 +118,7 @@ class WorldScreenMenuTable(val worldScreen: WorldScreen) : PopupTable(worldScree
|
||||
badGameIdLabel.isVisible = true
|
||||
return@addButton
|
||||
}
|
||||
thread {
|
||||
thread(name="MultiplayerDownload") {
|
||||
try {
|
||||
// The tryDownload can take more than 500ms. Therefore, to avoid ANRs,
|
||||
// we need to run it in a different thread.
|
||||
|
@ -182,7 +182,7 @@ class WorldScreenOptionsTable(val worldScreen:WorldScreen) : PopupTable(worldScr
|
||||
|
||||
downloadMusicButton.onClick {
|
||||
// So the whole game doesn't get stuck while downloading the file
|
||||
thread {
|
||||
thread(name="Music") {
|
||||
try {
|
||||
downloadMusicButton.disable()
|
||||
errorTable.clear()
|
||||
|
@ -58,7 +58,7 @@ class UnitContextMenu(val tileMapHolder: WorldMapHolder, val selectedUnit: MapUn
|
||||
|
||||
fun onMoveButtonClick() {
|
||||
// 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
|
||||
// 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user