Merge remote-tracking branch 'origin/1.18' into 1.19.2

This commit is contained in:
embeddedt 2023-04-27 12:15:58 -04:00
commit ba830aee5a
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
3 changed files with 66 additions and 0 deletions

View File

@ -75,6 +75,7 @@ public class ModernFixEarlyConfig {
this.addMixinRule("perf.datapack_reload_exceptions", true);
this.addMixinRule("perf.faster_texture_stitching", true);
this.addMixinRule("perf.faster_texture_loading", true);
this.addMixinRule("perf.faster_font_loading", true);
/* off by default in 1.18 because it doesn't work as well */
this.addMixinRule("perf.faster_singleplayer_load", false);
/* Keep this off if JEI/REI isn't installed to prevent breaking vanilla gameplay */

View File

@ -0,0 +1,64 @@
package org.embeddedt.modernfix.mixin.perf.faster_font_loading;
import com.mojang.blaze3d.platform.NativeImage;
import net.minecraft.client.gui.font.providers.LegacyUnicodeBitmapsProvider;
import net.minecraft.resources.ResourceLocation;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
/**
* Objective: avoid recomputing locations many times, as well as loading all the font sheets in the constructor
* only to do it again later.
*/
@Mixin(LegacyUnicodeBitmapsProvider.class)
public abstract class LegacyUnicodeBitmapsProviderMixin {
@Shadow protected abstract ResourceLocation getSheetLocation(int i);
@Shadow @Final private Map<ResourceLocation, NativeImage> textures;
private final ResourceLocation[] glyphLocations = new ResourceLocation[256];
private ResourceLocation currentCharIdx;
@Redirect(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/font/providers/LegacyUnicodeBitmapsProvider;getSheetLocation(I)Lnet/minecraft/resources/ResourceLocation;"))
private ResourceLocation storeCurrentCharIdx(LegacyUnicodeBitmapsProvider provider, int i) {
ResourceLocation location = getSheetLocation(i);
currentCharIdx = location;
return location;
}
@Redirect(method = "<init>", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/platform/NativeImage;read(Lcom/mojang/blaze3d/platform/NativeImage$Format;Ljava/io/InputStream;)Lcom/mojang/blaze3d/platform/NativeImage;"))
private NativeImage storeLoadedFontSheet(NativeImage.Format format, InputStream stream) throws IOException {
NativeImage image = NativeImage.read(format, stream);
textures.put(currentCharIdx, image);
return image;
}
@Inject(method = "<init>", at = @At("RETURN"))
private void clearLocation(CallbackInfo ci) {
currentCharIdx = null;
}
@Inject(method = "getSheetLocation", at = @At("HEAD"), cancellable = true)
private void useCachedLocation(int idx, CallbackInfoReturnable<ResourceLocation> cir) {
int cachedIdx = idx / 256;
if(cachedIdx >= 0 && cachedIdx < glyphLocations.length && glyphLocations[cachedIdx] != null)
cir.setReturnValue(glyphLocations[cachedIdx]);
}
@Inject(method = "getSheetLocation", at = @At("RETURN"))
private void saveCachedLocation(int idx, CallbackInfoReturnable<ResourceLocation> cir) {
int cachedIdx = idx / 256;
if(cachedIdx >= 0 && cachedIdx < glyphLocations.length)
glyphLocations[cachedIdx] = cir.getReturnValue();
}
}

View File

@ -79,6 +79,7 @@
"perf.cache_model_materials.MultipartMixin",
"perf.faster_texture_stitching.StitcherMixin",
"perf.faster_texture_loading.TextureAtlasMixin",
"perf.faster_font_loading.LegacyUnicodeBitmapsProviderMixin",
"perf.skip_first_datapack_reload.CreateWorldScreenMixin",
"devenv.MinecraftMixin",
"devenv.NarratorMixin"