From ce94cd2d1e75738b53f7ab990a49e75a01b80394 Mon Sep 17 00:00:00 2001 From: in1tiate Date: Wed, 11 Aug 2021 09:20:00 -0500 Subject: [PATCH 1/5] preload next frame before ticking over --- include/aolayer.h | 4 ++++ src/aolayer.cpp | 22 ++++++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/include/aolayer.h b/include/aolayer.h index 7a8e2fd..4b95ddb 100644 --- a/include/aolayer.h +++ b/include/aolayer.h @@ -7,6 +7,7 @@ #include #include #include +#include class AOApplication; class VPath; @@ -139,6 +140,9 @@ protected: // Center the QLabel in the viewport based on the dimensions of f_pixmap void center_pixmap(QPixmap f_pixmap); + // Populate the frame and delay vectors. Done asynchronously. + void load_next_frame(); + signals: void done(); diff --git a/src/aolayer.cpp b/src/aolayer.cpp index 3791d66..7ec42b9 100644 --- a/src/aolayer.cpp +++ b/src/aolayer.cpp @@ -532,7 +532,11 @@ void CharLayer::movie_ticker() void AOLayer::movie_ticker() { ++frame; - if (frame >= max_frames) { + QFuture future; + if (frame >= movie_frames.size() && frame < max_frames) { // need to load the image + future = QtConcurrent::run(this, &AOLayer::load_next_frame); + } + else if (frame >= max_frames) { if (play_once) { if (cull_image) this->stop(); @@ -544,19 +548,21 @@ void AOLayer::movie_ticker() else frame = 0; } - // qint64 difference = elapsed - movie_delays[frame]; - if (frame >= movie_frames.size()) { - movie_frames.append(this->get_pixmap(m_reader.read())); - movie_delays.append(m_reader.nextImageDelay()); - } - #ifdef DEBUG_MOVIE qDebug() << frame << movie_delays[frame] << "actual time taken from last frame:" << actual_time.restart(); #endif - + future.waitForFinished(); // don't set the frame before we definitely have it in memory this->set_frame(movie_frames[frame]); ticker->setInterval(this->get_frame_delay(movie_delays[frame])); + if (frame + 1 >= movie_frames.size() && frame + 1 < max_frames) { // load the next frame before we tick again + future = QtConcurrent::run(this, &AOLayer::load_next_frame); + } +} + +void AOLayer::load_next_frame() { + movie_frames.append(this->get_pixmap(m_reader.read())); + movie_delays.append(m_reader.nextImageDelay()); } void CharLayer::preanim_done() From 51698ca6ac57361ca3a5d9aa7d3b3a67374f8b49 Mon Sep 17 00:00:00 2001 From: in1tiate Date: Wed, 11 Aug 2021 09:28:59 -0500 Subject: [PATCH 2/5] debug_movie fixes --- Attorney_Online.pro | 2 ++ src/aolayer.cpp | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Attorney_Online.pro b/Attorney_Online.pro index 2a5c1e1..2498232 100644 --- a/Attorney_Online.pro +++ b/Attorney_Online.pro @@ -19,6 +19,8 @@ QMAKE_LFLAGS += -Wl,-rpath,"'\$$ORIGIN/lib'" # Uncomment for verbose network logging # DEFINES += DEBUG_NETWORK +DEFINES += DEBUG_MOVIE + # Uncomment for building with debug symbols # CONFIG += debug diff --git a/src/aolayer.cpp b/src/aolayer.cpp index 7ec42b9..075338b 100644 --- a/src/aolayer.cpp +++ b/src/aolayer.cpp @@ -344,7 +344,7 @@ void AOLayer::start_playback(QString p_image) if (duration > 0 && cull_image == true) shfx_timer->start(duration); #ifdef DEBUG_MOVIE - qDebug() << max_frames << "Setting image to " << image_path + qDebug() << max_frames << "Setting image to " << p_image << "Time taken to process image:" << actual_time.elapsed(); actual_time.restart(); @@ -548,11 +548,11 @@ void AOLayer::movie_ticker() else frame = 0; } + future.waitForFinished(); // don't set the frame before we definitely have it in memory #ifdef DEBUG_MOVIE qDebug() << frame << movie_delays[frame] << "actual time taken from last frame:" << actual_time.restart(); #endif - future.waitForFinished(); // don't set the frame before we definitely have it in memory this->set_frame(movie_frames[frame]); ticker->setInterval(this->get_frame_delay(movie_delays[frame])); if (frame + 1 >= movie_frames.size() && frame + 1 < max_frames) { // load the next frame before we tick again From d84194871e50d86ba36d01029192ecf0b7665127 Mon Sep 17 00:00:00 2001 From: in1tiate Date: Wed, 11 Aug 2021 09:38:05 -0500 Subject: [PATCH 3/5] comment out debug_movie --- Attorney_Online.pro | 3 ++- src/aolayer.cpp | 5 +---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Attorney_Online.pro b/Attorney_Online.pro index 2498232..abca0fb 100644 --- a/Attorney_Online.pro +++ b/Attorney_Online.pro @@ -19,7 +19,8 @@ QMAKE_LFLAGS += -Wl,-rpath,"'\$$ORIGIN/lib'" # Uncomment for verbose network logging # DEFINES += DEBUG_NETWORK -DEFINES += DEBUG_MOVIE +# Uncomment for verbose animation logging +# DEFINES += DEBUG_MOVIE # Uncomment for building with debug symbols # CONFIG += debug diff --git a/src/aolayer.cpp b/src/aolayer.cpp index 075338b..25873fe 100644 --- a/src/aolayer.cpp +++ b/src/aolayer.cpp @@ -320,10 +320,7 @@ void AOLayer::start_playback(QString p_image) for (int i = frame; i--;) { if (i <= -1) break; - QPixmap l_pixmap = this->get_pixmap(m_reader.read()); - int l_delay = m_reader.nextImageDelay(); - movie_frames.append(l_pixmap); - movie_delays.append(l_delay); + load_next_frame(); } } last_path = p_image; From 42760bc3f86e1d38acbf6c3c9f675dbf6acc37c8 Mon Sep 17 00:00:00 2001 From: in1tiate Date: Wed, 11 Aug 2021 09:40:11 -0500 Subject: [PATCH 4/5] more accurate comment --- include/aolayer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/aolayer.h b/include/aolayer.h index 4b95ddb..1216b32 100644 --- a/include/aolayer.h +++ b/include/aolayer.h @@ -140,7 +140,7 @@ protected: // Center the QLabel in the viewport based on the dimensions of f_pixmap void center_pixmap(QPixmap f_pixmap); - // Populate the frame and delay vectors. Done asynchronously. + // Populates the frame and delay vectors with the next frame's data. void load_next_frame(); signals: From 2a18c1cdec54a324c6ba9834d6e6b05cc46f2535 Mon Sep 17 00:00:00 2001 From: in1tiate Date: Wed, 11 Aug 2021 20:14:35 -0500 Subject: [PATCH 5/5] wait for thread to finish before starting new one --- include/aolayer.h | 3 +++ src/aolayer.cpp | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/include/aolayer.h b/include/aolayer.h index 1216b32..ffbd6da 100644 --- a/include/aolayer.h +++ b/include/aolayer.h @@ -143,6 +143,9 @@ protected: // Populates the frame and delay vectors with the next frame's data. void load_next_frame(); + // used in load_next_frame + QFuture future; + signals: void done(); diff --git a/src/aolayer.cpp b/src/aolayer.cpp index 25873fe..9952494 100644 --- a/src/aolayer.cpp +++ b/src/aolayer.cpp @@ -529,8 +529,8 @@ void CharLayer::movie_ticker() void AOLayer::movie_ticker() { ++frame; - QFuture future; if (frame >= movie_frames.size() && frame < max_frames) { // need to load the image + future.waitForFinished(); // Do Not want this to be running twice future = QtConcurrent::run(this, &AOLayer::load_next_frame); } else if (frame >= max_frames) {