From b1dc36d3582f9232b30e86aca8473e933a6a0b77 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Tue, 2 Mar 2021 23:12:43 -0800 Subject: [PATCH] Trying to tick everything is slow. - Keep track of tickable instances separately. --- .../block/belts/tunnel/BeltTunnelInstance.java | 2 +- .../logistics/block/funnel/FunnelInstance.java | 2 +- .../render/backend/instancing/ITickableInstance.java | 8 ++++++++ .../backend/instancing/InstancedTileRenderer.java | 11 ++++++++--- .../render/backend/instancing/TileEntityInstance.java | 5 ----- 5 files changed, 18 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/render/backend/instancing/ITickableInstance.java 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 5b38ee07f..654bea79b 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 @@ -16,7 +16,7 @@ import java.util.Collection; import java.util.EnumMap; import java.util.Map; -public class BeltTunnelInstance extends TileEntityInstance { +public class BeltTunnelInstance extends TileEntityInstance implements ITickableInstance { public static void register(TileEntityType type) { DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> InstancedTileRenderRegistry.instance.register(type, BeltTunnelInstance::new)); diff --git a/src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelInstance.java b/src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelInstance.java index 21d838502..b91a5b37f 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelInstance.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelInstance.java @@ -13,7 +13,7 @@ import net.minecraftforge.fml.DistExecutor; import java.util.ArrayList; -public class FunnelInstance extends TileEntityInstance { +public class FunnelInstance extends TileEntityInstance implements ITickableInstance { public static void register(TileEntityType type) { DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> InstancedTileRenderRegistry.instance.register(type, FunnelInstance::new)); diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/ITickableInstance.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/ITickableInstance.java new file mode 100644 index 000000000..4d79545a4 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/ITickableInstance.java @@ -0,0 +1,8 @@ +package com.simibubi.create.foundation.render.backend.instancing; + +public interface ITickableInstance { + /** + * Called every frame, this can be used to make more dynamic animations. + */ + void tick(); +} 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 2f7c37288..325a3c3a5 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 @@ -1,7 +1,6 @@ package com.simibubi.create.foundation.render.backend.instancing; -import java.util.HashMap; -import java.util.Map; +import java.util.*; import javax.annotation.Nullable; @@ -20,6 +19,8 @@ import net.minecraft.world.World; public abstract class InstancedTileRenderer

{ protected Map> instances = new HashMap<>(); + protected Map tickableInstances = new HashMap<>(); + protected Map, RenderMaterial> materials = new HashMap<>(); protected InstancedTileRenderer() { @@ -41,7 +42,7 @@ public abstract class InstancedTileRenderer

{ } public void beginFrame(double cameraX, double cameraY, double cameraZ) { - instances.values().forEach(TileEntityInstance::tick); + tickableInstances.values().forEach(ITickableInstance::tick); } public void render(RenderType layer, Matrix4f viewProjection, double camX, double camY, double camZ) { @@ -79,6 +80,9 @@ public abstract class InstancedTileRenderer

{ if (renderer != null) { instances.put(tile, renderer); + + if (renderer instanceof ITickableInstance) + tickableInstances.put(tile, (ITickableInstance) renderer); } return renderer; @@ -126,6 +130,7 @@ public abstract class InstancedTileRenderer

{ if (instance != null) { instance.remove(); instances.remove(tile); + tickableInstances.remove(tile); } } } 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 fd77e7fd3..8683832da 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 @@ -33,11 +33,6 @@ public abstract class TileEntityInstance { } } - /** - * Called every frame, this can be used to make more dynamic animations. - */ - public void tick() { } - /** * Acquire all {@link InstanceKey}s and initialize any data you may need to calculate the instance properties. */