Skip to content

Commit

Permalink
Hotfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
BloCamLimb committed Nov 9, 2023
1 parent 88587ec commit 0bc4f21
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 28 deletions.
16 changes: 12 additions & 4 deletions forge/src/main/java/icyllis/modernui/mc/forge/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ private Client(@Nonnull ForgeConfigSpec.Builder builder) {
"2) File path for external fonts on your PC, for instance: /usr/shared/fonts/x.otf",
"Fonts under 'modernui:font' in resource packs and OS builtin fonts will be registered.",
"Using bitmap fonts should consider other text settings, default glyph size should be 16x.",
"This list is only read once when the game is loaded. A game restart is required to reload")
"This list is only read once when the game is loaded, or reloaded via in-game GUI.")
.defineList("fallbackFontFamilyList", () -> {
List<String> list = new ArrayList<>();
list.add("Noto Sans");
Expand Down Expand Up @@ -589,7 +589,8 @@ private void reload() {
reload = true;
}*/
if (reloadStrike) {
ModernUIForge.Client.getInstance().reloadFontStrike();
Minecraft.getInstance().submit(
() -> FontResourceManager.getInstance().reloadAll());
}

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

if (reloadStrike) {
ModernUIForge.Client.getInstance().reloadFontStrike();
Minecraft.getInstance().submit(
() -> FontResourceManager.getInstance().reloadAll());
} else if (reload && ModernUIForge.Client.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
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,19 @@ public FontResourceManager() {
* @return the instance
*/
public static FontResourceManager getInstance() {
if (sInstance == null) {
synchronized (FontResourceManager.class) {
if (sInstance == null) {
if (ModernUIForge.Client.isTextEngineEnabled()) {
sInstance = new TextLayoutEngine();
LOGGER.info(ModernUI.MARKER, "Created TextLayoutEngine");
} else {
sInstance = new FontResourceManager();
LOGGER.info(ModernUI.MARKER, "Created FontResourceManager");
}
}
}
}
return sInstance;
}

Expand Down Expand Up @@ -145,7 +153,9 @@ protected void applyResources(@Nonnull LoadResults results) {
mEmojiShortcodes.clear();
mEmojiShortcodes.putAll(results.mEmojiShortcodes);
// reload the whole engine
ModernUIForge.Client.getInstance().reloadTypeface();
var client = ModernUIForge.Client.getInstance();
// this can be null if FML threw an exception
if (client != null) client.reloadTypeface();
reloadAll();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import icyllis.arc3d.engine.DriverBugWorkarounds;
import icyllis.modernui.ModernUI;
import icyllis.modernui.graphics.text.*;
import icyllis.modernui.mc.text.TextLayoutEngine;
import icyllis.modernui.text.Typeface;
import icyllis.modernui.view.WindowManager;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -284,12 +283,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 @@ -89,11 +89,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 @@ -320,9 +315,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 @@ -355,7 +347,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 @@ -165,7 +165,8 @@ public void onRenderWidget(@Nonnull PoseStack poseStack, int mouseX, int mouseY,
final float cursorX;
if (cursorInRange) {
if (!separate && !viewText.isEmpty()) {
TextLayout layout = TextLayoutEngine.getInstance().lookupVanillaLayout(viewText);
TextLayout layout = engine.lookupVanillaLayout(viewText,
Style.EMPTY, TextLayoutEngine.COMPUTE_ADVANCES);
float curAdv = 0;
int stripIndex = 0;
for (int i = 0; i < viewCursorPos; i++) {
Expand Down Expand Up @@ -204,7 +205,8 @@ public void onRenderWidget(@Nonnull PoseStack poseStack, int mouseX, int mouseY,
if (viewCursorPos != clampedViewHighlightPos) {
bufferSource.endBatch();

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

0 comments on commit 0bc4f21

Please sign in to comment.