Merge remote-tracking branch 'origin/1.18' into 1.19.2
This commit is contained in:
commit
2de8f02814
|
|
@ -0,0 +1,18 @@
|
||||||
|
package org.embeddedt.modernfix.common.mixin.perf.resourcepacks;
|
||||||
|
|
||||||
|
import net.minecraft.server.packs.resources.ReloadableResourceManager;
|
||||||
|
import org.embeddedt.modernfix.ModernFix;
|
||||||
|
import org.embeddedt.modernfix.resources.PackResourcesCacheEngine;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
@Mixin(ReloadableResourceManager.class)
|
||||||
|
public class ReloadableResourceManagerMixin {
|
||||||
|
@Inject(method = "createReload", at = @At("HEAD"))
|
||||||
|
private void invalidateResourceCaches(CallbackInfoReturnable<?> cir) {
|
||||||
|
ModernFix.LOGGER.info("Invalidating pack caches");
|
||||||
|
PackResourcesCacheEngine.invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
package org.embeddedt.modernfix.resources;
|
||||||
|
|
||||||
|
public interface ICachingResourcePack {
|
||||||
|
void invalidateCache();
|
||||||
|
}
|
||||||
|
|
@ -154,4 +154,20 @@ public class PackResourcesCacheEngine {
|
||||||
}
|
}
|
||||||
return resources;
|
return resources;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final WeakHashMap<ICachingResourcePack, Boolean> cachingPacks = new WeakHashMap<>();
|
||||||
|
public static void track(ICachingResourcePack pack) {
|
||||||
|
synchronized (cachingPacks) {
|
||||||
|
cachingPacks.put(pack, Boolean.TRUE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void invalidate() {
|
||||||
|
synchronized (cachingPacks) {
|
||||||
|
cachingPacks.keySet().forEach(pack -> {
|
||||||
|
if(pack != null)
|
||||||
|
pack.invalidateCache();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package org.embeddedt.modernfix.fabric.mixin.perf.fabric_resourcepacks;
|
package org.embeddedt.modernfix.fabric.mixin.perf.resourcepacks;
|
||||||
|
|
||||||
import net.fabricmc.fabric.impl.resource.loader.ModNioResourcePack;
|
import net.fabricmc.fabric.impl.resource.loader.ModNioResourcePack;
|
||||||
import net.fabricmc.loader.api.metadata.ModMetadata;
|
import net.fabricmc.loader.api.metadata.ModMetadata;
|
||||||
|
|
@ -6,6 +6,7 @@ import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.packs.PackType;
|
import net.minecraft.server.packs.PackType;
|
||||||
import org.embeddedt.modernfix.ModernFix;
|
import org.embeddedt.modernfix.ModernFix;
|
||||||
import org.embeddedt.modernfix.annotation.RequiresMod;
|
import org.embeddedt.modernfix.annotation.RequiresMod;
|
||||||
|
import org.embeddedt.modernfix.resources.ICachingResourcePack;
|
||||||
import org.embeddedt.modernfix.resources.PackResourcesCacheEngine;
|
import org.embeddedt.modernfix.resources.PackResourcesCacheEngine;
|
||||||
import org.spongepowered.asm.mixin.Final;
|
import org.spongepowered.asm.mixin.Final;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
|
@ -23,7 +24,7 @@ import java.util.Set;
|
||||||
|
|
||||||
@Mixin(ModNioResourcePack.class)
|
@Mixin(ModNioResourcePack.class)
|
||||||
@RequiresMod("fabric-resource-loader-v0")
|
@RequiresMod("fabric-resource-loader-v0")
|
||||||
public abstract class ModNioResourcePackMixin {
|
public abstract class ModNioResourcePackMixin implements ICachingResourcePack {
|
||||||
@Shadow public abstract Set<String> getNamespaces(PackType type);
|
@Shadow public abstract Set<String> getNamespaces(PackType type);
|
||||||
|
|
||||||
@Shadow @Final private List<Path> basePaths;
|
@Shadow @Final private List<Path> basePaths;
|
||||||
|
|
@ -32,6 +33,13 @@ public abstract class ModNioResourcePackMixin {
|
||||||
|
|
||||||
@Inject(method = "<init>", at = @At("RETURN"))
|
@Inject(method = "<init>", at = @At("RETURN"))
|
||||||
private void cacheResources(CallbackInfo ci) {
|
private void cacheResources(CallbackInfo ci) {
|
||||||
|
invalidateCache();
|
||||||
|
PackResourcesCacheEngine.track(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void invalidateCache() {
|
||||||
|
this.cacheEngine = null;
|
||||||
if(this.basePaths.size() == 1) {
|
if(this.basePaths.size() == 1) {
|
||||||
Path basePath = this.basePaths.get(0);
|
Path basePath = this.basePaths.get(0);
|
||||||
this.cacheEngine = new PackResourcesCacheEngine(this::getNamespaces, (type, namespace) -> {
|
this.cacheEngine = new PackResourcesCacheEngine(this::getNamespaces, (type, namespace) -> {
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
package org.embeddedt.modernfix.forge.mixin.perf.resourcepacks;
|
package org.embeddedt.modernfix.forge.mixin.perf.resourcepacks;
|
||||||
|
|
||||||
import net.minecraft.server.packs.PackType;
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.server.packs.PackType;
|
||||||
import net.minecraftforge.resource.PathPackResources;
|
import net.minecraftforge.resource.PathPackResources;
|
||||||
|
import org.embeddedt.modernfix.resources.ICachingResourcePack;
|
||||||
import org.embeddedt.modernfix.resources.PackResourcesCacheEngine;
|
import org.embeddedt.modernfix.resources.PackResourcesCacheEngine;
|
||||||
import org.embeddedt.modernfix.util.PackTypeHelper;
|
import org.embeddedt.modernfix.util.PackTypeHelper;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
@ -13,8 +14,9 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
import java.nio.file.*;
|
import java.nio.file.Path;
|
||||||
import java.util.*;
|
import java.util.Collection;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -23,7 +25,7 @@ import java.util.function.Predicate;
|
||||||
* and 1.18.
|
* and 1.18.
|
||||||
*/
|
*/
|
||||||
@Mixin(PathPackResources.class)
|
@Mixin(PathPackResources.class)
|
||||||
public abstract class ModFileResourcePackMixin {
|
public abstract class ModFileResourcePackMixin implements ICachingResourcePack {
|
||||||
@Shadow protected abstract Path resolve(String... paths);
|
@Shadow protected abstract Path resolve(String... paths);
|
||||||
|
|
||||||
@Shadow @NotNull
|
@Shadow @NotNull
|
||||||
|
|
@ -33,21 +35,30 @@ public abstract class ModFileResourcePackMixin {
|
||||||
|
|
||||||
@Inject(method = "<init>", at = @At("TAIL"))
|
@Inject(method = "<init>", at = @At("TAIL"))
|
||||||
private void cacheResources(String packName, Path source, CallbackInfo ci) {
|
private void cacheResources(String packName, Path source, CallbackInfo ci) {
|
||||||
this.cacheEngine = null;
|
invalidateCache();
|
||||||
|
PackResourcesCacheEngine.track(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateResourceCache() {
|
private PackResourcesCacheEngine generateResourceCache() {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if(this.cacheEngine != null)
|
PackResourcesCacheEngine engine = this.cacheEngine;
|
||||||
return;
|
if(engine != null)
|
||||||
this.cacheEngine = new PackResourcesCacheEngine(this::getNamespacesFromDisk, (type, namespace) -> this.resolve(type.getDirectory(), namespace));
|
return engine;
|
||||||
|
this.cacheEngine = engine = new PackResourcesCacheEngine(this::getNamespacesFromDisk, (type, namespace) -> this.resolve(type.getDirectory(), namespace));
|
||||||
|
return engine;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void invalidateCache() {
|
||||||
|
this.cacheEngine = null;
|
||||||
|
}
|
||||||
|
|
||||||
@Inject(method = "getNamespaces", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "getNamespaces", at = @At("HEAD"), cancellable = true)
|
||||||
private void useCacheForNamespaces(PackType type, CallbackInfoReturnable<Set<String>> cir) {
|
private void useCacheForNamespaces(PackType type, CallbackInfoReturnable<Set<String>> cir) {
|
||||||
if(cacheEngine != null) {
|
PackResourcesCacheEngine engine = cacheEngine;
|
||||||
Set<String> namespaces = cacheEngine.getNamespaces(type);
|
if(engine != null) {
|
||||||
|
Set<String> namespaces = engine.getNamespaces(type);
|
||||||
if(namespaces != null)
|
if(namespaces != null)
|
||||||
cir.setReturnValue(namespaces);
|
cir.setReturnValue(namespaces);
|
||||||
}
|
}
|
||||||
|
|
@ -55,9 +66,9 @@ public abstract class ModFileResourcePackMixin {
|
||||||
|
|
||||||
@Inject(method = "hasResource(Ljava/lang/String;)Z", at = @At(value = "HEAD"), cancellable = true)
|
@Inject(method = "hasResource(Ljava/lang/String;)Z", at = @At(value = "HEAD"), cancellable = true)
|
||||||
private void useCacheForExistence(String path, CallbackInfoReturnable<Boolean> cir) {
|
private void useCacheForExistence(String path, CallbackInfoReturnable<Boolean> cir) {
|
||||||
this.generateResourceCache();
|
PackResourcesCacheEngine engine = this.generateResourceCache();
|
||||||
if(cacheEngine != null)
|
if(engine != null)
|
||||||
cir.setReturnValue(this.cacheEngine.hasResource(path));
|
cir.setReturnValue(engine.hasResource(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -69,7 +80,6 @@ public abstract class ModFileResourcePackMixin {
|
||||||
{
|
{
|
||||||
if(!PackTypeHelper.isVanillaPackType(type) || this.cacheEngine == null)
|
if(!PackTypeHelper.isVanillaPackType(type) || this.cacheEngine == null)
|
||||||
return;
|
return;
|
||||||
this.generateResourceCache();
|
cir.setReturnValue(this.generateResourceCache().getResources(type, resourceNamespace, pathIn, Integer.MAX_VALUE, filter));
|
||||||
cir.setReturnValue(this.cacheEngine.getResources(type, resourceNamespace, pathIn, Integer.MAX_VALUE, filter));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user