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:
This commit is contained in:
Jozufozu 2024-01-28 20:58:07 -08:00
parent 55254a6876
commit 94a9146abc
5 changed files with 17 additions and 39 deletions

View file

@ -4,11 +4,5 @@ import org.jetbrains.annotations.ApiStatus;
@ApiStatus.NonExtendable @ApiStatus.NonExtendable
public interface VisualTickContext { public interface VisualTickContext {
double cameraX(); // TODO: remove?
double cameraY();
double cameraZ();
DistanceUpdateLimiter limiter();
} }

View file

@ -1,8 +1,6 @@
package com.jozufozu.flywheel.impl.visual; package com.jozufozu.flywheel.impl.visual;
import com.jozufozu.flywheel.api.visual.DistanceUpdateLimiter;
import com.jozufozu.flywheel.api.visual.VisualTickContext; import com.jozufozu.flywheel.api.visual.VisualTickContext;
public record VisualTickContextImpl(double cameraX, double cameraY, double cameraZ, public record VisualTickContextImpl() implements VisualTickContext {
DistanceUpdateLimiter limiter) implements VisualTickContext {
} }

View file

@ -3,46 +3,36 @@ package com.jozufozu.flywheel.impl.visualization;
import com.jozufozu.flywheel.api.event.BeginFrameEvent; import com.jozufozu.flywheel.api.event.BeginFrameEvent;
import com.jozufozu.flywheel.api.event.RenderStageEvent; import com.jozufozu.flywheel.api.event.RenderStageEvent;
import com.jozufozu.flywheel.api.visualization.VisualizationManager; import com.jozufozu.flywheel.api.visualization.VisualizationManager;
import com.jozufozu.flywheel.lib.util.FlwUtil;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.entity.EntityJoinLevelEvent; import net.minecraftforge.event.entity.EntityJoinLevelEvent;
import net.minecraftforge.event.entity.EntityLeaveLevelEvent; import net.minecraftforge.event.entity.EntityLeaveLevelEvent;
import net.minecraftforge.fml.LogicalSide;
public final class VisualizationEventHandler { public final class VisualizationEventHandler {
private VisualizationEventHandler() { private VisualizationEventHandler() {
} }
public static void onClientTick(TickEvent.ClientTickEvent event) { public static void onClientTick(TickEvent.LevelTickEvent event) {
if (event.phase != TickEvent.Phase.END || !FlwUtil.isGameActive()) { // Make sure we don't tick on the server somehow.
if (event.phase != TickEvent.Phase.END || event.side != LogicalSide.CLIENT) {
return; return;
} }
Minecraft mc = Minecraft.getInstance(); // The game won't be paused in the tick event, but let's make sure there's a player.
if (mc.isPaused()) { if (Minecraft.getInstance().player == null) {
return; return;
} }
Entity cameraEntity = mc.getCameraEntity() == null ? mc.player : mc.getCameraEntity(); VisualizationManagerImpl manager = VisualizationManagerImpl.get(event.level);
if (cameraEntity == null) {
return;
}
Level level = cameraEntity.level();
VisualizationManagerImpl manager = VisualizationManagerImpl.get(level);
if (manager == null) { if (manager == null) {
return; return;
} }
double cameraX = cameraEntity.getX(); manager.tick();
double cameraY = cameraEntity.getEyeY();
double cameraZ = cameraEntity.getZ();
manager.tick(cameraX, cameraY, cameraZ);
} }
public static void onBeginFrame(BeginFrameEvent event) { public static void onBeginFrame(BeginFrameEvent event) {

View file

@ -77,11 +77,9 @@ public class VisualizationManagerImpl implements VisualizationManager {
private final Flag frameVisualsFlag = new NamedFlag("frameVisualUpdates"); private final Flag frameVisualsFlag = new NamedFlag("frameVisualUpdates");
private final Flag frameFlag = new NamedFlag("frameComplete"); private final Flag frameFlag = new NamedFlag("frameComplete");
protected DistanceUpdateLimiterImpl tickLimiter;
protected DistanceUpdateLimiterImpl frameLimiter; protected DistanceUpdateLimiterImpl frameLimiter;
private VisualizationManagerImpl(LevelAccessor level) { private VisualizationManagerImpl(LevelAccessor level) {
tickLimiter = createUpdateLimiter();
frameLimiter = createUpdateLimiter(); frameLimiter = createUpdateLimiter();
engine = BackendManager.getBackend() engine = BackendManager.getBackend()
@ -219,7 +217,7 @@ public class VisualizationManagerImpl implements VisualizationManager {
* Call {@link TickableVisual#tick} on all visuals in this world. * Call {@link TickableVisual#tick} on all visuals in this world.
* </p> * </p>
*/ */
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. // Make sure we're done with any prior frame or tick to avoid racing.
taskExecutor.syncUntil(frameFlag::isRaised); taskExecutor.syncUntil(frameFlag::isRaised);
frameFlag.lower(); frameFlag.lower();
@ -227,18 +225,15 @@ public class VisualizationManagerImpl implements VisualizationManager {
taskExecutor.syncUntil(tickFlag::isRaised); taskExecutor.syncUntil(tickFlag::isRaised);
tickFlag.lower(); tickFlag.lower();
tickLimiter.tick(); tickPlan.execute(taskExecutor, new VisualTickContextImpl());
tickPlan.execute(taskExecutor, new VisualTickContextImpl(cameraX, cameraY, cameraZ, frameLimiter));
} }
/** /**
* Get ready to render a frame. * Get ready to render a frame.
* <p> *
* Check and update the render origin. * <p>Check and update the render origin.
* <br> * <br>
* Call {@link DynamicVisual#beginFrame} on all visuals in this world. * Call {@link DynamicVisual#beginFrame} on all visuals in this world.</p>
* </p>
*/ */
public void beginFrame(RenderContext context) { public void beginFrame(RenderContext context) {
// Make sure we're done with the last tick. // Make sure we're done with the last tick.

View file

@ -24,6 +24,7 @@ public class BlockEntityStorage extends Storage<BlockEntity> {
super(visualizationContextSupplier); super(visualizationContextSupplier);
} }
@Nullable
public BlockEntityVisual<?> visualAtPos(long pos) { public BlockEntityVisual<?> visualAtPos(long pos) {
return posLookup.get(pos); return posLookup.get(pos);
} }