Significantly improved the performance of video rendering by using the magic of multithreading

This commit is contained in:
Marius Metzger
2015-04-05 02:10:44 +02:00
parent 9df94fd789
commit e7c2a462f3
5 changed files with 22 additions and 12 deletions

View File

@@ -121,7 +121,6 @@ public class GuiReplayOverlay extends Gui {
@SubscribeEvent
public void tick(TickEvent event) {
if(!ReplayHandler.isInReplay()) return;
if(ReplayHandler.isInPath()) ReplayProcess.unblockAndTick();
if(ReplayHandler.getCameraEntity() != null)
ReplayHandler.getCameraEntity().updateMovement();
if(!ReplayHandler.isInPath()) onMouseMove(new MouseEvent());
@@ -145,15 +144,15 @@ public class GuiReplayOverlay extends Gui {
throws IllegalAccessException, IllegalArgumentException,
InvocationTargetException, IOException {
if(!ReplayHandler.isInReplay()) return;
if(ReplayHandler.isInPath()) ReplayProcess.unblockAndTick();
if(ReplayHandler.isCamera()) ReplayHandler.setCameraEntity(ReplayHandler.getCameraEntity());
if(ReplayHandler.isInReplay() && ReplayHandler.isPaused()) {
if(mc != null && mc.thePlayer != null)
MinecraftTicker.runMouseKeyboardTick(mc);
}
if((mc.getRenderViewEntity() == mc.thePlayer || !mc.getRenderViewEntity().isEntityAlive())
&& ReplayHandler.getCameraEntity() != null) {
&& ReplayHandler.getCameraEntity() != null && !ReplayHandler.isInPath()) {
ReplayHandler.spectateCamera();
ReplayHandler.getCameraEntity().movePath(new Position(lastX, lastY, lastZ, lastPitch, lastYaw));
} else if(!ReplayHandler.isCamera()) {
lastX = mc.getRenderViewEntity().posX;
lastY = mc.getRenderViewEntity().posY;

View File

@@ -30,5 +30,12 @@ public class SafeEntityRenderer extends EntityRenderer {
} catch(Exception e) {} //This is plain easier than doing proper error prevention.
//If Johni reads this, don't think I'm a bad programmer... Just a lazy one :P
}
@Override
public void updateRenderer() {
try {
super.updateRenderer();
} catch(Exception e) {}
}
}

View File

@@ -63,6 +63,8 @@ public class ReplayProcess {
return;
}
blocked = deepBlock = false;
startRealTime = System.currentTimeMillis();
lastRealTime = startRealTime;
lastRealReplayTime = 0;
@@ -110,7 +112,6 @@ public class ReplayProcess {
if(!deepBlock) blocked = false;
if(!blocked || !isVideoRecording())
ReplayProcess.tickReplay();
else System.out.println("nope");
}
public static void tickReplay() {
@@ -272,7 +273,9 @@ public class ReplayProcess {
curPos = timeLinear.getPoint(Math.max(0, Math.min(1, timePos)));
}
if(pos != null) ReplayHandler.getCameraEntity().movePath(pos);
if(pos != null) {
ReplayHandler.getCameraEntity().movePath(pos);
}
ReplayHandler.setSpeed(curSpeed);
@@ -288,7 +291,6 @@ public class ReplayProcess {
lastRealReplayTime = curRealReplayTime;
lastRealTime = curTime;
//Video capturing, for testing purposes
if(isVideoRecording()) {
try {
if(!VideoWriter.isRecording() && ReplayHandler.isInPath()) {

View File

@@ -615,11 +615,13 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
CameraEntity cent = ReplayHandler.getCameraEntity();
if(!allowMovement && !((Math.abs(cent.posX - ppl.func_148932_c()) > ReplayMod.TP_DISTANCE_LIMIT) ||
(Math.abs(cent.posZ - ppl.func_148933_e()) > ReplayMod.TP_DISTANCE_LIMIT))) {
return;
} else {
allowMovement = false;
if(cent != null) {
if(!allowMovement && !((Math.abs(cent.posX - ppl.func_148932_c()) > ReplayMod.TP_DISTANCE_LIMIT) ||
(Math.abs(cent.posZ - ppl.func_148933_e()) > ReplayMod.TP_DISTANCE_LIMIT))) {
return;
} else {
allowMovement = false;
}
}
Thread t = new Thread(new Runnable() {

View File

@@ -62,7 +62,7 @@ public class VideoWriter {
VideoFormatKeys.WidthKey, width,
VideoFormatKeys.HeightKey, height,
VideoFormatKeys.DepthKey, 24,
VideoFormatKeys.QualityKey, ReplayMod.replaySettings.getVideoQuality());
VideoFormatKeys.QualityKey, (float)ReplayMod.replaySettings.getVideoQuality());
track = out.addTrack(format);