Remove WrappedTimer
This commit is contained in:
@@ -7,11 +7,6 @@ import org.spongepowered.asm.mixin.gen.Accessor;
|
|||||||
|
|
||||||
@Mixin(RenderTickCounter.class)
|
@Mixin(RenderTickCounter.class)
|
||||||
public interface TimerAccessor {
|
public interface TimerAccessor {
|
||||||
@Accessor("prevTimeMillis")
|
|
||||||
long getLastSyncSysClock();
|
|
||||||
@Accessor("prevTimeMillis")
|
|
||||||
void setLastSyncSysClock(long value);
|
|
||||||
|
|
||||||
//#if MC>=11200
|
//#if MC>=11200
|
||||||
@Accessor("tickTime")
|
@Accessor("tickTime")
|
||||||
float getTickLength();
|
float getTickLength();
|
||||||
@@ -23,25 +18,5 @@ public interface TimerAccessor {
|
|||||||
//$$ float getTimerSpeed();
|
//$$ float getTimerSpeed();
|
||||||
//$$ @Accessor
|
//$$ @Accessor
|
||||||
//$$ void setTimerSpeed(float value);
|
//$$ 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
|
//#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,6 +71,8 @@ import static com.replaymod.core.versions.MCVer.getMinecraft;
|
|||||||
public class Utils {
|
public class Utils {
|
||||||
private static Logger LOGGER = LogManager.getLogger();
|
private static Logger LOGGER = LogManager.getLogger();
|
||||||
|
|
||||||
|
public static final float DEFAULT_MS_PER_TICK = 1000 / 20;
|
||||||
|
|
||||||
private static InputStream getResourceAsStream(String path) {
|
private static InputStream getResourceAsStream(String path) {
|
||||||
return Utils.class.getResourceAsStream(path);
|
return Utils.class.getResourceAsStream(path);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -8,7 +8,6 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||||||
import com.google.common.util.concurrent.SettableFuture;
|
import com.google.common.util.concurrent.SettableFuture;
|
||||||
import com.replaymod.core.mixin.MinecraftAccessor;
|
import com.replaymod.core.mixin.MinecraftAccessor;
|
||||||
import com.replaymod.core.mixin.TimerAccessor;
|
import com.replaymod.core.mixin.TimerAccessor;
|
||||||
import com.replaymod.core.utils.WrappedTimer;
|
|
||||||
import com.replaymod.replay.ReplayHandler;
|
import com.replaymod.replay.ReplayHandler;
|
||||||
import com.replaymod.replaystudio.pathing.path.Keyframe;
|
import com.replaymod.replaystudio.pathing.path.Keyframe;
|
||||||
import com.replaymod.replaystudio.pathing.path.Path;
|
import com.replaymod.replaystudio.pathing.path.Path;
|
||||||
@@ -20,6 +19,7 @@ import net.minecraft.client.render.RenderTickCounter;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import static com.replaymod.core.utils.Utils.DEFAULT_MS_PER_TICK;
|
||||||
import static com.replaymod.core.versions.MCVer.*;
|
import static com.replaymod.core.versions.MCVer.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,6 +31,7 @@ public abstract class AbstractTimelinePlayer extends EventRegistrations {
|
|||||||
private Timeline timeline;
|
private Timeline timeline;
|
||||||
protected long startOffset;
|
protected long startOffset;
|
||||||
private boolean wasAsyncMode;
|
private boolean wasAsyncMode;
|
||||||
|
private RenderTickCounter orgTimer;
|
||||||
private long lastTime;
|
private long lastTime;
|
||||||
private long lastTimestamp;
|
private long lastTimestamp;
|
||||||
private ListenableFuture<Void> future;
|
private ListenableFuture<Void> future;
|
||||||
@@ -76,13 +77,14 @@ public abstract class AbstractTimelinePlayer extends EventRegistrations {
|
|||||||
lastTime = 0;
|
lastTime = 0;
|
||||||
|
|
||||||
MinecraftAccessor mcA = (MinecraftAccessor) mc;
|
MinecraftAccessor mcA = (MinecraftAccessor) mc;
|
||||||
ReplayTimer timer = new ReplayTimer(mcA.getTimer());
|
orgTimer = mcA.getTimer();
|
||||||
|
ReplayTimer timer = new ReplayTimer();
|
||||||
mcA.setTimer(timer);
|
mcA.setTimer(timer);
|
||||||
|
|
||||||
//noinspection ConstantConditions
|
//noinspection ConstantConditions
|
||||||
TimerAccessor timerA = (TimerAccessor) timer;
|
TimerAccessor timerA = (TimerAccessor) timer;
|
||||||
//#if MC>=11200
|
//#if MC>=11200
|
||||||
timerA.setTickLength(WrappedTimer.DEFAULT_MS_PER_TICK);
|
timerA.setTickLength(DEFAULT_MS_PER_TICK);
|
||||||
timer.tickDelta = timer.ticksThisFrame = 0;
|
timer.tickDelta = timer.ticksThisFrame = 0;
|
||||||
//#else
|
//#else
|
||||||
//$$ timer.timerSpeed = 1;
|
//$$ timer.timerSpeed = 1;
|
||||||
@@ -103,7 +105,7 @@ public abstract class AbstractTimelinePlayer extends EventRegistrations {
|
|||||||
public void onTick() {
|
public void onTick() {
|
||||||
if (future.isDone()) {
|
if (future.isDone()) {
|
||||||
MinecraftAccessor mcA = (MinecraftAccessor) mc;
|
MinecraftAccessor mcA = (MinecraftAccessor) mc;
|
||||||
mcA.setTimer(((ReplayTimer) mcA.getTimer()).getWrapped());
|
mcA.setTimer(orgTimer);
|
||||||
replayHandler.getReplaySender().setReplaySpeed(0);
|
replayHandler.getReplaySender().setReplaySpeed(0);
|
||||||
if (wasAsyncMode) {
|
if (wasAsyncMode) {
|
||||||
replayHandler.getReplaySender().setAsyncMode(true);
|
replayHandler.getReplaySender().setAsyncMode(true);
|
||||||
|
|||||||
@@ -1,27 +1,24 @@
|
|||||||
package com.replaymod.pathing.player;
|
package com.replaymod.pathing.player;
|
||||||
|
|
||||||
import com.replaymod.core.utils.WrappedTimer;
|
|
||||||
import de.johni0702.minecraft.gui.utils.Event;
|
import de.johni0702.minecraft.gui.utils.Event;
|
||||||
import net.minecraft.client.render.RenderTickCounter;
|
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 {
|
public class ReplayTimer extends RenderTickCounter {
|
||||||
//#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
|
|
||||||
|
|
||||||
//#if MC>=11600
|
//#if MC>=11600
|
||||||
public int ticksThisFrame;
|
public int ticksThisFrame;
|
||||||
//#endif
|
//#endif
|
||||||
|
|
||||||
public ReplayTimer(RenderTickCounter wrapped) {
|
public ReplayTimer() {
|
||||||
super(wrapped);
|
//#if MC>=12003
|
||||||
|
//$$ super(0, 0, f -> f);
|
||||||
|
//#elseif MC>=11400
|
||||||
|
super(0, 0);
|
||||||
|
//#else
|
||||||
|
//$$ super(0);
|
||||||
|
//#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -41,29 +38,12 @@ public class ReplayTimer extends WrappedTimer {
|
|||||||
long sysClock
|
long sysClock
|
||||||
//#endif
|
//#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
|
//#if MC>=11600
|
||||||
return ticksThisFrame;
|
return ticksThisFrame;
|
||||||
//#endif
|
//#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public RenderTickCounter getWrapped() {
|
|
||||||
return wrapped;
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface UpdatedCallback {
|
public interface UpdatedCallback {
|
||||||
Event<UpdatedCallback> EVENT = Event.create((listeners) ->
|
Event<UpdatedCallback> EVENT = Event.create((listeners) ->
|
||||||
() -> {
|
() -> {
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package com.replaymod.render.rendering;
|
|||||||
import com.mojang.blaze3d.platform.GlStateManager;
|
import com.mojang.blaze3d.platform.GlStateManager;
|
||||||
import com.replaymod.core.mixin.MinecraftAccessor;
|
import com.replaymod.core.mixin.MinecraftAccessor;
|
||||||
import com.replaymod.core.mixin.TimerAccessor;
|
import com.replaymod.core.mixin.TimerAccessor;
|
||||||
import com.replaymod.core.utils.WrappedTimer;
|
|
||||||
import com.replaymod.core.versions.MCVer;
|
import com.replaymod.core.versions.MCVer;
|
||||||
import com.replaymod.pathing.player.AbstractTimelinePlayer;
|
import com.replaymod.pathing.player.AbstractTimelinePlayer;
|
||||||
import com.replaymod.pathing.properties.TimestampProperty;
|
import com.replaymod.pathing.properties.TimestampProperty;
|
||||||
@@ -85,6 +84,7 @@ import java.util.concurrent.FutureTask;
|
|||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import static com.google.common.collect.Iterables.getLast;
|
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.core.versions.MCVer.*;
|
||||||
import static com.replaymod.render.ReplayModRender.LOGGER;
|
import static com.replaymod.render.ReplayModRender.LOGGER;
|
||||||
import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
|
import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
|
||||||
@@ -207,7 +207,7 @@ public class VideoRenderer implements RenderInfo {
|
|||||||
int replayTime = videoStart - 1000;
|
int replayTime = videoStart - 1000;
|
||||||
//#if MC>=11200
|
//#if MC>=11200
|
||||||
timer.tickDelta = 0;
|
timer.tickDelta = 0;
|
||||||
((TimerAccessor) timer).setTickLength(WrappedTimer.DEFAULT_MS_PER_TICK);
|
((TimerAccessor) timer).setTickLength(DEFAULT_MS_PER_TICK);
|
||||||
//#else
|
//#else
|
||||||
//$$ timer.elapsedPartialTicks = timer.renderPartialTicks = 0;
|
//$$ timer.elapsedPartialTicks = timer.renderPartialTicks = 0;
|
||||||
//$$ timer.timerSpeed = 1;
|
//$$ timer.timerSpeed = 1;
|
||||||
|
|||||||
@@ -117,7 +117,6 @@ import net.minecraft.util.Identifier;
|
|||||||
//#endif
|
//#endif
|
||||||
|
|
||||||
//#if MC>=11200
|
//#if MC>=11200
|
||||||
import com.replaymod.core.utils.WrappedTimer;
|
|
||||||
import net.minecraft.network.packet.s2c.play.AdvancementUpdateS2CPacket;
|
import net.minecraft.network.packet.s2c.play.AdvancementUpdateS2CPacket;
|
||||||
import net.minecraft.network.packet.s2c.play.SelectAdvancementTabS2CPacket;
|
import net.minecraft.network.packet.s2c.play.SelectAdvancementTabS2CPacket;
|
||||||
import net.minecraft.network.packet.s2c.play.SynchronizeRecipesS2CPacket;
|
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.Executors;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
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.core.versions.MCVer.*;
|
||||||
import static com.replaymod.replaystudio.util.Utils.readInt;
|
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();
|
TimerAccessor timer = (TimerAccessor) ((MinecraftAccessor) mc).getTimer();
|
||||||
//#if MC>=11200
|
//#if MC>=11200
|
||||||
timer.setTickLength(WrappedTimer.DEFAULT_MS_PER_TICK / (float) d);
|
timer.setTickLength(DEFAULT_MS_PER_TICK / (float) d);
|
||||||
//#else
|
//#else
|
||||||
//$$ timer.setTimerSpeed((float) d);
|
//$$ timer.setTimerSpeed((float) d);
|
||||||
//#endif
|
//#endif
|
||||||
|
|||||||
@@ -24,10 +24,7 @@ import javax.annotation.Nullable;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
//#if MC>=11200
|
import static com.replaymod.core.utils.Utils.DEFAULT_MS_PER_TICK;
|
||||||
import com.replaymod.core.utils.WrappedTimer;
|
|
||||||
//#endif
|
|
||||||
|
|
||||||
import static com.replaymod.core.versions.MCVer.getMinecraft;
|
import static com.replaymod.core.versions.MCVer.getMinecraft;
|
||||||
import static com.replaymod.core.versions.MCVer.getPacketTypeRegistry;
|
import static com.replaymod.core.versions.MCVer.getPacketTypeRegistry;
|
||||||
import static com.replaymod.replay.ReplayModReplay.LOGGER;
|
import static com.replaymod.replay.ReplayModReplay.LOGGER;
|
||||||
@@ -164,7 +161,7 @@ public class QuickReplaySender extends ChannelHandlerAdapter implements ReplaySe
|
|||||||
}
|
}
|
||||||
TimerAccessor timer = (TimerAccessor) ((MinecraftAccessor) mc).getTimer();
|
TimerAccessor timer = (TimerAccessor) ((MinecraftAccessor) mc).getTimer();
|
||||||
//#if MC>=11200
|
//#if MC>=11200
|
||||||
timer.setTickLength(WrappedTimer.DEFAULT_MS_PER_TICK / (float) factor);
|
timer.setTickLength(DEFAULT_MS_PER_TICK / (float) factor);
|
||||||
//#else
|
//#else
|
||||||
//$$ timer.setTimerSpeed((float) factor);
|
//$$ timer.setTimerSpeed((float) factor);
|
||||||
//#endif
|
//#endif
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import com.replaymod.core.mixin.MinecraftAccessor;
|
|||||||
import com.replaymod.core.mixin.TimerAccessor;
|
import com.replaymod.core.mixin.TimerAccessor;
|
||||||
import com.replaymod.core.utils.Restrictions;
|
import com.replaymod.core.utils.Restrictions;
|
||||||
import com.replaymod.core.utils.Utils;
|
import com.replaymod.core.utils.Utils;
|
||||||
import com.replaymod.core.utils.WrappedTimer;
|
|
||||||
import com.replaymod.replay.camera.CameraEntity;
|
import com.replaymod.replay.camera.CameraEntity;
|
||||||
import com.replaymod.replay.camera.SpectatorCameraController;
|
import com.replaymod.replay.camera.SpectatorCameraController;
|
||||||
import com.replaymod.replay.events.ReplayClosedCallback;
|
import com.replaymod.replay.events.ReplayClosedCallback;
|
||||||
@@ -124,6 +123,7 @@ import net.minecraft.network.NetworkSide;
|
|||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
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.core.versions.MCVer.*;
|
||||||
import static com.replaymod.replay.ReplayModReplay.LOGGER;
|
import static com.replaymod.replay.ReplayModReplay.LOGGER;
|
||||||
import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
|
import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
|
||||||
@@ -263,7 +263,7 @@ public class ReplayHandler {
|
|||||||
|
|
||||||
TimerAccessor timer = (TimerAccessor) ((MinecraftAccessor) mc).getTimer();
|
TimerAccessor timer = (TimerAccessor) ((MinecraftAccessor) mc).getTimer();
|
||||||
//#if MC>=11200
|
//#if MC>=11200
|
||||||
timer.setTickLength(WrappedTimer.DEFAULT_MS_PER_TICK);
|
timer.setTickLength(DEFAULT_MS_PER_TICK);
|
||||||
//#else
|
//#else
|
||||||
//$$ timer.setTimerSpeed(1);
|
//$$ timer.setTimerSpeed(1);
|
||||||
//#endif
|
//#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user