From f40bd6fef7d5a6a718f89014149da80f201787f3 Mon Sep 17 00:00:00 2001 From: isXander Date: Thu, 25 May 2023 22:07:13 +0100 Subject: Synchronously generate ImageRenderer off-thread --- common/src/main/java/dev/isxander/yacl/gui/ImageRenderer.java | 3 ++- common/src/main/java/dev/isxander/yacl/impl/utils/YACLConstants.java | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'common/src') diff --git a/common/src/main/java/dev/isxander/yacl/gui/ImageRenderer.java b/common/src/main/java/dev/isxander/yacl/gui/ImageRenderer.java index 26aacb7..25be791 100644 --- a/common/src/main/java/dev/isxander/yacl/gui/ImageRenderer.java +++ b/common/src/main/java/dev/isxander/yacl/gui/ImageRenderer.java @@ -3,6 +3,7 @@ package dev.isxander.yacl.gui; import com.mojang.blaze3d.Blaze3D; import com.mojang.blaze3d.platform.NativeImage; import com.twelvemonkeys.imageio.plugins.webp.WebPImageReaderSpi; +import dev.isxander.yacl.impl.utils.YACLConstants; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.renderer.texture.DynamicTexture; @@ -38,7 +39,7 @@ public interface ImageRenderer { Map>> CACHE = new ConcurrentHashMap<>(); static CompletableFuture> getOrMakeAsync(ResourceLocation id, Supplier> factory) { - return CACHE.computeIfAbsent(id, key -> CompletableFuture.supplyAsync(factory)); + return CACHE.computeIfAbsent(id, key -> CompletableFuture.supplyAsync(factory, YACLConstants.SINGLE_THREAD_EXECUTOR)); } static CompletableFuture> getOrMakeSync(ResourceLocation id, Supplier> factory) { diff --git a/common/src/main/java/dev/isxander/yacl/impl/utils/YACLConstants.java b/common/src/main/java/dev/isxander/yacl/impl/utils/YACLConstants.java index 3d382d4..7b84ee1 100644 --- a/common/src/main/java/dev/isxander/yacl/impl/utils/YACLConstants.java +++ b/common/src/main/java/dev/isxander/yacl/impl/utils/YACLConstants.java @@ -3,6 +3,11 @@ package dev.isxander.yacl.impl.utils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + public class YACLConstants { public static final Logger LOGGER = LoggerFactory.getLogger("YetAnotherConfigLib"); + + public static final ExecutorService SINGLE_THREAD_EXECUTOR = Executors.newSingleThreadExecutor(); } -- cgit