From b05d726ad0dcfedb9bab369e212e896e5ebde55f Mon Sep 17 00:00:00 2001 From: ButterscotchVanilla Date: Thu, 19 Aug 2021 01:54:28 -0400 Subject: [PATCH] AutoBone: Return recording ASAP and check if it's empty --- .../io/eiren/gui/autobone/AutoBoneWindow.java | 12 +++++++--- .../io/eiren/gui/autobone/PoseRecorder.java | 22 ++++++++++++------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/main/java/io/eiren/gui/autobone/AutoBoneWindow.java b/src/main/java/io/eiren/gui/autobone/AutoBoneWindow.java index 88ad0ba75..c1b66ff6a 100644 --- a/src/main/java/io/eiren/gui/autobone/AutoBoneWindow.java +++ b/src/main/java/io/eiren/gui/autobone/AutoBoneWindow.java @@ -180,10 +180,16 @@ public class AutoBoneWindow extends JFrame { if (frameRecordings.size() > 0) { LogManager.log.info("[AutoBone] Done loading frames!"); } else { - Future frames = poseRecorder.getFramesAsync(); - if (frames != null) { + Future framesFuture = poseRecorder.getFramesAsync(); + if (framesFuture != null) { setText("Waiting for Recording..."); - frameRecordings.add(Pair.of("", frames.get())); + PoseFrame[] frames = framesFuture.get(); + + if (frames.length <= 0) { + throw new IllegalStateException("Recording has no frames"); + } + + frameRecordings.add(Pair.of("", frames)); } else { setText("No Recordings..."); LogManager.log.severe("[AutoBone] No recordings found in \"" + loadFolder.getPath() + "\" and no recording was done..."); diff --git a/src/main/java/io/eiren/gui/autobone/PoseRecorder.java b/src/main/java/io/eiren/gui/autobone/PoseRecorder.java index 110851b3c..dc2fb8c35 100644 --- a/src/main/java/io/eiren/gui/autobone/PoseRecorder.java +++ b/src/main/java/io/eiren/gui/autobone/PoseRecorder.java @@ -39,13 +39,15 @@ public class PoseRecorder { if (System.currentTimeMillis() >= nextFrameTimeMs) { nextFrameTimeMs = System.currentTimeMillis() + frameRecordingInterval; frames.add(new PoseFrame(skeleton)); + + // If done, send finished recording + if (frames.size() >= numFrames) { + internalStopRecording(); + } } } else { - // If done, send finished recording - CompletableFuture currentRecording = this.currentRecording; - if (currentRecording != null && !currentRecording.isDone()) { - currentRecording.complete(frames.toArray(new PoseFrame[0])); - } + // If done and hasn't yet, send finished recording + internalStopRecording(); } } } @@ -79,8 +81,8 @@ public class PoseRecorder { return currentRecording; } - public synchronized void stopFrameRecording() { - // Synchronized, this value can be expected to stay the same + private void internalStopRecording() { + CompletableFuture currentRecording = this.currentRecording; if (currentRecording != null && !currentRecording.isDone()) { // Stop the recording, returning the frames recorded currentRecording.complete(frames.toArray(new PoseFrame[0])); @@ -89,8 +91,12 @@ public class PoseRecorder { numFrames = -1; } + public synchronized void stopFrameRecording() { + internalStopRecording(); + } + public synchronized void cancelFrameRecording() { - // Synchronized, this value can be expected to stay the same + CompletableFuture currentRecording = this.currentRecording; if (currentRecording != null && !currentRecording.isDone()) { // Cancel the current recording and return nothing currentRecording.cancel(true);