From cc01d517d5dc81324c0b100b9a602b58a3b41dd1 Mon Sep 17 00:00:00 2001 From: Hileb <107909747+Ecdcaeb@users.noreply.github.com> Date: Wed, 1 May 2024 17:51:46 +0800 Subject: [PATCH 1/7] cache and load textures --- .../fml/client/SplashProgress.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/minecraftforge/fml/client/SplashProgress.java b/src/main/java/net/minecraftforge/fml/client/SplashProgress.java index cd609923c..2d84c94bd 100644 --- a/src/main/java/net/minecraftforge/fml/client/SplashProgress.java +++ b/src/main/java/net/minecraftforge/fml/client/SplashProgress.java @@ -405,6 +405,7 @@ public void run() Display.sync(100); } } + SplashFontRenderer.clear(); clearGL(); } @@ -893,19 +894,22 @@ public void texCoord(int frame, float u, float v) } } - private static class SplashFontRenderer extends FontRenderer + public static class SplashFontRenderer extends FontRenderer { + public static final HashMap CACHED_IMAGES = new HashMap<>(); public SplashFontRenderer() { - super(Minecraft.getMinecraft().gameSettings, fontTexture.getLocation(), null, false); + super(Minecraft.getMinecraft().gameSettings, fontTexture.getLocation(), null, true); super.onResourceManagerReload(null); } @Override protected void bindTexture(@Nonnull ResourceLocation location) { - if(location != locationFontTexture) throw new IllegalArgumentException(); - fontTexture.bind(); + if (!CACHED_IMAGES.containsKey(location)) { + CACHED_IMAGES.put(location, new Texture(location, null)); + } + CACHED_IMAGES.get(location).bind(); } @Nonnull @@ -915,6 +919,12 @@ protected IResource getResource(@Nonnull ResourceLocation location) throws IOExc DefaultResourcePack pack = Minecraft.getMinecraft().defaultResourcePack; return new SimpleResource(pack.getPackName(), location, pack.getInputStream(location), null, null); } + public static void clear(){ + for(Texture texture : CACHED_IMAGES.values()){ + texture.delete(); + } + CACHED_IMAGES.clear(); + } } public static void drawVanillaScreen(TextureManager renderEngine) throws LWJGLException From 89f3eda48f597f9a113c664b9e578f6c75247f74 Mon Sep 17 00:00:00 2001 From: Hileb <107909747+Ecdcaeb@users.noreply.github.com> Date: Wed, 1 May 2024 18:02:23 +0800 Subject: [PATCH 2/7] fix import --- src/main/java/net/minecraftforge/fml/client/SplashProgress.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/net/minecraftforge/fml/client/SplashProgress.java b/src/main/java/net/minecraftforge/fml/client/SplashProgress.java index 2d84c94bd..8b0e6edbd 100644 --- a/src/main/java/net/minecraftforge/fml/client/SplashProgress.java +++ b/src/main/java/net/minecraftforge/fml/client/SplashProgress.java @@ -35,6 +35,7 @@ import java.lang.Thread.UncaughtExceptionHandler; import java.nio.IntBuffer; import java.nio.charset.StandardCharsets; +import java.util.HashMap; import java.util.Iterator; import java.util.Properties; import java.util.concurrent.Semaphore; From d20de65bcd5e06e6fc4715f0dd294c3b8f87817a Mon Sep 17 00:00:00 2001 From: Hileb <107909747+Ecdcaeb@users.noreply.github.com> Date: Wed, 1 May 2024 18:07:58 +0800 Subject: [PATCH 3/7] make it un-static --- .../fml/client/SplashProgress.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/minecraftforge/fml/client/SplashProgress.java b/src/main/java/net/minecraftforge/fml/client/SplashProgress.java index 8b0e6edbd..eae29edf2 100644 --- a/src/main/java/net/minecraftforge/fml/client/SplashProgress.java +++ b/src/main/java/net/minecraftforge/fml/client/SplashProgress.java @@ -406,7 +406,7 @@ public void run() Display.sync(100); } } - SplashFontRenderer.clear(); + fontRenderer.clear(); clearGL(); } @@ -897,7 +897,7 @@ public void texCoord(int frame, float u, float v) public static class SplashFontRenderer extends FontRenderer { - public static final HashMap CACHED_IMAGES = new HashMap<>(); + public final HashMap cachedImages = new HashMap<>(); public SplashFontRenderer() { super(Minecraft.getMinecraft().gameSettings, fontTexture.getLocation(), null, true); @@ -907,10 +907,10 @@ public SplashFontRenderer() @Override protected void bindTexture(@Nonnull ResourceLocation location) { - if (!CACHED_IMAGES.containsKey(location)) { - CACHED_IMAGES.put(location, new Texture(location, null)); + if (!cachedImages.containsKey(location)) { + cachedImages.put(location, new Texture(location, null)); } - CACHED_IMAGES.get(location).bind(); + cachedImages.get(location).bind(); } @Nonnull @@ -920,11 +920,11 @@ protected IResource getResource(@Nonnull ResourceLocation location) throws IOExc DefaultResourcePack pack = Minecraft.getMinecraft().defaultResourcePack; return new SimpleResource(pack.getPackName(), location, pack.getInputStream(location), null, null); } - public static void clear(){ - for(Texture texture : CACHED_IMAGES.values()){ + public void clear(){ + for(Texture texture : cachedImages.values()){ texture.delete(); } - CACHED_IMAGES.clear(); + cachedImages.clear(); } } From 32f7e2e8042af3415071d268b4fb04348bde934b Mon Sep 17 00:00:00 2001 From: Hileb <107909747+Ecdcaeb@users.noreply.github.com> Date: Wed, 1 May 2024 18:23:16 +0800 Subject: [PATCH 4/7] set default not forced unicode --- .../java/net/minecraftforge/fml/client/SplashProgress.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/minecraftforge/fml/client/SplashProgress.java b/src/main/java/net/minecraftforge/fml/client/SplashProgress.java index eae29edf2..6c3ee3e86 100644 --- a/src/main/java/net/minecraftforge/fml/client/SplashProgress.java +++ b/src/main/java/net/minecraftforge/fml/client/SplashProgress.java @@ -261,7 +261,7 @@ public void run() logoTexture = new Texture(logoLoc, null, false); forgeTexture = new Texture(forgeLoc, forgeFallbackLoc); glEnable(GL_TEXTURE_2D); - fontRenderer = new SplashFontRenderer(); + fontRenderer = new SplashFontRenderer(false); glDisable(GL_TEXTURE_2D); while(!done) { @@ -898,9 +898,9 @@ public void texCoord(int frame, float u, float v) public static class SplashFontRenderer extends FontRenderer { public final HashMap cachedImages = new HashMap<>(); - public SplashFontRenderer() + public SplashFontRenderer(boolean isForcedUnicode) { - super(Minecraft.getMinecraft().gameSettings, fontTexture.getLocation(), null, true); + super(Minecraft.getMinecraft().gameSettings, fontTexture.getLocation(), null, isForcedUnicode); super.onResourceManagerReload(null); } From df88d6340a7b8b4484195c108c509fc3c01203a4 Mon Sep 17 00:00:00 2001 From: Hileb <107909747+Ecdcaeb@users.noreply.github.com> Date: Thu, 2 May 2024 07:28:54 +0800 Subject: [PATCH 5/7] fix npe --- .../minecraftforge/fml/client/SplashProgress.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/minecraftforge/fml/client/SplashProgress.java b/src/main/java/net/minecraftforge/fml/client/SplashProgress.java index 6c3ee3e86..17b93531c 100644 --- a/src/main/java/net/minecraftforge/fml/client/SplashProgress.java +++ b/src/main/java/net/minecraftforge/fml/client/SplashProgress.java @@ -897,7 +897,7 @@ public void texCoord(int frame, float u, float v) public static class SplashFontRenderer extends FontRenderer { - public final HashMap cachedImages = new HashMap<>(); + public HashMap cachedImages; public SplashFontRenderer(boolean isForcedUnicode) { super(Minecraft.getMinecraft().gameSettings, fontTexture.getLocation(), null, isForcedUnicode); @@ -907,6 +907,7 @@ public SplashFontRenderer(boolean isForcedUnicode) @Override protected void bindTexture(@Nonnull ResourceLocation location) { + if(cachedImages == null) cachedImages = new HashMap<>(); if (!cachedImages.containsKey(location)) { cachedImages.put(location, new Texture(location, null)); } @@ -921,10 +922,13 @@ protected IResource getResource(@Nonnull ResourceLocation location) throws IOExc return new SimpleResource(pack.getPackName(), location, pack.getInputStream(location), null, null); } public void clear(){ - for(Texture texture : cachedImages.values()){ - texture.delete(); + if(cachedImages != null){ + for(Texture texture : cachedImages.values()){ + texture.delete(); + } + cachedImages.clear(); + cachedImages = null; } - cachedImages.clear(); } } From 89dbd6b6b97fad214a8a1c566ecf320e9501e4b9 Mon Sep 17 00:00:00 2001 From: Hileb <107909747+Ecdcaeb@users.noreply.github.com> Date: Fri, 30 Aug 2024 13:18:52 +0800 Subject: [PATCH 6/7] Update SplashProgress make it implements Closeable --- .../fml/client/SplashProgress.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/minecraftforge/fml/client/SplashProgress.java b/src/main/java/net/minecraftforge/fml/client/SplashProgress.java index 17b93531c..4ff0fe8f1 100644 --- a/src/main/java/net/minecraftforge/fml/client/SplashProgress.java +++ b/src/main/java/net/minecraftforge/fml/client/SplashProgress.java @@ -745,7 +745,7 @@ private static IResourcePack createResourcePack(File file) private static final IntBuffer buf = BufferUtils.createIntBuffer(4 * 1024 * 1024); @SuppressWarnings("unused") - private static class Texture + private static class Texture implements Closeable { private final ResourceLocation location; private final int name; @@ -893,9 +893,14 @@ public void texCoord(int frame, float u, float v) { glTexCoord2f(getU(frame, u), getV(frame, v)); } + + @Override + public void close(){ + this.delete(); + } } - public static class SplashFontRenderer extends FontRenderer + public static class SplashFontRenderer extends FontRenderer implements Closeable { public HashMap cachedImages; public SplashFontRenderer(boolean isForcedUnicode) @@ -921,6 +926,7 @@ protected IResource getResource(@Nonnull ResourceLocation location) throws IOExc DefaultResourcePack pack = Minecraft.getMinecraft().defaultResourcePack; return new SimpleResource(pack.getPackName(), location, pack.getInputStream(location), null, null); } + public void clear(){ if(cachedImages != null){ for(Texture texture : cachedImages.values()){ @@ -930,6 +936,11 @@ public void clear(){ cachedImages = null; } } + + @Override + public void close(){ + this.clear(); + } } public static void drawVanillaScreen(TextureManager renderEngine) throws LWJGLException @@ -981,4 +992,4 @@ private static int bytesToMb(long bytes) { return (int) (bytes / 1024L / 1024L); } -} \ No newline at end of file +} From 72fdbbf5d93ffb16de08ed2c982ca8f1c6368e7d Mon Sep 17 00:00:00 2001 From: Hileb <107909747+Ecdcaeb@users.noreply.github.com> Date: Fri, 30 Aug 2024 22:29:34 +0800 Subject: [PATCH 7/7] fix import --- src/main/java/net/minecraftforge/fml/client/SplashProgress.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/net/minecraftforge/fml/client/SplashProgress.java b/src/main/java/net/minecraftforge/fml/client/SplashProgress.java index 4ff0fe8f1..aeccecdba 100644 --- a/src/main/java/net/minecraftforge/fml/client/SplashProgress.java +++ b/src/main/java/net/minecraftforge/fml/client/SplashProgress.java @@ -23,6 +23,7 @@ import static org.lwjgl.opengl.GL12.*; import java.awt.image.BufferedImage; +import java.io.Closeable; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream;