Skip to content

Commit

Permalink
Mod icon loading optimization disabled by default with a setting to r…
Browse files Browse the repository at this point in the history
…e-enable it, a blacklist for mods that cause issues with it enabled
  • Loading branch information
buthed010203 committed Sep 21, 2024
1 parent cd97aaa commit aabf293
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions core/assets/bundles/bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion core/src/mindustry/mod/Mods.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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<String> iconDeferralUnsupported = ObjectSet.with("mi2-utilities-java", "olupis");

public LoadedMod(Fi file, Fi root, Mod main, ClassLoader loader, ModMeta meta){
this.root = root;
Expand All @@ -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. */
Expand Down
1 change: 1 addition & 0 deletions core/src/mindustry/ui/dialogs/SettingsMenuDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit aabf293

Please sign in to comment.