diff --git a/src/main/java/com/jozufozu/flywheel/api/event/RenderContext.java b/src/main/java/com/jozufozu/flywheel/api/event/RenderContext.java index a336d97be..4108b9934 100644 --- a/src/main/java/com/jozufozu/flywheel/api/event/RenderContext.java +++ b/src/main/java/com/jozufozu/flywheel/api/event/RenderContext.java @@ -9,13 +9,20 @@ import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.renderer.LevelRenderer; import net.minecraft.client.renderer.RenderBuffers; -public record RenderContext(LevelRenderer renderer, ClientLevel level, RenderBuffers buffers, PoseStack stack, - Matrix4f projection, Matrix4f viewProjection, Camera camera, float partialTick) { - public static RenderContext create(LevelRenderer renderer, ClientLevel level, RenderBuffers buffers, PoseStack stack, Matrix4f projection, Camera camera, float partialTick) { - Matrix4f viewProjection = new Matrix4f(projection); - viewProjection.mul(stack.last() - .pose()); +public interface RenderContext { + LevelRenderer renderer(); - return new RenderContext(renderer, level, buffers, stack, projection, viewProjection, camera, partialTick); - } + ClientLevel level(); + + RenderBuffers buffers(); + + PoseStack stack(); + + Matrix4f projection(); + + Matrix4f viewProjection(); + + Camera camera(); + + float partialTick(); } diff --git a/src/main/java/com/jozufozu/flywheel/api/visual/DynamicVisual.java b/src/main/java/com/jozufozu/flywheel/api/visual/DynamicVisual.java index 28a85ec0a..426fa419c 100644 --- a/src/main/java/com/jozufozu/flywheel/api/visual/DynamicVisual.java +++ b/src/main/java/com/jozufozu/flywheel/api/visual/DynamicVisual.java @@ -15,9 +15,12 @@ import com.jozufozu.flywheel.api.instance.Instancer; public interface DynamicVisual extends Visual { /** * Called every frame. - *
- * DISPATCHED IN PARALLEL. Ensure proper synchronization if you need to mutate anything outside this visual. - *
+ *
+ * The implementation is free to parallelize calls to this method.
+ * You must ensure proper synchronization if you need to mutate anything outside this visual.
+ *
+ * This method and {@link TickableVisual#tick} will never be called simultaneously.
+ *
* {@link Instancer}/{@link Instance} creation/acquisition is safe here.
*/
void beginFrame(VisualFrameContext ctx);
diff --git a/src/main/java/com/jozufozu/flywheel/api/visual/LitVisual.java b/src/main/java/com/jozufozu/flywheel/api/visual/LitVisual.java
index a60eb753e..697f324d0 100644
--- a/src/main/java/com/jozufozu/flywheel/api/visual/LitVisual.java
+++ b/src/main/java/com/jozufozu/flywheel/api/visual/LitVisual.java
@@ -15,6 +15,11 @@ public interface LitVisual extends Visual {
* Called when a section this visual is contained in receives a light update.
*
* Even if multiple sections are updated at the same time, this method will only be called once.
+ *
+ * The implementation is free to parallelize calls to this method, as well as call into
+ * {@link DynamicVisual#beginFrame} simultaneously. It is safe to query/update light here,
+ * but you must ensure proper synchronization if you want to mutate anything outside this
+ * visual or anything that is also mutated by {@link DynamicVisual#beginFrame}.
*/
void updateLight();
diff --git a/src/main/java/com/jozufozu/flywheel/api/visual/TickableVisual.java b/src/main/java/com/jozufozu/flywheel/api/visual/TickableVisual.java
index 822d34f84..1d4f3056b 100644
--- a/src/main/java/com/jozufozu/flywheel/api/visual/TickableVisual.java
+++ b/src/main/java/com/jozufozu/flywheel/api/visual/TickableVisual.java
@@ -22,9 +22,12 @@ import com.jozufozu.flywheel.api.instance.Instancer;
public interface TickableVisual extends Visual {
/**
* Called every tick.
- *
- * DISPATCHED IN PARALLEL. Ensure proper synchronization if you need to mutate anything outside this visual. - *
+ *
+ * The implementation is free to parallelize calls to this method.
+ * You must ensure proper synchronization if you need to mutate anything outside this visual.
+ *
+ * This method and {@link DynamicVisual#beginFrame} will never be called simultaneously.
+ *
* {@link Instancer}/{@link Instance} creation/acquisition is safe here.
*/
void tick(VisualTickContext ctx);
diff --git a/src/main/java/com/jozufozu/flywheel/api/visual/Visual.java b/src/main/java/com/jozufozu/flywheel/api/visual/Visual.java
index 87c392315..5421d4397 100644
--- a/src/main/java/com/jozufozu/flywheel/api/visual/Visual.java
+++ b/src/main/java/com/jozufozu/flywheel/api/visual/Visual.java
@@ -5,6 +5,8 @@ package com.jozufozu.flywheel.api.visual;
*
* @see DynamicVisual
* @see TickableVisual
+ * @see PlannedVisual
+ * @see LitVisual
*/
public interface Visual {
/**
diff --git a/src/main/java/com/jozufozu/flywheel/api/visual/VisualFrameContext.java b/src/main/java/com/jozufozu/flywheel/api/visual/VisualFrameContext.java
index dc0011b3b..2fe30d1ad 100644
--- a/src/main/java/com/jozufozu/flywheel/api/visual/VisualFrameContext.java
+++ b/src/main/java/com/jozufozu/flywheel/api/visual/VisualFrameContext.java
@@ -2,6 +2,16 @@ package com.jozufozu.flywheel.api.visual;
import org.joml.FrustumIntersection;
-public record VisualFrameContext(double cameraX, double cameraY, double cameraZ, FrustumIntersection frustum,
- float partialTick, DistanceUpdateLimiter limiter) {
+public interface VisualFrameContext {
+ double cameraX();
+
+ double cameraY();
+
+ double cameraZ();
+
+ FrustumIntersection frustum();
+
+ float partialTick();
+
+ DistanceUpdateLimiter limiter();
}
diff --git a/src/main/java/com/jozufozu/flywheel/api/visual/VisualTickContext.java b/src/main/java/com/jozufozu/flywheel/api/visual/VisualTickContext.java
index 6185d2dd9..7faa1ff29 100644
--- a/src/main/java/com/jozufozu/flywheel/api/visual/VisualTickContext.java
+++ b/src/main/java/com/jozufozu/flywheel/api/visual/VisualTickContext.java
@@ -1,4 +1,11 @@
package com.jozufozu.flywheel.api.visual;
-public record VisualTickContext(double cameraX, double cameraY, double cameraZ, DistanceUpdateLimiter limiter) {
+public interface VisualTickContext {
+ double cameraX();
+
+ double cameraY();
+
+ double cameraZ();
+
+ DistanceUpdateLimiter limiter();
}
diff --git a/src/main/java/com/jozufozu/flywheel/api/visualization/VisualizationContext.java b/src/main/java/com/jozufozu/flywheel/api/visualization/VisualizationContext.java
index cc2c30d53..f8c116359 100644
--- a/src/main/java/com/jozufozu/flywheel/api/visualization/VisualizationContext.java
+++ b/src/main/java/com/jozufozu/flywheel/api/visualization/VisualizationContext.java
@@ -6,10 +6,17 @@ import net.minecraft.core.Vec3i;
/**
* A context object passed on visual creation.
- *
- * @param instancerProvider The {@link InstancerProvider} that the visual can use to get instancers to render models.
- * @param renderOrigin The origin of the renderer as a world position.
- * All models render as if this position is (0, 0, 0).
*/
-public record VisualizationContext(InstancerProvider instancerProvider, Vec3i renderOrigin) {
+public interface VisualizationContext {
+ /**
+ * @return The {@link InstancerProvider} that the visual can use to get instancers to render models.
+ */
+ InstancerProvider instancerProvider();
+
+ /**
+ * All models render as if this position is (0, 0, 0).
+ *
+ * @return The origin of the renderer as a world position.
+ */
+ Vec3i renderOrigin();
}
diff --git a/src/main/java/com/jozufozu/flywheel/impl/event/RenderContextImpl.java b/src/main/java/com/jozufozu/flywheel/impl/event/RenderContextImpl.java
new file mode 100644
index 000000000..d5d5d1636
--- /dev/null
+++ b/src/main/java/com/jozufozu/flywheel/impl/event/RenderContextImpl.java
@@ -0,0 +1,23 @@
+package com.jozufozu.flywheel.impl.event;
+
+import org.joml.Matrix4f;
+
+import com.jozufozu.flywheel.api.event.RenderContext;
+import com.mojang.blaze3d.vertex.PoseStack;
+
+import net.minecraft.client.Camera;
+import net.minecraft.client.multiplayer.ClientLevel;
+import net.minecraft.client.renderer.LevelRenderer;
+import net.minecraft.client.renderer.RenderBuffers;
+
+public record RenderContextImpl(LevelRenderer renderer, ClientLevel level, RenderBuffers buffers, PoseStack stack,
+ Matrix4f projection, Matrix4f viewProjection, Camera camera,
+ float partialTick) implements RenderContext {
+ public static RenderContextImpl create(LevelRenderer renderer, ClientLevel level, RenderBuffers buffers, PoseStack stack, Matrix4f projection, Camera camera, float partialTick) {
+ Matrix4f viewProjection = new Matrix4f(projection);
+ viewProjection.mul(stack.last()
+ .pose());
+
+ return new RenderContextImpl(renderer, level, buffers, stack, projection, viewProjection, camera, partialTick);
+ }
+}
diff --git a/src/main/java/com/jozufozu/flywheel/impl/visual/VisualFrameContextImpl.java b/src/main/java/com/jozufozu/flywheel/impl/visual/VisualFrameContextImpl.java
new file mode 100644
index 000000000..2fa833c12
--- /dev/null
+++ b/src/main/java/com/jozufozu/flywheel/impl/visual/VisualFrameContextImpl.java
@@ -0,0 +1,10 @@
+package com.jozufozu.flywheel.impl.visual;
+
+import org.joml.FrustumIntersection;
+
+import com.jozufozu.flywheel.api.visual.DistanceUpdateLimiter;
+import com.jozufozu.flywheel.api.visual.VisualFrameContext;
+
+public record VisualFrameContextImpl(double cameraX, double cameraY, double cameraZ, FrustumIntersection frustum,
+ float partialTick, DistanceUpdateLimiter limiter) implements VisualFrameContext {
+}
diff --git a/src/main/java/com/jozufozu/flywheel/impl/visual/VisualTickContextImpl.java b/src/main/java/com/jozufozu/flywheel/impl/visual/VisualTickContextImpl.java
new file mode 100644
index 000000000..176d58543
--- /dev/null
+++ b/src/main/java/com/jozufozu/flywheel/impl/visual/VisualTickContextImpl.java
@@ -0,0 +1,8 @@
+package com.jozufozu.flywheel.impl.visual;
+
+import com.jozufozu.flywheel.api.visual.DistanceUpdateLimiter;
+import com.jozufozu.flywheel.api.visual.VisualTickContext;
+
+public record VisualTickContextImpl(double cameraX, double cameraY, double cameraZ,
+ DistanceUpdateLimiter limiter) implements VisualTickContext {
+}
diff --git a/src/main/java/com/jozufozu/flywheel/impl/visualization/TickContext.java b/src/main/java/com/jozufozu/flywheel/impl/visualization/TickContext.java
deleted file mode 100644
index 4d005e58e..000000000
--- a/src/main/java/com/jozufozu/flywheel/impl/visualization/TickContext.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package com.jozufozu.flywheel.impl.visualization;
-
-public record TickContext(double cameraX, double cameraY, double cameraZ) {
-}
diff --git a/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationContextImpl.java b/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationContextImpl.java
new file mode 100644
index 000000000..eaf888a82
--- /dev/null
+++ b/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationContextImpl.java
@@ -0,0 +1,17 @@
+package com.jozufozu.flywheel.impl.visualization;
+
+import com.jozufozu.flywheel.api.instance.InstancerProvider;
+import com.jozufozu.flywheel.api.visualization.VisualizationContext;
+
+import net.minecraft.core.Vec3i;
+
+/**
+ * A context object passed on visual creation.
+ *
+ * @param instancerProvider The {@link InstancerProvider} that the visual can use to get instancers to render models.
+ * @param renderOrigin The origin of the renderer as a world position.
+ * All models render as if this position is (0, 0, 0).
+ */
+public record VisualizationContextImpl(InstancerProvider instancerProvider,
+ Vec3i renderOrigin) implements VisualizationContext {
+}
diff --git a/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationManagerImpl.java b/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationManagerImpl.java
index 7417641da..432ee9670 100644
--- a/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationManagerImpl.java
+++ b/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationManagerImpl.java
@@ -5,6 +5,7 @@ import java.util.List;
import java.util.SortedSet;
import java.util.function.Supplier;
+import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.Nullable;
import org.joml.FrustumIntersection;
import org.joml.Matrix4f;
@@ -28,6 +29,8 @@ import com.jozufozu.flywheel.api.visualization.VisualizationManager;
import com.jozufozu.flywheel.config.FlwConfig;
import com.jozufozu.flywheel.extension.LevelExtension;
import com.jozufozu.flywheel.impl.task.FlwTaskExecutor;
+import com.jozufozu.flywheel.impl.visual.VisualFrameContextImpl;
+import com.jozufozu.flywheel.impl.visual.VisualTickContextImpl;
import com.jozufozu.flywheel.impl.visualization.manager.BlockEntityStorage;
import com.jozufozu.flywheel.impl.visualization.manager.EffectStorage;
import com.jozufozu.flywheel.impl.visualization.manager.EntityStorage;
@@ -57,7 +60,7 @@ import net.minecraft.world.level.block.entity.BlockEntity;
/**
* A manager class for a single world where visualization is supported.
*/
-public class VisualizationManagerImpl implements VisualizationManager, Supplier