aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCrystalwarrior <varsash@gmail.com>2019-09-15 02:14:40 +0300
committerCrystalwarrior <varsash@gmail.com>2019-09-15 02:14:40 +0300
commit37d192b4300efd1c2f3e35b2efb40e93ec99fa03 (patch)
treef08e346d791d8a450bd670fecd65645a11a5dcb2
parent938f1aeea15c6b68495bb1cb0a80467f4e8cf343 (diff)
Load frames as they're needed instead of loading everything at once, and cache them for optimization. The cache is cleared when a new animation is played.
Resolve an issue where if a preanim transitions into (a)idle it would get stuck on the first frame of that (removed the ticker->stop();)
-rw-r--r--include/aocharmovie.h2
-rw-r--r--src/aocharmovie.cpp46
2 files changed, 33 insertions, 15 deletions
diff --git a/include/aocharmovie.h b/include/aocharmovie.h
index 0921bc5f..c852bb36 100644
--- a/include/aocharmovie.h
+++ b/include/aocharmovie.h
@@ -42,6 +42,7 @@ private:
QTimer *preanim_timer;
QTimer *ticker;
QString last_path;
+ QImageReader *m_reader = new QImageReader();
QElapsedTimer actual_time;
const int time_mod = 60;
@@ -51,6 +52,7 @@ private:
int y = 0;
int frame = 0;
+ int max_frames = 0;
bool m_flipped = false;
bool play_once = true;
diff --git a/src/aocharmovie.cpp b/src/aocharmovie.cpp
index 2d370ec7..1251a200 100644
--- a/src/aocharmovie.cpp
+++ b/src/aocharmovie.cpp
@@ -21,7 +21,9 @@ AOCharMovie::AOCharMovie(QWidget *p_parent, AOApplication *p_ao_app) : QLabel(p_
void AOCharMovie::play(QString p_char, QString p_emote, QString emote_prefix)
{
+#ifdef DEBUG_CHARMOVIE
actual_time.restart();
+#endif
QString emote_path;
QList<QString> pathlist;
pathlist = {
@@ -42,28 +44,31 @@ void AOCharMovie::play(QString p_char, QString p_emote, QString emote_prefix)
this->clear();
ticker->stop();
+ preanim_timer->stop();
movie_frames.clear();
movie_delays.clear();
- QImageReader *m_reader = new QImageReader(emote_path);
-
+ m_reader->setFileName(emote_path);
QImage f_image = m_reader->read();
- while (!f_image.isNull())
- {
- movie_frames.append(this->get_pixmap(f_image));
- movie_delays.append(m_reader->nextImageDelay());
- f_image = m_reader->read();
- }
+ int f_delay = m_reader->nextImageDelay();
- delete m_reader;
-
- this->show();
- qDebug() << "Setting image to " << emote_path << "Time taken to process image:" << actual_time.elapsed();
frame = 0;
+ max_frames = m_reader->imageCount();
+
+#ifdef DEBUG_CHARMOVIE
+ qDebug() << max_frames << "Setting image to " << emote_path << "Time taken to process image:" << actual_time.elapsed();
+
actual_time.restart();
+#endif
+
this->set_frame(movie_frames[frame]);
- if (movie_frames.size() > 0)
+ this->show();
+ if (max_frames > 1)
+ {
+ movie_frames.append(this->get_pixmap(f_image));
+ movie_delays.append(f_delay);
ticker->start(movie_delays[frame]);
+ }
}
void AOCharMovie::play_pre(QString p_char, QString p_emote, int duration)
@@ -136,19 +141,30 @@ void AOCharMovie::move(int ax, int ay)
void AOCharMovie::movie_ticker()
{
++frame;
- if(frame == movie_frames.size())
+ if(frame == max_frames)
{
if(play_once)
{
preanim_done();
- ticker->stop();
return;
}
else
frame = 0;
}
// qint64 difference = elapsed - movie_delays[frame];
+ if(frame >= movie_frames.size())
+ {
+ m_reader->jumpToImage(frame);
+ movie_frames.resize(frame + 1);
+ movie_frames[frame] = this->get_pixmap(m_reader->read());
+ movie_delays.resize(frame + 1);
+ movie_delays[frame] = m_reader->nextImageDelay();
+ }
+
+#ifdef DEBUG_CHARMOVIE
qDebug() << frame << movie_delays[frame] << "actual time taken from last frame:" << actual_time.restart();
+#endif
+
this->set_frame(movie_frames[frame]);
ticker->setInterval(movie_delays[frame]);
}