From aabf293bebeb3f031f01c5139ff4955ba4cff98a Mon Sep 17 00:00:00 2001 From: buthed010203 Date: Fri, 20 Sep 2024 21:12:11 -0400 Subject: [PATCH] Mod icon loading optimization disabled by default with a setting to re-enable it, a blacklist for mods that cause issues with it enabled --- core/assets/bundles/bundle.properties | 2 ++ core/src/mindustry/mod/Mods.java | 8 +++++++- core/src/mindustry/ui/dialogs/SettingsMenuDialog.java | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index 54fdf94665..0266899f88 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -536,6 +536,8 @@ client.setting.schematicbrowserimporttags.description = Whether to import tags w client.setting.experimental.category = Experimental client.setting.trackcoreitems.name = Track Core Items client.setting.trackcoreitems.description = Store the history of core items each game. [scarlet]May use a lot of RAM for long games![] +client.setting.modiconloadingoptimization.name = Optimize Mod Icon Loading +client.setting.modiconloadingoptimization.description = [scarlet]This breaks some mods, please report them to us so we can disable the optimization for that mod client.setting.seer-warnings.name = Enable Seer warnings client.setting.seer-warnings.description = Whether to send Seer warnings client.setting.seer-scoring.name = Enable Seer scoring system diff --git a/core/src/mindustry/mod/Mods.java b/core/src/mindustry/mod/Mods.java index 48a046f100..008f1f96a6 100644 --- a/core/src/mindustry/mod/Mods.java +++ b/core/src/mindustry/mod/Mods.java @@ -15,6 +15,7 @@ import arc.util.serialization.*; import arc.util.serialization.Jval.*; import kotlin.*; +import mindustry.*; import mindustry.core.*; import mindustry.ctype.*; import mindustry.game.EventType.*; @@ -215,13 +216,13 @@ public void loadIcons(long start, int limit) { // FINISHME: This could be furthe hasLoadedIcons = false; var startM = Time.nanos(); if(Time.nanosToMillis(startM) - start > limit) return; - m.attemptedIconLoad = true; loadIcon(m); Log.debug("Attempted icon load for mod '@' in @ms", m.meta.name, Time.millisSinceNanos(startM)); }); } private void loadIcon(LoadedMod mod){ + mod.attemptedIconLoad = true; //try to load icon for each mod that can have one if(mod.root.child("icon.png").exists() && !headless){ try{ @@ -1132,6 +1133,8 @@ public static class LoadedMod implements Publishable, Disposable{ /** Foo's addition to track whether we have tried to load this mod's icon */ public boolean attemptedIconLoad; + private static boolean iconLoadingOptimization = Core.settings.getBool("modiconloadingoptimization"); + private static ObjectSet iconDeferralUnsupported = ObjectSet.with("mi2-utilities-java", "olupis"); public LoadedMod(Fi file, Fi root, Mod main, ClassLoader loader, ModMeta meta){ this.root = root; @@ -1140,6 +1143,9 @@ public LoadedMod(Fi file, Fi root, Mod main, ClassLoader loader, ModMeta meta){ this.main = main; this.meta = meta; this.name = meta.name.toLowerCase(Locale.ROOT).replace(" ", "-"); + if(shouldBeEnabled() && (!iconLoadingOptimization || iconDeferralUnsupported.contains(this.name))){ // This is terrible. + Core.app.post(() -> Vars.mods.loadIcon(this)); + } } /** @return whether this is a java class mod. */ diff --git a/core/src/mindustry/ui/dialogs/SettingsMenuDialog.java b/core/src/mindustry/ui/dialogs/SettingsMenuDialog.java index 2a8856db12..92138207e4 100644 --- a/core/src/mindustry/ui/dialogs/SettingsMenuDialog.java +++ b/core/src/mindustry/ui/dialogs/SettingsMenuDialog.java @@ -464,6 +464,7 @@ void addSettings(){ if (settings.getBool("client-experimentals") || OS.hasProp("policone")) { client.category("experimental"); client.checkPref("trackcoreitems", false, i -> CoreItemsDisplay.trackItems = i && !net.server()); + client.checkPref("modiconloadingoptimization", false); client.checkPref("seer-warnings", false); client.checkPref("seer-scoring", false);