aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoroldmud0 <oldmud0@users.noreply.github.com>2021-08-12 21:37:52 -0500
committerGitHub <noreply@github.com>2021-08-12 21:37:52 -0500
commit1bf12a919c89919f958354582721dd68b2af1070 (patch)
treea4ae3a0aa2c64c49427ebe5f4ba685ec24bd6ab6
parent579456fbd766b64f4ba11b9ff83ece3dad9d6553 (diff)
parent2a18c1cdec54a324c6ba9834d6e6b05cc46f2535 (diff)
Merge pull request #581 from AttorneyOnline/aolayer-preload
Massively improve AOLayer performance by preloading next frame from disk before the current frame is done ticking
-rw-r--r--Attorney_Online.pro3
-rw-r--r--include/aolayer.h7
-rw-r--r--src/aolayer.cpp29
3 files changed, 26 insertions, 13 deletions
diff --git a/Attorney_Online.pro b/Attorney_Online.pro
index 2a5c1e14..abca0fb0 100644
--- a/Attorney_Online.pro
+++ b/Attorney_Online.pro
@@ -19,6 +19,9 @@ QMAKE_LFLAGS += -Wl,-rpath,"'\$$ORIGIN/lib'"
# Uncomment for verbose network logging
# DEFINES += DEBUG_NETWORK
+# Uncomment for verbose animation logging
+# DEFINES += DEBUG_MOVIE
+
# Uncomment for building with debug symbols
# CONFIG += debug
diff --git a/include/aolayer.h b/include/aolayer.h
index 7a8e2fd9..ffbd6dac 100644
--- a/include/aolayer.h
+++ b/include/aolayer.h
@@ -7,6 +7,7 @@
#include <QLabel>
#include <QTimer>
#include <QBitmap>
+#include <QtConcurrent/QtConcurrentRun>
class AOApplication;
class VPath;
@@ -139,6 +140,12 @@ protected:
// Center the QLabel in the viewport based on the dimensions of f_pixmap
void center_pixmap(QPixmap f_pixmap);
+ // Populates the frame and delay vectors with the next frame's data.
+ void load_next_frame();
+
+ // used in load_next_frame
+ QFuture<void> future;
+
signals:
void done();
diff --git a/src/aolayer.cpp b/src/aolayer.cpp
index 3791d66b..99524947 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;
@@ -344,7 +341,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();
@@ -532,7 +529,11 @@ void CharLayer::movie_ticker()
void AOLayer::movie_ticker()
{
++frame;
- if (frame >= max_frames) {
+ 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) {
if (play_once) {
if (cull_image)
this->stop();
@@ -544,19 +545,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());
- }
-
+ 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
-
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()