mirror of
https://github.com/xfl03/MCCustomSkinLoader.git
synced 2026-11-20 15:49:40 +00:00
Allow users to customize the size of thread pools. (#86)
* Increase compatible Java version to 8. * Support Forge & Fabric 1.15.2 * Fix lag spike while loading player skull textures. * Allow users to customize the size of thread pools. * Use the old scheme about loading skulls to avoid blocking the thread pool when "enableUpdateSkull" is true. * Fix merge.
This commit is contained in:
1 parent
8b1400ef0d
commit
a9f19cfc8d
3 files changed
+12
-13
No files matched your search
@@ -2,8 +2,7 @@ package customskinloader;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.LinkedBlockingDeque;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -55,7 +54,7 @@ public class CustomSkinLoader {
|
||||
private static final ProfileCache profileCache=new ProfileCache();
|
||||
private static final DynamicSkullManager dynamicSkullManager=new DynamicSkullManager();
|
||||
|
||||
private static final ThreadPoolExecutor threadPool = new ThreadPoolExecutor(3, 33, 3, TimeUnit.MINUTES, new LinkedBlockingDeque<>(333), Executors.defaultThreadFactory(), new ThreadPoolExecutor.DiscardOldestPolicy());
|
||||
private static final ThreadPoolExecutor threadPool = new ThreadPoolExecutor(config.threadPoolSize, config.threadPoolSize, 1L, TimeUnit.MINUTES, new LinkedBlockingQueue<>());
|
||||
|
||||
//For User Skin
|
||||
public static Map<Type, MinecraftProfileTexture> loadProfile(GameProfile gameProfile){
|
||||
@@ -168,12 +167,17 @@ public class CustomSkinLoader {
|
||||
}
|
||||
if (!profileCache.isLoading(credential)) {
|
||||
profileCache.setLoading(credential, true);
|
||||
threadPool.execute(() -> {
|
||||
Runnable loadThread = () -> {
|
||||
String tempName = Thread.currentThread().getName();
|
||||
Thread.currentThread().setName(username + "'s skull");
|
||||
loadProfile0(gameProfile);//Load in thread
|
||||
Thread.currentThread().setName(tempName);
|
||||
});
|
||||
};
|
||||
if (config.enableUpdateSkull) {
|
||||
new Thread(loadThread).start();
|
||||
} else {
|
||||
threadPool.execute(loadThread);
|
||||
}
|
||||
}
|
||||
return Maps.newHashMap();
|
||||
}
|
||||
@@ -185,8 +189,4 @@ public class CustomSkinLoader {
|
||||
logger.info("Minecraft: "+MinecraftUtil.getMinecraftMainVersion()+"("+MinecraftUtil.getMinecraftVersionText()+")");
|
||||
return logger;
|
||||
}
|
||||
|
||||
public static void initStatic(){
|
||||
//Do nothing
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ public class Config {
|
||||
public boolean ignoreHttpsCertificate=false;
|
||||
public boolean forceLoadAllTextures=false;
|
||||
public boolean enableCape = true;
|
||||
public int threadPoolSize = 1;
|
||||
|
||||
//Cache
|
||||
public int cacheExpiry=30;
|
||||
@@ -56,6 +57,7 @@ public class Config {
|
||||
//Init program
|
||||
config.loadExtraList();
|
||||
config.initLocalFolder();
|
||||
config.threadPoolSize = Math.max(config.threadPoolSize, 1);
|
||||
if(config.ignoreHttpsCertificate)
|
||||
HttpUtil0.ignoreHttpsCertificate();
|
||||
if(config.enableCacheAutoClean && !config.enableLocalProfileCache){
|
||||
|
||||
@@ -31,7 +31,7 @@ import net.minecraft.client.resources.SkinManager.SkinAvailableCallback;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class FakeSkinManager {
|
||||
private static final ExecutorService THREAD_POOL = new ThreadPoolExecutor(0, 2, 1L, TimeUnit.MINUTES, new LinkedBlockingQueue<Runnable>());
|
||||
private static final ExecutorService THREAD_POOL = new ThreadPoolExecutor(CustomSkinLoader.config.threadPoolSize, CustomSkinLoader.config.threadPoolSize, 1L, TimeUnit.MINUTES, new LinkedBlockingQueue<>());
|
||||
private final TextureManager textureManager;
|
||||
|
||||
private final Map<ResourceLocation, MinecraftProfileTexture> modelCache = new HashMap<>();
|
||||
@@ -39,9 +39,6 @@ public class FakeSkinManager {
|
||||
public FakeSkinManager(TextureManager textureManagerInstance, File skinCacheDirectory, MinecraftSessionService sessionService) {
|
||||
this.textureManager = textureManagerInstance;
|
||||
HttpTextureUtil.defaultCacheDir = skinCacheDirectory;
|
||||
|
||||
//Init CustomSkinLoader earlier
|
||||
CustomSkinLoader.initStatic();
|
||||
}
|
||||
|
||||
public ResourceLocation loadSkin(MinecraftProfileTexture profileTexture, Type textureType) {
|
||||
|
||||
Reference in new issue
Block a user