Remove WrappedTimer

This commit is contained in:
Jonas Herzig
2024-06-23 14:30:59 +02:00
parent 454e990849
commit 310dc90e11
9 changed files with 27 additions and 142 deletions

View File

@@ -7,11 +7,6 @@ import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(RenderTickCounter.class)
public interface TimerAccessor {
@Accessor("prevTimeMillis")
long getLastSyncSysClock();
@Accessor("prevTimeMillis")
void setLastSyncSysClock(long value);
//#if MC>=11200
@Accessor("tickTime")
float getTickLength();
@@ -23,25 +18,5 @@ public interface TimerAccessor {
//$$ float getTimerSpeed();
//$$ @Accessor
//$$ void setTimerSpeed(float value);
//$$ @Accessor
//$$ float getTicksPerSecond();
//$$ @Accessor
//$$ void setTicksPerSecond(float value);
//$$ @Accessor
//$$ double getLastHRTime();
//$$ @Accessor
//$$ void setLastHRTime(double value);
//$$ @Accessor
//$$ long getLastSyncHRClock();
//$$ @Accessor
//$$ void setLastSyncHRClock(long value);
//$$ @Accessor
//$$ double getTimeSyncAdjustment();
//$$ @Accessor
//$$ void setTimeSyncAdjustment(double value);
//$$ @Accessor
//$$ long getCounter();
//$$ @Accessor
//$$ void setCounter(long value);
//#endif
}

View File

@@ -71,6 +71,8 @@ import static com.replaymod.core.versions.MCVer.getMinecraft;
public class Utils {
private static Logger LOGGER = LogManager.getLogger();
public static final float DEFAULT_MS_PER_TICK = 1000 / 20;
private static InputStream getResourceAsStream(String path) {
return Utils.class.getResourceAsStream(path);
}

View File

@@ -1,71 +0,0 @@
package com.replaymod.core.utils;
import com.replaymod.core.mixin.TimerAccessor;
import net.minecraft.client.render.RenderTickCounter;
public class WrappedTimer extends RenderTickCounter {
public static final float DEFAULT_MS_PER_TICK = 1000 / 20;
protected final RenderTickCounter wrapped;
public WrappedTimer(RenderTickCounter wrapped) {
//#if MC>=12003
//$$ super(0, 0, f -> f);
//#elseif MC>=11400
super(0, 0);
//#else
//$$ super(0);
//#endif
this.wrapped = wrapped;
copy(wrapped, this);
}
@Override
public
//#if MC>=11600
int
//#else
//$$ void
//#endif
beginRenderTick(
//#if MC>=11400
long sysClock
//#endif
) {
copy(this, wrapped);
try {
//#if MC>=11600
return
//#endif
wrapped.beginRenderTick(
//#if MC>=11400
sysClock
//#endif
);
} finally {
copy(wrapped, this);
}
}
protected void copy(RenderTickCounter from, RenderTickCounter to) {
TimerAccessor fromA = (TimerAccessor) from;
TimerAccessor toA = (TimerAccessor) to;
//#if MC<11600
//$$ to.ticksThisFrame = from.ticksThisFrame;
//#endif
to.tickDelta = from.tickDelta;
toA.setLastSyncSysClock(fromA.getLastSyncSysClock());
to.lastFrameDuration = from.lastFrameDuration;
//#if MC>=11200
toA.setTickLength(fromA.getTickLength());
//#else
//$$ toA.setTicksPerSecond(fromA.getTicksPerSecond());
//$$ toA.setLastHRTime(fromA.getLastHRTime());
//$$ toA.setTimerSpeed(fromA.getTimerSpeed());
//$$ toA.setLastSyncHRClock(fromA.getLastSyncHRClock());
//$$ toA.setCounter(fromA.getCounter());
//$$ toA.setTimeSyncAdjustment(fromA.getTimeSyncAdjustment());
//#endif
}
}

View File

@@ -8,7 +8,6 @@ import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
import com.replaymod.core.mixin.MinecraftAccessor;
import com.replaymod.core.mixin.TimerAccessor;
import com.replaymod.core.utils.WrappedTimer;
import com.replaymod.replay.ReplayHandler;
import com.replaymod.replaystudio.pathing.path.Keyframe;
import com.replaymod.replaystudio.pathing.path.Path;
@@ -20,6 +19,7 @@ import net.minecraft.client.render.RenderTickCounter;
import javax.annotation.Nullable;
import java.util.Iterator;
import static com.replaymod.core.utils.Utils.DEFAULT_MS_PER_TICK;
import static com.replaymod.core.versions.MCVer.*;
/**
@@ -31,6 +31,7 @@ public abstract class AbstractTimelinePlayer extends EventRegistrations {
private Timeline timeline;
protected long startOffset;
private boolean wasAsyncMode;
private RenderTickCounter orgTimer;
private long lastTime;
private long lastTimestamp;
private ListenableFuture<Void> future;
@@ -76,13 +77,14 @@ public abstract class AbstractTimelinePlayer extends EventRegistrations {
lastTime = 0;
MinecraftAccessor mcA = (MinecraftAccessor) mc;
ReplayTimer timer = new ReplayTimer(mcA.getTimer());
orgTimer = mcA.getTimer();
ReplayTimer timer = new ReplayTimer();
mcA.setTimer(timer);
//noinspection ConstantConditions
TimerAccessor timerA = (TimerAccessor) timer;
//#if MC>=11200
timerA.setTickLength(WrappedTimer.DEFAULT_MS_PER_TICK);
timerA.setTickLength(DEFAULT_MS_PER_TICK);
timer.tickDelta = timer.ticksThisFrame = 0;
//#else
//$$ timer.timerSpeed = 1;
@@ -103,7 +105,7 @@ public abstract class AbstractTimelinePlayer extends EventRegistrations {
public void onTick() {
if (future.isDone()) {
MinecraftAccessor mcA = (MinecraftAccessor) mc;
mcA.setTimer(((ReplayTimer) mcA.getTimer()).getWrapped());
mcA.setTimer(orgTimer);
replayHandler.getReplaySender().setReplaySpeed(0);
if (wasAsyncMode) {
replayHandler.getReplaySender().setAsyncMode(true);

View File

@@ -1,27 +1,24 @@
package com.replaymod.pathing.player;
import com.replaymod.core.utils.WrappedTimer;
import de.johni0702.minecraft.gui.utils.Event;
import net.minecraft.client.render.RenderTickCounter;
/**
* Wrapper around the current timer that prevents the timer from advancing by itself.
* A timer that does not advance by itself.
*/
public class ReplayTimer extends WrappedTimer {
//#if MC>=12003
//$$ private final RenderTickCounter state = new RenderTickCounter(0, 0, f -> f);
//#elseif MC>=11400
private final RenderTickCounter state = new RenderTickCounter(0, 0);
//#else
//$$ private final Timer state = new Timer(0);
//#endif
public class ReplayTimer extends RenderTickCounter {
//#if MC>=11600
public int ticksThisFrame;
//#endif
public ReplayTimer(RenderTickCounter wrapped) {
super(wrapped);
public ReplayTimer() {
//#if MC>=12003
//$$ super(0, 0, f -> f);
//#elseif MC>=11400
super(0, 0);
//#else
//$$ super(0);
//#endif
}
@Override
@@ -41,29 +38,12 @@ public class ReplayTimer extends WrappedTimer {
long sysClock
//#endif
) {
copy(this, state); // Save our current state
try {
//#if MC>=11600
ticksThisFrame =
//#endif
wrapped.beginRenderTick(
//#if MC>=11400
sysClock
//#endif
); // Update current state
} finally {
copy(state, this); // Restore our old state
UpdatedCallback.EVENT.invoker().onUpdate();
}
UpdatedCallback.EVENT.invoker().onUpdate();
//#if MC>=11600
return ticksThisFrame;
//#endif
}
public RenderTickCounter getWrapped() {
return wrapped;
}
public interface UpdatedCallback {
Event<UpdatedCallback> EVENT = Event.create((listeners) ->
() -> {

View File

@@ -3,7 +3,6 @@ package com.replaymod.render.rendering;
import com.mojang.blaze3d.platform.GlStateManager;
import com.replaymod.core.mixin.MinecraftAccessor;
import com.replaymod.core.mixin.TimerAccessor;
import com.replaymod.core.utils.WrappedTimer;
import com.replaymod.core.versions.MCVer;
import com.replaymod.pathing.player.AbstractTimelinePlayer;
import com.replaymod.pathing.properties.TimestampProperty;
@@ -85,6 +84,7 @@ import java.util.concurrent.FutureTask;
import java.util.stream.Stream;
import static com.google.common.collect.Iterables.getLast;
import static com.replaymod.core.utils.Utils.DEFAULT_MS_PER_TICK;
import static com.replaymod.core.versions.MCVer.*;
import static com.replaymod.render.ReplayModRender.LOGGER;
import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
@@ -207,7 +207,7 @@ public class VideoRenderer implements RenderInfo {
int replayTime = videoStart - 1000;
//#if MC>=11200
timer.tickDelta = 0;
((TimerAccessor) timer).setTickLength(WrappedTimer.DEFAULT_MS_PER_TICK);
((TimerAccessor) timer).setTickLength(DEFAULT_MS_PER_TICK);
//#else
//$$ timer.elapsedPartialTicks = timer.renderPartialTicks = 0;
//$$ timer.timerSpeed = 1;

View File

@@ -117,7 +117,6 @@ import net.minecraft.util.Identifier;
//#endif
//#if MC>=11200
import com.replaymod.core.utils.WrappedTimer;
import net.minecraft.network.packet.s2c.play.AdvancementUpdateS2CPacket;
import net.minecraft.network.packet.s2c.play.SelectAdvancementTabS2CPacket;
import net.minecraft.network.packet.s2c.play.SynchronizeRecipesS2CPacket;
@@ -152,6 +151,7 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;
import static com.replaymod.core.utils.Utils.DEFAULT_MS_PER_TICK;
import static com.replaymod.core.versions.MCVer.*;
import static com.replaymod.replaystudio.util.Utils.readInt;
@@ -985,7 +985,7 @@ public class FullReplaySender extends ChannelInboundHandlerAdapter implements Re
}
TimerAccessor timer = (TimerAccessor) ((MinecraftAccessor) mc).getTimer();
//#if MC>=11200
timer.setTickLength(WrappedTimer.DEFAULT_MS_PER_TICK / (float) d);
timer.setTickLength(DEFAULT_MS_PER_TICK / (float) d);
//#else
//$$ timer.setTimerSpeed((float) d);
//#endif

View File

@@ -24,10 +24,7 @@ import javax.annotation.Nullable;
import java.io.IOException;
import java.util.function.Consumer;
//#if MC>=11200
import com.replaymod.core.utils.WrappedTimer;
//#endif
import static com.replaymod.core.utils.Utils.DEFAULT_MS_PER_TICK;
import static com.replaymod.core.versions.MCVer.getMinecraft;
import static com.replaymod.core.versions.MCVer.getPacketTypeRegistry;
import static com.replaymod.replay.ReplayModReplay.LOGGER;
@@ -164,7 +161,7 @@ public class QuickReplaySender extends ChannelHandlerAdapter implements ReplaySe
}
TimerAccessor timer = (TimerAccessor) ((MinecraftAccessor) mc).getTimer();
//#if MC>=11200
timer.setTickLength(WrappedTimer.DEFAULT_MS_PER_TICK / (float) factor);
timer.setTickLength(DEFAULT_MS_PER_TICK / (float) factor);
//#else
//$$ timer.setTimerSpeed((float) factor);
//#endif

View File

@@ -10,7 +10,6 @@ import com.replaymod.core.mixin.MinecraftAccessor;
import com.replaymod.core.mixin.TimerAccessor;
import com.replaymod.core.utils.Restrictions;
import com.replaymod.core.utils.Utils;
import com.replaymod.core.utils.WrappedTimer;
import com.replaymod.replay.camera.CameraEntity;
import com.replaymod.replay.camera.SpectatorCameraController;
import com.replaymod.replay.events.ReplayClosedCallback;
@@ -124,6 +123,7 @@ import net.minecraft.network.NetworkSide;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import static com.replaymod.core.utils.Utils.DEFAULT_MS_PER_TICK;
import static com.replaymod.core.versions.MCVer.*;
import static com.replaymod.replay.ReplayModReplay.LOGGER;
import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
@@ -263,7 +263,7 @@ public class ReplayHandler {
TimerAccessor timer = (TimerAccessor) ((MinecraftAccessor) mc).getTimer();
//#if MC>=11200
timer.setTickLength(WrappedTimer.DEFAULT_MS_PER_TICK);
timer.setTickLength(DEFAULT_MS_PER_TICK);
//#else
//$$ timer.setTimerSpeed(1);
//#endif