Disabled Head rotation while saving replay video

Made video rendering possible while Minecraft is in background
This commit is contained in:
Marius Metzger
2015-03-08 22:51:50 +01:00
parent 5ce12162ce
commit b4ce266375
14 changed files with 122 additions and 143 deletions

View File

@@ -8,8 +8,6 @@ public class PacketInfo {
private EnumConnectionState connectionState;
private int packetID;
public PacketInfo(byte[] bytes, EnumConnectionState connectionState,
int packetID) {
super();

View File

@@ -40,13 +40,13 @@ public class ReplayHandler {
private static Keyframe selectedKeyframe;
private static boolean isReplaying = false;
private static boolean inPath = false;
private static CameraEntity cameraEntity;
private static List<Keyframe> keyframes = new ArrayList<Keyframe>();
private static boolean replayActive = false;
private static boolean inReplay = false;
public static long lastExit = 0;
@@ -93,20 +93,20 @@ public class ReplayHandler {
return gamma;
}
public static void setReplaying(boolean replaying) {
isReplaying = replaying;
public static void setInPath(boolean replaying) {
inPath = replaying;
}
public static void startPath(boolean save) {
if(!ReplayHandler.isReplaying()) ReplayProcess.startReplayProcess(save);
if(!ReplayHandler.isInPath()) ReplayProcess.startReplayProcess(save);
}
public static void interruptReplay() {
ReplayProcess.stopReplayProcess(false);
}
public static boolean isReplaying() {
return isReplaying;
public static boolean isInPath() {
return inPath;
}
public static void setCameraEntity(CameraEntity entity) {
@@ -309,8 +309,8 @@ public class ReplayHandler {
sortKeyframes();
}
public static boolean replayActive() {
return replayActive;
public static boolean isInReplay() {
return inReplay;
}
public static boolean isPaused() {
@@ -364,7 +364,7 @@ public class ReplayHandler {
//Load lighting and trigger update
ReplayMod.replaySettings.setLightingEnabled(ReplayMod.replaySettings.isLightingEnabled());
replayActive = true;
inReplay = true;
}
public static void restartReplay() {
@@ -390,7 +390,7 @@ public class ReplayHandler {
ReplayMod.overlay.resetUI();
} catch(Exception e) {}
replayActive = true;
inReplay = true;
}
public static void endReplay() {
@@ -406,7 +406,7 @@ public class ReplayHandler {
}
*/
replayActive = false;
inReplay = false;
}
public static Keyframe getSelected() {

View File

@@ -63,7 +63,7 @@ public class ReplayProcess {
lastTimestamp = -1;
linear = ReplayMod.replaySettings.isLinearMovement();
ReplayHandler.sortKeyframes();
ReplayHandler.setReplaying(true);
ReplayHandler.setInPath(true);
previousReplaySpeed = ReplayHandler.getSpeed();
TimeKeyframe tf = ReplayHandler.getNextTimeKeyframe(-1);
@@ -85,7 +85,7 @@ public class ReplayProcess {
@Override
public void run() {
while(ReplayHandler.isReplaying()) {
while(ReplayHandler.isInPath()) {
if(!blocked) {
mc.addScheduledTask(new Runnable() {
@Override
@@ -109,10 +109,10 @@ public class ReplayProcess {
}
public static void stopReplayProcess(boolean finished) {
if(!ReplayHandler.isReplaying()) return;
if(!ReplayHandler.isInPath()) return;
if(finished) ChatMessageRequests.addChatMessage("Replay finished!", ChatMessageType.INFORMATION);
else ChatMessageRequests.addChatMessage("Replay stopped!", ChatMessageType.INFORMATION);
ReplayHandler.setReplaying(false);
ReplayHandler.setInPath(false);
MCTimerHandler.setActiveTimer();
ReplayHandler.setSpeed(previousReplaySpeed);
ReplayHandler.setSpeed(0);
@@ -434,7 +434,7 @@ public class ReplayProcess {
//Video capturing, for testing purposes
if(isVideoRecording()) {
try {
if(!VideoWriter.isRecording() && ReplayHandler.isReplaying()) {
if(!VideoWriter.isRecording() && ReplayHandler.isInPath()) {
VideoWriter.startRecording(mc.displayWidth, mc.displayHeight);
} else {
VideoWriter.writeImage(ScreenCapture.captureScreen());

View File

@@ -15,7 +15,6 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.UUID;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiDownloadTerrain;
@@ -48,7 +47,6 @@ import net.minecraft.network.play.server.S30PacketWindowItems;
import net.minecraft.network.play.server.S36PacketSignEditorOpen;
import net.minecraft.network.play.server.S37PacketStatistics;
import net.minecraft.network.play.server.S38PacketPlayerListItem;
import net.minecraft.network.play.server.S38PacketPlayerListItem.AddPlayerData;
import net.minecraft.network.play.server.S39PacketPlayerAbilities;
import net.minecraft.network.play.server.S43PacketCamera;
import net.minecraft.network.play.server.S45PacketTitle;
@@ -63,11 +61,12 @@ import org.apache.commons.compress.archivers.zip.ZipFile;
import org.apache.commons.io.FilenameUtils;
import com.google.gson.Gson;
import com.mojang.authlib.GameProfile;
import eu.crushedpixel.replaymod.ReplayMod;
import eu.crushedpixel.replaymod.editor.ReplayFileIO;
import eu.crushedpixel.replaymod.entities.CameraEntity;
import eu.crushedpixel.replaymod.events.RecordingHandler;
import eu.crushedpixel.replaymod.holders.PacketData;
import eu.crushedpixel.replaymod.holders.Position;
import eu.crushedpixel.replaymod.recording.ConnectionEventHandler;
import eu.crushedpixel.replaymod.recording.ReplayMetaData;
@@ -86,7 +85,6 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
private long toleratedTimeStamp = Long.MAX_VALUE;
private File replayFile;
private PacketDeserializer ds = new PacketDeserializer(EnumPacketDirection.SERVERBOUND);
private boolean active = true;
private ZipFile archive;
private DataInputStream dis;
@@ -148,7 +146,7 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
setReplaySpeed(replaySpeed);
if((millis < currentTimeStamp && !isHurrying())) {
if(ReplayHandler.isReplaying()) {
if(ReplayHandler.isInPath()) {
if(millis < toleratedTimeStamp) {
return;
}
@@ -255,9 +253,9 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
lastPacketSent = System.currentTimeMillis();
ReplayHandler.restartReplay();
}
while(!terminate && !startFromBeginning && (!paused() || FMLClientHandler.instance().isGUIOpen(GuiDownloadTerrain.class))) {
try {
/*
* LOGIC:
* While behind desired timestamp, only send packets
@@ -270,15 +268,16 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
*/
if(!hurryToTimestamp && ReplayHandler.isReplaying()) {
if(!hurryToTimestamp && ReplayHandler.isInPath()) {
continue;
}
int timestamp = dis.readInt();
PacketData pd = ReplayFileIO.readPacketData(dis);
currentTimeStamp = timestamp;
currentTimeStamp = pd.getTimestamp();
//System.out.println(currentTimeStamp);
if(!ReplayHandler.isReplaying() && !hurryToTimestamp && !FMLClientHandler.instance().isGUIOpen(GuiDownloadTerrain.class)) {
if(!ReplayHandler.isInPath() && !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;
@@ -287,15 +286,11 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
Thread.sleep(timeToSleep);
}
int bytes = dis.readInt();
byte[] bb = new byte[bytes];
dis.readFully(bb);
ReplaySender.this.channelRead(ctx, bb);
ReplaySender.this.channelRead(ctx, pd.getByteArray());
lastTimeStamp = currentTimeStamp;
if(ReplayHandler.isReplaying()) {
if(ReplayHandler.isInPath()) {
toleratedTimeStamp = lastTimeStamp;
} else {
toleratedTimeStamp = -1;
@@ -303,12 +298,12 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
if(hurryToTimestamp && currentTimeStamp >= desiredTimeStamp && !startFromBeginning) {
hurryToTimestamp = false;
if(!ReplayHandler.isReplaying() || hasRestarted) {
if(!ReplayHandler.isInPath() || hasRestarted) {
MCTimerHandler.advanceRenderPartialTicks(5);
MCTimerHandler.advancePartialTicks(5);
MCTimerHandler.advanceTicks(5);
}
if(!ReplayHandler.isReplaying()) {
if(!ReplayHandler.isInPath()) {
Position pos = ReplayHandler.getLastPosition();
CameraEntity cam = ReplayHandler.getCameraEntity();
if(cam != null) {
@@ -320,17 +315,18 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
}
}
}
if(!ReplayHandler.isReplaying()) {
if(!ReplayHandler.isInPath()) {
setReplaySpeed(0);
}
hasRestarted = false;
}
} catch(EOFException eof) {
System.out.println("End of File encountered!");
dis = new DataInputStream(archive.getInputStream(replayEntry));
setReplaySpeed(0);
} catch(IOException e) {
//e.printStackTrace();
e.printStackTrace();
}
}
}
@@ -398,12 +394,7 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
byte[] ba = (byte[])msg;
try {
ByteBuf bb = Unpooled.wrappedBuffer(ba);
PacketBuffer pb = new PacketBuffer(bb);
int i = pb.readVarIntFromBuffer();
Packet p = EnumConnectionState.PLAY.getPacket(EnumPacketDirection.CLIENTBOUND, i);
Packet p = ReplayFileIO.deserializePacket(ba);
if(hurryToTimestamp) { //If hurrying, ignore some packets
if(p instanceof S45PacketTitle ||
@@ -425,8 +416,6 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
if(badPackets.contains(p.getClass())) return;
try {
p.readPacketData(pb);
if(p instanceof S1CPacketEntityMetadata) {
if((Integer)metadataPacketEntityId.get(p) == actualID) {
metadataPacketEntityId.set(p, RecordingHandler.entityID);
@@ -434,6 +423,7 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
}
if(p instanceof S01PacketJoinGame) {
//System.out.println("FOUND JOIN PACKET");
allowMovement = true;
int entId = (Integer)joinPacketEntityId.get(p);
actualID = entId;
@@ -493,7 +483,7 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
if(p instanceof S08PacketPlayerPosLook) {
final S08PacketPlayerPosLook ppl = (S08PacketPlayerPosLook)p;
if(ReplayHandler.isReplaying() && !hurryToTimestamp) return;
if(ReplayHandler.isInPath() && !hurryToTimestamp) return;
CameraEntity cent = ReplayHandler.getCameraEntity();
@@ -531,6 +521,7 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
if(p instanceof S43PacketCamera) {
return;
}
super.channelRead(ctx, p);
} catch(Exception e) {
System.out.println(p.getClass());
@@ -538,7 +529,7 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
}
} catch(Exception e) {
//e.printStackTrace();
e.printStackTrace();
}
}

View File

@@ -24,7 +24,7 @@ public class SpectateHandler {
};
public static void openSpectateSelection() {
if(!ReplayHandler.replayActive()) {
if(!ReplayHandler.isInReplay()) {
return;
}