mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-11-10 12:34:11 +01:00
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:
parent
55254a6876
commit
94a9146abc
@ -4,11 +4,5 @@ import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
@ApiStatus.NonExtendable
|
||||
public interface VisualTickContext {
|
||||
double cameraX();
|
||||
|
||||
double cameraY();
|
||||
|
||||
double cameraZ();
|
||||
|
||||
DistanceUpdateLimiter limiter();
|
||||
// TODO: remove?
|
||||
}
|
||||
|
@ -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 {
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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.
|
||||
* </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.
|
||||
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.
|
||||
* <p>
|
||||
* Check and update the render origin.
|
||||
*
|
||||
* <p>Check and update the render origin.
|
||||
* <br>
|
||||
* Call {@link DynamicVisual#beginFrame} on all visuals in this world.
|
||||
* </p>
|
||||
* Call {@link DynamicVisual#beginFrame} on all visuals in this world.</p>
|
||||
*/
|
||||
public void beginFrame(RenderContext context) {
|
||||
// Make sure we're done with the last tick.
|
||||
|
@ -24,6 +24,7 @@ public class BlockEntityStorage extends Storage<BlockEntity> {
|
||||
super(visualizationContextSupplier);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public BlockEntityVisual<?> visualAtPos(long pos) {
|
||||
return posLookup.get(pos);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user