From a2b9dfc28a38b11f7bebe7fe669922e9aebd48e9 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Tue, 30 Mar 2021 14:14:58 -0700 Subject: [PATCH] Change the locks - InstanceKey is no more. - InstanceData and co. keep track of removals and updates. - InstancedModel's buffer management is much more sane now. - Re-add mixin to #tickBlockEntities and ensure compat with Performant. - Move ...backend.instancing.impl to backend.core --- .../com/simibubi/create/AllBlockPartials.java | 6 +- .../contraptions/base/KineticData.java | 4 +- .../base/KineticRenderMaterials.java | 2 +- .../base/KineticTileInstance.java | 11 +- .../contraptions/base/RotatingData.java | 1 + .../contraptions/base/RotatingModel.java | 2 +- .../base/SingleRotatingInstance.java | 7 +- .../components/actors/ActorData.java | 8 + .../components/actors/DrillActorInstance.java | 11 +- .../actors/HarvesterActorInstance.java | 10 +- .../components/crank/HandCrankInstance.java | 9 +- .../deployer/DeployerActorInstance.java | 22 +- .../components/deployer/DeployerInstance.java | 24 +- .../components/fan/FanInstance.java | 14 +- .../components/flywheel/FlyWheelInstance.java | 34 +-- .../flywheel/engine/EngineInstance.java | 10 +- .../components/mixer/MixerInstance.java | 19 +- .../components/press/PressInstance.java | 16 +- .../structureMovement/ContraptionLighter.java | 2 +- .../chassis/StickerInstance.java | 9 +- .../gantry/GantryCarriageInstance.java | 9 +- .../render/ContraptionKineticRenderer.java | 10 +- .../fluids/pipes/FluidValveInstance.java | 9 +- .../contraptions/relays/belt/BeltData.java | 3 + .../relays/belt/BeltInstance.java | 24 +- .../relays/belt/BeltInstancedModel.java | 2 +- .../relays/encased/SplitShaftInstance.java | 11 +- .../relays/gauge/GaugeInstance.java | 20 +- .../relays/gearbox/GearboxInstance.java | 17 +- .../content/logistics/block/FlapData.java | 11 +- .../belts/tunnel/BeltTunnelInstance.java | 31 +-- .../block/depot/EjectorInstance.java | 10 +- .../diodes/AdjustableRepeaterInstance.java | 10 +- .../block/funnel/FunnelInstance.java | 15 +- .../block/mechanicalArm/ArmInstance.java | 43 ++- .../block/redstone/AnalogLeverInstance.java | 14 +- .../block/SchematicannonInstance.java | 12 +- .../create/foundation/mixin/TileAddMixin.java | 29 -- .../foundation/mixin/TileWorldHookMixin.java | 54 ++++ .../foundation/render/AllProgramSpecs.java | 8 +- .../foundation/render/KineticRenderer.java | 10 +- .../render/backend/MaterialType.java | 11 + ...enderMaterials.java => MaterialTypes.java} | 7 +- .../impl => core}/BasicAttributes.java | 2 +- .../{instancing/impl => core}/BasicData.java | 6 +- .../{instancing/impl => core}/IFlatLight.java | 2 +- .../impl => core}/ModelAttributes.java | 2 +- .../{instancing/impl => core}/ModelData.java | 3 +- .../impl => core}/OrientedAttributes.java | 2 +- .../impl => core}/OrientedData.java | 6 +- .../impl => core}/OrientedModel.java | 2 +- .../impl => core}/TransformAttributes.java | 2 +- .../impl => core}/TransformedModel.java | 2 +- .../backend/gl/versioned/MapBuffer.java | 4 +- .../backend/instancing/InstanceData.java | 13 + .../backend/instancing/InstanceKey.java | 29 -- .../backend/instancing/InstancedModel.java | 251 +++++++++--------- .../instancing/InstancedTileRenderer.java | 11 +- .../backend/instancing/MaterialType.java | 5 - .../instancing/TileEntityInstance.java | 10 +- src/main/resources/create.mixins.json | 3 +- 61 files changed, 466 insertions(+), 480 deletions(-) delete mode 100644 src/main/java/com/simibubi/create/foundation/mixin/TileAddMixin.java create mode 100644 src/main/java/com/simibubi/create/foundation/mixin/TileWorldHookMixin.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/backend/MaterialType.java rename src/main/java/com/simibubi/create/foundation/render/backend/{RenderMaterials.java => MaterialTypes.java} (55%) rename src/main/java/com/simibubi/create/foundation/render/backend/{instancing/impl => core}/BasicAttributes.java (91%) rename src/main/java/com/simibubi/create/foundation/render/backend/{instancing/impl => core}/BasicData.java (92%) rename src/main/java/com/simibubi/create/foundation/render/backend/{instancing/impl => core}/IFlatLight.java (92%) rename src/main/java/com/simibubi/create/foundation/render/backend/{instancing/impl => core}/ModelAttributes.java (93%) rename src/main/java/com/simibubi/create/foundation/render/backend/{instancing/impl => core}/ModelData.java (90%) rename src/main/java/com/simibubi/create/foundation/render/backend/{instancing/impl => core}/OrientedAttributes.java (92%) rename src/main/java/com/simibubi/create/foundation/render/backend/{instancing/impl => core}/OrientedData.java (94%) rename src/main/java/com/simibubi/create/foundation/render/backend/{instancing/impl => core}/OrientedModel.java (92%) rename src/main/java/com/simibubi/create/foundation/render/backend/{instancing/impl => core}/TransformAttributes.java (92%) rename src/main/java/com/simibubi/create/foundation/render/backend/{instancing/impl => core}/TransformedModel.java (92%) delete mode 100644 src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstanceKey.java delete mode 100644 src/main/java/com/simibubi/create/foundation/render/backend/instancing/MaterialType.java diff --git a/src/main/java/com/simibubi/create/AllBlockPartials.java b/src/main/java/com/simibubi/create/AllBlockPartials.java index f855246c5..95ff6745c 100644 --- a/src/main/java/com/simibubi/create/AllBlockPartials.java +++ b/src/main/java/com/simibubi/create/AllBlockPartials.java @@ -16,10 +16,10 @@ import com.simibubi.create.content.contraptions.fluids.FluidTransportBehaviour.A import com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock.HeatLevel; import com.simibubi.create.content.contraptions.relays.belt.BeltData; import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.render.backend.RenderMaterials; +import com.simibubi.create.foundation.render.backend.MaterialTypes; import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; -import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData; +import com.simibubi.create.foundation.render.backend.core.ModelData; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.Lang; @@ -278,7 +278,7 @@ public class AllBlockPartials { .unCentre(); return stack; }; - return dispatcher.getMaterial(RenderMaterials.TRANSFORMED).getModel(this, referenceState, facing, ms); + return dispatcher.getMaterial(MaterialTypes.TRANSFORMED).getModel(this, referenceState, facing, ms); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticData.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticData.java index 376f46514..4e1eaf3c4 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticData.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticData.java @@ -3,7 +3,7 @@ package com.simibubi.create.content.contraptions.base; import java.nio.ByteBuffer; import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; -import com.simibubi.create.foundation.render.backend.instancing.impl.BasicData; +import com.simibubi.create.foundation.render.backend.core.BasicData; import com.simibubi.create.foundation.utility.ColorHelper; import net.minecraft.client.renderer.Vector3f; @@ -32,6 +32,7 @@ public class KineticData extends BasicData { this.x = x; this.y = y; this.z = z; + markDirty(); return this; } @@ -39,6 +40,7 @@ public class KineticData extends BasicData { this.x += x; this.y += y; this.z += z; + markDirty(); return this; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticRenderMaterials.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticRenderMaterials.java index 2320fcb41..4efbb13c5 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticRenderMaterials.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticRenderMaterials.java @@ -4,7 +4,7 @@ import com.simibubi.create.content.contraptions.components.actors.ActorData; import com.simibubi.create.content.contraptions.relays.belt.BeltData; import com.simibubi.create.content.logistics.block.FlapData; import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; -import com.simibubi.create.foundation.render.backend.instancing.MaterialType; +import com.simibubi.create.foundation.render.backend.MaterialType; public class KineticRenderMaterials { public static final MaterialType> ROTATING = new MaterialType<>(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java index b238c772b..7fdd7e680 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java @@ -39,21 +39,20 @@ public abstract class KineticTileInstance extends T .setColor(tile); } - protected final InstanceKey setup(InstanceKey key) { + protected final RotatingData setup(RotatingData key) { return setup(key, getRotationAxis(), getTileSpeed()); } - protected final InstanceKey setup(InstanceKey key, Direction.Axis axis) { + protected final RotatingData setup(RotatingData key, Direction.Axis axis) { return setup(key, axis, getTileSpeed()); } - protected final InstanceKey setup(InstanceKey key, float speed) { + protected final RotatingData setup(RotatingData key, float speed) { return setup(key, getRotationAxis(), speed); } - protected final InstanceKey setup(InstanceKey key, Direction.Axis axis, float speed) { - key.getInstance() - .setRotationAxis(axis) + protected final RotatingData setup(RotatingData key, Direction.Axis axis, float speed) { + key.setRotationAxis(axis) .setRotationalSpeed(speed) .setRotationOffset(getRotationOffset(axis)) .setColor(tile) diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/RotatingData.java b/src/main/java/com/simibubi/create/content/contraptions/base/RotatingData.java index 22d33f30e..8e8be0beb 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/RotatingData.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/RotatingData.java @@ -31,6 +31,7 @@ public class RotatingData extends KineticData { this.rotationAxisX = (byte) (rotationAxisX * 127); this.rotationAxisY = (byte) (rotationAxisY * 127); this.rotationAxisZ = (byte) (rotationAxisZ * 127); + markDirty(); return this; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/RotatingModel.java b/src/main/java/com/simibubi/create/content/contraptions/base/RotatingModel.java index 8c0d77c17..ec3becb67 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/RotatingModel.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/RotatingModel.java @@ -3,7 +3,7 @@ package com.simibubi.create.content.contraptions.base; import com.simibubi.create.foundation.render.backend.gl.attrib.VertexFormat; import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; -import com.simibubi.create.foundation.render.backend.instancing.impl.BasicAttributes; +import com.simibubi.create.foundation.render.backend.core.BasicAttributes; import net.minecraft.client.renderer.BufferBuilder; diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/SingleRotatingInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/SingleRotatingInstance.java index c0d7d9e93..1749e308f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/SingleRotatingInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/SingleRotatingInstance.java @@ -1,6 +1,5 @@ package com.simibubi.create.content.contraptions.base; -import com.simibubi.create.foundation.render.backend.instancing.InstanceKey; import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; @@ -8,7 +7,7 @@ import net.minecraft.block.BlockState; public class SingleRotatingInstance extends KineticTileInstance { - protected final InstanceKey rotatingModel; + protected final RotatingData rotatingModel; public SingleRotatingInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { super(modelManager, tile); @@ -18,12 +17,12 @@ public class SingleRotatingInstance extends KineticTileInstance drillHead; + ActorData drillHead; private Direction facing; public DrillActorInstance(ContraptionKineticRenderer modelManager, MovementContext context) { @@ -37,8 +37,7 @@ public class DrillActorInstance extends com.simibubi.create.content.contraptions drillHead = renderMaterial.getModel(AllBlockPartials.DRILL_HEAD, state).createInstance(); - drillHead.getInstance() - .setPosition(context.localPos) + drillHead.setPosition(context.localPos) .setBlockLight(localBlockLight()) .setRotationOffset(0) .setRotationAxis(0, 0, 1) @@ -48,7 +47,7 @@ public class DrillActorInstance extends com.simibubi.create.content.contraptions @Override public void beginFrame() { - drillHead.getInstance().setSpeed(getSpeed(facing)); + drillHead.setSpeed(getSpeed(facing)); } protected float getSpeed(Direction facing) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterActorInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterActorInstance.java index 43d31684c..629fcf620 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterActorInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterActorInstance.java @@ -5,10 +5,9 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; import com.simibubi.create.content.contraptions.components.structureMovement.render.ActorInstance; import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionKineticRenderer; -import com.simibubi.create.foundation.render.backend.instancing.InstanceKey; import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; import com.simibubi.create.foundation.render.backend.instancing.RenderMaterial; -import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData; +import com.simibubi.create.foundation.render.backend.core.ModelData; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.MatrixStacker; @@ -25,7 +24,7 @@ public class HarvesterActorInstance extends ActorInstance { static Vec3d rotOffset = new Vec3d(0.5f, -2 * originOffset + 0.5f, originOffset + 0.5f); - InstanceKey harvester; + ModelData harvester; private Direction facing; private float horizontalAngle; @@ -46,8 +45,7 @@ public class HarvesterActorInstance extends ActorInstance { horizontalAngle = facing.getHorizontalAngle() + ((facing.getAxis() == Direction.Axis.X) ? 180 : 0); - harvester.getInstance() - .setBlockLight(localBlockLight()); + harvester.setBlockLight(localBlockLight()); } @Override @@ -85,7 +83,7 @@ public class HarvesterActorInstance extends ActorInstance { .rotateX(getRotation()) .translateBack(rotOffset); - harvester.getInstance().setTransform(ms); + harvester.setTransform(ms); } private double getRotation() { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crank/HandCrankInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/crank/HandCrankInstance.java index 8035fb705..33fb21234 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crank/HandCrankInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crank/HandCrankInstance.java @@ -2,10 +2,9 @@ package com.simibubi.create.content.contraptions.components.crank; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; -import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; import com.simibubi.create.foundation.render.backend.instancing.*; -import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData; +import com.simibubi.create.foundation.render.backend.core.ModelData; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.MatrixStacker; import net.minecraft.block.Block; @@ -15,7 +14,7 @@ import net.minecraft.util.Direction; public class HandCrankInstance extends SingleRotatingInstance implements IDynamicInstance { private final HandCrankTileEntity tile; - private InstanceKey crank; + private ModelData crank; private Direction facing; public HandCrankInstance(InstancedTileRenderer modelManager, HandCrankTileEntity tile) { @@ -54,7 +53,7 @@ public class HandCrankInstance extends SingleRotatingInstance implements IDynami .rotate(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis), angle) .unCentre(); - crank.getInstance().setTransform(ms); + crank.setTransform(ms); } @Override @@ -66,6 +65,6 @@ public class HandCrankInstance extends SingleRotatingInstance implements IDynami @Override public void updateLight() { super.updateLight(); - if (crank != null) relight(pos, crank.getInstance()); + if (crank != null) relight(pos, crank); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerActorInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerActorInstance.java index 8cf440adf..8e64335b6 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerActorInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerActorInstance.java @@ -7,10 +7,9 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Mov import com.simibubi.create.content.contraptions.components.structureMovement.render.ActorInstance; import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionKineticRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionProgram; -import com.simibubi.create.foundation.render.backend.instancing.InstanceKey; import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; import com.simibubi.create.foundation.render.backend.instancing.RenderMaterial; -import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData; +import com.simibubi.create.foundation.render.backend.core.ModelData; import com.simibubi.create.foundation.utility.*; import net.minecraft.block.BlockState; import net.minecraft.util.Direction; @@ -30,9 +29,9 @@ public class DeployerActorInstance extends ActorInstance { float zRot; float zRotPole; - InstanceKey pole; - InstanceKey hand; - InstanceKey shaft; + ModelData pole; + ModelData hand; + RotatingData shaft; public DeployerActorInstance(ContraptionKineticRenderer modelManager, MovementContext context) { super(modelManager, context); @@ -61,13 +60,12 @@ public class DeployerActorInstance extends ActorInstance { int blockLight = localBlockLight(); - shaft.getInstance() - .setRotationAxis(axis) + shaft.setRotationAxis(axis) .setPosition(context.localPos) .setBlockLight(blockLight); - pole.getInstance().setBlockLight(blockLight); - hand.getInstance().setBlockLight(blockLight); + pole.setBlockLight(blockLight); + hand.setBlockLight(blockLight); } @Override @@ -94,7 +92,7 @@ public class DeployerActorInstance extends ActorInstance { transformModel(msr, pole, hand, yRot, zRot, zRotPole); } - static void transformModel(MatrixStacker msr, InstanceKey pole, InstanceKey hand, float yRot, float zRot, float zRotPole) { + static void transformModel(MatrixStacker msr, ModelData pole, ModelData hand, float yRot, float zRot, float zRotPole) { msr.centre(); msr.rotate(Direction.SOUTH, (float) ((zRot) / 180 * Math.PI)); @@ -103,11 +101,11 @@ public class DeployerActorInstance extends ActorInstance { msr.push(); msr.rotate(Direction.SOUTH, (float) ((zRotPole) / 180 * Math.PI)); msr.unCentre(); - pole.getInstance().setTransform(msr.unwrap()); + pole.setTransform(msr.unwrap()); msr.pop(); msr.unCentre(); - hand.getInstance().setTransform(msr.unwrap()); + hand.setTransform(msr.unwrap()); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerInstance.java index bb6b8f6bb..818cddfc5 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerInstance.java @@ -4,7 +4,7 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.relays.encased.ShaftInstance; import com.simibubi.create.foundation.render.backend.instancing.*; -import com.simibubi.create.foundation.render.backend.instancing.impl.OrientedData; +import com.simibubi.create.foundation.render.backend.core.OrientedData; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; @@ -25,9 +25,9 @@ public class DeployerInstance extends ShaftInstance implements IDynamicInstance, final float zRot; final float zRotPole; - protected final InstanceKey pole; + protected final OrientedData pole; - protected InstanceKey hand; + protected OrientedData hand; AllBlockPartials currentHand; float progress = Float.NaN; @@ -48,7 +48,7 @@ public class DeployerInstance extends ShaftInstance implements IDynamicInstance, pole = getOrientedMaterial().getModel(AllBlockPartials.DEPLOYER_POLE, blockState).createInstance(); updateHandPose(); - relight(pos, pole.getInstance()); + relight(pos, pole); updateRotation(pole, hand, yRot, zRot, zRotPole); @@ -80,15 +80,15 @@ public class DeployerInstance extends ShaftInstance implements IDynamicInstance, float y = blockPos.getY() + ((float) facingVec.getY()) * distance; float z = blockPos.getZ() + ((float) facingVec.getZ()) * distance; - pole.getInstance().setPosition(x, y, z); - hand.getInstance().setPosition(x, y, z); + pole.setPosition(x, y, z); + hand.setPosition(x, y, z); } @Override public void updateLight() { super.updateLight(); - relight(pos, hand.getInstance(), pole.getInstance()); + relight(pos, hand, pole); } @Override @@ -96,8 +96,6 @@ public class DeployerInstance extends ShaftInstance implements IDynamicInstance, super.remove(); hand.delete(); pole.delete(); - currentHand = null; // updateHandPose() uses an invalid key after a block update otherwise. - hand = null; } private boolean updateHandPose() { @@ -110,7 +108,7 @@ public class DeployerInstance extends ShaftInstance implements IDynamicInstance, hand = getOrientedMaterial().getModel(currentHand, blockState).createInstance(); - relight(pos, hand.getInstance()); + relight(pos, hand); updateRotation(pole, hand, yRot, zRot, zRotPole); return true; @@ -124,15 +122,15 @@ public class DeployerInstance extends ShaftInstance implements IDynamicInstance, return 0; } - static void updateRotation(InstanceKey pole, InstanceKey hand, float yRot, float zRot, float zRotPole) { + static void updateRotation(OrientedData pole, OrientedData hand, float yRot, float zRot, float zRotPole) { Quaternion q = Direction.SOUTH.getUnitVector().getDegreesQuaternion(zRot); q.multiply(Direction.UP.getUnitVector().getDegreesQuaternion(yRot)); - hand.getInstance().setRotation(q); + hand.setRotation(q); q.multiply(Direction.SOUTH.getUnitVector().getDegreesQuaternion(zRotPole)); - pole.getInstance().setRotation(q); + pole.setRotation(q); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/fan/FanInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/fan/FanInstance.java index b2beb5a75..62ab42d6e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/fan/FanInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/fan/FanInstance.java @@ -3,10 +3,8 @@ package com.simibubi.create.content.contraptions.components.fan; import static net.minecraft.state.properties.BlockStateProperties.FACING; import com.simibubi.create.AllBlockPartials; -import com.simibubi.create.content.contraptions.base.IRotate; import com.simibubi.create.content.contraptions.base.KineticTileInstance; import com.simibubi.create.content.contraptions.base.RotatingData; -import com.simibubi.create.foundation.render.backend.instancing.InstanceKey; import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; import net.minecraft.util.Direction; @@ -15,8 +13,8 @@ import net.minecraft.util.math.MathHelper; public class FanInstance extends KineticTileInstance { - protected final InstanceKey shaft; - protected final InstanceKey fan; + protected final RotatingData shaft; + protected final RotatingData fan; final Direction direction; public FanInstance(InstancedTileRenderer modelManager, EncasedFanTileEntity tile) { @@ -42,17 +40,17 @@ public class FanInstance extends KineticTileInstance { @Override protected void update() { - updateRotation(shaft.getInstance()); - updateRotation(fan.getInstance(), getFanSpeed()); + updateRotation(shaft); + updateRotation(fan, getFanSpeed()); } @Override public void updateLight() { BlockPos behind = pos.offset(direction.getOpposite()); - relight(behind, shaft.getInstance()); + relight(behind, shaft); BlockPos inFront = pos.offset(direction); - relight(inFront, fan.getInstance()); + relight(inFront, fan); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java index c3c0d478e..c2975d56c 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java @@ -10,7 +10,7 @@ import com.simibubi.create.content.contraptions.base.KineticTileInstance; import com.simibubi.create.content.contraptions.base.RotatingData; import com.simibubi.create.foundation.render.backend.instancing.*; -import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData; +import com.simibubi.create.foundation.render.backend.core.ModelData; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.MatrixStacker; @@ -27,15 +27,15 @@ public class FlyWheelInstance extends KineticTileInstance im protected boolean connectedLeft; protected float connectorAngleMult; - protected final InstanceKey shaft; + protected final RotatingData shaft; - protected final InstanceKey wheel; + protected final ModelData wheel; - protected List> connectors; - protected InstanceKey upperRotating; - protected InstanceKey lowerRotating; - protected InstanceKey upperSliding; - protected InstanceKey lowerSliding; + protected List connectors; + protected ModelData upperRotating; + protected ModelData lowerRotating; + protected ModelData upperSliding; + protected ModelData lowerSliding; protected float lastAngle = Float.NaN; @@ -100,22 +100,22 @@ public class FlyWheelInstance extends KineticTileInstance im ms.push(); transformConnector(msr, true, true, rotation, connectedLeft); - upperRotating.getInstance().setTransform(ms); + upperRotating.setTransform(ms); ms.pop(); ms.push(); transformConnector(msr, false, true, rotation, connectedLeft); - lowerRotating.getInstance().setTransform(ms); + lowerRotating.setTransform(ms); ms.pop(); ms.push(); transformConnector(msr, true, false, rotation, connectedLeft); - upperSliding.getInstance().setTransform(ms); + upperSliding.setTransform(ms); ms.pop(); ms.push(); transformConnector(msr, false, false, rotation, connectedLeft); - lowerSliding.getInstance().setTransform(ms); + lowerSliding.setTransform(ms); ms.pop(); ms.pop(); @@ -125,20 +125,20 @@ public class FlyWheelInstance extends KineticTileInstance im .rotate(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, facing.getAxis()), AngleHelper.rad(angle)) .unCentre(); - wheel.getInstance().setTransform(ms); + wheel.setTransform(ms); } @Override protected void update() { - updateRotation(shaft.getInstance()); + updateRotation(shaft); } @Override public void updateLight() { - relight(pos, shaft.getInstance(), wheel.getInstance()); + relight(pos, shaft, wheel); if (connection != null) { - relight(this.pos.offset(connection), connectors.stream().map(InstanceKey::getInstance)); + relight(this.pos.offset(connection), connectors.stream()); } } @@ -147,7 +147,7 @@ public class FlyWheelInstance extends KineticTileInstance im shaft.delete(); wheel.delete(); - connectors.forEach(InstanceKey::delete); + connectors.forEach(InstanceData::delete); connectors.clear(); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineInstance.java index 370cd50e0..43f63e5e1 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineInstance.java @@ -2,10 +2,9 @@ package com.simibubi.create.content.contraptions.components.flywheel.engine; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; -import com.simibubi.create.foundation.render.backend.instancing.InstanceKey; import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; import com.simibubi.create.foundation.render.backend.instancing.TileEntityInstance; -import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData; +import com.simibubi.create.foundation.render.backend.core.ModelData; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.MatrixStacker; import net.minecraft.block.Block; @@ -14,7 +13,7 @@ import net.minecraft.util.Direction; public class EngineInstance extends TileEntityInstance { - protected InstanceKey frame; + protected ModelData frame; public EngineInstance(InstancedTileRenderer modelManager, EngineTileEntity tile) { super(modelManager, tile); @@ -43,8 +42,7 @@ public class EngineInstance extends TileEntityInstance { .unCentre() .translate(0, 0, -1); - this.frame.getInstance() - .setTransform(ms); + this.frame.setTransform(ms); } @Override @@ -54,6 +52,6 @@ public class EngineInstance extends TileEntityInstance { @Override public void updateLight() { - relight(pos, frame.getInstance()); + relight(pos, frame); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MixerInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MixerInstance.java index 9cd7c0c7b..5929e3d7c 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MixerInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MixerInstance.java @@ -4,15 +4,15 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.RotatingData; import com.simibubi.create.content.contraptions.base.ShaftlessCogInstance; import com.simibubi.create.foundation.render.backend.instancing.*; -import com.simibubi.create.foundation.render.backend.instancing.impl.OrientedData; +import com.simibubi.create.foundation.render.backend.core.OrientedData; import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.util.Direction; public class MixerInstance extends ShaftlessCogInstance implements IDynamicInstance { - private final InstanceKey mixerHead; - private final InstanceKey mixerPole; + private final RotatingData mixerHead; + private final OrientedData mixerPole; private final MechanicalMixerTileEntity mixer; public MixerInstance(InstancedTileRenderer dispatcher, MechanicalMixerTileEntity tile) { @@ -22,8 +22,7 @@ public class MixerInstance extends ShaftlessCogInstance implements IDynamicInsta mixerHead = getRotatingMaterial().getModel(AllBlockPartials.MECHANICAL_MIXER_HEAD, blockState) .createInstance(); - mixerHead.getInstance() - .setRotationAxis(Direction.Axis.Y); + mixerHead.setRotationAxis(Direction.Axis.Y); mixerPole = getOrientedMaterial() .getModel(AllBlockPartials.MECHANICAL_MIXER_POLE, blockState) @@ -48,15 +47,13 @@ public class MixerInstance extends ShaftlessCogInstance implements IDynamicInsta private void transformHead(float renderedHeadOffset) { float speed = mixer.getRenderedHeadRotationSpeed(AnimationTickHolder.getPartialTicks()); - mixerHead.getInstance() - .setPosition(getInstancePosition()) + mixerHead.setPosition(getInstancePosition()) .nudge(0, -renderedHeadOffset, 0) .setRotationalSpeed(speed * 2); } private void transformPole(float renderedHeadOffset) { - mixerPole.getInstance() - .setPosition(getInstancePosition()) + mixerPole.setPosition(getInstancePosition()) .nudge(0, -renderedHeadOffset, 0); } @@ -68,8 +65,8 @@ public class MixerInstance extends ShaftlessCogInstance implements IDynamicInsta public void updateLight() { super.updateLight(); - relight(pos.down(), mixerHead.getInstance()); - relight(pos, mixerPole.getInstance()); + relight(pos.down(), mixerHead); + relight(pos, mixerPole); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/press/PressInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/press/PressInstance.java index d40e9d421..68a7bc3af 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/press/PressInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/press/PressInstance.java @@ -3,22 +3,17 @@ package com.simibubi.create.content.contraptions.components.press; import net.minecraft.client.renderer.Quaternion; import net.minecraft.client.renderer.Vector3f; -import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; -import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.relays.encased.ShaftInstance; import com.simibubi.create.foundation.render.backend.instancing.IDynamicInstance; -import com.simibubi.create.foundation.render.backend.instancing.InstanceKey; import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; -import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData; -import com.simibubi.create.foundation.render.backend.instancing.impl.OrientedData; +import com.simibubi.create.foundation.render.backend.core.OrientedData; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; -import com.simibubi.create.foundation.utility.MatrixStacker; public class PressInstance extends ShaftInstance implements IDynamicInstance { - private final InstanceKey pressHead; + private final OrientedData pressHead; private final MechanicalPressTileEntity press; public PressInstance(InstancedTileRenderer dispatcher, MechanicalPressTileEntity tile) { @@ -31,7 +26,7 @@ public class PressInstance extends ShaftInstance implements IDynamicInstance { Quaternion q = Vector3f.POSITIVE_Y.getDegreesQuaternion(AngleHelper.horizontalAngle(blockState.get(MechanicalPressBlock.HORIZONTAL_FACING))); - pressHead.getInstance().setRotation(q); + pressHead.setRotation(q); transformModels(); } @@ -47,8 +42,7 @@ public class PressInstance extends ShaftInstance implements IDynamicInstance { private void transformModels() { float renderedHeadOffset = getRenderedHeadOffset(press); - pressHead.getInstance() - .setPosition(getInstancePosition()) + pressHead.setPosition(getInstancePosition()) .nudge(0, -renderedHeadOffset, 0); } @@ -60,7 +54,7 @@ public class PressInstance extends ShaftInstance implements IDynamicInstance { public void updateLight() { super.updateLight(); - relight(pos, pressHead.getInstance()); + relight(pos, pressHead); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionLighter.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionLighter.java index 697fb4a63..0eafb4754 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionLighter.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionLighter.java @@ -56,7 +56,7 @@ public abstract class ContraptionLighter implements Light } protected GridAlignedBB contraptionBoundsToVolume(GridAlignedBB bounds) { - bounds.grow(1); // so we have at least enough data on the edges to avoid artifacts and have smooth lighting + bounds.grow(2); // so we have at least enough data on the edges to avoid artifacts and have smooth lighting bounds.minY = Math.max(bounds.minY, 0); bounds.maxY = Math.min(bounds.maxY, 255); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/StickerInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/StickerInstance.java index 2d0a9dec7..ec99e4fd4 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/StickerInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/StickerInstance.java @@ -3,7 +3,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement.ch import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.foundation.render.backend.instancing.*; -import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData; +import com.simibubi.create.foundation.render.backend.core.ModelData; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.MatrixStacker; @@ -18,7 +18,7 @@ public class StickerInstance extends TileEntityInstance imple final boolean fakeWorld; final int offset; - private final InstanceKey head; + private final ModelData head; public StickerInstance(InstancedTileRenderer modelManager, StickerTileEntity tile) { super(modelManager, tile); @@ -58,13 +58,12 @@ public class StickerInstance extends TileEntityInstance imple .unCentre() .translate(0, (offset * offset) * 4 / 16f, 0); - head.getInstance() - .setTransform(stack); + head.setTransform(stack); } @Override public void updateLight() { - relight(pos, head.getInstance()); + relight(pos, head); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryCarriageInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryCarriageInstance.java index ff9e962d6..ffc74db82 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryCarriageInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryCarriageInstance.java @@ -6,9 +6,8 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.relays.encased.ShaftInstance; import com.simibubi.create.foundation.render.backend.instancing.IDynamicInstance; -import com.simibubi.create.foundation.render.backend.instancing.InstanceKey; import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; -import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData; +import com.simibubi.create.foundation.render.backend.core.ModelData; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.MatrixStacker; @@ -19,7 +18,7 @@ import net.minecraft.util.math.MathHelper; public class GantryCarriageInstance extends ShaftInstance implements IDynamicInstance { - private final InstanceKey gantryCogs; + private final ModelData gantryCogs; final Direction facing; final Boolean alongFirst; @@ -75,7 +74,7 @@ public class GantryCarriageInstance extends ShaftInstance implements IDynamicIns .translate(0, 9 / 16f, 0) .unCentre(); - gantryCogs.getInstance().setTransform(ms); + gantryCogs.setTransform(ms); } static float getRotationMultiplier(Direction.Axis gantryAxis, Direction facing) { @@ -100,7 +99,7 @@ public class GantryCarriageInstance extends ShaftInstance implements IDynamicIns @Override public void updateLight() { - relight(pos, gantryCogs.getInstance(), rotatingModel.getInstance()); + relight(pos, gantryCogs, rotatingModel); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionKineticRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionKineticRenderer.java index 86e523d75..9478495f7 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionKineticRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionKineticRenderer.java @@ -10,11 +10,11 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Mov import com.simibubi.create.content.contraptions.relays.belt.BeltInstancedModel; import com.simibubi.create.content.logistics.block.FlapModel; import com.simibubi.create.foundation.render.AllProgramSpecs; -import com.simibubi.create.foundation.render.backend.RenderMaterials; +import com.simibubi.create.foundation.render.backend.MaterialTypes; import com.simibubi.create.foundation.render.backend.instancing.*; -import com.simibubi.create.foundation.render.backend.instancing.impl.OrientedModel; -import com.simibubi.create.foundation.render.backend.instancing.impl.TransformedModel; +import com.simibubi.create.foundation.render.backend.core.OrientedModel; +import com.simibubi.create.foundation.render.backend.core.TransformedModel; import net.minecraft.client.renderer.ActiveRenderInfo; import net.minecraft.util.math.BlockPos; @@ -37,8 +37,8 @@ public class ContraptionKineticRenderer extends InstancedTileRenderer(this, AllProgramSpecs.C_MODEL, TransformedModel::new)); - materials.put(RenderMaterials.ORIENTED, new RenderMaterial<>(this, AllProgramSpecs.C_ORIENTED, OrientedModel::new)); + materials.put(MaterialTypes.TRANSFORMED, new RenderMaterial<>(this, AllProgramSpecs.C_MODEL, TransformedModel::new)); + materials.put(MaterialTypes.ORIENTED, new RenderMaterial<>(this, AllProgramSpecs.C_ORIENTED, OrientedModel::new)); materials.put(KineticRenderMaterials.BELTS, new RenderMaterial<>(this, AllProgramSpecs.C_BELT, BeltInstancedModel::new)); materials.put(KineticRenderMaterials.ROTATING, new RenderMaterial<>(this, AllProgramSpecs.C_ROTATING, RotatingModel::new)); diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveInstance.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveInstance.java index 2fa1f8a28..e5f8c76ff 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveInstance.java @@ -6,9 +6,8 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.relays.encased.ShaftInstance; import com.simibubi.create.foundation.render.backend.instancing.IDynamicInstance; -import com.simibubi.create.foundation.render.backend.instancing.InstanceKey; import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; -import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData; +import com.simibubi.create.foundation.render.backend.core.ModelData; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.MatrixStacker; @@ -17,7 +16,7 @@ import net.minecraft.util.math.MathHelper; public class FluidValveInstance extends ShaftInstance implements IDynamicInstance { - protected InstanceKey pointer; + protected ModelData pointer; protected final double xRot; protected final double yRot; @@ -64,13 +63,13 @@ public class FluidValveInstance extends ShaftInstance implements IDynamicInstanc .rotateY(pointerRotationOffset + pointerRotation) .unCentre(); - pointer.getInstance().setTransform(ms); + pointer.setTransform(ms); } @Override public void updateLight() { super.updateLight(); - relight(pos, pointer.getInstance()); + relight(pos, pointer); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltData.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltData.java index 3ac819ab7..ed796c43b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltData.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltData.java @@ -31,6 +31,7 @@ public class BeltData extends KineticData { this.qY = q.getY(); this.qZ = q.getZ(); this.qW = q.getW(); + markDirty(); return this; } @@ -44,12 +45,14 @@ public class BeltData extends KineticData { this.minV = target.getMinV(); this.maxU = target.getMaxU(); this.maxV = target.getMaxV(); + markDirty(); return this; } public BeltData setScrollMult(float scrollMult) { this.scrollMult = (byte) (scrollMult * 127); + markDirty(); return this; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java index 5781336c3..9983b0899 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java @@ -9,7 +9,7 @@ import com.simibubi.create.AllBlocks; import com.simibubi.create.content.contraptions.base.KineticTileInstance; import com.simibubi.create.content.contraptions.base.RotatingData; import com.simibubi.create.foundation.block.render.SpriteShiftEntry; -import com.simibubi.create.foundation.render.backend.instancing.InstanceKey; +import com.simibubi.create.foundation.render.backend.instancing.InstanceData; import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; import com.simibubi.create.foundation.utility.Iterate; @@ -30,8 +30,8 @@ public class BeltInstance extends KineticTileInstance { boolean alongZ; BeltSlope beltSlope; Direction facing; - protected ArrayList> keys; - protected InstanceKey pulleyKey; + protected ArrayList keys; + protected RotatingData pulleyKey; public BeltInstance(InstancedTileRenderer modelManager, BeltTileEntity tile) { super(modelManager, tile); @@ -78,31 +78,30 @@ public class BeltInstance extends KineticTileInstance { DyeColor color = tile.color.orElse(null); boolean bottom = true; - for (InstanceKey key : keys) { + for (BeltData key : keys) { SpriteShiftEntry spriteShiftEntry = BeltRenderer.getSpriteShiftEntry(color, diagonal, bottom); - key.getInstance() - .setScrollTexture(spriteShiftEntry) + key.setScrollTexture(spriteShiftEntry) .setColor(tile) .setRotationalSpeed(getScrollSpeed()); bottom = false; } if (pulleyKey != null) { - updateRotation(pulleyKey.getInstance()); + updateRotation(pulleyKey); } } @Override public void updateLight() { - relight(pos, keys.stream().map(InstanceKey::getInstance)); + relight(pos, keys.stream()); - if (pulleyKey != null) relight(pos, pulleyKey.getInstance()); + if (pulleyKey != null) relight(pos, pulleyKey); } @Override public void remove() { - keys.forEach(InstanceKey::delete); + keys.forEach(InstanceData::delete); keys.clear(); if (pulleyKey != null) pulleyKey.delete(); pulleyKey = null; @@ -151,7 +150,7 @@ public class BeltInstance extends KineticTileInstance { return dir; } - private InstanceKey setup(InstanceKey key, boolean bottom, SpriteShiftEntry spriteShift) { + private BeltData setup(BeltData key, boolean bottom, SpriteShiftEntry spriteShift) { boolean downward = beltSlope == BeltSlope.DOWNWARD; float rotX = (!diagonal && beltSlope != BeltSlope.HORIZONTAL ? 90 : 0) + (downward ? 180 : 0) + (sideways ? 90 : 0) + (vertical && alongZ ? 180 : 0); float rotY = facing.getHorizontalAngle() + ((diagonal ^ alongX) && !downward ? 180 : 0) + (sideways && alongZ ? 180 : 0) + (vertical && alongX ? 90 : 0); @@ -159,8 +158,7 @@ public class BeltInstance extends KineticTileInstance { Quaternion q = new Quaternion(rotX, rotY, rotZ, true); - key.getInstance() - .setScrollTexture(spriteShift) + key.setScrollTexture(spriteShift) .setScrollMult(diagonal ? 3f / 8f : 0.5f) .setRotation(q) .setRotationalSpeed(getScrollSpeed()) diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstancedModel.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstancedModel.java index efbb86b44..fd8cd918b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstancedModel.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstancedModel.java @@ -4,7 +4,7 @@ import com.simibubi.create.content.contraptions.base.KineticAttributes; import com.simibubi.create.foundation.render.backend.gl.attrib.VertexFormat; import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; -import com.simibubi.create.foundation.render.backend.instancing.impl.BasicAttributes; +import com.simibubi.create.foundation.render.backend.core.BasicAttributes; import net.minecraft.client.renderer.BufferBuilder; diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java index 1a82c8645..9a4e50292 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java @@ -4,10 +4,9 @@ import java.util.ArrayList; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.IRotate; -import com.simibubi.create.content.contraptions.base.KineticData; import com.simibubi.create.content.contraptions.base.KineticTileInstance; import com.simibubi.create.content.contraptions.base.RotatingData; -import com.simibubi.create.foundation.render.backend.instancing.InstanceKey; +import com.simibubi.create.foundation.render.backend.instancing.InstanceData; import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; import com.simibubi.create.foundation.utility.Iterate; @@ -17,7 +16,7 @@ import net.minecraft.util.Direction; public class SplitShaftInstance extends KineticTileInstance { - protected final ArrayList> keys; + protected final ArrayList keys; public SplitShaftInstance(InstancedTileRenderer modelManager, SplitShaftTileEntity tile) { super(modelManager, tile); @@ -44,18 +43,18 @@ public class SplitShaftInstance extends KineticTileInstance getHeadModel(); - private class DialFace extends Couple> { + private class DialFace extends Couple { Direction face; - public DialFace(Direction face, InstanceKey first, InstanceKey second) { + public DialFace(Direction face, ModelData first, ModelData second) { super(first, second); this.face = face; } @@ -103,13 +99,13 @@ public abstract class GaugeInstance extends ShaftInstance implements IDynamicIns ms.push(); rotateToFace(msr); - getSecond().getInstance().setTransform(ms); + getSecond().setTransform(ms); msr.translate(0, dialPivot, dialPivot) .rotate(Direction.EAST, (float) (Math.PI / 2 * -progress)) .translate(0, -dialPivot, -dialPivot); - getFirst().getInstance().setTransform(ms); + getFirst().setTransform(ms); ms.pop(); } @@ -124,7 +120,7 @@ public abstract class GaugeInstance extends ShaftInstance implements IDynamicIns .rotate(Direction.EAST, (float) (Math.PI / 2 * -progress)) .translate(0, -dialPivot, -dialPivot); - getFirst().getInstance().setTransform(ms); + getFirst().setTransform(ms); ms.pop(); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java index b34e56917..bfece3f61 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java @@ -6,7 +6,7 @@ import java.util.Map; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileInstance; import com.simibubi.create.content.contraptions.base.RotatingData; -import com.simibubi.create.foundation.render.backend.instancing.InstanceKey; +import com.simibubi.create.foundation.render.backend.instancing.InstanceData; import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; import com.simibubi.create.foundation.utility.Iterate; @@ -18,7 +18,7 @@ import net.minecraft.world.LightType; public class GearboxInstance extends KineticTileInstance { - protected final EnumMap> keys; + protected final EnumMap keys; protected Direction sourceFacing; public GearboxInstance(InstancedTileRenderer modelManager, GearboxTileEntity tile) { @@ -39,10 +39,9 @@ public class GearboxInstance extends KineticTileInstance { InstancedModel shaft = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, blockState, direction); - InstanceKey key = shaft.createInstance(); + RotatingData key = shaft.createInstance(); - key.getInstance() - .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()) + key.setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()) .setRotationalSpeed(getSpeed(direction)) .setRotationOffset(getRotationOffset(axis)).setColor(tile) .setPosition(getInstancePosition()) @@ -77,22 +76,22 @@ public class GearboxInstance extends KineticTileInstance { @Override public void update() { updateSourceFacing(); - for (Map.Entry> key : keys.entrySet()) { + for (Map.Entry key : keys.entrySet()) { Direction direction = key.getKey(); Direction.Axis axis = direction.getAxis(); - updateRotation(key.getValue().getInstance(), axis, getSpeed(direction)); + updateRotation(key.getValue(), axis, getSpeed(direction)); } } @Override public void updateLight() { - relight(pos, keys.values().stream().map(InstanceKey::getInstance)); + relight(pos, keys.values().stream()); } @Override public void remove() { - keys.values().forEach(InstanceKey::delete); + keys.values().forEach(InstanceData::delete); keys.clear(); } } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/FlapData.java b/src/main/java/com/simibubi/create/content/logistics/block/FlapData.java index 3b6b6a5ac..f6619ae05 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/FlapData.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/FlapData.java @@ -2,7 +2,7 @@ package com.simibubi.create.content.logistics.block; import com.simibubi.create.foundation.render.backend.instancing.InstanceData; import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; -import com.simibubi.create.foundation.render.backend.instancing.impl.IFlatLight; +import com.simibubi.create.foundation.render.backend.core.IFlatLight; import net.minecraft.client.renderer.Vector3f; import net.minecraft.util.math.BlockPos; @@ -54,18 +54,21 @@ public class FlapData extends InstanceData implements IFlatLight { this.x = x; this.y = y; this.z = z; + markDirty(); return this; } @Override public FlapData setBlockLight(int blockLight) { this.blockLight = (byte) ((blockLight & 0xF) << 4); + markDirty(); return this; } @Override public FlapData setSkyLight(int skyLight) { this.skyLight = (byte) ((skyLight & 0xF) << 4); + markDirty(); return this; } @@ -73,26 +76,31 @@ public class FlapData extends InstanceData implements IFlatLight { this.segmentOffsetX = x; this.segmentOffsetY = y; this.segmentOffsetZ = z; + markDirty(); return this; } public FlapData setIntensity(float intensity) { this.intensity = intensity; + markDirty(); return this; } public FlapData setHorizontalAngle(float horizontalAngle) { this.horizontalAngle = horizontalAngle; + markDirty(); return this; } public FlapData setFlapScale(float flapScale) { this.flapScale = flapScale; + markDirty(); return this; } public FlapData setFlapness(float flapness) { this.flapness = flapness; + markDirty(); return this; } @@ -100,6 +108,7 @@ public class FlapData extends InstanceData implements IFlatLight { pivotX = x / 16f; pivotY = y / 16f; pivotZ = z / 16f; + markDirty(); return this; } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelInstance.java b/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelInstance.java index 11f493dbb..b9f8c8aca 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelInstance.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelInstance.java @@ -9,11 +9,7 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticRenderMaterials; import com.simibubi.create.content.logistics.block.FlapData; import com.simibubi.create.foundation.gui.widgets.InterpolatedValue; -import com.simibubi.create.foundation.render.backend.instancing.IDynamicInstance; -import com.simibubi.create.foundation.render.backend.instancing.InstanceKey; -import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; -import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; -import com.simibubi.create.foundation.render.backend.instancing.TileEntityInstance; +import com.simibubi.create.foundation.render.backend.instancing.*; import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.util.Direction; @@ -21,7 +17,7 @@ import net.minecraft.world.LightType; public class BeltTunnelInstance extends TileEntityInstance implements IDynamicInstance { - private final Map>> tunnelFlaps; + private final Map> tunnelFlaps; public BeltTunnelInstance(InstancedTileRenderer modelManager, BeltTunnelTileEntity tile) { super(modelManager, tile); @@ -42,16 +38,15 @@ public class BeltTunnelInstance extends TileEntityInstance float flapScale = direction.getAxis() == Direction.Axis.X ? 1 : -1; - ArrayList> flaps = new ArrayList<>(4); + ArrayList flaps = new ArrayList<>(4); for (int segment = 0; segment <= 3; segment++) { float intensity = segment == 3 ? 1.5f : segment + 1; float segmentOffset = -3 / 16f * segment; - InstanceKey key = model.createInstance(); + FlapData key = model.createInstance(); - key.getInstance() - .setPosition(pos) + key.setPosition(pos) .setSegmentOffset(segmentOffset, 0, 0) .setBlockLight(blockLight) .setSkyLight(skyLight) @@ -82,23 +77,15 @@ public class BeltTunnelInstance extends TileEntityInstance } float flapness = flapValue.get(AnimationTickHolder.getPartialTicks()); - for (InstanceKey key : keys) { - key.getInstance().setFlapness(flapness); + for (FlapData flap : keys) { + flap.setFlapness(flapness); } }); } @Override public void updateLight() { - int blockLight = world.getLightLevel(LightType.BLOCK, pos); - int skyLight = world.getLightLevel(LightType.SKY, pos); - - for (ArrayList> instanceKeys : tunnelFlaps.values()) { - for (InstanceKey it : instanceKeys) { - it.getInstance().setBlockLight(blockLight) - .setSkyLight(skyLight); - } - } + relight(pos, tunnelFlaps.values().stream().flatMap(Collection::stream)); } @Override @@ -106,6 +93,6 @@ public class BeltTunnelInstance extends TileEntityInstance tunnelFlaps.values() .stream() .flatMap(Collection::stream) - .forEach(InstanceKey::delete); + .forEach(InstanceData::delete); } } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorInstance.java b/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorInstance.java index 81e74da4c..fb36deb8b 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorInstance.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorInstance.java @@ -4,12 +4,10 @@ import net.minecraft.util.math.MathHelper; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; -import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.relays.encased.ShaftInstance; import com.simibubi.create.foundation.render.backend.instancing.IDynamicInstance; -import com.simibubi.create.foundation.render.backend.instancing.InstanceKey; import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; -import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData; +import com.simibubi.create.foundation.render.backend.core.ModelData; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.MatrixStacker; @@ -17,7 +15,7 @@ public class EjectorInstance extends ShaftInstance implements IDynamicInstance { protected final EjectorTileEntity tile; - protected final InstanceKey plate; + protected final ModelData plate; private float lastProgress = Float.NaN; @@ -43,7 +41,7 @@ public class EjectorInstance extends ShaftInstance implements IDynamicInstance { @Override public void updateLight() { super.updateLight(); - relight(pos, plate.getInstance()); + relight(pos, plate); } @Override @@ -67,6 +65,6 @@ public class EjectorInstance extends ShaftInstance implements IDynamicInstance { EjectorRenderer.applyLidAngle(tile, angle, MatrixStacker.of(ms).translate(getInstancePosition())); - plate.getInstance().setTransform(ms); + plate.setTransform(ms); } } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/diodes/AdjustableRepeaterInstance.java b/src/main/java/com/simibubi/create/content/logistics/block/diodes/AdjustableRepeaterInstance.java index 4666c2b39..c7979e95e 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/diodes/AdjustableRepeaterInstance.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/diodes/AdjustableRepeaterInstance.java @@ -3,13 +3,13 @@ package com.simibubi.create.content.logistics.block.diodes; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.foundation.render.backend.instancing.*; -import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData; +import com.simibubi.create.foundation.render.backend.core.ModelData; import com.simibubi.create.foundation.utility.ColorHelper; import com.simibubi.create.foundation.utility.MatrixStacker; public class AdjustableRepeaterInstance extends TileEntityInstance implements ITickableInstance { - protected final InstanceKey indicator; + protected final ModelData indicator; protected int previousState; @@ -21,7 +21,7 @@ public class AdjustableRepeaterInstance extends TileEntityInstance implements IDynamicInstance { - private final ArrayList> flaps; + private final ArrayList flaps; public FunnelInstance(InstancedTileRenderer modelManager, FunnelTileEntity tile) { super(modelManager, tile); @@ -38,10 +38,9 @@ public class FunnelInstance extends TileEntityInstance impleme float intensity = segment == 3 ? 1.5f : segment + 1; float segmentOffset = -3 / 16f * segment; - InstanceKey key = model.createInstance(); + FlapData key = model.createInstance(); - key.getInstance() - .setPosition(pos) + key.setPosition(pos) .setSegmentOffset(segmentOffset, 0, -tile.getFlapOffset()) .setBlockLight(blockLight) .setSkyLight(skyLight) @@ -61,21 +60,21 @@ public class FunnelInstance extends TileEntityInstance impleme float flapness = tile.flap.get(AnimationTickHolder.getPartialTicks()); - for (InstanceKey key : flaps) { - key.getInstance().setFlapness(flapness); + for (FlapData flap : flaps) { + flap.setFlapness(flapness); } } @Override public void updateLight() { if (flaps != null) - relight(pos, flaps.stream().map(InstanceKey::getInstance)); + relight(pos, flaps.stream()); } @Override public void remove() { if (flaps == null) return; - flaps.forEach(InstanceKey::delete); + flaps.forEach(InstanceData::delete); } } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInstance.java b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInstance.java index 4944bb4f7..ca3e99a8f 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInstance.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInstance.java @@ -7,7 +7,7 @@ import com.simibubi.create.content.contraptions.base.RotatingData; import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; import com.simibubi.create.foundation.render.backend.instancing.*; -import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData; +import com.simibubi.create.foundation.render.backend.core.ModelData; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.ColorHelper; import com.simibubi.create.foundation.utility.Iterate; @@ -22,14 +22,14 @@ import java.util.ArrayList; public class ArmInstance extends SingleRotatingInstance implements IDynamicInstance { - final InstanceKey base; - final InstanceKey lowerBody; - final InstanceKey upperBody; - final InstanceKey head; - final InstanceKey claw; - private final ArrayList> clawGrips; + final ModelData base; + final ModelData lowerBody; + final ModelData upperBody; + final ModelData head; + final ModelData claw; + private final ArrayList clawGrips; - private final ArrayList> models; + private final ArrayList models; private final ArmTileEntity arm; private boolean firstTick = true; @@ -46,8 +46,8 @@ public class ArmInstance extends SingleRotatingInstance implements IDynamicInsta claw = mat.getModel(AllBlockPartials.ARM_CLAW_BASE, blockState).createInstance(); InstancedModel clawHalfModel = mat.getModel(AllBlockPartials.ARM_CLAW_GRIP, blockState); - InstanceKey clawGrip1 = clawHalfModel.createInstance(); - InstanceKey clawGrip2 = clawHalfModel.createInstance(); + ModelData clawGrip1 = clawHalfModel.createInstance(); + ModelData clawGrip2 = clawHalfModel.createInstance(); clawGrips = Lists.newArrayList(clawGrip1, clawGrip2); models = Lists.newArrayList(base, lowerBody, upperBody, head, claw, clawGrip1, clawGrip2); @@ -96,26 +96,21 @@ public class ArmInstance extends SingleRotatingInstance implements IDynamicInsta msr.rotateX(180); ArmRenderer.transformBase(msr, baseAngle); - base.getInstance() - .setTransform(msLocal); + base.setTransform(msLocal); ArmRenderer.transformLowerArm(msr, lowerArmAngle); - lowerBody.getInstance() - .setTransform(msLocal) + lowerBody.setTransform(msLocal) .setColor(color); ArmRenderer.transformUpperArm(msr, upperArmAngle); - upperBody.getInstance() - .setTransform(msLocal) + upperBody.setTransform(msLocal) .setColor(color); ArmRenderer.transformHead(msr, headAngle); - head.getInstance() - .setTransform(msLocal); + head.setTransform(msLocal); ArmRenderer.transformClaw(msr); - claw.getInstance() - .setTransform(msLocal); + claw.setTransform(msLocal); ItemStack item = this.arm.heldItem; ItemRenderer itemRenderer = Minecraft.getInstance() @@ -129,9 +124,7 @@ public class ArmInstance extends SingleRotatingInstance implements IDynamicInsta msLocal.push(); int flip = index * 2 - 1; ArmRenderer.transformClawHalf(msr, hasItem, isBlockItem, flip); - clawGrips.get(index) - .getInstance() - .setTransform(msLocal); + clawGrips.get(index).setTransform(msLocal); msLocal.pop(); } } @@ -140,7 +133,7 @@ public class ArmInstance extends SingleRotatingInstance implements IDynamicInsta public void updateLight() { super.updateLight(); - relight(pos, models.stream().map(InstanceKey::getInstance)); + relight(pos, models.stream()); } @Override @@ -151,6 +144,6 @@ public class ArmInstance extends SingleRotatingInstance implements IDynamicInsta @Override public void remove() { super.remove(); - models.forEach(InstanceKey::delete); + models.forEach(InstanceData::delete); } } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverInstance.java b/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverInstance.java index 3be2796a3..dc3e83671 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverInstance.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverInstance.java @@ -3,7 +3,7 @@ package com.simibubi.create.content.logistics.block.redstone; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.foundation.render.backend.instancing.*; -import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData; +import com.simibubi.create.foundation.render.backend.core.ModelData; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.ColorHelper; @@ -13,8 +13,8 @@ import net.minecraft.util.Direction; public class AnalogLeverInstance extends TileEntityInstance implements IDynamicInstance { - protected final InstanceKey handle; - protected final InstanceKey indicator; + protected final ModelData handle; + protected final ModelData indicator; final float rX; final float rY; @@ -50,8 +50,7 @@ public class AnalogLeverInstance extends TileEntityInstance implements IDynamicInstance { - private final InstanceKey connector; - private final InstanceKey pipe; + private final ModelData connector; + private final ModelData pipe; public SchematicannonInstance(InstancedTileRenderer modelManager, SchematicannonTileEntity tile) { super(modelManager, tile); @@ -44,7 +44,7 @@ public class SchematicannonInstance extends TileEntityInstance cir) { - if (isRemote) { - CreateClient.kineticRenderer.get((World)(Object) this).queueAdd(te); - } - } -} diff --git a/src/main/java/com/simibubi/create/foundation/mixin/TileWorldHookMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/TileWorldHookMixin.java new file mode 100644 index 000000000..0d7bca29c --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/mixin/TileWorldHookMixin.java @@ -0,0 +1,54 @@ +package com.simibubi.create.foundation.mixin; + +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.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import com.simibubi.create.CreateClient; +import com.simibubi.create.foundation.render.KineticRenderer; + +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +import java.util.Set; + +@OnlyIn(Dist.CLIENT) +@Mixin(value = World.class, priority = 1100) // this and create.mixins.json have high priority to load after Performant +public class TileWorldHookMixin { + + final World self = (World) (Object) this; + + @Shadow @Final public boolean isRemote; + + @Shadow @Final protected Set tileEntitiesToBeRemoved; + + @Inject(at = @At("TAIL"), method = "addTileEntity") + private void onAddTile(TileEntity te, CallbackInfoReturnable cir) { + if (isRemote) { + CreateClient.kineticRenderer.get(self).queueAdd(te); + } + } + + /** + * Without this we don't unload instances when a chunk unloads. + */ + @Inject(at = @At( + value = "INVOKE", + target = "Ljava/util/Set;clear()V", ordinal = 0 + ), + method = "tickBlockEntities") + private void onChunkUnload(CallbackInfo ci) { + if (isRemote) { + KineticRenderer kineticRenderer = CreateClient.kineticRenderer.get(self); + for (TileEntity tile : tileEntitiesToBeRemoved) { + kineticRenderer.remove(tile); + } + } + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/AllProgramSpecs.java b/src/main/java/com/simibubi/create/foundation/render/AllProgramSpecs.java index 502f4ee3e..d49cf8ca2 100644 --- a/src/main/java/com/simibubi/create/foundation/render/AllProgramSpecs.java +++ b/src/main/java/com/simibubi/create/foundation/render/AllProgramSpecs.java @@ -11,10 +11,10 @@ import com.simibubi.create.content.contraptions.components.structureMovement.ren import com.simibubi.create.content.contraptions.relays.belt.BeltAttributes; import com.simibubi.create.content.logistics.block.FlapAttributes; import com.simibubi.create.foundation.render.backend.gl.BasicProgram; -import com.simibubi.create.foundation.render.backend.instancing.impl.BasicAttributes; -import com.simibubi.create.foundation.render.backend.instancing.impl.TransformAttributes; -import com.simibubi.create.foundation.render.backend.instancing.impl.ModelAttributes; -import com.simibubi.create.foundation.render.backend.instancing.impl.OrientedAttributes; +import com.simibubi.create.foundation.render.backend.core.BasicAttributes; +import com.simibubi.create.foundation.render.backend.core.TransformAttributes; +import com.simibubi.create.foundation.render.backend.core.ModelAttributes; +import com.simibubi.create.foundation.render.backend.core.OrientedAttributes; import com.simibubi.create.foundation.render.backend.gl.shader.ProgramSpec; import com.simibubi.create.foundation.render.backend.gl.shader.ShaderConstants; diff --git a/src/main/java/com/simibubi/create/foundation/render/KineticRenderer.java b/src/main/java/com/simibubi/create/foundation/render/KineticRenderer.java index 250bc904b..f5bd3b237 100644 --- a/src/main/java/com/simibubi/create/foundation/render/KineticRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/KineticRenderer.java @@ -6,14 +6,14 @@ import com.simibubi.create.content.contraptions.base.KineticRenderMaterials; import com.simibubi.create.content.contraptions.base.RotatingModel; import com.simibubi.create.content.contraptions.relays.belt.BeltInstancedModel; import com.simibubi.create.content.logistics.block.FlapModel; -import com.simibubi.create.foundation.render.backend.RenderMaterials; +import com.simibubi.create.foundation.render.backend.MaterialTypes; import com.simibubi.create.foundation.render.backend.gl.BasicProgram; import com.simibubi.create.foundation.render.backend.gl.shader.ShaderCallback; import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; import com.simibubi.create.foundation.render.backend.instancing.RenderMaterial; -import com.simibubi.create.foundation.render.backend.instancing.impl.OrientedModel; -import com.simibubi.create.foundation.render.backend.instancing.impl.TransformedModel; +import com.simibubi.create.foundation.render.backend.core.OrientedModel; +import com.simibubi.create.foundation.render.backend.core.TransformedModel; import net.minecraft.client.renderer.ActiveRenderInfo; import net.minecraft.client.renderer.Matrix4f; @@ -29,8 +29,8 @@ public class KineticRenderer extends InstancedTileRenderer { @Override public void registerMaterials() { - materials.put(RenderMaterials.TRANSFORMED, new RenderMaterial<>(this, AllProgramSpecs.MODEL, TransformedModel::new)); - materials.put(RenderMaterials.ORIENTED, new RenderMaterial<>(this, AllProgramSpecs.ORIENTED, OrientedModel::new)); + materials.put(MaterialTypes.TRANSFORMED, new RenderMaterial<>(this, AllProgramSpecs.MODEL, TransformedModel::new)); + materials.put(MaterialTypes.ORIENTED, new RenderMaterial<>(this, AllProgramSpecs.ORIENTED, OrientedModel::new)); materials.put(KineticRenderMaterials.BELTS, new RenderMaterial<>(this, AllProgramSpecs.BELT, BeltInstancedModel::new)); materials.put(KineticRenderMaterials.ROTATING, new RenderMaterial<>(this, AllProgramSpecs.ROTATING, RotatingModel::new)); diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/MaterialType.java b/src/main/java/com/simibubi/create/foundation/render/backend/MaterialType.java new file mode 100644 index 000000000..f3c770051 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/backend/MaterialType.java @@ -0,0 +1,11 @@ +package com.simibubi.create.foundation.render.backend; + +import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; + +public class MaterialType> { + + @Override + public int hashCode() { + return super.hashCode() * 31 * 493286711; + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/RenderMaterials.java b/src/main/java/com/simibubi/create/foundation/render/backend/MaterialTypes.java similarity index 55% rename from src/main/java/com/simibubi/create/foundation/render/backend/RenderMaterials.java rename to src/main/java/com/simibubi/create/foundation/render/backend/MaterialTypes.java index 927b81601..59d519b79 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/RenderMaterials.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/MaterialTypes.java @@ -1,11 +1,10 @@ package com.simibubi.create.foundation.render.backend; -import com.simibubi.create.foundation.render.backend.instancing.MaterialType; import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; -import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData; -import com.simibubi.create.foundation.render.backend.instancing.impl.OrientedData; +import com.simibubi.create.foundation.render.backend.core.ModelData; +import com.simibubi.create.foundation.render.backend.core.OrientedData; -public class RenderMaterials { +public class MaterialTypes { public static final MaterialType> TRANSFORMED = new MaterialType<>(); public static final MaterialType> ORIENTED = new MaterialType<>(); } diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/BasicAttributes.java b/src/main/java/com/simibubi/create/foundation/render/backend/core/BasicAttributes.java similarity index 91% rename from src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/BasicAttributes.java rename to src/main/java/com/simibubi/create/foundation/render/backend/core/BasicAttributes.java index 0223037a7..8721aac88 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/BasicAttributes.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/core/BasicAttributes.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.render.backend.instancing.impl; +package com.simibubi.create.foundation.render.backend.core; import com.simibubi.create.foundation.render.backend.gl.attrib.CommonAttributes; import com.simibubi.create.foundation.render.backend.gl.attrib.IAttribSpec; diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/BasicData.java b/src/main/java/com/simibubi/create/foundation/render/backend/core/BasicData.java similarity index 92% rename from src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/BasicData.java rename to src/main/java/com/simibubi/create/foundation/render/backend/core/BasicData.java index 38fba8424..7d27c8eb1 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/BasicData.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/core/BasicData.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.render.backend.instancing.impl; +package com.simibubi.create.foundation.render.backend.core; import java.nio.ByteBuffer; import com.simibubi.create.foundation.render.backend.instancing.InstanceData; @@ -21,12 +21,14 @@ public class BasicData extends InstanceData implements IFlatLight { @Override public BasicData setBlockLight(int blockLight) { this.blockLight = (byte) (blockLight << 4); + markDirty(); return this; } @Override public BasicData setSkyLight(int skyLight) { this.skyLight = (byte) (skyLight << 4); + markDirty(); return this; } @@ -55,6 +57,7 @@ public class BasicData extends InstanceData implements IFlatLight { this.r = r; this.g = g; this.b = b; + markDirty(); return this; } @@ -63,6 +66,7 @@ public class BasicData extends InstanceData implements IFlatLight { this.g = g; this.b = b; this.a = a; + markDirty(); return this; } diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/IFlatLight.java b/src/main/java/com/simibubi/create/foundation/render/backend/core/IFlatLight.java similarity index 92% rename from src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/IFlatLight.java rename to src/main/java/com/simibubi/create/foundation/render/backend/core/IFlatLight.java index 7dea998b1..0920e037a 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/IFlatLight.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/core/IFlatLight.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.render.backend.instancing.impl; +package com.simibubi.create.foundation.render.backend.core; import com.simibubi.create.foundation.render.backend.instancing.InstanceData; diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/ModelAttributes.java b/src/main/java/com/simibubi/create/foundation/render/backend/core/ModelAttributes.java similarity index 93% rename from src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/ModelAttributes.java rename to src/main/java/com/simibubi/create/foundation/render/backend/core/ModelAttributes.java index 8854f3550..b4d220bc3 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/ModelAttributes.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/core/ModelAttributes.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.render.backend.instancing.impl; +package com.simibubi.create.foundation.render.backend.core; import com.simibubi.create.foundation.render.backend.gl.attrib.CommonAttributes; import com.simibubi.create.foundation.render.backend.gl.attrib.IAttribSpec; diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/ModelData.java b/src/main/java/com/simibubi/create/foundation/render/backend/core/ModelData.java similarity index 90% rename from src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/ModelData.java rename to src/main/java/com/simibubi/create/foundation/render/backend/core/ModelData.java index 2ad27e1b2..1db0f88da 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/ModelData.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/core/ModelData.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.render.backend.instancing.impl; +package com.simibubi.create.foundation.render.backend.core; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.foundation.render.backend.RenderUtil; @@ -17,6 +17,7 @@ public class ModelData extends BasicData { public ModelData setTransform(MatrixStack stack) { matrices = RenderUtil.writeMatrixStack(stack); + markDirty(); return this; } diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/OrientedAttributes.java b/src/main/java/com/simibubi/create/foundation/render/backend/core/OrientedAttributes.java similarity index 92% rename from src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/OrientedAttributes.java rename to src/main/java/com/simibubi/create/foundation/render/backend/core/OrientedAttributes.java index a5a7cef0d..9ee10ce4b 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/OrientedAttributes.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/core/OrientedAttributes.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.render.backend.instancing.impl; +package com.simibubi.create.foundation.render.backend.core; import com.simibubi.create.foundation.render.backend.gl.attrib.CommonAttributes; import com.simibubi.create.foundation.render.backend.gl.attrib.IAttribSpec; diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/OrientedData.java b/src/main/java/com/simibubi/create/foundation/render/backend/core/OrientedData.java similarity index 94% rename from src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/OrientedData.java rename to src/main/java/com/simibubi/create/foundation/render/backend/core/OrientedData.java index 2b4c8a185..246caad0d 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/OrientedData.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/core/OrientedData.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.render.backend.instancing.impl; +package com.simibubi.create.foundation.render.backend.core; import net.minecraft.client.renderer.Quaternion; import net.minecraft.client.renderer.Vector3f; @@ -39,6 +39,7 @@ public class OrientedData extends BasicData { this.posX = x; this.posY = y; this.posZ = z; + markDirty(); return this; } @@ -46,6 +47,7 @@ public class OrientedData extends BasicData { this.posX += x; this.posY += y; this.posZ += z; + markDirty(); return this; } @@ -61,6 +63,7 @@ public class OrientedData extends BasicData { this.pivotX = x; this.pivotY = y; this.pivotZ = z; + markDirty(); return this; } @@ -73,6 +76,7 @@ public class OrientedData extends BasicData { this.qY = y; this.qZ = z; this.qW = w; + markDirty(); return this; } diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/OrientedModel.java b/src/main/java/com/simibubi/create/foundation/render/backend/core/OrientedModel.java similarity index 92% rename from src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/OrientedModel.java rename to src/main/java/com/simibubi/create/foundation/render/backend/core/OrientedModel.java index 0389d119c..562bb9a74 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/OrientedModel.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/core/OrientedModel.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.render.backend.instancing.impl; +package com.simibubi.create.foundation.render.backend.core; import net.minecraft.client.renderer.BufferBuilder; diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/TransformAttributes.java b/src/main/java/com/simibubi/create/foundation/render/backend/core/TransformAttributes.java similarity index 92% rename from src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/TransformAttributes.java rename to src/main/java/com/simibubi/create/foundation/render/backend/core/TransformAttributes.java index 31daa9542..db7428aa9 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/TransformAttributes.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/core/TransformAttributes.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.render.backend.instancing.impl; +package com.simibubi.create.foundation.render.backend.core; import com.simibubi.create.foundation.render.backend.gl.attrib.IAttribSpec; import com.simibubi.create.foundation.render.backend.gl.attrib.IVertexAttrib; diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/TransformedModel.java b/src/main/java/com/simibubi/create/foundation/render/backend/core/TransformedModel.java similarity index 92% rename from src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/TransformedModel.java rename to src/main/java/com/simibubi/create/foundation/render/backend/core/TransformedModel.java index 27fef7d04..50a86fe80 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/impl/TransformedModel.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/core/TransformedModel.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.render.backend.instancing.impl; +package com.simibubi.create.foundation.render.backend.core; import com.simibubi.create.foundation.render.backend.gl.attrib.VertexFormat; import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/MapBuffer.java b/src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/MapBuffer.java index e5e03d4b3..74bd7baa4 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/MapBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/MapBuffer.java @@ -18,7 +18,7 @@ public enum MapBuffer implements GlVersioned { @Override public void mapBuffer(int target, int offset, int length, Consumer upload) { - ByteBuffer buffer = GL30.glMapBufferRange(target, offset, length, GL30.GL_MAP_WRITE_BIT | GL30.GL_MAP_INVALIDATE_RANGE_BIT); + ByteBuffer buffer = GL30.glMapBufferRange(target, offset, length, GL30.GL_MAP_WRITE_BIT); upload.accept(buffer); buffer.rewind(); @@ -34,7 +34,7 @@ public enum MapBuffer implements GlVersioned { @Override public void mapBuffer(int target, int offset, int length, Consumer upload) { - ByteBuffer buffer = ARBMapBufferRange.glMapBufferRange(target, offset, length, GL30.GL_MAP_WRITE_BIT | GL30.GL_MAP_INVALIDATE_RANGE_BIT); + ByteBuffer buffer = ARBMapBufferRange.glMapBufferRange(target, offset, length, GL30.GL_MAP_WRITE_BIT); upload.accept(buffer); buffer.rewind(); diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstanceData.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstanceData.java index 2facfb415..d77c75fb7 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstanceData.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstanceData.java @@ -6,12 +6,25 @@ public abstract class InstanceData { protected final InstancedModel owner; + boolean dirty; + boolean removed; + protected InstanceData(InstancedModel owner) { this.owner = owner; } public abstract void write(ByteBuffer buf); + public void markDirty() { + owner.anyToUpdate = true; + dirty = true; + } + + public void delete() { + owner.anyToRemove = true; + removed = true; + } + public void putVec4(ByteBuffer buf, float x, float y, float z, float w) { put(buf, x); put(buf, y); diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstanceKey.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstanceKey.java deleted file mode 100644 index 9927128c2..000000000 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstanceKey.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.simibubi.create.foundation.render.backend.instancing; - -public class InstanceKey { - public static final int INVALID = -1; - - InstancedModel model; - int index; - - public InstanceKey(InstancedModel model, int index) { - this.model = model; - this.index = index; - } - - void invalidate() { - index = INVALID; - } - - public boolean isValid() { - return index != INVALID; - } - - public D getInstance() { - return model.getInstance(this); - } - - public void delete() { - model.deleteInstance(this); - } -} diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedModel.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedModel.java index 2cefbb58a..5bc5465dc 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedModel.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedModel.java @@ -5,7 +5,6 @@ import java.nio.ByteBuffer; import java.util.*; import com.simibubi.create.foundation.render.backend.Backend; -import com.simibubi.create.foundation.render.backend.RenderUtil; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL15; import org.lwjgl.opengl.GL20; @@ -13,7 +12,7 @@ import org.lwjgl.opengl.GL20; import com.simibubi.create.foundation.render.backend.BufferedModel; import com.simibubi.create.foundation.render.backend.gl.GlBuffer; import com.simibubi.create.foundation.render.backend.gl.GlVertexArray; -import com.simibubi.create.foundation.render.backend.instancing.impl.ModelAttributes; +import com.simibubi.create.foundation.render.backend.core.ModelAttributes; import com.simibubi.create.foundation.render.backend.gl.attrib.VertexFormat; import net.minecraft.client.renderer.BufferBuilder; @@ -28,12 +27,10 @@ public abstract class InstancedModel extends BufferedMod protected int glBufferSize = -1; protected int glInstanceCount = 0; - protected final ArrayList> keys = new ArrayList<>(); protected final ArrayList data = new ArrayList<>(); - protected int minIndexChanged = -1; - protected int maxIndexChanged = -1; - protected boolean anyToRemove; + boolean anyToRemove; + boolean anyToUpdate; public InstancedModel(InstancedTileRenderer renderer, BufferBuilder buf) { super(buf); @@ -63,39 +60,19 @@ public abstract class InstancedModel extends BufferedMod } protected void deleteInternal() { - keys.forEach(InstanceKey::invalidate); super.deleteInternal(); instanceVBO.delete(); vao.delete(); } - public synchronized void deleteInstance(InstanceKey key) { - verifyKey(key); - - key.invalidate(); - - anyToRemove = true; - } - - public D getInstance(InstanceKey key) { - verifyKey(key); - - markIndexChanged(key.index); - - return this.data.get(key.index); - } - - public synchronized InstanceKey createInstance() { + public synchronized D createInstance() { D instanceData = newInstance(); - - InstanceKey key = new InstanceKey<>(this, data.size()); + instanceData.dirty = true; + anyToUpdate = true; data.add(instanceData); - keys.add(key); - markIndexChanged(key.index); - - return key; + return instanceData; } protected abstract D newInstance(); @@ -103,133 +80,153 @@ public abstract class InstancedModel extends BufferedMod protected void doRender() { vao.with(vao -> { renderSetup(); - Backend.compat.drawArraysInstanced(GL11.GL_QUADS, 0, vertexCount, glInstanceCount); + + if (glInstanceCount > 0) + Backend.compat.drawArraysInstanced(GL11.GL_QUADS, 0, vertexCount, glInstanceCount); }); } protected void renderSetup() { - boolean anyRemoved = doRemoval(); + if (anyToRemove) { + removeDeletedInstances(); + } - if (!anyRemoved && (minIndexChanged < 0 || data.isEmpty())) return; + instanceVBO.bind(); + if (!realloc()) { - VertexFormat instanceFormat = getInstanceFormat(); - - int stride = instanceFormat.getStride(); - int newInstanceCount = instanceCount(); - int instanceSize = RenderUtil.nextPowerOf2((newInstanceCount + 1) * stride); - - instanceVBO.with(vbo -> { - // this probably changes enough that it's not worth reallocating the entire buffer every time. - if (instanceSize > glBufferSize) { - GL15.glBufferData(vbo.getBufferType(), instanceSize, GL15.GL_STATIC_DRAW); - glBufferSize = instanceSize; - minIndexChanged = 0; - maxIndexChanged = newInstanceCount - 1; + if (anyToRemove) { + clearBufferTail(); } - int offset = minIndexChanged * stride; - int length = (1 + maxIndexChanged - minIndexChanged) * stride; - - if (length > 0) { - vbo.map(offset, length, buffer -> { - for (int i = minIndexChanged; i <= maxIndexChanged; i++) { - data.get(i).write(buffer); - } - }); + if (anyToUpdate) { + updateBuffer(); } - if (newInstanceCount < glInstanceCount) { - int clearFrom = (maxIndexChanged + 1) * stride; - int clearTo = (glInstanceCount) * stride; - vbo.map(clearFrom, clearTo - clearFrom, buffer -> { - for (int i = clearFrom; i < clearTo; i++) { - buffer.put((byte) 0); - } - }); - } + } - glInstanceCount = newInstanceCount; + glInstanceCount = data.size(); + informAttribDivisors(); + instanceVBO.unbind(); - int staticAttributes = getModelFormat().getShaderAttributeCount(); - instanceFormat.vertexAttribPointers(staticAttributes); - - for (int i = 0; i < instanceFormat.getShaderAttributeCount(); i++) { - Backend.compat.vertexAttribDivisor(i + staticAttributes, 1); - } - }); - - minIndexChanged = -1; - maxIndexChanged = -1; + this.anyToRemove = false; + this.anyToUpdate = false; } - // copied from ArrayList#removeIf - protected boolean doRemoval() { - if (!anyToRemove) return false; + private void informAttribDivisors() { + int staticAttributes = getModelFormat().getShaderAttributeCount(); + getInstanceFormat().vertexAttribPointers(staticAttributes); + for (int i = 0; i < getInstanceFormat().getShaderAttributeCount(); i++) { + Backend.compat.vertexAttribDivisor(i + staticAttributes, 1); + } + } + + private void clearBufferTail() { + int size = data.size(); + final int offset = size * getInstanceFormat().getStride(); + final int length = glBufferSize - offset; + if (length > 0) { + instanceVBO.map(offset, length, buffer -> { + buffer.put(new byte[length]); + }); + } + } + + private void updateBuffer() { + final int size = data.size(); + + if (size <= 0) return; + + final int stride = getInstanceFormat().getStride(); + final BitSet dirtySet = getDirtyBitSet(); + + if (dirtySet.isEmpty()) return; + + final int firstDirty = dirtySet.nextSetBit(0); + final int lastDirty = dirtySet.previousSetBit(size); + + final int offset = firstDirty * stride; + final int length = (1 + lastDirty - firstDirty) * stride; + + if (length > 0) { + instanceVBO.map(offset, length, buffer -> { + dirtySet.stream().forEach(i -> { + final D d = data.get(i); + + buffer.position(i * stride - offset); + d.write(buffer); + }); + }); + } + } + + private BitSet getDirtyBitSet() { + final int size = data.size(); + final BitSet dirtySet = new BitSet(size); + + for (int i = 0; i < size; i++) { + D element = data.get(i); + if (element.dirty) { + dirtySet.set(i); + + element.dirty = false; + } + } + return dirtySet; + } + + private boolean realloc() { + int size = this.data.size(); + int stride = getInstanceFormat().getStride(); + int requiredSize = size * stride; + if (requiredSize > glBufferSize) { + glBufferSize = requiredSize + stride * 16; + GL15.glBufferData(instanceVBO.getBufferType(), glBufferSize, GL15.GL_STATIC_DRAW); + + instanceVBO.map(glBufferSize, buffer -> { + for (D datum : data) { + datum.write(buffer); + } + }); + + glInstanceCount = size; + return true; + } + return false; + } + + private void removeDeletedInstances() { // figure out which elements are to be removed // any exception thrown from the filter predicate at this stage // will leave the collection unmodified + final int oldSize = this.data.size(); int removeCount = 0; - final int size = this.keys.size(); - final BitSet removeSet = new BitSet(size); - for (int i=0; i < size; i++) { - final InstanceKey element = this.keys.get(i); - if (!element.isValid()) { + final BitSet removeSet = new BitSet(oldSize); + for (int i = 0; i < oldSize; i++) { + final D element = this.data.get(i); + if (element.removed) { removeSet.set(i); removeCount++; } } + final int newSize = oldSize - removeCount; + // shift surviving elements left over the spaces left by removed elements - final boolean anyToRemove = removeCount > 0; - if (anyToRemove) { - final int newSize = size - removeCount; - for (int i = 0, j = 0; (i < size) && (j < newSize); i++, j++) { - i = removeSet.nextClearBit(i); - keys.set(j, keys.get(i)); - data.set(j, data.get(i)); + for (int i = 0, j = 0; (i < oldSize) && (j < newSize); i++, j++) { + i = removeSet.nextClearBit(i); + + if (i != j) { + D element = data.get(i); + data.set(j, element); + element.dirty = true; } - - keys.subList(newSize, size).clear(); - data.subList(newSize, size).clear(); - - int firstChanged = removeSet.nextSetBit(0); - - for (int i = firstChanged; i < newSize; i++) { - keys.get(i).index = i; - } - - minIndexChanged = 0; - maxIndexChanged = newSize - 1; } - this.anyToRemove = false; + anyToUpdate = true; - return anyToRemove; - } + data.subList(newSize, oldSize).clear(); - protected void markIndexChanged(int index) { - if (minIndexChanged < 0) { - minIndexChanged = index; - } else if (index < minIndexChanged) { - minIndexChanged = index; - } - - if (maxIndexChanged < 0) { - maxIndexChanged = index; - } else if (index > maxIndexChanged) { - maxIndexChanged = index; - } - } - - protected final void verifyKey(InstanceKey key) { - if (key.model != this) throw new IllegalStateException("Provided key does not belong to model."); - - if (!key.isValid()) throw new IllegalStateException("Provided key has been invalidated."); - - if (key.index >= data.size()) throw new IndexOutOfBoundsException("Key points out of bounds. (" + key.index + " > " + (data.size() - 1) + ")"); - - if (keys.get(key.index) != key) throw new IllegalStateException("Key desync!!"); } @Override diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java index 500a7a930..bcc7f7866 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java @@ -5,11 +5,12 @@ import java.util.*; import javax.annotation.Nullable; import com.simibubi.create.foundation.render.backend.Backend; -import com.simibubi.create.foundation.render.backend.RenderMaterials; +import com.simibubi.create.foundation.render.backend.MaterialType; +import com.simibubi.create.foundation.render.backend.MaterialTypes; import com.simibubi.create.foundation.render.backend.gl.BasicProgram; import com.simibubi.create.foundation.render.backend.gl.shader.ShaderCallback; -import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData; -import com.simibubi.create.foundation.render.backend.instancing.impl.OrientedData; +import com.simibubi.create.foundation.render.backend.core.ModelData; +import com.simibubi.create.foundation.render.backend.core.OrientedData; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.*; @@ -107,11 +108,11 @@ public abstract class InstancedTileRenderer

{ } public RenderMaterial> getTransformMaterial() { - return getMaterial(RenderMaterials.TRANSFORMED); + return getMaterial(MaterialTypes.TRANSFORMED); } public RenderMaterial> getOrientedMaterial() { - return getMaterial(RenderMaterials.ORIENTED); + return getMaterial(MaterialTypes.ORIENTED); } @SuppressWarnings("unchecked") diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/MaterialType.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/MaterialType.java deleted file mode 100644 index 4865eecd6..000000000 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/MaterialType.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.simibubi.create.foundation.render.backend.instancing; - -public class MaterialType> { - -} diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/TileEntityInstance.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/TileEntityInstance.java index 768171aee..cddd81123 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/TileEntityInstance.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/TileEntityInstance.java @@ -1,8 +1,8 @@ package com.simibubi.create.foundation.render.backend.instancing; -import com.simibubi.create.foundation.render.backend.instancing.impl.IFlatLight; -import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData; -import com.simibubi.create.foundation.render.backend.instancing.impl.OrientedData; +import com.simibubi.create.foundation.render.backend.core.IFlatLight; +import com.simibubi.create.foundation.render.backend.core.ModelData; +import com.simibubi.create.foundation.render.backend.core.OrientedData; import net.minecraft.block.BlockState; import net.minecraft.tileentity.TileEntity; @@ -103,7 +103,7 @@ public abstract class TileEntityInstance implements IInsta relight(world.getLightLevel(LightType.BLOCK, pos), world.getLightLevel(LightType.SKY, pos), models); } - protected void relight(BlockPos pos, Stream> models) { + protected > void relight(BlockPos pos, Stream models) { relight(world.getLightLevel(LightType.BLOCK, pos), world.getLightLevel(LightType.SKY, pos), models); } @@ -111,7 +111,7 @@ public abstract class TileEntityInstance implements IInsta relight(block, sky, Arrays.stream(models)); } - protected void relight(int block, int sky, Stream> models) { + protected > void relight(int block, int sky, Stream models) { models.forEach(model -> model.setBlockLight(block).setSkyLight(sky)); } diff --git a/src/main/resources/create.mixins.json b/src/main/resources/create.mixins.json index 1789b3b03..24c2db2a5 100644 --- a/src/main/resources/create.mixins.json +++ b/src/main/resources/create.mixins.json @@ -1,11 +1,12 @@ { "required": true, + "priority": 1100, "package": "com.simibubi.create.foundation.mixin", "compatibilityLevel": "JAVA_8", "refmap": "create.refmap.json", "mixins": ["StepSoundMixin"], "client": [ - "TileAddMixin", + "TileWorldHookMixin", "CancelTileEntityRenderMixin", "FogColorTrackerMixin", "LightUpdateMixin",