More improvements to async model loading, but still crashes sometimes
This commit is contained in:
parent
eb99ce47d8
commit
08fd01c09f
|
|
@ -27,6 +27,8 @@ import java.util.concurrent.CompletableFuture;
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.embeddedt.modernfix.ModernFix.LOGGER;
|
||||
|
||||
@Mixin(ModelBakery.class)
|
||||
public abstract class ModelBakeryMixin {
|
||||
@Shadow @Final private Map<ResourceLocation, IUnbakedModel> topLevelModels;
|
||||
|
|
@ -35,8 +37,6 @@ public abstract class ModelBakeryMixin {
|
|||
|
||||
@Shadow @Deprecated @Nullable public abstract IBakedModel bake(ResourceLocation pLocation, IModelTransform pTransform);
|
||||
|
||||
@Shadow @Final private static Logger LOGGER;
|
||||
|
||||
@Shadow private Map<ResourceLocation, Pair<AtlasTexture, AtlasTexture.SheetData>> atlasPreparations;
|
||||
|
||||
@Shadow @Nullable private SpriteMap atlasSet;
|
||||
|
|
@ -78,7 +78,7 @@ public abstract class ModelBakeryMixin {
|
|||
}));
|
||||
List<Map.Entry<ResourceLocation, IUnbakedModel>> serialModels = this.modelsToBakeParallel.get(false);
|
||||
List<Map.Entry<ResourceLocation, IUnbakedModel>> parallelModels = this.modelsToBakeParallel.get(true);
|
||||
ModernFix.LOGGER.debug("Collected "
|
||||
LOGGER.debug("Collected "
|
||||
+ serialModels.size()
|
||||
+ " serial models, "
|
||||
+ parallelModels.size()
|
||||
|
|
|
|||
|
|
@ -150,36 +150,6 @@ public abstract class ModelBakeryMixin {
|
|||
useModelCache = false;
|
||||
}
|
||||
|
||||
@Redirect(method = "processLoading", at = @At(value = "INVOKE", target = "Ljava/util/stream/Stream;collect(Ljava/util/stream/Collector;)Ljava/lang/Object;", ordinal = 0), remap = false)
|
||||
private Object collectTexturesParallel(Stream instance, Collector arCollector) {
|
||||
ModernFix.LOGGER.warn("Collecting textures in parallel...");
|
||||
Stopwatch stopwatch = Stopwatch.createStarted();
|
||||
ConcurrentHashMap<ResourceLocation, IUnbakedModel> threadedunbakedCache = new ConcurrentHashMap<>(this.unbakedCache);
|
||||
Function<ResourceLocation, IUnbakedModel> safeUnbakedGetter = (location) -> {
|
||||
IUnbakedModel candidate = threadedunbakedCache.get(location);
|
||||
if(candidate == null) {
|
||||
synchronized (this.unbakedCache) {
|
||||
candidate = this.getModel(location);
|
||||
threadedunbakedCache.put(location, candidate);
|
||||
}
|
||||
}
|
||||
return candidate;
|
||||
};
|
||||
Set<Pair<String, String>> set = Collections.synchronizedSet(Sets.newLinkedHashSet());
|
||||
String modelMissingString = MISSING_MODEL_LOCATION.toString();
|
||||
Set<RenderMaterial> materials = this.topLevelModels.values().parallelStream().flatMap((unbaked) -> {
|
||||
return unbaked.getMaterials(safeUnbakedGetter, set).stream();
|
||||
}).collect(Collectors.toSet());
|
||||
set.stream().filter((stringPair) -> {
|
||||
return !stringPair.getSecond().equals(modelMissingString);
|
||||
}).forEach((textureReferenceErrors) -> {
|
||||
ModernFix.LOGGER.warn("Unable to resolve texture reference: {} in {}", textureReferenceErrors.getFirst(), textureReferenceErrors.getSecond());
|
||||
});
|
||||
ModernFix.LOGGER.warn("Collecting textures took " + stopwatch.elapsed(TimeUnit.MILLISECONDS)/1000f + " seconds");
|
||||
stopwatch.stop();
|
||||
return materials;
|
||||
}
|
||||
|
||||
private List<?> replacementList = null;
|
||||
|
||||
@Redirect(method = "loadModel", at = @At(value = "INVOKE", target = "Lnet/minecraft/resources/IResourceManager;getResources(Lnet/minecraft/util/ResourceLocation;)Ljava/util/List;", ordinal = 0))
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user