diff options
author | isXander <xandersmith2008@gmail.com> | 2023-05-25 22:07:13 +0100 |
---|---|---|
committer | isXander <xandersmith2008@gmail.com> | 2023-05-25 22:07:13 +0100 |
commit | f40bd6fef7d5a6a718f89014149da80f201787f3 (patch) | |
tree | 4a1c1d158db78b1f65035aabbe5e01675ac81101 /common/src | |
parent | c3f1e6836ea0fbbe5944125a121606aad849d9b4 (diff) | |
download | YetAnotherConfigLib-f40bd6fef7d5a6a718f89014149da80f201787f3.tar.gz YetAnotherConfigLib-f40bd6fef7d5a6a718f89014149da80f201787f3.tar.bz2 YetAnotherConfigLib-f40bd6fef7d5a6a718f89014149da80f201787f3.zip |
Synchronously generate ImageRenderer off-thread
Diffstat (limited to 'common/src')
-rw-r--r-- | common/src/main/java/dev/isxander/yacl/gui/ImageRenderer.java | 3 | ||||
-rw-r--r-- | common/src/main/java/dev/isxander/yacl/impl/utils/YACLConstants.java | 5 |
2 files changed, 7 insertions, 1 deletions
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<ResourceLocation, CompletableFuture<Optional<ImageRenderer>>> CACHE = new ConcurrentHashMap<>(); static CompletableFuture<Optional<ImageRenderer>> getOrMakeAsync(ResourceLocation id, Supplier<Optional<ImageRenderer>> factory) { - return CACHE.computeIfAbsent(id, key -> CompletableFuture.supplyAsync(factory)); + return CACHE.computeIfAbsent(id, key -> CompletableFuture.supplyAsync(factory, YACLConstants.SINGLE_THREAD_EXECUTOR)); } static CompletableFuture<Optional<ImageRenderer>> getOrMakeSync(ResourceLocation id, Supplier<Optional<ImageRenderer>> 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(); } |