Skip to content

Commit

Permalink
Hotfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
BloCamLimb committed Nov 10, 2023
1 parent 48ee3c7 commit 7841a88
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 56 deletions.
16 changes: 12 additions & 4 deletions fabric/src/main/java/icyllis/modernui/mc/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ private Client(@Nonnull ForgeConfigSpec.Builder builder) {

mTooltip = builder.comment(
"Whether to enable Modern UI enhanced tooltip, or back to vanilla default.")
.define("enable", true);
.define("enable", !ModernUIMod.isSodiumLoaded() && !ModernUIMod.isLegendaryTooltipsLoaded());
mRoundedTooltip = builder.comment(
"Whether to use rounded tooltip shapes, or to use rectangular shapes.")
.define("roundedShape", true);
Expand Down Expand Up @@ -590,7 +590,8 @@ private void reload() {
reload = true;
}*/
if (reloadStrike) {
ModernUIClient.getInstance().reloadFontStrike();
Minecraft.getInstance().submit(
() -> FontResourceManager.getInstance().reloadAll());
}

//ModernUI.getSelectedTypeface();
Expand Down Expand Up @@ -966,9 +967,16 @@ void reload() {
ModernTextRenderer.sAllowSDFTextIn2D = mAllowSDFTextIn2D.get();

if (reloadStrike) {
ModernUIClient.getInstance().reloadFontStrike();
Minecraft.getInstance().submit(
() -> FontResourceManager.getInstance().reloadAll());
} else if (reload && ModernUIClient.isTextEngineEnabled()) {
Minecraft.getInstance().submit(() -> TextLayoutEngine.getInstance().reload());
Minecraft.getInstance().submit(
() -> {
try {
TextLayoutEngine.getInstance().reload();
} catch (Exception ignored) {
}
});
}
/*GlyphManagerForge.sPreferredFont = preferredFont.get();
GlyphManagerForge.sAntiAliasing = antiAliasing.get();
Expand Down
23 changes: 15 additions & 8 deletions fabric/src/main/java/icyllis/modernui/mc/FontResourceManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@

import com.google.gson.Gson;
import com.google.gson.JsonArray;
import icyllis.modernui.ModernUI;
import icyllis.modernui.graphics.font.GlyphManager;
import icyllis.modernui.graphics.text.*;
import icyllis.modernui.mc.text.TextLayoutEngine;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import it.unimi.dsi.fastutil.ints.IntSet;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
Expand Down Expand Up @@ -70,14 +72,7 @@ public class FontResourceManager implements PreparableReloadListener {
*/
protected final HashMap<String, String> mEmojiShortcodes = new HashMap<>();

public FontResourceManager() {
synchronized (FontResourceManager.class) {
if (sInstance == null) {
sInstance = this;
} else {
throw new RuntimeException("Multiple instances");
}
}
protected FontResourceManager() {
// init first
mGlyphManager = GlyphManager.getInstance();
}
Expand All @@ -88,6 +83,18 @@ public FontResourceManager() {
* @return the instance
*/
public static FontResourceManager getInstance() {
if (sInstance == null) {
synchronized (FontResourceManager.class) {
if (sInstance == null) {
if (ModernUIClient.isTextEngineEnabled()) {
sInstance = new TextLayoutEngine();
} else {
sInstance = new FontResourceManager();
LOGGER.info(ModernUI.MARKER, "Created FontResourceManager");
}
}
}
}
return sInstance;
}

Expand Down
14 changes: 12 additions & 2 deletions fabric/src/main/java/icyllis/modernui/mc/ModernUIMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ public abstract class ModernUIMod {
public static volatile boolean sDevelopment;
public static volatile boolean sDeveloperMode;

public static boolean sOptiFineLoaded;
public static boolean sIrisApiLoaded;
protected static boolean sOptiFineLoaded;
protected static boolean sIrisApiLoaded;
protected static volatile boolean sLegendaryTooltipsLoaded;
protected static volatile boolean sSodiumLoaded;

static {
try {
Expand Down Expand Up @@ -89,6 +91,14 @@ public static boolean isIrisApiLoaded() {
return sIrisApiLoaded;
}

public static boolean isLegendaryTooltipsLoaded() {
return sLegendaryTooltipsLoaded;
}

public static boolean isSodiumLoaded() {
return sSodiumLoaded;
}

public static boolean isDeveloperMode() {
return sDeveloperMode || sDevelopment;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public void onInitialize() {
LOGGER.warn(MARKER, "Signature is missing");
}

sLegendaryTooltipsLoaded = FabricLoader.getInstance().isModLoaded("legendarytooltips");
sSodiumLoaded = FabricLoader.getInstance().isModLoaded("sodium");

ModConfigEvents.loading(ID).register(Config::reloadCommon);
ModConfigEvents.reloading(ID).register(Config::reloadCommon);
Config.initCommonConfig(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ public void onResourceManagerReload(@Nonnull ResourceManager resourceManager) {
ModernUI.NAME_CPT + "/text.toml")
);

FontResourceManager.getInstance();
if (isTextEngineEnabled()) {
ClientLifecycleEvents.CLIENT_STARTED.register((mc) -> {
MuiModApi.addOnWindowResizeListener(TextLayoutEngine.getInstance());
Expand All @@ -192,8 +193,6 @@ public void onResourceManagerReload(@Nonnull ResourceManager resourceManager) {
MuiTextCommand.register(dispatcher);
});

new TextLayoutEngine();

MuiModApi.addOnDebugDumpListener(TextLayoutEngine.getInstance());

ClientTickEvents.END_CLIENT_TICK.register((mc) -> TextLayoutEngine.getInstance().onEndClientTick());
Expand Down Expand Up @@ -225,8 +224,6 @@ public CompletableFuture<Void> reload(@Nonnull PreparationBarrier preparationBar
);
}
});

new FontResourceManager();
}
LOGGER.info(MARKER, "Initialized Modern UI client");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,6 @@ public class TextLayoutEngine extends FontResourceManager

public static final Marker MARKER = MarkerManager.getMarker("TextLayout");

/**
* Global instance
*/
private static volatile TextLayoutEngine sInstance;

/**
* Config values
*/
Expand Down Expand Up @@ -309,9 +304,6 @@ private record FontStrikeDesc(Font font, int resLevel) {
private int mTimer;

public TextLayoutEngine() {
super();
sInstance = this;

/* StringCache is created by the main game thread; remember it for later thread safety checks */
//mainThread = Thread.currentThread();

Expand Down Expand Up @@ -344,7 +336,7 @@ public TextLayoutEngine() {
*/
@Nonnull
public static TextLayoutEngine getInstance() {
return sInstance;
return (TextLayoutEngine) FontResourceManager.getInstance();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public void onRenderWidget(@Nonnull GuiGraphics gr, int mouseX, int mouseY, floa
if (viewCursorPos != clampedViewHighlightPos) {
gr.flush();

TextLayout layout = TextLayoutEngine.getInstance().lookupVanillaLayout(viewText,
TextLayout layout = engine.lookupVanillaLayout(viewText,
Style.EMPTY, TextLayoutEngine.COMPUTE_ADVANCES);
float startX = baseX;
float endX = cursorX;
Expand Down
16 changes: 12 additions & 4 deletions forge/src/main/java/icyllis/modernui/mc/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ private Client(@Nonnull ForgeConfigSpec.Builder builder) {

mTooltip = builder.comment(
"Whether to enable Modern UI enhanced tooltip, or back to vanilla default.")
.define("enable", true);
.define("enable", !ModernUIMod.isLegendaryTooltipsLoaded());
mRoundedTooltip = builder.comment(
"Whether to use rounded tooltip shapes, or to use rectangular shapes.")
.define("roundedShape", true);
Expand Down Expand Up @@ -591,7 +591,8 @@ private void reload() {
reload = true;
}*/
if (reloadStrike) {
ModernUIClient.getInstance().reloadFontStrike();
Minecraft.getInstance().submit(
() -> FontResourceManager.getInstance().reloadAll());
}

// scan and preload typeface in background thread
Expand Down Expand Up @@ -968,9 +969,16 @@ void reload() {
ModernTextRenderer.sAllowSDFTextIn2D = mAllowSDFTextIn2D.get();

if (reloadStrike) {
ModernUIClient.getInstance().reloadFontStrike();
Minecraft.getInstance().submit(
() -> FontResourceManager.getInstance().reloadAll());
} else if (reload && ModernUIClient.isTextEngineEnabled()) {
Minecraft.getInstance().submit(() -> TextLayoutEngine.getInstance().reload());
Minecraft.getInstance().submit(
() -> {
try {
TextLayoutEngine.getInstance().reload();
} catch (Exception ignored) {
}
});
}
/*GlyphManagerForge.sPreferredFont = preferredFont.get();
GlyphManagerForge.sAntiAliasing = antiAliasing.get();
Expand Down
23 changes: 15 additions & 8 deletions forge/src/main/java/icyllis/modernui/mc/FontResourceManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@

import com.google.gson.Gson;
import com.google.gson.JsonArray;
import icyllis.modernui.ModernUI;
import icyllis.modernui.graphics.font.GlyphManager;
import icyllis.modernui.graphics.text.*;
import icyllis.modernui.mc.text.TextLayoutEngine;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import it.unimi.dsi.fastutil.ints.IntSet;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
Expand Down Expand Up @@ -70,14 +72,7 @@ public class FontResourceManager implements PreparableReloadListener {
*/
protected final HashMap<String, String> mEmojiShortcodes = new HashMap<>();

public FontResourceManager() {
synchronized (FontResourceManager.class) {
if (sInstance == null) {
sInstance = this;
} else {
throw new RuntimeException("Multiple instances");
}
}
protected FontResourceManager() {
// init first
mGlyphManager = GlyphManager.getInstance();
}
Expand All @@ -88,6 +83,18 @@ public FontResourceManager() {
* @return the instance
*/
public static FontResourceManager getInstance() {
if (sInstance == null) {
synchronized (FontResourceManager.class) {
if (sInstance == null) {
if (ModernUIClient.isTextEngineEnabled()) {
sInstance = new TextLayoutEngine();
} else {
sInstance = new FontResourceManager();
LOGGER.info(ModernUI.MARKER, "Created FontResourceManager");
}
}
}
}
return sInstance;
}

Expand Down
9 changes: 7 additions & 2 deletions forge/src/main/java/icyllis/modernui/mc/ModernUIMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ public abstract class ModernUIMod {
public static volatile boolean sDevelopment;
public static volatile boolean sDeveloperMode;

public static boolean sOptiFineLoaded;
public static boolean sIrisApiLoaded;
protected static boolean sOptiFineLoaded;
protected static boolean sIrisApiLoaded;
protected static volatile boolean sLegendaryTooltipsLoaded;

static {
try {
Expand Down Expand Up @@ -76,6 +77,10 @@ public static boolean isIrisApiLoaded() {
return sIrisApiLoaded;
}

public static boolean isLegendaryTooltipsLoaded() {
return sLegendaryTooltipsLoaded;
}

public static boolean isDeveloperMode() {
return sDeveloperMode || sDevelopment;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.mojang.blaze3d.systems.RenderSystem;
import icyllis.modernui.ModernUI;
import icyllis.modernui.mc.*;
import icyllis.modernui.mc.text.TextLayoutEngine;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.language.LanguageManager;
import net.minecraftforge.api.distmarker.Dist;
Expand Down Expand Up @@ -82,6 +81,7 @@ public ModernUIForge() {
warnSetup("You should remove ReBlurred, Modern UI already includes its features, " +
"and Modern UI has better performance than it");
}
sLegendaryTooltipsLoaded = ModList.get().isLoaded("legendarytooltips");

Config.initCommonConfig(
spec -> ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, spec,
Expand Down Expand Up @@ -156,12 +156,10 @@ private Client() {
spec -> ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, spec,
ModernUI.NAME_CPT + "/text.toml")
);
FontResourceManager.getInstance();
if (isTextEngineEnabled()) {
ModernUIText.init();
new TextLayoutEngine();
LOGGER.info(MARKER, "Initialized Modern UI text engine");
} else {
new FontResourceManager();
}
FMLJavaModLoadingContext.get().getModEventBus().addListener(
(Consumer<ModConfigEvent>) event -> Config.reloadAnyClient(event.getConfig())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,6 @@ public class TextLayoutEngine extends FontResourceManager

public static final Marker MARKER = MarkerManager.getMarker("TextLayout");

/**
* Global instance
*/
private static volatile TextLayoutEngine sInstance;

/**
* Config values
*/
Expand Down Expand Up @@ -309,9 +304,6 @@ private record FontStrikeDesc(Font font, int resLevel) {
private int mTimer;

public TextLayoutEngine() {
super();
sInstance = this;

/* StringCache is created by the main game thread; remember it for later thread safety checks */
//mainThread = Thread.currentThread();

Expand Down Expand Up @@ -344,7 +336,7 @@ public TextLayoutEngine() {
*/
@Nonnull
public static TextLayoutEngine getInstance() {
return sInstance;
return (TextLayoutEngine) FontResourceManager.getInstance();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public void onRenderWidget(@Nonnull GuiGraphics gr, int mouseX, int mouseY, floa
if (viewCursorPos != clampedViewHighlightPos) {
gr.flush();

TextLayout layout = TextLayoutEngine.getInstance().lookupVanillaLayout(viewText,
TextLayout layout = engine.lookupVanillaLayout(viewText,
Style.EMPTY, TextLayoutEngine.COMPUTE_ADVANCES);
float startX = baseX;
float endX = cursorX;
Expand Down

0 comments on commit 7841a88

Please sign in to comment.