From a7a612aa9bd9b76f72462149a34b35a21ea8a476 Mon Sep 17 00:00:00 2001 From: ButterscotchVanilla Date: Thu, 19 Aug 2021 00:52:09 -0400 Subject: [PATCH] AutoBone: Add recording cancellation, always check if the recording is done and not submitted --- .../io/eiren/gui/autobone/AutoBoneWindow.java | 2 - .../io/eiren/gui/autobone/PoseRecorder.java | 40 +++++++++++++------ 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/main/java/io/eiren/gui/autobone/AutoBoneWindow.java b/src/main/java/io/eiren/gui/autobone/AutoBoneWindow.java index 3d199a8e5..88ad0ba75 100644 --- a/src/main/java/io/eiren/gui/autobone/AutoBoneWindow.java +++ b/src/main/java/io/eiren/gui/autobone/AutoBoneWindow.java @@ -1,7 +1,5 @@ package io.eiren.gui.autobone; -import java.awt.Container; - import javax.swing.BoxLayout; import javax.swing.JFrame; import javax.swing.JLabel; diff --git a/src/main/java/io/eiren/gui/autobone/PoseRecorder.java b/src/main/java/io/eiren/gui/autobone/PoseRecorder.java index fd517654c..110851b3c 100644 --- a/src/main/java/io/eiren/gui/autobone/PoseRecorder.java +++ b/src/main/java/io/eiren/gui/autobone/PoseRecorder.java @@ -34,15 +34,18 @@ public class PoseRecorder { @VRServerThread public void onTick() { HumanSkeletonWithLegs skeleton = this.skeleton; - if (skeleton != null && frames.size() < numFrames && System.currentTimeMillis() >= nextFrameTimeMs) { - nextFrameTimeMs = System.currentTimeMillis() + frameRecordingInterval; - - frames.add(new PoseFrame(skeleton)); - - // If done recording - CompletableFuture currentRecording = this.currentRecording; - if (currentRecording != null && frames.size() >= numFrames) { - currentRecording.complete(frames.toArray(new PoseFrame[0])); + if (skeleton != null) { + if (frames.size() < numFrames) { + if (System.currentTimeMillis() >= nextFrameTimeMs) { + nextFrameTimeMs = System.currentTimeMillis() + frameRecordingInterval; + frames.add(new PoseFrame(skeleton)); + } + } else { + // If done, send finished recording + CompletableFuture currentRecording = this.currentRecording; + if (currentRecording != null && !currentRecording.isDone()) { + currentRecording.complete(frames.toArray(new PoseFrame[0])); + } } } } @@ -59,7 +62,7 @@ public class PoseRecorder { throw new IllegalStateException("PoseRecorder isn't ready to record!"); } - stopFrameRecording(); + cancelFrameRecording(); // Clear old frames and ensure new size can be held frames.clear(); @@ -77,12 +80,23 @@ public class PoseRecorder { } public synchronized void stopFrameRecording() { - numFrames = -1; - // Synchronized, this value can be expected to stay the same - if (currentRecording != null) { + if (currentRecording != null && !currentRecording.isDone()) { + // Stop the recording, returning the frames recorded currentRecording.complete(frames.toArray(new PoseFrame[0])); } + + numFrames = -1; + } + + public synchronized void cancelFrameRecording() { + // Synchronized, this value can be expected to stay the same + if (currentRecording != null && !currentRecording.isDone()) { + // Cancel the current recording and return nothing + currentRecording.cancel(true); + } + + numFrames = -1; } public boolean isRecording() {