diff --git a/src/main/java/eu/crushedpixel/replaymod/events/GuiReplayOverlay.java b/src/main/java/eu/crushedpixel/replaymod/events/GuiReplayOverlay.java index 16b44e75..0ae72bc8 100644 --- a/src/main/java/eu/crushedpixel/replaymod/events/GuiReplayOverlay.java +++ b/src/main/java/eu/crushedpixel/replaymod/events/GuiReplayOverlay.java @@ -50,8 +50,6 @@ public class GuiReplayOverlay extends Gui { private int realTimelineX = 10 + 3*25; private int realTimelineY = 33+10; - private int realTimePosition = 0; - private int ppButtonX = 10; private int ppButtonY = 10; @@ -110,7 +108,7 @@ public class GuiReplayOverlay extends Gui { if(FMLClientHandler.instance().isGUIOpen(GuiMouseInput.class)) { mc.displayGuiScreen((GuiScreen)null); } - realTimePosition = 0; + ReplayHandler.setRealTimelineCursor(0); speedSlider = new GuiReplaySpeedSlider(1, sliderX, sliderY, "Speed"); } @@ -163,7 +161,8 @@ public class GuiReplayOverlay extends Gui { //GlStateManager.resetColor(); - if(Mouse.isButtonDown(0) && FMLClientHandler.instance().isGUIOpen(GuiMouseInput.class)) { //clicking the Button + //When hurrying, no Timeline jumping etc. is possible + if(Mouse.isButtonDown(0) && FMLClientHandler.instance().isGUIOpen(GuiMouseInput.class) && !ReplayHandler.isHurrying()) { //clicking the Button speedSlider.mousePressed(mc, mouseX, mouseY); if(!mouseDown) { mouseDown = true; @@ -543,7 +542,7 @@ public class GuiReplayOverlay extends Gui { float abs_width = (zoom_scale*(float)timelineLength); int real_pos = Math.round(left_real+((rel_pos)*abs_width)); - realTimePosition = real_pos; + ReplayHandler.setRealTimelineCursor(real_pos); //Keyframe click handling here if(isClick()) { @@ -551,18 +550,18 @@ public class GuiReplayOverlay extends Gui { int tolerance = 2*Math.round(abs_width/(float)width); if(mouseY >= y+9) { - TimeKeyframe close = ReplayHandler.getClosestTimeKeyframeForRealTime(realTimePosition, tolerance); + TimeKeyframe close = ReplayHandler.getClosestTimeKeyframeForRealTime(ReplayHandler.getRealTimelineCursor(), tolerance); ReplayHandler.selectKeyframe(close); //can be null, deselects keyframe } else { - PositionKeyframe close = ReplayHandler.getClosestPlaceKeyframeForRealTime(realTimePosition, tolerance); + PositionKeyframe close = ReplayHandler.getClosestPlaceKeyframeForRealTime(ReplayHandler.getRealTimelineCursor(), tolerance); ReplayHandler.selectKeyframe(close); //can be null, deselects keyframe } } } //Draw Realtime Cursor - if(realTimePosition >= left_real && realTimePosition <= right_real) { - long rel_pos = realTimePosition-left_real; + if(ReplayHandler.getRealTimelineCursor() >= left_real && ReplayHandler.getRealTimelineCursor() <= right_real) { + long rel_pos = ReplayHandler.getRealTimelineCursor()-left_real; long rel_width = right_real-left_real; double perc = (double)rel_pos/(double)rel_width; @@ -650,11 +649,11 @@ public class GuiReplayOverlay extends Gui { private void addPlaceKeyframe() { CameraEntity cam = ReplayHandler.getCameraEntity(); if(cam == null) return; - ReplayHandler.addKeyframe(new PositionKeyframe(realTimePosition, new Position(cam.posX, cam.posY, cam.posZ, cam.rotationPitch, cam.rotationYaw))); + ReplayHandler.addKeyframe(new PositionKeyframe(ReplayHandler.getRealTimelineCursor(), new Position(cam.posX, cam.posY, cam.posZ, cam.rotationPitch, cam.rotationYaw))); } private void addTimeKeyframe() { - ReplayHandler.addKeyframe(new TimeKeyframe(realTimePosition, ReplayHandler.getReplayTime())); + ReplayHandler.addKeyframe(new TimeKeyframe(ReplayHandler.getRealTimelineCursor(), ReplayHandler.getReplayTime())); } private enum MarkerType { diff --git a/src/main/java/eu/crushedpixel/replaymod/replay/ReplayHandler.java b/src/main/java/eu/crushedpixel/replaymod/replay/ReplayHandler.java index 56171a3c..6e479ac7 100644 --- a/src/main/java/eu/crushedpixel/replaymod/replay/ReplayHandler.java +++ b/src/main/java/eu/crushedpixel/replaymod/replay/ReplayHandler.java @@ -33,6 +33,8 @@ public class ReplayHandler { private static ReplaySender replaySender; private static OpenEmbeddedChannel channel; + private static int realTimelinePosition = 0; + private static Keyframe selectedKeyframe; private static boolean isReplaying = false; @@ -232,7 +234,13 @@ public class ReplayHandler { public static void setReplayPos(int pos) { if(replaySender != null) { - replaySender.jumpToTime(pos); + replaySender.jumpToTime(pos, false); + } + } + + public static void forceReplayPos(int pos) { + if(replaySender != null) { + replaySender.jumpToTime(pos, true); } } @@ -358,4 +366,12 @@ public class ReplayHandler { public static Keyframe getSelected() { return selectedKeyframe; } + + public static int getRealTimelineCursor() { + return realTimelinePosition; + } + + public static void setRealTimelineCursor(int pos) { + realTimelinePosition = pos; + } } diff --git a/src/main/java/eu/crushedpixel/replaymod/replay/ReplayProcess.java b/src/main/java/eu/crushedpixel/replaymod/replay/ReplayProcess.java index e72fa06f..83fe0024 100644 --- a/src/main/java/eu/crushedpixel/replaymod/replay/ReplayProcess.java +++ b/src/main/java/eu/crushedpixel/replaymod/replay/ReplayProcess.java @@ -1,6 +1,7 @@ package eu.crushedpixel.replaymod.replay; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiScreen; import eu.crushedpixel.replaymod.ReplayMod; import eu.crushedpixel.replaymod.chat.ChatMessageRequests; import eu.crushedpixel.replaymod.chat.ChatMessageRequests.ChatMessageType; @@ -48,13 +49,16 @@ public class ReplayProcess { ReplayHandler.sortKeyframes(); ReplayHandler.setReplaying(true); previousReplaySpeed = ReplayHandler.getSpeed(); - /* + TimeKeyframe tf = ReplayHandler.getNextTimeKeyframe(-1); if(tf != null) { int ts = tf.getTimestamp(); - ReplayHandler.setReplayPos(ts); + if(ts < ReplayHandler.getReplayTime()) { + mc.displayGuiScreen((GuiScreen)null); + } + ReplayHandler.forceReplayPos(ts); } - */ + ChatMessageRequests.addChatMessage("Replay started!", ChatMessageType.INFORMATION); } @@ -65,13 +69,10 @@ public class ReplayProcess { ReplayHandler.setSpeed(previousReplaySpeed); ReplayHandler.setSpeed(0); } - - public static void tickReplay() { - if(!ReplayHandler.isReplaying()) return; - + + public static void tickReplay() { if(ReplayHandler.isHurrying()) { lastRealTime = System.currentTimeMillis(); - System.out.println("rethurrn"); return; } @@ -113,8 +114,9 @@ public class ReplayProcess { //timeLinear.getPoint(x); System.out.println(x+" | "+timeLinear.getPoint(x)); } - */ + */ //System.out.println(timeLinear.getPoint(0)); + } long curTime = System.currentTimeMillis(); @@ -125,6 +127,8 @@ public class ReplayProcess { PositionKeyframe lastPos = ReplayHandler.getPreviousPositionKeyframe(curRealReplayTime); PositionKeyframe nextPos = ReplayHandler.getNextPositionKeyframe(curRealReplayTime); + ReplayHandler.setRealTimelineCursor(curRealReplayTime); + int lastPosStamp = 0; int nextPosStamp = 0; @@ -176,23 +180,23 @@ public class ReplayProcess { float splinePos = ((float)ReplayHandler.getKeyframeIndex(lastPos) + currentStepPerc)/(float)(ReplayHandler.getPosKeyframeCount()-1); float timePos = ((float)ReplayHandler.getKeyframeIndex(lastTime) + currentStepPerc)/(float)(ReplayHandler.getTimeKeyframeCount()-1); - + Position pos = null; if(!linear) { pos = motionSpline.getPoint(Math.max(0, Math.min(1, splinePos))); } else { pos = motionLinear.getPoint(Math.max(0, Math.min(1, splinePos))); } - - //int curPos = timeLinear.getPoint(Math.max(0, Math.min(1, timePos))); + + int curPos = timeLinear.getPoint(Math.max(0, Math.min(1, timePos))); //set replay speed if(pos != null) ReplayHandler.getCameraEntity().movePath(pos); //System.out.println(curSpeed+" | "+curPos); - //ReplayHandler.setSpeed(curSpeed); + ReplayHandler.setSpeed(curSpeed); //System.out.println("sent "+curPos); - //ReplayHandler.setReplayPos(curPos, timePos == 0); - + ReplayHandler.setReplayPos(curPos); + //calculate replay speed @@ -201,11 +205,11 @@ public class ReplayProcess { if(ts != lastTimestamp) { lastTimestamp = ts; } - */ + */ //splinePos = (index of last entry + add) / total entries - + lastRealReplayTime = curRealReplayTime; lastRealTime = curTime; diff --git a/src/main/java/eu/crushedpixel/replaymod/replay/ReplaySender.java b/src/main/java/eu/crushedpixel/replaymod/replay/ReplaySender.java index 208f1363..4e8b00fa 100644 --- a/src/main/java/eu/crushedpixel/replaymod/replay/ReplaySender.java +++ b/src/main/java/eu/crushedpixel/replaymod/replay/ReplaySender.java @@ -89,9 +89,7 @@ public class ReplaySender extends ChannelInboundHandlerAdapter { private float defaultReplaySpeed = 0.5f; - private int packetAt = 0; private double replaySpeed = 1f; - private long lastTime = 0, lastTimestamp = 0; private Field joinPacketEntityId, joinPacketWorldType, joinPacketDimension, joinPacketDifficulty, joinPacketMaxPlayers; @@ -137,15 +135,18 @@ public class ReplaySender extends ChannelInboundHandlerAdapter { } } - public void jumpToTime(int millis) { + public void jumpToTime(int millis, boolean force) { setReplaySpeed(replaySpeed); if((millis < currentTimeStamp && !isHurrying())) { - startFromBeginning = true; + if(!(ReplayHandler.isReplaying() && !force)) { + startFromBeginning = true; + } } desiredTimeStamp = millis; hurryToTimestamp = true; + } public void setReplaySpeed(final double d) { @@ -244,8 +245,10 @@ public class ReplaySender extends ChannelInboundHandlerAdapter { while(!terminate) { if(startFromBeginning) { currentTimeStamp = 0; + dis.close(); dis = new DataInputStream(archive.getInputStream(replayEntry)); startFromBeginning = false; + lastPacketSent = System.currentTimeMillis(); ReplayHandler.restartReplay(); } while(!startFromBeginning && (!paused() || FMLClientHandler.instance().isGUIOpen(GuiDownloadTerrain.class))) { @@ -262,24 +265,22 @@ public class ReplaySender extends ChannelInboundHandlerAdapter { * If hurrying, don't wait for correct timing. */ - /* + if(!hurryToTimestamp && ReplayHandler.isReplaying()) { continue; - } else if(ReplayHandler.isReplaying()) { - System.out.println("nocont "+currentTimeStamp+" | "+((Timer)mcTimer.get(mc)).timerSpeed); } - */ - + int timestamp = dis.readInt(); currentTimeStamp = timestamp; - //if(!ReplayHandler.isReplaying() && !hurryToTimestamp && !FMLClientHandler.instance().isGUIOpen(GuiDownloadTerrain.class)) { - if(!hurryToTimestamp && !FMLClientHandler.instance().isGUIOpen(GuiDownloadTerrain.class)) { + if(!ReplayHandler.isReplaying() && !hurryToTimestamp && !FMLClientHandler.instance().isGUIOpen(GuiDownloadTerrain.class)) { + //if(!hurryToTimestamp && !FMLClientHandler.instance().isGUIOpen(GuiDownloadTerrain.class)) { int timeWait = (int)Math.round((currentTimeStamp - lastTimeStamp)/replaySpeed); long timeDiff = System.currentTimeMillis() - lastPacketSent; lastPacketSent = System.currentTimeMillis(); - Thread.sleep(Math.max(0, timeWait-timeDiff)); + long timeToSleep = Math.max(0, timeWait-timeDiff); + Thread.sleep(timeToSleep); } int bytes = dis.readInt(); @@ -292,7 +293,9 @@ public class ReplaySender extends ChannelInboundHandlerAdapter { if(hurryToTimestamp && currentTimeStamp >= desiredTimeStamp && !startFromBeginning) { hurryToTimestamp = false; - System.out.println("stop hurrying"); + if(!ReplayHandler.isReplaying()) { + setReplaySpeed(0); + } } } catch(EOFException eof) { @@ -320,7 +323,7 @@ public class ReplaySender extends ChannelInboundHandlerAdapter { add(S37PacketStatistics.class); } }; - + @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { @@ -353,7 +356,7 @@ public class ReplaySender extends ChannelInboundHandlerAdapter { return; } } - + if(badPackets.contains(p.getClass())) return; try { @@ -395,7 +398,7 @@ public class ReplaySender extends ChannelInboundHandlerAdapter { if(p instanceof S08PacketPlayerPosLook) { final S08PacketPlayerPosLook ppl = (S08PacketPlayerPosLook)p; - if(ReplayHandler.isReplaying()) return; + //if(ReplayHandler.isReplaying()) return; Thread t = new Thread(new Runnable() { @Override