From c7bd5280522a21e8ec4fff36ae466527580df774 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Mon, 15 Mar 2021 22:13:55 +0200 Subject: [PATCH] Shortened initial loading time by removing double loading of atlas --- core/src/com/unciv/UncivGame.kt | 6 ++---- core/src/com/unciv/ui/utils/ImageGetter.kt | 18 +++++------------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/core/src/com/unciv/UncivGame.kt b/core/src/com/unciv/UncivGame.kt index 474c96ec34..6ffed20fe7 100644 --- a/core/src/com/unciv/UncivGame.kt +++ b/core/src/com/unciv/UncivGame.kt @@ -70,14 +70,11 @@ class UncivGame(parameters: UncivGameParameters) : Game() { viewEntireMapForDebug = false } Current = this - - GameSaver.customSaveLocationHelper = customSaveLocationHelper + // If this takes too long players, especially with older phones, get ANR problems. // Whatever needs graphics needs to be done on the main thread, // So it's basically a long set of deferred actions. - settings = GameSaver.getGeneralSettings() // needed for the screen - /** When we recreate the GL context for whatever reason (say - we moved to a split screen on Android), * ALL objects that were related to the old context - need to be recreated. @@ -90,6 +87,7 @@ class UncivGame(parameters: UncivGameParameters) : Game() { ImageGetter.atlas = TextureAtlas("game.atlas") ImageGetter.setNewRuleset(ImageGetter.ruleset) CameraStageBaseScreen.setSkin() // needs to come AFTER the Texture reset, since the buttons depend on it + settings = GameSaver.getGeneralSettings() // needed for the screen - this also needs the atlas to be configured Gdx.graphics.isContinuousRendering = settings.continuousRendering screen = LoadingScreen() diff --git a/core/src/com/unciv/ui/utils/ImageGetter.kt b/core/src/com/unciv/ui/utils/ImageGetter.kt index 433f47ac0a..96faa9645e 100644 --- a/core/src/com/unciv/ui/utils/ImageGetter.kt +++ b/core/src/com/unciv/ui/utils/ImageGetter.kt @@ -30,24 +30,16 @@ object ImageGetter { // always have to switch between like 170 different textures. // So, we now use TexturePacker in the DesktopLauncher class to pack all the different images into single images, // and the atlas is what tells us what was packed where. - var atlas = TextureAtlas("game.atlas") + lateinit var atlas: TextureAtlas var ruleset = Ruleset() // We then shove all the drawables into a hashmap, because the atlas specifically tells us // that the search on it is inefficient private val textureRegionDrawables = HashMap() - init { - reload() - } - + /** Required every time the ruleset changes, in order to load mod-specific images */ fun setNewRuleset(ruleset: Ruleset) { this.ruleset = ruleset - reload() - } - - /** Required every time the ruleset changes, in order to load mod-specific images */ - private fun reload() { textureRegionDrawables.clear() // These are the drawables from the base game for (region in atlas.regions) { @@ -183,8 +175,7 @@ object ImageGetter { cityStateIcon.color = nation.getInnerColor() cityStateIcon.surroundWithCircle(size * 0.9f).apply { circle.color = nation.getOuterColor() } .surroundWithCircle(size, false).apply { circle.color = nation.getInnerColor() } - } - else getCircle().apply { color = nation.getOuterColor() } + } else getCircle().apply { color = nation.getOuterColor() } .surroundWithCircle(size).apply { circle.color = nation.getInnerColor() } } @@ -274,7 +265,8 @@ object ImageGetter { fun getResourceImage(resourceName: String, size: Float): Actor { val iconGroup = getImage("ResourceIcons/$resourceName").surroundWithCircle(size) - val resource = ruleset.tileResources[resourceName] ?: return iconGroup // This is the result of a bad modding setup, just give em an empty circle. Their problem. + val resource = ruleset.tileResources[resourceName] + ?: return iconGroup // This is the result of a bad modding setup, just give em an empty circle. Their problem. iconGroup.circle.color = getColorFromStats(resource) if (resource.resourceType == ResourceType.Luxury) {