From a82e3f8dd51e541e2d772c882a0106511090e250 Mon Sep 17 00:00:00 2001
From: Jozufozu
Date: Sun, 28 Jan 2024 20:58:07 -0800
Subject: [PATCH] What makes it tick
- Tick visual managers on post LevelTickEvent.
- Remove all field from VisualTickContext, but keep the interface there
for later review.
- Remove tick update limiter, though apparently we were passing the
frame limiter to the tick context :lwe:
---
.../api/visual/VisualTickContext.java | 8 +-----
.../impl/visual/VisualTickContextImpl.java | 4 +--
.../VisualizationEventHandler.java | 26 ++++++-------------
.../VisualizationManagerImpl.java | 17 +++++-------
.../manager/BlockEntityStorage.java | 1 +
5 files changed, 17 insertions(+), 39 deletions(-)
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 31a1ab6a1..b74294d23 100644
--- a/src/main/java/com/jozufozu/flywheel/api/visual/VisualTickContext.java
+++ b/src/main/java/com/jozufozu/flywheel/api/visual/VisualTickContext.java
@@ -4,11 +4,5 @@ import org.jetbrains.annotations.ApiStatus;
@ApiStatus.NonExtendable
public interface VisualTickContext {
- double cameraX();
-
- double cameraY();
-
- double cameraZ();
-
- DistanceUpdateLimiter limiter();
+ // TODO: remove?
}
diff --git a/src/main/java/com/jozufozu/flywheel/impl/visual/VisualTickContextImpl.java b/src/main/java/com/jozufozu/flywheel/impl/visual/VisualTickContextImpl.java
index 176d58543..e17eb7bc0 100644
--- a/src/main/java/com/jozufozu/flywheel/impl/visual/VisualTickContextImpl.java
+++ b/src/main/java/com/jozufozu/flywheel/impl/visual/VisualTickContextImpl.java
@@ -1,8 +1,6 @@
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 {
+public record VisualTickContextImpl() implements VisualTickContext {
}
diff --git a/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationEventHandler.java b/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationEventHandler.java
index 5d62c8e0c..2d704ffaf 100644
--- a/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationEventHandler.java
+++ b/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationEventHandler.java
@@ -3,46 +3,36 @@ package com.jozufozu.flywheel.impl.visualization;
import com.jozufozu.flywheel.api.event.BeginFrameEvent;
import com.jozufozu.flywheel.api.event.RenderStageEvent;
import com.jozufozu.flywheel.api.visualization.VisualizationManager;
-import com.jozufozu.flywheel.lib.util.FlwUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
-import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.entity.EntityJoinLevelEvent;
import net.minecraftforge.event.entity.EntityLeaveLevelEvent;
+import net.minecraftforge.fml.LogicalSide;
public final class VisualizationEventHandler {
private VisualizationEventHandler() {
}
- public static void onClientTick(TickEvent.ClientTickEvent event) {
- if (event.phase != TickEvent.Phase.END || !FlwUtil.isGameActive()) {
+ public static void onClientTick(TickEvent.LevelTickEvent event) {
+ // Make sure we don't tick on the server somehow.
+ if (event.phase != TickEvent.Phase.END || event.side != LogicalSide.CLIENT) {
return;
}
- Minecraft mc = Minecraft.getInstance();
- if (mc.isPaused()) {
+ // The game won't be paused in the tick event, but let's make sure there's a player.
+ if (Minecraft.getInstance().player == null) {
return;
}
- Entity cameraEntity = mc.getCameraEntity() == null ? mc.player : mc.getCameraEntity();
- if (cameraEntity == null) {
- return;
- }
-
- Level level = cameraEntity.level();
- VisualizationManagerImpl manager = VisualizationManagerImpl.get(level);
+ VisualizationManagerImpl manager = VisualizationManagerImpl.get(event.level);
if (manager == null) {
return;
}
- double cameraX = cameraEntity.getX();
- double cameraY = cameraEntity.getEyeY();
- double cameraZ = cameraEntity.getZ();
-
- manager.tick(cameraX, cameraY, cameraZ);
+ manager.tick();
}
public static void onBeginFrame(BeginFrameEvent event) {
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 42e268138..76fdedcb1 100644
--- a/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationManagerImpl.java
+++ b/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationManagerImpl.java
@@ -77,11 +77,9 @@ public class VisualizationManagerImpl implements VisualizationManager {
private final Flag frameVisualsFlag = new NamedFlag("frameVisualUpdates");
private final Flag frameFlag = new NamedFlag("frameComplete");
- protected DistanceUpdateLimiterImpl tickLimiter;
protected DistanceUpdateLimiterImpl frameLimiter;
private VisualizationManagerImpl(LevelAccessor level) {
- tickLimiter = createUpdateLimiter();
frameLimiter = createUpdateLimiter();
engine = BackendManager.getBackend()
@@ -219,7 +217,7 @@ public class VisualizationManagerImpl implements VisualizationManager {
* Call {@link TickableVisual#tick} on all visuals in this world.
*
*/
- public void tick(double cameraX, double cameraY, double cameraZ) {
+ public void tick() {
// Make sure we're done with any prior frame or tick to avoid racing.
taskExecutor.syncUntil(frameFlag::isRaised);
frameFlag.lower();
@@ -227,18 +225,15 @@ public class VisualizationManagerImpl implements VisualizationManager {
taskExecutor.syncUntil(tickFlag::isRaised);
tickFlag.lower();
- tickLimiter.tick();
-
- tickPlan.execute(taskExecutor, new VisualTickContextImpl(cameraX, cameraY, cameraZ, frameLimiter));
+ tickPlan.execute(taskExecutor, new VisualTickContextImpl());
}
/**
* Get ready to render a frame.
- *
- * Check and update the render origin.
- *
- * Call {@link DynamicVisual#beginFrame} on all visuals in this world.
- *
+ *
+ * Check and update the render origin.
+ *
+ * Call {@link DynamicVisual#beginFrame} on all visuals in this world.
*/
public void beginFrame(RenderContext context) {
// Make sure we're done with the last tick.
diff --git a/src/main/java/com/jozufozu/flywheel/impl/visualization/manager/BlockEntityStorage.java b/src/main/java/com/jozufozu/flywheel/impl/visualization/manager/BlockEntityStorage.java
index 64a772cbc..ae7d93341 100644
--- a/src/main/java/com/jozufozu/flywheel/impl/visualization/manager/BlockEntityStorage.java
+++ b/src/main/java/com/jozufozu/flywheel/impl/visualization/manager/BlockEntityStorage.java
@@ -24,6 +24,7 @@ public class BlockEntityStorage extends Storage {
super(visualizationContextSupplier);
}
+ @Nullable
public BlockEntityVisual> visualAtPos(long pos) {
return posLookup.get(pos);
}