From ddcc96e52a950a607ad2809940635e5e5c9599dc Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Tue, 24 Dec 2024 16:44:29 -0800 Subject: [PATCH] Cover me! - Switch ResourceReloadCache to RendererReloadCache --- .../dev/engine_room/flywheel/lib/model/Models.java | 8 ++++---- .../engine_room/flywheel/lib/model/part/MeshTree.java | 4 ++-- .../flywheel/lib/model/part/ModelTrees.java | 4 ++-- ...sourceReloadCache.java => RendererReloadCache.java} | 10 +++++----- .../flywheel/lib/visual/component/FireComponent.java | 4 ++-- .../dev/engine_room/flywheel/impl/FlywheelFabric.java | 4 ++-- .../dev/engine_room/flywheel/impl/FlywheelForge.java | 4 ++-- 7 files changed, 19 insertions(+), 19 deletions(-) rename common/src/lib/java/dev/engine_room/flywheel/lib/util/{ResourceReloadCache.java => RendererReloadCache.java} (72%) diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/model/Models.java b/common/src/lib/java/dev/engine_room/flywheel/lib/model/Models.java index 9e0e3a813..18d8ffb19 100644 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/model/Models.java +++ b/common/src/lib/java/dev/engine_room/flywheel/lib/model/Models.java @@ -9,7 +9,7 @@ import dev.engine_room.flywheel.lib.model.baked.BlockModelBuilder; import dev.engine_room.flywheel.lib.model.baked.PartialModel; import dev.engine_room.flywheel.lib.transform.TransformStack; -import dev.engine_room.flywheel.lib.util.ResourceReloadCache; +import dev.engine_room.flywheel.lib.util.RendererReloadCache; import net.minecraft.core.Direction; import net.minecraft.world.level.block.state.BlockState; @@ -20,11 +20,11 @@ * method with the same parameters will return the same object. */ public final class Models { - private static final ResourceReloadCache BLOCK_STATE = new ResourceReloadCache<>(it -> BlockModelBuilder.create(it) + private static final RendererReloadCache BLOCK_STATE = new RendererReloadCache<>(it -> BlockModelBuilder.create(it) .build()); - private static final ResourceReloadCache PARTIAL = new ResourceReloadCache<>(it -> BakedModelBuilder.create(it.get()) + private static final RendererReloadCache PARTIAL = new RendererReloadCache<>(it -> BakedModelBuilder.create(it.get()) .build()); - private static final ResourceReloadCache, Model> TRANSFORMED_PARTIAL = new ResourceReloadCache<>(TransformedPartial::create); + private static final RendererReloadCache, Model> TRANSFORMED_PARTIAL = new RendererReloadCache<>(TransformedPartial::create); private Models() { } diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/model/part/MeshTree.java b/common/src/lib/java/dev/engine_room/flywheel/lib/model/part/MeshTree.java index 98c10fc0c..c79bb8c83 100644 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/model/part/MeshTree.java +++ b/common/src/lib/java/dev/engine_room/flywheel/lib/model/part/MeshTree.java @@ -11,7 +11,7 @@ import dev.engine_room.flywheel.lib.internal.FlwLibLink; import dev.engine_room.flywheel.lib.memory.MemoryBlock; import dev.engine_room.flywheel.lib.model.SimpleQuadMesh; -import dev.engine_room.flywheel.lib.util.ResourceReloadCache; +import dev.engine_room.flywheel.lib.util.RendererReloadCache; import dev.engine_room.flywheel.lib.vertex.PosTexNormalVertexView; import dev.engine_room.flywheel.lib.vertex.VertexView; import net.minecraft.client.Minecraft; @@ -25,7 +25,7 @@ public final class MeshTree { private static final ThreadLocal THREAD_LOCAL_OBJECTS = ThreadLocal.withInitial(ThreadLocalObjects::new); private static final PoseStack.Pose IDENTITY_POSE = new PoseStack().last(); - private static final ResourceReloadCache CACHE = new ResourceReloadCache<>(MeshTree::convert); + private static final RendererReloadCache CACHE = new RendererReloadCache<>(MeshTree::convert); @Nullable private final Mesh mesh; diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/model/part/ModelTrees.java b/common/src/lib/java/dev/engine_room/flywheel/lib/model/part/ModelTrees.java index 7b9599f82..1f26053f4 100644 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/model/part/ModelTrees.java +++ b/common/src/lib/java/dev/engine_room/flywheel/lib/model/part/ModelTrees.java @@ -12,12 +12,12 @@ import dev.engine_room.flywheel.api.model.Model; import dev.engine_room.flywheel.lib.model.RetexturedMesh; import dev.engine_room.flywheel.lib.model.SingleMeshModel; -import dev.engine_room.flywheel.lib.util.ResourceReloadCache; +import dev.engine_room.flywheel.lib.util.RendererReloadCache; import net.minecraft.client.model.geom.ModelLayerLocation; import net.minecraft.client.renderer.texture.TextureAtlasSprite; public final class ModelTrees { - private static final ResourceReloadCache CACHE = new ResourceReloadCache<>(k -> { + private static final RendererReloadCache CACHE = new RendererReloadCache<>(k -> { ModelTree tree = convert("", MeshTree.of(k.layer), k.pathsToPrune, k.texture != null ? k.texture.sprite() : null, k.material); if (tree == null) { diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/util/ResourceReloadCache.java b/common/src/lib/java/dev/engine_room/flywheel/lib/util/RendererReloadCache.java similarity index 72% rename from common/src/lib/java/dev/engine_room/flywheel/lib/util/ResourceReloadCache.java rename to common/src/lib/java/dev/engine_room/flywheel/lib/util/RendererReloadCache.java index dcacb38d3..2bee75275 100644 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/util/ResourceReloadCache.java +++ b/common/src/lib/java/dev/engine_room/flywheel/lib/util/RendererReloadCache.java @@ -9,12 +9,12 @@ import org.jetbrains.annotations.ApiStatus; -public final class ResourceReloadCache implements Function { - private static final Set> ALL = Collections.newSetFromMap(new WeakHashMap<>()); +public final class RendererReloadCache implements Function { + private static final Set> ALL = Collections.newSetFromMap(new WeakHashMap<>()); private final Function factory; private final Map map = new ConcurrentHashMap<>(); - public ResourceReloadCache(Function factory) { + public RendererReloadCache(Function factory) { this.factory = factory; synchronized (ALL) { @@ -36,8 +36,8 @@ public final void clear() { } @ApiStatus.Internal - public static void onEndClientResourceReload() { - for (ResourceReloadCache cache : ALL) { + public static void onReloadLevelRenderer() { + for (RendererReloadCache cache : ALL) { cache.clear(); } } diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/visual/component/FireComponent.java b/common/src/lib/java/dev/engine_room/flywheel/lib/visual/component/FireComponent.java index 0e0cb8301..884ba3bf5 100644 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/visual/component/FireComponent.java +++ b/common/src/lib/java/dev/engine_room/flywheel/lib/visual/component/FireComponent.java @@ -17,7 +17,7 @@ import dev.engine_room.flywheel.lib.material.SimpleMaterial; import dev.engine_room.flywheel.lib.model.QuadMesh; import dev.engine_room.flywheel.lib.model.SingleMeshModel; -import dev.engine_room.flywheel.lib.util.ResourceReloadCache; +import dev.engine_room.flywheel.lib.util.RendererReloadCache; import dev.engine_room.flywheel.lib.visual.util.SmartRecycler; import net.minecraft.client.renderer.LightTexture; import net.minecraft.client.renderer.texture.TextureAtlasSprite; @@ -36,7 +36,7 @@ public final class FireComponent implements EntityComponent { // Parameterize by the material instead of the sprite // because Material#sprite is a surprisingly heavy operation // and because sprites are invalidated after a resource reload. - private static final ResourceReloadCache FIRE_MODELS = new ResourceReloadCache<>(texture -> { + private static final RendererReloadCache FIRE_MODELS = new RendererReloadCache<>(texture -> { return new SingleMeshModel(new FireMesh(texture.sprite()), FIRE_MATERIAL); }); diff --git a/fabric/src/main/java/dev/engine_room/flywheel/impl/FlywheelFabric.java b/fabric/src/main/java/dev/engine_room/flywheel/impl/FlywheelFabric.java index 50d5129a9..f7ba7914b 100644 --- a/fabric/src/main/java/dev/engine_room/flywheel/impl/FlywheelFabric.java +++ b/fabric/src/main/java/dev/engine_room/flywheel/impl/FlywheelFabric.java @@ -9,7 +9,7 @@ import dev.engine_room.flywheel.backend.engine.uniform.Uniforms; import dev.engine_room.flywheel.impl.visualization.VisualizationEventHandler; import dev.engine_room.flywheel.lib.model.baked.PartialModelEventHandler; -import dev.engine_room.flywheel.lib.util.ResourceReloadCache; +import dev.engine_room.flywheel.lib.util.RendererReloadCache; import dev.engine_room.flywheel.lib.util.ResourceReloadHolder; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; @@ -66,7 +66,7 @@ private static void setupImpl() { } private static void setupLib() { - EndClientResourceReloadCallback.EVENT.register((minecraft, resourceManager, initialReload, error) -> ResourceReloadCache.onEndClientResourceReload()); + ReloadLevelRendererCallback.EVENT.register(level -> RendererReloadCache.onReloadLevelRenderer()); EndClientResourceReloadCallback.EVENT.register((minecraft, resourceManager, initialReload, error) -> ResourceReloadHolder.onEndClientResourceReload()); ModelLoadingPlugin.register(ctx -> { diff --git a/forge/src/main/java/dev/engine_room/flywheel/impl/FlywheelForge.java b/forge/src/main/java/dev/engine_room/flywheel/impl/FlywheelForge.java index cb8874dab..f91023871 100644 --- a/forge/src/main/java/dev/engine_room/flywheel/impl/FlywheelForge.java +++ b/forge/src/main/java/dev/engine_room/flywheel/impl/FlywheelForge.java @@ -12,7 +12,7 @@ import dev.engine_room.flywheel.impl.visualization.VisualizationEventHandler; import dev.engine_room.flywheel.lib.model.baked.PartialModelEventHandler; import dev.engine_room.flywheel.lib.util.LevelAttached; -import dev.engine_room.flywheel.lib.util.ResourceReloadCache; +import dev.engine_room.flywheel.lib.util.RendererReloadCache; import dev.engine_room.flywheel.lib.util.ResourceReloadHolder; import net.minecraft.client.Minecraft; import net.minecraft.commands.synchronization.ArgumentTypeInfos; @@ -111,7 +111,7 @@ private static void registerImplEventListeners(IEventBus forgeEventBus, IEventBu private static void registerLibEventListeners(IEventBus forgeEventBus, IEventBus modEventBus) { forgeEventBus.addListener((LevelEvent.Unload e) -> LevelAttached.invalidateLevel(e.getLevel())); - modEventBus.addListener((EndClientResourceReloadEvent e) -> ResourceReloadCache.onEndClientResourceReload()); + modEventBus.addListener((EndClientResourceReloadEvent e) -> RendererReloadCache.onReloadLevelRenderer()); modEventBus.addListener((EndClientResourceReloadEvent e) -> ResourceReloadHolder.onEndClientResourceReload()); modEventBus.addListener(PartialModelEventHandler::onRegisterAdditional);