From e19cc337feb270ce46b40a9749ab57f7c4ac3c6e Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Sat, 18 May 2024 17:34:45 -0700 Subject: [PATCH] A ticking time bomb - Add context object back to SimpleTickableVisual#tick - Document base *Visual plan methods --- .../jozufozu/flywheel/api/visual/DynamicVisual.java | 12 ++++++++++++ .../jozufozu/flywheel/api/visual/TickableVisual.java | 12 ++++++++++++ .../flywheel/lib/visual/SimpleTickableVisual.java | 2 +- .../jozufozu/flywheel/vanilla/MinecartVisual.java | 3 ++- 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/common/src/api/java/com/jozufozu/flywheel/api/visual/DynamicVisual.java b/common/src/api/java/com/jozufozu/flywheel/api/visual/DynamicVisual.java index f128ada4e..2f815a807 100644 --- a/common/src/api/java/com/jozufozu/flywheel/api/visual/DynamicVisual.java +++ b/common/src/api/java/com/jozufozu/flywheel/api/visual/DynamicVisual.java @@ -3,6 +3,8 @@ import org.jetbrains.annotations.ApiStatus; import org.joml.FrustumIntersection; +import com.jozufozu.flywheel.api.instance.Instance; +import com.jozufozu.flywheel.api.instance.Instancer; import com.jozufozu.flywheel.api.task.Plan; import net.minecraft.client.Camera; @@ -14,6 +16,16 @@ * parameterization. */ public interface DynamicVisual extends Visual { + /** + * Invoked every frame. + *
+ * The implementation is free to parallelize the invocation of this plan. + * You must ensure proper synchronization if you need to mutate anything outside this visual. + *
+ * This plan and the one returned by {@link TickableVisual#planTick} will never be invoked simultaneously. + *
+ * {@link Instancer}/{@link Instance} creation/acquisition is safe here. + */ Plan planFrame(); /** diff --git a/common/src/api/java/com/jozufozu/flywheel/api/visual/TickableVisual.java b/common/src/api/java/com/jozufozu/flywheel/api/visual/TickableVisual.java index 8d25ef0a8..26ab8e76a 100644 --- a/common/src/api/java/com/jozufozu/flywheel/api/visual/TickableVisual.java +++ b/common/src/api/java/com/jozufozu/flywheel/api/visual/TickableVisual.java @@ -2,6 +2,8 @@ import org.jetbrains.annotations.ApiStatus; +import com.jozufozu.flywheel.api.instance.Instance; +import com.jozufozu.flywheel.api.instance.Instancer; import com.jozufozu.flywheel.api.task.Plan; /** @@ -9,6 +11,16 @@ * the end of every tick. */ public interface TickableVisual extends Visual { + /** + * Invoked every tick. + *
+ * The implementation is free to parallelize the invocation of this plan. + * You must ensure proper synchronization if you need to mutate anything outside this visual. + *
+ * This plan and the one returned by {@link DynamicVisual#planFrame} will never be invoked simultaneously. + *
+ * {@link Instancer}/{@link Instance} creation/acquisition is safe here. + */ Plan planTick(); /** diff --git a/common/src/lib/java/com/jozufozu/flywheel/lib/visual/SimpleTickableVisual.java b/common/src/lib/java/com/jozufozu/flywheel/lib/visual/SimpleTickableVisual.java index ac9a2d658..110adcd49 100644 --- a/common/src/lib/java/com/jozufozu/flywheel/lib/visual/SimpleTickableVisual.java +++ b/common/src/lib/java/com/jozufozu/flywheel/lib/visual/SimpleTickableVisual.java @@ -18,7 +18,7 @@ public interface SimpleTickableVisual extends TickableVisual { *
* {@link Instancer}/{@link Instance} creation/acquisition is safe here. */ - void tick(); + void tick(Context context); @Override default Plan planTick() { diff --git a/common/src/main/java/com/jozufozu/flywheel/vanilla/MinecartVisual.java b/common/src/main/java/com/jozufozu/flywheel/vanilla/MinecartVisual.java index c231457a7..54d4ca073 100644 --- a/common/src/main/java/com/jozufozu/flywheel/vanilla/MinecartVisual.java +++ b/common/src/main/java/com/jozufozu/flywheel/vanilla/MinecartVisual.java @@ -3,6 +3,7 @@ import org.jetbrains.annotations.Nullable; import com.jozufozu.flywheel.api.visual.DynamicVisual; +import com.jozufozu.flywheel.api.visual.TickableVisual; import com.jozufozu.flywheel.api.visualization.VisualizationContext; import com.jozufozu.flywheel.lib.instance.InstanceTypes; import com.jozufozu.flywheel.lib.instance.TransformedInstance; @@ -99,7 +100,7 @@ private TransformedInstance createContentsInstance() { } @Override - public void tick() { + public void tick(TickableVisual.Context context) { BlockState displayBlockState = entity.getDisplayBlockState(); if (displayBlockState != blockState) {