From c9718b0a1bc4bca17922b0f05f61cec0ef0daa87 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Fri, 30 Apr 2021 00:31:52 -0700 Subject: [PATCH] No more compartments in Flywheel. It never really needed them in the first place. --- .../foundation/render/backend/RenderUtil.java | 19 +++++- .../backend/instancing/RenderMaterial.java | 59 +++++-------------- 2 files changed, 33 insertions(+), 45 deletions(-) diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/RenderUtil.java b/src/main/java/com/simibubi/create/foundation/render/backend/RenderUtil.java index 43058e362..9ed534cde 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/RenderUtil.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/RenderUtil.java @@ -1,7 +1,12 @@ package com.simibubi.create.foundation.render.backend; -import com.mojang.blaze3d.matrix.MatrixStack; +import java.util.function.Supplier; +import com.mojang.blaze3d.matrix.MatrixStack; +import com.simibubi.create.foundation.utility.AngleHelper; +import com.simibubi.create.foundation.utility.MatrixStacker; + +import net.minecraft.util.Direction; import net.minecraft.util.math.vector.Matrix3f; import net.minecraft.util.math.vector.Matrix4f; @@ -71,4 +76,16 @@ public class RenderUtil { model.a33, }; } + + public static Supplier rotateToFace(Direction facing) { + return () -> { + MatrixStack stack = new MatrixStack(); + MatrixStacker.of(stack) + .centre() + .rotateY(AngleHelper.horizontalAngle(facing)) + .rotateX(AngleHelper.verticalAngle(facing)) + .unCentre(); + return stack; + }; + } } diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/RenderMaterial.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/RenderMaterial.java index d91077e2b..9458f4f6a 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/RenderMaterial.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/RenderMaterial.java @@ -1,9 +1,5 @@ package com.simibubi.create.foundation.render.backend.instancing; -import static com.simibubi.create.foundation.render.Compartment.PARTIAL; - -import java.util.HashMap; -import java.util.Map; import java.util.concurrent.ExecutionException; import java.util.function.Consumer; import java.util.function.Predicate; @@ -14,16 +10,14 @@ import org.apache.commons.lang3.tuple.Pair; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import com.mojang.blaze3d.matrix.MatrixStack; -import com.simibubi.create.foundation.render.Compartment; import com.simibubi.create.foundation.render.SuperByteBufferCache; import com.simibubi.create.foundation.render.backend.Backend; import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; +import com.simibubi.create.foundation.render.backend.RenderUtil; import com.simibubi.create.foundation.render.backend.core.PartialModel; import com.simibubi.create.foundation.render.backend.gl.BasicProgram; import com.simibubi.create.foundation.render.backend.gl.shader.ProgramSpec; import com.simibubi.create.foundation.render.backend.gl.shader.ShaderCallback; -import com.simibubi.create.foundation.utility.AngleHelper; -import com.simibubi.create.foundation.utility.MatrixStacker; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; @@ -37,7 +31,7 @@ import net.minecraft.util.math.vector.Matrix4f; public class RenderMaterial

> { protected final InstancedTileRenderer renderer; - protected final Map, Cache> models; + protected final Cache models; protected final ModelFactory factory; protected final ProgramSpec

programSpec; protected final Predicate layerPredicate; @@ -51,13 +45,12 @@ public class RenderMaterial

renderer, ProgramSpec

programSpec, ModelFactory factory, Predicate layerPredicate) { this.renderer = renderer; - this.models = new HashMap<>(); + this.models = CacheBuilder.newBuilder() + .removalListener(notification -> ((InstancedModel) notification.getValue()).delete()) + .build(); this.factory = factory; this.programSpec = programSpec; this.layerPredicate = layerPredicate; - registerCompartment(Compartment.PARTIAL); - registerCompartment(Compartment.DIRECTIONAL_PARTIAL); - registerCompartment(Compartment.GENERIC_TILE); } public boolean canRenderInLayer(RenderType layer) { @@ -75,15 +68,11 @@ public class RenderMaterial

f) { - for (Cache cache : models.values()) { - for (MODEL model : cache.asMap().values()) { - f.accept(model); - } + for (MODEL model : models.asMap().values()) { + f.accept(model); } } - public void registerCompartment(Compartment instance) { - models.put(instance, CacheBuilder.newBuilder().build()); - } - public MODEL getModel(PartialModel partial, BlockState referenceState) { - return get(PARTIAL, partial, () -> buildModel(partial.get(), referenceState)); + return get(partial, () -> buildModel(partial.get(), referenceState)); } public MODEL getModel(PartialModel partial, BlockState referenceState, Direction dir) { - return getModel(partial, referenceState, dir, rotateToFace(dir)); + return getModel(partial, referenceState, dir, RenderUtil.rotateToFace(dir)); } public MODEL getModel(PartialModel partial, BlockState referenceState, Direction dir, Supplier modelTransform) { - return get(Compartment.DIRECTIONAL_PARTIAL, Pair.of(dir, partial), + return get(Pair.of(dir, partial), () -> buildModel(partial.get(), referenceState, modelTransform.get())); } public MODEL getModel(BlockState toRender) { - return get(Compartment.GENERIC_TILE, toRender, () -> buildModel(toRender)); + return get(toRender, () -> buildModel(toRender)); } - public MODEL get(Compartment compartment, T key, Supplier supplier) { - Cache compartmentCache = models.get(compartment); + public MODEL get(Object key, Supplier supplier) { try { - return compartmentCache.get(key, supplier::get); + return models.get(key, supplier::get); } catch (ExecutionException e) { e.printStackTrace(); return null; @@ -144,15 +126,4 @@ public class RenderMaterial

rotateToFace(Direction facing) { - return () -> { - MatrixStack stack = new MatrixStack(); - MatrixStacker.of(stack) - .centre() - .rotateY(AngleHelper.horizontalAngle(facing)) - .rotateX(AngleHelper.verticalAngle(facing)) - .unCentre(); - return stack; - }; - } }