Wrap loadTexture in a executor.

Fixes #18
This commit is contained in:
Matthew Messinger 2016-11-10 17:34:59 -05:00
parent ab982a4125
commit 1fb6426bea

View file

@ -8,6 +8,8 @@ import java.net.URL;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -61,10 +63,11 @@ public final class HDSkinManager implements IResourceManagerReloadListener {
private List<ISkinModifier> skinModifiers = Lists.newArrayList(); private List<ISkinModifier> skinModifiers = Lists.newArrayList();
private SkinResourceManager resources = new SkinResourceManager(); private SkinResourceManager resources = new SkinResourceManager();
private ExecutorService executor = Executors.newCachedThreadPool();
public HDSkinManager() {} public HDSkinManager() {}
public Optional<ResourceLocation> getSkinLocation(GameProfile profile1, Type type, boolean loadIfAbsent) { public Optional<ResourceLocation> getSkinLocation(GameProfile profile1, final Type type, boolean loadIfAbsent) {
if (!enabled) if (!enabled)
return Optional.absent(); return Optional.absent();
@ -101,10 +104,15 @@ public final class HDSkinManager implements IResourceManagerReloadListener {
if (skin == null) { if (skin == null) {
if (loadIfAbsent) { if (loadIfAbsent) {
skinCache.get(profile.getId()).put(type, LOADING); skinCache.get(profile.getId()).put(type, LOADING);
loadTexture(profile, type, new SkinAvailableCallback() { executor.submit(new Runnable() {
@Override @Override
public void skinAvailable(Type type, ResourceLocation location, MinecraftProfileTexture profileTexture) { public void run() {
skinCache.get(profile.getId()).put(type, location); loadTexture(profile, type, new SkinAvailableCallback() {
@Override
public void skinAvailable(Type type, ResourceLocation location, MinecraftProfileTexture profileTexture) {
skinCache.get(profile.getId()).put(type, location);
}
});
} }
}); });
} }