From 9aa88b1d6e84538761a963249d8c8029314e26d7 Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Fri, 13 Sep 2019 11:37:06 +0300 Subject: Use brace constructors instead of << append operator for path lists Rename gif_path into emote_path for charmovie.cpp Rename p_gif into p_image for aomovie.cpp --- src/aocharmovie.cpp | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) (limited to 'src/aocharmovie.cpp') diff --git a/src/aocharmovie.cpp b/src/aocharmovie.cpp index 5748723..90baa55 100644 --- a/src/aocharmovie.cpp +++ b/src/aocharmovie.cpp @@ -19,28 +19,28 @@ AOCharMovie::AOCharMovie(QWidget *p_parent, AOApplication *p_ao_app) : QLabel(p_ void AOCharMovie::play(QString p_char, QString p_emote, QString emote_prefix) { - QString original_path = ao_app->get_character_path(p_char, emote_prefix + p_emote + ".gif"); - QString alt_path = ao_app->get_character_path(p_char, p_emote + ".png"); - QString apng_path = ao_app->get_character_path(p_char, emote_prefix + p_emote + ".apng"); - QString placeholder_path = ao_app->get_theme_path("placeholder.gif"); - QString placeholder_default_path = ao_app->get_default_theme_path("placeholder.gif"); - QString gif_path; - - if (file_exists(apng_path)) - gif_path = apng_path; - else if (file_exists(original_path)) - gif_path = original_path; - else if (file_exists(alt_path)) - gif_path = alt_path; - else if (file_exists(placeholder_path)) - gif_path = placeholder_path; - else - gif_path = placeholder_default_path; + QString emote_path; + QList pathlist; + pathlist = { + ao_app->get_image_suffix(ao_app->get_character_path(p_char, emote_prefix + p_emote)), //Default path + ao_app->get_character_path(p_char, p_emote + ".png"), //Non-animated path if emote_prefix fails + ao_app->get_image_suffix(ao_app->get_theme_path("placeholder")), //Theme placeholder path + ao_app->get_image_suffix(ao_app->get_default_theme_path("placeholder")), //Default theme placeholder path + }; + + for (QString path : pathlist) + { + if (file_exists(path)) + { + emote_path = path; + break; + } + } m_movie->stop(); - m_movie->setFileName(gif_path); + m_movie->setFileName(emote_path); - QImageReader *reader = new QImageReader(gif_path); + QImageReader *reader = new QImageReader(emote_path); movie_frames.clear(); QImage f_image = reader->read(); @@ -61,11 +61,11 @@ void AOCharMovie::play(QString p_char, QString p_emote, QString emote_prefix) void AOCharMovie::play_pre(QString p_char, QString p_emote, int duration) { - QString gif_path = ao_app->get_character_path(p_char, p_emote); + QString emote_path = ao_app->get_character_path(p_char, p_emote); m_movie->stop(); this->clear(); - m_movie->setFileName(gif_path); + m_movie->setFileName(emote_path); m_movie->jumpToFrame(0); int full_duration = duration * time_mod; @@ -116,11 +116,11 @@ void AOCharMovie::play_pre(QString p_char, QString p_emote, int duration) void AOCharMovie::play_talking(QString p_char, QString p_emote) { - QString gif_path = ao_app->get_character_path(p_char, "(b)" + p_emote); + QString emote_path = ao_app->get_character_path(p_char, "(b)" + p_emote); m_movie->stop(); this->clear(); - m_movie->setFileName(gif_path); + m_movie->setFileName(emote_path); play_once = false; m_movie->setSpeed(100); @@ -129,11 +129,11 @@ void AOCharMovie::play_talking(QString p_char, QString p_emote) void AOCharMovie::play_idle(QString p_char, QString p_emote) { - QString gif_path = ao_app->get_character_path(p_char, "(a)" + p_emote); + QString emote_path = ao_app->get_character_path(p_char, "(a)" + p_emote); m_movie->stop(); this->clear(); - m_movie->setFileName(gif_path); + m_movie->setFileName(emote_path); play_once = false; m_movie->setSpeed(100); -- cgit From 51c97ad51ce564ab400f5333eaad75b1fb2e5461 Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Sat, 14 Sep 2019 19:38:56 +0300 Subject: Allow [Time] to be blank for pre-anims to not be required to use it play_talking and play_idle reduced in useless code --- src/aocharmovie.cpp | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) (limited to 'src/aocharmovie.cpp') diff --git a/src/aocharmovie.cpp b/src/aocharmovie.cpp index 90baa55..ac12f63 100644 --- a/src/aocharmovie.cpp +++ b/src/aocharmovie.cpp @@ -75,6 +75,7 @@ void AOCharMovie::play_pre(QString p_char, QString p_emote, int duration) for (int n_frame = 0 ; n_frame < m_movie->frameCount() ; ++n_frame) { + qDebug() << "frame " << n_frame << " delay of " << m_movie->nextFrameDelay(); real_duration += m_movie->nextFrameDelay(); m_movie->jumpToFrame(n_frame + 1); } @@ -86,7 +87,7 @@ void AOCharMovie::play_pre(QString p_char, QString p_emote, int duration) double percentage_modifier = 100.0; - if (real_duration != 0 && duration != 0) + if (real_duration != 0 && duration > 0) { double modifier = full_duration / static_cast(real_duration); percentage_modifier = 100 / modifier; @@ -116,12 +117,6 @@ void AOCharMovie::play_pre(QString p_char, QString p_emote, int duration) void AOCharMovie::play_talking(QString p_char, QString p_emote) { - QString emote_path = ao_app->get_character_path(p_char, "(b)" + p_emote); - - m_movie->stop(); - this->clear(); - m_movie->setFileName(emote_path); - play_once = false; m_movie->setSpeed(100); play(p_char, p_emote, "(b)"); @@ -129,12 +124,6 @@ void AOCharMovie::play_talking(QString p_char, QString p_emote) void AOCharMovie::play_idle(QString p_char, QString p_emote) { - QString emote_path = ao_app->get_character_path(p_char, "(a)" + p_emote); - - m_movie->stop(); - this->clear(); - m_movie->setFileName(emote_path); - play_once = false; m_movie->setSpeed(100); play(p_char, p_emote, "(a)"); -- cgit From ab30cca586a05506c3cfb502cee53957409242e8 Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Sat, 14 Sep 2019 19:50:46 +0300 Subject: Use a ticker and QImageReader instead of QMovie Issue: absolutely fucking broken, needs shittons of fixing or ditching. Might not be that efficient, anyway. --- src/aocharmovie.cpp | 169 +++++++++++++++++++++------------------------------- 1 file changed, 69 insertions(+), 100 deletions(-) (limited to 'src/aocharmovie.cpp') diff --git a/src/aocharmovie.cpp b/src/aocharmovie.cpp index ac12f63..8004a54 100644 --- a/src/aocharmovie.cpp +++ b/src/aocharmovie.cpp @@ -7,14 +7,15 @@ AOCharMovie::AOCharMovie(QWidget *p_parent, AOApplication *p_ao_app) : QLabel(p_parent) { ao_app = p_ao_app; - - m_movie = new QMovie(this); - preanim_timer = new QTimer(this); preanim_timer->setSingleShot(true); - connect(m_movie, SIGNAL(frameChanged(int)), this, SLOT(frame_change(int))); - connect(preanim_timer, SIGNAL(timeout()), this, SLOT(timer_done())); + ticker = new QTimer(this); + ticker->setSingleShot(true); + connect(ticker, SIGNAL(timeout()), this, SLOT(movie_ticker())); + +// connect(m_movie, SIGNAL(frameChanged(int)), this, SLOT(frame_change(int))); + connect(preanim_timer, SIGNAL(timeout()), this, SLOT(preanim_done())); } void AOCharMovie::play(QString p_char, QString p_emote, QString emote_prefix) @@ -37,111 +38,79 @@ void AOCharMovie::play(QString p_char, QString p_emote, QString emote_prefix) } } - m_movie->stop(); - m_movie->setFileName(emote_path); - - QImageReader *reader = new QImageReader(emote_path); - - movie_frames.clear(); - QImage f_image = reader->read(); - while (!f_image.isNull()) - { - if (m_flipped) - movie_frames.append(f_image.mirrored(true, false)); - else - movie_frames.append(f_image); - f_image = reader->read(); - } - - delete reader; - + this->clear(); + m_reader = new QImageReader(emote_path); + + QImage f_image = m_reader->read(); +// while (!f_image.isNull()) +// { +// if (m_flipped) +// movie_frames.append(f_image.mirrored(true, false)); +// else +// movie_frames.append(f_image); +// f_image = reader->read(); +// } + +// delete m_reader; this->show(); - m_movie->start(); + qDebug() << "Setting image to " << f_image; + this->set_frame(f_image); + if (m_reader->supportsAnimation()) + ticker->start(m_reader->nextImageDelay()); } void AOCharMovie::play_pre(QString p_char, QString p_emote, int duration) { - QString emote_path = ao_app->get_character_path(p_char, p_emote); - - m_movie->stop(); - this->clear(); - m_movie->setFileName(emote_path); - m_movie->jumpToFrame(0); - - int full_duration = duration * time_mod; - int real_duration = 0; - - play_once = false; - - for (int n_frame = 0 ; n_frame < m_movie->frameCount() ; ++n_frame) - { - qDebug() << "frame " << n_frame << " delay of " << m_movie->nextFrameDelay(); - real_duration += m_movie->nextFrameDelay(); - m_movie->jumpToFrame(n_frame + 1); - } - -#ifdef DEBUG_GIF - qDebug() << "full_duration: " << full_duration; - qDebug() << "real_duration: " << real_duration; -#endif - - double percentage_modifier = 100.0; - - if (real_duration != 0 && duration > 0) - { - double modifier = full_duration / static_cast(real_duration); - percentage_modifier = 100 / modifier; - - if (percentage_modifier > 100.0) - percentage_modifier = 100.0; - } - -#ifdef DEBUG_GIF - qDebug() << "% mod: " << percentage_modifier; -#endif - - if (full_duration == 0 || full_duration >= real_duration) - { - play_once = true; - } - else - { - play_once = false; - preanim_timer->start(full_duration); - } - - - m_movie->setSpeed(static_cast(percentage_modifier)); +// QString emote_path = ao_app->get_character_path(p_char, p_emote); + play_once = true; play(p_char, p_emote, ""); } void AOCharMovie::play_talking(QString p_char, QString p_emote) { play_once = false; - m_movie->setSpeed(100); play(p_char, p_emote, "(b)"); } void AOCharMovie::play_idle(QString p_char, QString p_emote) { play_once = false; - m_movie->setSpeed(100); play(p_char, p_emote, "(a)"); } void AOCharMovie::stop() { //for all intents and purposes, stopping is the same as hiding. at no point do we want a frozen gif to display - m_movie->stop(); + ticker->stop(); preanim_timer->stop(); this->hide(); } +void AOCharMovie::set_frame(QImage image) +{ + QPixmap f_pixmap; + if(m_flipped) + f_pixmap = QPixmap::fromImage(image.mirrored(true, false)); + else + f_pixmap = QPixmap::fromImage(image); + auto aspect_ratio = Qt::KeepAspectRatio; + + if (f_pixmap.size().width() > f_pixmap.size().height()) + aspect_ratio = Qt::KeepAspectRatioByExpanding; + + if (f_pixmap.size().width() > this->size().width() || f_pixmap.size().height() > this->size().height()) + this->setPixmap(f_pixmap.scaled(this->width(), this->height(), aspect_ratio, Qt::SmoothTransformation)); + else + this->setPixmap(f_pixmap.scaled(this->width(), this->height(), aspect_ratio, Qt::FastTransformation)); + + QLabel::move(x + (this->width() - this->pixmap()->width())/2, y); +} + void AOCharMovie::combo_resize(int w, int h) { QSize f_size(w, h); this->resize(f_size); - m_movie->setScaledSize(f_size); +// m_reader->setScaledSize(f_size); } void AOCharMovie::move(int ax, int ay) @@ -151,34 +120,34 @@ void AOCharMovie::move(int ax, int ay) QLabel::move(x, y); } -void AOCharMovie::frame_change(int n_frame) +void AOCharMovie::movie_ticker() { - - if (movie_frames.size() > n_frame) + if(m_reader->format() != "gif") + ticker->start(m_reader->nextImageDelay()); + if(m_reader->currentImageNumber() == -1) { - QPixmap f_pixmap = QPixmap::fromImage(movie_frames.at(n_frame)); - auto aspect_ratio = Qt::KeepAspectRatio; - - if (f_pixmap.size().width() > f_pixmap.size().height()) - aspect_ratio = Qt::KeepAspectRatioByExpanding; - - if (f_pixmap.size().width() > this->size().width() || f_pixmap.size().height() > this->size().height()) - this->setPixmap(f_pixmap.scaled(this->width(), this->height(), aspect_ratio, Qt::SmoothTransformation)); + if(play_once) + { + preanim_done(); + return; + } else - this->setPixmap(f_pixmap.scaled(this->width(), this->height(), aspect_ratio, Qt::FastTransformation)); - - QLabel::move(x + (this->width() - this->pixmap()->width())/2, y); - } - - if (m_movie->frameCount() - 1 == n_frame && play_once) + m_reader->jumpToImage(0); //Loop back + } + QImage f_image = m_reader->read(); + if(f_image.isNull()) { - preanim_timer->start(m_movie->nextFrameDelay()); - m_movie->stop(); + qDebug() << "Animated image error on frame" << m_reader->currentImageNumber() << m_reader->errorString(); + stop(); + return; } + this->set_frame(f_image); + qDebug() << m_reader->format() << "frame" << m_reader->nextImageDelay() << m_reader->currentImageNumber() << m_reader->imageCount(); + if(m_reader->format() == "gif") + ticker->start(m_reader->nextImageDelay()); } -void AOCharMovie::timer_done() +void AOCharMovie::preanim_done() { - done(); } -- cgit From 938f1aeea15c6b68495bb1cb0a80467f4e8cf343 Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Sat, 14 Sep 2019 22:35:02 +0300 Subject: Optimize the heck out of animated images. There is no lag after the image is loaded now. HOWEVER, there's lag when the image is first loaded due to the aspect ratio and sizing (at least with .apng's). --- src/aocharmovie.cpp | 74 +++++++++++++++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 34 deletions(-) (limited to 'src/aocharmovie.cpp') diff --git a/src/aocharmovie.cpp b/src/aocharmovie.cpp index 8004a54..2d370ec 100644 --- a/src/aocharmovie.cpp +++ b/src/aocharmovie.cpp @@ -11,7 +11,8 @@ AOCharMovie::AOCharMovie(QWidget *p_parent, AOApplication *p_ao_app) : QLabel(p_ preanim_timer->setSingleShot(true); ticker = new QTimer(this); - ticker->setSingleShot(true); + ticker->setTimerType(Qt::PreciseTimer); + ticker->setSingleShot(false); connect(ticker, SIGNAL(timeout()), this, SLOT(movie_ticker())); // connect(m_movie, SIGNAL(frameChanged(int)), this, SLOT(frame_change(int))); @@ -20,6 +21,7 @@ AOCharMovie::AOCharMovie(QWidget *p_parent, AOApplication *p_ao_app) : QLabel(p_ void AOCharMovie::play(QString p_char, QString p_emote, QString emote_prefix) { + actual_time.restart(); QString emote_path; QList pathlist; pathlist = { @@ -39,24 +41,29 @@ void AOCharMovie::play(QString p_char, QString p_emote, QString emote_prefix) } this->clear(); - m_reader = new QImageReader(emote_path); + ticker->stop(); + movie_frames.clear(); + movie_delays.clear(); + + QImageReader *m_reader = new QImageReader(emote_path); QImage f_image = m_reader->read(); -// while (!f_image.isNull()) -// { -// if (m_flipped) -// movie_frames.append(f_image.mirrored(true, false)); -// else -// movie_frames.append(f_image); -// f_image = reader->read(); -// } - -// delete m_reader; + while (!f_image.isNull()) + { + movie_frames.append(this->get_pixmap(f_image)); + movie_delays.append(m_reader->nextImageDelay()); + f_image = m_reader->read(); + } + + delete m_reader; + this->show(); - qDebug() << "Setting image to " << f_image; - this->set_frame(f_image); - if (m_reader->supportsAnimation()) - ticker->start(m_reader->nextImageDelay()); + qDebug() << "Setting image to " << emote_path << "Time taken to process image:" << actual_time.elapsed(); + frame = 0; + actual_time.restart(); + this->set_frame(movie_frames[frame]); + if (movie_frames.size() > 0) + ticker->start(movie_delays[frame]); } void AOCharMovie::play_pre(QString p_char, QString p_emote, int duration) @@ -86,7 +93,7 @@ void AOCharMovie::stop() this->hide(); } -void AOCharMovie::set_frame(QImage image) +QPixmap AOCharMovie::get_pixmap(QImage image) { QPixmap f_pixmap; if(m_flipped) @@ -99,10 +106,16 @@ void AOCharMovie::set_frame(QImage image) aspect_ratio = Qt::KeepAspectRatioByExpanding; if (f_pixmap.size().width() > this->size().width() || f_pixmap.size().height() > this->size().height()) - this->setPixmap(f_pixmap.scaled(this->width(), this->height(), aspect_ratio, Qt::SmoothTransformation)); + f_pixmap = f_pixmap.scaled(this->width(), this->height(), aspect_ratio, Qt::SmoothTransformation); else - this->setPixmap(f_pixmap.scaled(this->width(), this->height(), aspect_ratio, Qt::FastTransformation)); + f_pixmap = f_pixmap.scaled(this->width(), this->height(), aspect_ratio, Qt::FastTransformation); + return f_pixmap; +} + +void AOCharMovie::set_frame(QPixmap f_pixmap) +{ + this->setPixmap(f_pixmap); QLabel::move(x + (this->width() - this->pixmap()->width())/2, y); } @@ -122,29 +135,22 @@ void AOCharMovie::move(int ax, int ay) void AOCharMovie::movie_ticker() { - if(m_reader->format() != "gif") - ticker->start(m_reader->nextImageDelay()); - if(m_reader->currentImageNumber() == -1) + ++frame; + if(frame == movie_frames.size()) { if(play_once) { preanim_done(); + ticker->stop(); return; } else - m_reader->jumpToImage(0); //Loop back - } - QImage f_image = m_reader->read(); - if(f_image.isNull()) - { - qDebug() << "Animated image error on frame" << m_reader->currentImageNumber() << m_reader->errorString(); - stop(); - return; + frame = 0; } - this->set_frame(f_image); - qDebug() << m_reader->format() << "frame" << m_reader->nextImageDelay() << m_reader->currentImageNumber() << m_reader->imageCount(); - if(m_reader->format() == "gif") - ticker->start(m_reader->nextImageDelay()); +// qint64 difference = elapsed - movie_delays[frame]; + qDebug() << frame << movie_delays[frame] << "actual time taken from last frame:" << actual_time.restart(); + this->set_frame(movie_frames[frame]); + ticker->setInterval(movie_delays[frame]); } void AOCharMovie::preanim_done() -- cgit From 37d192b4300efd1c2f3e35b2efb40e93ec99fa03 Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Sun, 15 Sep 2019 02:14:40 +0300 Subject: 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();) --- src/aocharmovie.cpp | 46 +++++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 15 deletions(-) (limited to 'src/aocharmovie.cpp') diff --git a/src/aocharmovie.cpp b/src/aocharmovie.cpp index 2d370ec..1251a20 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 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]); } -- cgit From 4db114007456f12c77f002cac4e26cd3f6917638 Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Sun, 15 Sep 2019 14:26:57 +0300 Subject: Add a bunch of cool refactors to support variable speed percentage Partially bring back the differing [Time] duration variable, however, the speed of the image will not be adjusted to accomodate it due to the need for using m_reader to read through every frame to determine the final full delay value (which tanks performance). Comment all the functions for the charmovie in aocharmovie.h --- src/aocharmovie.cpp | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) (limited to 'src/aocharmovie.cpp') diff --git a/src/aocharmovie.cpp b/src/aocharmovie.cpp index 1251a20..0c389b1 100644 --- a/src/aocharmovie.cpp +++ b/src/aocharmovie.cpp @@ -19,7 +19,7 @@ AOCharMovie::AOCharMovie(QWidget *p_parent, AOApplication *p_ao_app) : QLabel(p_ connect(preanim_timer, SIGNAL(timeout()), this, SLOT(preanim_done())); } -void AOCharMovie::play(QString p_char, QString p_emote, QString emote_prefix) +void AOCharMovie::load_image(QString p_char, QString p_emote, QString emote_prefix) { #ifdef DEBUG_CHARMOVIE actual_time.restart(); @@ -49,45 +49,56 @@ void AOCharMovie::play(QString p_char, QString p_emote, QString emote_prefix) movie_delays.clear(); m_reader->setFileName(emote_path); - QImage f_image = m_reader->read(); + QPixmap f_pixmap = this->get_pixmap(m_reader->read()); int f_delay = m_reader->nextImageDelay(); frame = 0; max_frames = m_reader->imageCount(); + this->set_frame(f_pixmap); + this->show(); + if (max_frames > 1) + { + movie_frames.append(f_pixmap); + movie_delays.append(f_delay); + } #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]); - 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() +{ + if (max_frames <= 1) + return; + ticker->start(this->get_frame_delay(movie_delays[frame])); } void AOCharMovie::play_pre(QString p_char, QString p_emote, int duration) { -// QString emote_path = ao_app->get_character_path(p_char, p_emote); + load_image(p_char, p_emote, ""); + //As much as I'd like to screw around with [Time] durations modifying the animation speed, I don't think I can reliably do that, + //not without looping through all frames in the image at least - which causes lag. So for now it simply ends the preanimation early instead. play_once = true; - play(p_char, p_emote, ""); + if (duration > 0) //It's -1 if there's no definition in [Time] for it. In which case, it will let the animation run out in full. Duration 0 does the same. + preanim_timer->start(duration); //This timer will not fire if the animation finishes earlier than that + play(); } void AOCharMovie::play_talking(QString p_char, QString p_emote) { play_once = false; - play(p_char, p_emote, "(b)"); + load_image(p_char, p_emote, "(b)"); + play(); } void AOCharMovie::play_idle(QString p_char, QString p_emote) { play_once = false; - play(p_char, p_emote, "(a)"); + load_image(p_char, p_emote, "(a)"); + play(); } void AOCharMovie::stop() @@ -131,6 +142,11 @@ void AOCharMovie::combo_resize(int w, int h) // m_reader->setScaledSize(f_size); } +int AOCharMovie::get_frame_delay(int delay) +{ + return static_cast(double(delay) * double(speed/100)); +} + void AOCharMovie::move(int ax, int ay) { x = ax; @@ -166,10 +182,11 @@ void AOCharMovie::movie_ticker() #endif this->set_frame(movie_frames[frame]); - ticker->setInterval(movie_delays[frame]); + ticker->setInterval(this->get_frame_delay(movie_delays[frame])); } void AOCharMovie::preanim_done() { + preanim_timer->stop(); done(); } -- cgit From a2f9df4042585ab0849b54e2bb0b9699f9064aed Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Sun, 15 Sep 2019 17:44:02 +0300 Subject: Finally implement frame-specific effects such as screenshake, realization flash, sound effects, etc. Fix screenshake animation modifying the default positions of shook elements Fix aomovie sometimes not playing the last frame and causing lagspikes due to the delay() method --- src/aocharmovie.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'src/aocharmovie.cpp') diff --git a/src/aocharmovie.cpp b/src/aocharmovie.cpp index 0c389b1..efe2473 100644 --- a/src/aocharmovie.cpp +++ b/src/aocharmovie.cpp @@ -47,6 +47,7 @@ void AOCharMovie::load_image(QString p_char, QString p_emote, QString emote_pref preanim_timer->stop(); movie_frames.clear(); movie_delays.clear(); + movie_effects.clear(); m_reader->setFileName(emote_path); QPixmap f_pixmap = this->get_pixmap(m_reader->read()); @@ -62,6 +63,32 @@ void AOCharMovie::load_image(QString p_char, QString p_emote, QString emote_pref movie_frames.append(f_pixmap); movie_delays.append(f_delay); } + + movie_effects.resize(max_frames); + for (int e_frame = 0; e_frame < max_frames; ++e_frame) + { + qDebug() << p_char << p_emote << e_frame; + QString effect = ao_app->get_screenshake_frame(p_char, emote_prefix + p_emote, e_frame); + if (effect != "") + { + movie_effects[e_frame].append("shake"); + qDebug() << e_frame << "shake"; + } + + effect = ao_app->get_flash_frame(p_char, emote_prefix + p_emote, e_frame); + if (effect != "") + { + movie_effects[e_frame].append("flash"); + qDebug() << e_frame << "flash"; + } + + effect = ao_app->get_sfx_frame(p_char, emote_prefix + p_emote, e_frame); + if (effect != "") + { + movie_effects[e_frame].append("sfx^"+effect); + qDebug() << e_frame << effect; + } + } #ifdef DEBUG_CHARMOVIE qDebug() << max_frames << "Setting image to " << emote_path << "Time taken to process image:" << actual_time.elapsed(); @@ -71,6 +98,7 @@ void AOCharMovie::load_image(QString p_char, QString p_emote, QString emote_pref void AOCharMovie::play() { + play_frame_effect(frame); if (max_frames <= 1) return; ticker->start(this->get_frame_delay(movie_delays[frame])); @@ -101,6 +129,34 @@ void AOCharMovie::play_idle(QString p_char, QString p_emote) play(); } +void AOCharMovie::play_frame_effect(int frame) +{ + if(frame < max_frames) + { + foreach (QString effect, movie_effects[frame]) + { + if(effect == "shake") + { + shake(); + qDebug() << "Attempting to play shake on frame" << frame; + } + + if(effect == "flash") + { + flash(); + qDebug() << "Attempting to play flash on frame" << frame; + } + + if(effect.startsWith("sfx^")) + { + QString sfx = effect.section("^", 1); + play_sfx(sfx); + qDebug() << "Attempting to play sfx" << sfx << "on frame" << frame; + } + } + } +} + void AOCharMovie::stop() { //for all intents and purposes, stopping is the same as hiding. at no point do we want a frozen gif to display @@ -182,6 +238,7 @@ void AOCharMovie::movie_ticker() #endif this->set_frame(movie_frames[frame]); + play_frame_effect(frame); ticker->setInterval(this->get_frame_delay(movie_delays[frame])); } -- cgit From e94640b3493700a266619388d75dac5e56b3189a Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Sun, 15 Sep 2019 17:44:47 +0300 Subject: Looping SFX system - Defined this way: [SoundL] sfx-roar = 1 --- src/aocharmovie.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/aocharmovie.cpp') diff --git a/src/aocharmovie.cpp b/src/aocharmovie.cpp index efe2473..d67cf98 100644 --- a/src/aocharmovie.cpp +++ b/src/aocharmovie.cpp @@ -67,26 +67,34 @@ void AOCharMovie::load_image(QString p_char, QString p_emote, QString emote_pref movie_effects.resize(max_frames); for (int e_frame = 0; e_frame < max_frames; ++e_frame) { +#ifdef DEBUG_CHARMOVIE qDebug() << p_char << p_emote << e_frame; +#endif QString effect = ao_app->get_screenshake_frame(p_char, emote_prefix + p_emote, e_frame); if (effect != "") { movie_effects[e_frame].append("shake"); +#ifdef DEBUG_CHARMOVIE qDebug() << e_frame << "shake"; +#endif } effect = ao_app->get_flash_frame(p_char, emote_prefix + p_emote, e_frame); if (effect != "") { movie_effects[e_frame].append("flash"); +#ifdef DEBUG_CHARMOVIE qDebug() << e_frame << "flash"; +#endif } effect = ao_app->get_sfx_frame(p_char, emote_prefix + p_emote, e_frame); if (effect != "") { movie_effects[e_frame].append("sfx^"+effect); +#ifdef DEBUG_CHARMOVIE qDebug() << e_frame << effect; +#endif } } #ifdef DEBUG_CHARMOVIE @@ -138,20 +146,26 @@ void AOCharMovie::play_frame_effect(int frame) if(effect == "shake") { shake(); +#ifdef DEBUG_CHARMOVIE qDebug() << "Attempting to play shake on frame" << frame; +#endif } if(effect == "flash") { flash(); +#ifdef DEBUG_CHARMOVIE qDebug() << "Attempting to play flash on frame" << frame; +#endif } if(effect.startsWith("sfx^")) { QString sfx = effect.section("^", 1); play_sfx(sfx); +#ifdef DEBUG_CHARMOVIE qDebug() << "Attempting to play sfx" << sfx << "on frame" << frame; +#endif } } } -- cgit From 661ec87646fe57a0081d49e428267b0dfe3f0d65 Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Sun, 15 Sep 2019 20:02:24 +0300 Subject: Implement networking for frame-specific effects data sending/parsing if the server supports it Reorganize charmovie.h a bit and make some functions private Add a new helper function "read_char_ini_tag" which returns a qstringlist of all key=value strings associated with the tag --- src/aocharmovie.cpp | 83 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 64 insertions(+), 19 deletions(-) (limited to 'src/aocharmovie.cpp') diff --git a/src/aocharmovie.cpp b/src/aocharmovie.cpp index d67cf98..34c6c81 100644 --- a/src/aocharmovie.cpp +++ b/src/aocharmovie.cpp @@ -64,44 +64,89 @@ void AOCharMovie::load_image(QString p_char, QString p_emote, QString emote_pref movie_delays.append(f_delay); } + m_char = p_char; + m_emote = emote_prefix + p_emote; + + if (network_strings.size() > 0) //our FX overwritten by networked ones + this->load_network_effects(); + else //Use default ini FX + this->load_effects(); +#ifdef DEBUG_CHARMOVIE + qDebug() << max_frames << "Setting image to " << emote_path << "Time taken to process image:" << actual_time.elapsed(); + + actual_time.restart(); +#endif +} + +void AOCharMovie::load_effects() +{ + movie_effects.clear(); movie_effects.resize(max_frames); for (int e_frame = 0; e_frame < max_frames; ++e_frame) { -#ifdef DEBUG_CHARMOVIE - qDebug() << p_char << p_emote << e_frame; -#endif - QString effect = ao_app->get_screenshake_frame(p_char, emote_prefix + p_emote, e_frame); + QString effect = ao_app->get_screenshake_frame(m_char, m_emote, e_frame); if (effect != "") { movie_effects[e_frame].append("shake"); -#ifdef DEBUG_CHARMOVIE - qDebug() << e_frame << "shake"; -#endif } - effect = ao_app->get_flash_frame(p_char, emote_prefix + p_emote, e_frame); + effect = ao_app->get_flash_frame(m_char, m_emote, e_frame); if (effect != "") { movie_effects[e_frame].append("flash"); -#ifdef DEBUG_CHARMOVIE - qDebug() << e_frame << "flash"; -#endif } - effect = ao_app->get_sfx_frame(p_char, emote_prefix + p_emote, e_frame); + effect = ao_app->get_sfx_frame(m_char, m_emote, e_frame); if (effect != "") { movie_effects[e_frame].append("sfx^"+effect); -#ifdef DEBUG_CHARMOVIE - qDebug() << e_frame << effect; -#endif } } -#ifdef DEBUG_CHARMOVIE - qDebug() << max_frames << "Setting image to " << emote_path << "Time taken to process image:" << actual_time.elapsed(); +} - actual_time.restart(); -#endif +void AOCharMovie::load_network_effects() +{ + movie_effects.clear(); + movie_effects.resize(max_frames); + //Order is important!!! + QStringList effects_list = {"shake", "flash", "sfx^"}; + + //Determines which list is smaller - effects_list or network_strings - and uses it as basis for the loop. + //This way, incomplete network_strings would still be parsed, and excess/unaccounted for networked information is omitted. + int effects_size = qMin(effects_list.size(), network_strings.size()); + + for (int i = 0; i < effects_size; ++i) + { + QString netstring = network_strings.at(i); + QStringList emote_splits = netstring.split("^"); + foreach (QString emote, emote_splits) + { + QStringList parsed = emote.split("|"); + if (parsed.size() <= 0 || parsed.at(0) != m_emote) + continue; + foreach (QString frame_data, parsed) + { + QStringList frame_split = frame_data.split("="); + if (frame_split.size() <= 1) //We might still be hanging at the emote itself (entry 0). + continue; + int f_frame = frame_split.at(0).toInt(); + if (f_frame >= max_frames) + { + qDebug() << "Warning: out of bounds" << effects_list[i] << "frame" << f_frame << "out of" << max_frames << "for" << m_char << m_emote; + continue; + } + QString f_data = frame_split.at(1); + if (f_data != "") + { + QString effect = effects_list[i]; + if (effect == "sfx^") //Currently the only frame result that feeds us data, let's yank it in. + effect += f_data; + qDebug() << effect << f_data << "frame" << f_frame << "for" << m_char << m_emote; + movie_effects[f_frame].append(effect); + } + } + } + } } void AOCharMovie::play() -- cgit From 2268df7b152ac6de774d4eb8afa7ae502026b543 Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Mon, 16 Sep 2019 01:17:13 +0300 Subject: Update preanim_timer to follow the weird ass time_mod constant --- src/aocharmovie.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/aocharmovie.cpp') diff --git a/src/aocharmovie.cpp b/src/aocharmovie.cpp index 34c6c81..b795847 100644 --- a/src/aocharmovie.cpp +++ b/src/aocharmovie.cpp @@ -164,7 +164,7 @@ void AOCharMovie::play_pre(QString p_char, QString p_emote, int duration) //not without looping through all frames in the image at least - which causes lag. So for now it simply ends the preanimation early instead. play_once = true; if (duration > 0) //It's -1 if there's no definition in [Time] for it. In which case, it will let the animation run out in full. Duration 0 does the same. - preanim_timer->start(duration); //This timer will not fire if the animation finishes earlier than that + preanim_timer->start(duration * time_mod); //This timer will not fire if the animation finishes earlier than that play(); } -- cgit From 6dd0845f1c732e9c07afaaffb9163ba736a2ae25 Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Fri, 20 Sep 2019 17:03:49 +0300 Subject: Better scaling algorithm for characters of variable size --- src/aocharmovie.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'src/aocharmovie.cpp') diff --git a/src/aocharmovie.cpp b/src/aocharmovie.cpp index b795847..89d832d 100644 --- a/src/aocharmovie.cpp +++ b/src/aocharmovie.cpp @@ -232,14 +232,22 @@ QPixmap AOCharMovie::get_pixmap(QImage image) else f_pixmap = QPixmap::fromImage(image); auto aspect_ratio = Qt::KeepAspectRatio; + auto transform_mode = Qt::SmoothTransformation; - if (f_pixmap.size().width() > f_pixmap.size().height()) - aspect_ratio = Qt::KeepAspectRatioByExpanding; - - if (f_pixmap.size().width() > this->size().width() || f_pixmap.size().height() > this->size().height()) - f_pixmap = f_pixmap.scaled(this->width(), this->height(), aspect_ratio, Qt::SmoothTransformation); + if (f_pixmap.size().width() > this->size().width() && f_pixmap.size().height() <= this->size().height()) + { + f_pixmap = f_pixmap.scaledToHeight(this->height(), transform_mode); + } + else if (f_pixmap.size().height() > this->size().height()) + { + f_pixmap = f_pixmap.scaledToWidth(this->width(), transform_mode); + } else - f_pixmap = f_pixmap.scaled(this->width(), this->height(), aspect_ratio, Qt::FastTransformation); + { + f_pixmap = f_pixmap.scaled(this->width(), this->height(), aspect_ratio, transform_mode); + } + this->move((f_w - f_pixmap.width())/2, (f_h - f_pixmap.height())/2); + this->resize(f_pixmap.size()); return f_pixmap; } @@ -253,8 +261,9 @@ void AOCharMovie::set_frame(QPixmap f_pixmap) void AOCharMovie::combo_resize(int w, int h) { QSize f_size(w, h); + f_w = w; + f_h = h; this->resize(f_size); -// m_reader->setScaledSize(f_size); } int AOCharMovie::get_frame_delay(int delay) -- cgit From 520c4f5947528d8c8b56fdc7e93428d06b77e50c Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Fri, 20 Sep 2019 17:04:44 +0300 Subject: *better-rer* character scaling algorithm --- src/aocharmovie.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/aocharmovie.cpp') diff --git a/src/aocharmovie.cpp b/src/aocharmovie.cpp index 89d832d..d764d1a 100644 --- a/src/aocharmovie.cpp +++ b/src/aocharmovie.cpp @@ -234,19 +234,19 @@ QPixmap AOCharMovie::get_pixmap(QImage image) auto aspect_ratio = Qt::KeepAspectRatio; auto transform_mode = Qt::SmoothTransformation; - if (f_pixmap.size().width() > this->size().width() && f_pixmap.size().height() <= this->size().height()) + if (f_pixmap.size().width() > this->size().width() || f_pixmap.size().height() > this->size().height()) { f_pixmap = f_pixmap.scaledToHeight(this->height(), transform_mode); } - else if (f_pixmap.size().height() > this->size().height()) - { - f_pixmap = f_pixmap.scaledToWidth(this->width(), transform_mode); - } +// else if (f_pixmap.size().height() > this->size().height()) +// { +// f_pixmap = f_pixmap.scaledToWidth(this->width(), transform_mode); +// } else { f_pixmap = f_pixmap.scaled(this->width(), this->height(), aspect_ratio, transform_mode); } - this->move((f_w - f_pixmap.width())/2, (f_h - f_pixmap.height())/2); + this->move((f_w - f_pixmap.width())/2, (f_pixmap.height() - f_h)); //Always center horizontally, always put at the bottom vertically this->resize(f_pixmap.size()); return f_pixmap; -- cgit From 9911aeb5e6741279715f05d76c054907c58b47de Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Tue, 24 Sep 2019 13:29:08 +0300 Subject: Fix an issue with AOCharmovie hanging on frame1 animations Fix an issue with the logger screwing up the server folder name string if character ' was used --- src/aocharmovie.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/aocharmovie.cpp') diff --git a/src/aocharmovie.cpp b/src/aocharmovie.cpp index d764d1a..e8dc8fc 100644 --- a/src/aocharmovie.cpp +++ b/src/aocharmovie.cpp @@ -153,8 +153,12 @@ void AOCharMovie::play() { play_frame_effect(frame); if (max_frames <= 1) - return; - ticker->start(this->get_frame_delay(movie_delays[frame])); + { + play_once = true; + ticker->start(60); + } + else + ticker->start(this->get_frame_delay(movie_delays[frame])); } void AOCharMovie::play_pre(QString p_char, QString p_emote, int duration) @@ -281,7 +285,7 @@ void AOCharMovie::move(int ax, int ay) void AOCharMovie::movie_ticker() { ++frame; - if(frame == max_frames) + if(frame >= max_frames) { if(play_once) { -- cgit From a028b8496e6684f89efc3b8bf7946fb5901faa99 Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Wed, 25 Sep 2019 03:39:32 +0300 Subject: Fix objections botching up single frame preanims, etc. --- src/aocharmovie.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/aocharmovie.cpp') diff --git a/src/aocharmovie.cpp b/src/aocharmovie.cpp index e8dc8fc..5294b23 100644 --- a/src/aocharmovie.cpp +++ b/src/aocharmovie.cpp @@ -154,8 +154,8 @@ void AOCharMovie::play() play_frame_effect(frame); if (max_frames <= 1) { - play_once = true; - ticker->start(60); + if (play_once) + ticker->start(60); } else ticker->start(this->get_frame_delay(movie_delays[frame])); @@ -316,6 +316,7 @@ void AOCharMovie::movie_ticker() void AOCharMovie::preanim_done() { + ticker->stop(); preanim_timer->stop(); done(); } -- cgit From 4f738bfe34695db745d251e9461823b8835de201 Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Tue, 1 Oct 2019 01:07:03 +0300 Subject: Fix some read_file errors on effect loading Make FM packet only fetch music, and new FA packet to fetch areas (this way you don't have to reload the entire music list just to get new areas) Fix a possible segfault with emote lists if emote list size is bad Hide casing button if server doesn't support casing Hide the remove buttons by default for iniswaps and sfx list so they're not clickable when they shouldn't be Prevent background from being displayed unless the server asked us to Fix some redundancy surrounding current_side Rework music list so list_music doesn't care about search bar and the hiding is actually done in the search function Implement text centering, rightening and justifying Fix text scrolling meme that happened with \n and skipped chars Fix the pos dropdown not actually caring if you selected jur and sea pos. Fix the pos dropdown sending like a million packets when scrolled through. Prevent characters from being incorrectly resized if a different-scaled character speaks Fix character select screen letting you choose characters that the server doesn't want us to be --- src/aocharmovie.cpp | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) (limited to 'src/aocharmovie.cpp') diff --git a/src/aocharmovie.cpp b/src/aocharmovie.cpp index 5294b23..96e84d4 100644 --- a/src/aocharmovie.cpp +++ b/src/aocharmovie.cpp @@ -235,23 +235,12 @@ QPixmap AOCharMovie::get_pixmap(QImage image) f_pixmap = QPixmap::fromImage(image.mirrored(true, false)); else f_pixmap = QPixmap::fromImage(image); - auto aspect_ratio = Qt::KeepAspectRatio; +// auto aspect_ratio = Qt::KeepAspectRatio; auto transform_mode = Qt::SmoothTransformation; - if (f_pixmap.size().width() > this->size().width() || f_pixmap.size().height() > this->size().height()) - { - f_pixmap = f_pixmap.scaledToHeight(this->height(), transform_mode); - } -// else if (f_pixmap.size().height() > this->size().height()) -// { -// f_pixmap = f_pixmap.scaledToWidth(this->width(), transform_mode); -// } - else - { - f_pixmap = f_pixmap.scaled(this->width(), this->height(), aspect_ratio, transform_mode); - } - this->move((f_w - f_pixmap.width())/2, (f_pixmap.height() - f_h)); //Always center horizontally, always put at the bottom vertically + f_pixmap = f_pixmap.scaledToHeight(f_h, transform_mode); this->resize(f_pixmap.size()); + this->move((f_w - f_pixmap.width())/2, (f_h - f_pixmap.height())); //Always center horizontally, always put at the bottom vertically return f_pixmap; } -- cgit From 4c23e159350eeb3d74faf7e814f2874787e02565 Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Wed, 2 Oct 2019 01:20:00 +0300 Subject: Rewrite pairing character ordering logic to instead operate based on a user-accessible drpodown menu (it's a dropdown for the future when there's more options) Fix current charmovie breaking offsets Make pairing offsets applicable even without a pairing partner, making it a generic offset Fix the chat message hardcoding max colors to 8 (when it should be max_colors) Come up with a way to convey the ordering information without creating an extra new packet in a cool way (backwards compatibility AND less clutter!) More info on the evidence_x and evidence_ok tooltips Don't mute music when you switch to CSS anymore --- src/aocharmovie.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/aocharmovie.cpp') diff --git a/src/aocharmovie.cpp b/src/aocharmovie.cpp index 96e84d4..6f6c3a1 100644 --- a/src/aocharmovie.cpp +++ b/src/aocharmovie.cpp @@ -240,7 +240,7 @@ QPixmap AOCharMovie::get_pixmap(QImage image) f_pixmap = f_pixmap.scaledToHeight(f_h, transform_mode); this->resize(f_pixmap.size()); - this->move((f_w - f_pixmap.width())/2, (f_h - f_pixmap.height())); //Always center horizontally, always put at the bottom vertically + this->move(x + (f_w - f_pixmap.width())/2, y + (f_h - f_pixmap.height())); //Always center horizontally, always put at the bottom vertically return f_pixmap; } -- cgit From 9451822e0929643f638b3c79d4fd646df98b567a Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Thu, 3 Oct 2019 23:17:21 +0300 Subject: Fix move func making characters slowly move to the left every frame on animated chars which are sized differently from viewport Add a new get_qfont function Fix message box font being different from every other font due to incorrect font loading scheme Fix ui_evidence_save and ui_evidence_load tooltips being wrong --- src/aocharmovie.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/aocharmovie.cpp') diff --git a/src/aocharmovie.cpp b/src/aocharmovie.cpp index 6f6c3a1..f8dc8d2 100644 --- a/src/aocharmovie.cpp +++ b/src/aocharmovie.cpp @@ -240,7 +240,7 @@ QPixmap AOCharMovie::get_pixmap(QImage image) f_pixmap = f_pixmap.scaledToHeight(f_h, transform_mode); this->resize(f_pixmap.size()); - this->move(x + (f_w - f_pixmap.width())/2, y + (f_h - f_pixmap.height())); //Always center horizontally, always put at the bottom vertically + QLabel::move(x + (f_w - f_pixmap.width())/2, y + (f_h - f_pixmap.height())); //Always center horizontally, always put at the bottom vertically return f_pixmap; } -- cgit From 85f33e13c70a523df6554f0983e84777266563e4 Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Sun, 6 Oct 2019 13:27:11 +0300 Subject: Fix some edge cases where the AOChar qlabel is moved around in weird ways (reload theme still puts qlabel at 0,0 without centering) Fix a full message of speed 0 not properly displaying itself --- src/aocharmovie.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/aocharmovie.cpp') diff --git a/src/aocharmovie.cpp b/src/aocharmovie.cpp index f8dc8d2..b05d7f6 100644 --- a/src/aocharmovie.cpp +++ b/src/aocharmovie.cpp @@ -240,7 +240,6 @@ QPixmap AOCharMovie::get_pixmap(QImage image) f_pixmap = f_pixmap.scaledToHeight(f_h, transform_mode); this->resize(f_pixmap.size()); - QLabel::move(x + (f_w - f_pixmap.width())/2, y + (f_h - f_pixmap.height())); //Always center horizontally, always put at the bottom vertically return f_pixmap; } @@ -248,7 +247,7 @@ QPixmap AOCharMovie::get_pixmap(QImage image) void AOCharMovie::set_frame(QPixmap f_pixmap) { this->setPixmap(f_pixmap); - QLabel::move(x + (this->width() - this->pixmap()->width())/2, y); + QLabel::move(x + (f_w - f_pixmap.width())/2, y + (f_h - f_pixmap.height())); //Always center horizontally, always put at the bottom vertically } void AOCharMovie::combo_resize(int w, int h) -- cgit From 330aa9755095cd4f12f028452d268c50311d3710 Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Sat, 12 Oct 2019 01:43:48 +0300 Subject: Properly handle "true song name" even with folders/categories and file formats (paving way for folder-categorized music lists set up by servers) Prevent BG's from falling back on default BG path (this isn't really user-convenient and causes more trouble than its worth, e.g. stands appearing on BG's that dont' want stands to appear) Implement Case Cafe's method of categorization for (a) and (b) emotes --- src/aocharmovie.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/aocharmovie.cpp') diff --git a/src/aocharmovie.cpp b/src/aocharmovie.cpp index b05d7f6..9bbb876 100644 --- a/src/aocharmovie.cpp +++ b/src/aocharmovie.cpp @@ -28,6 +28,7 @@ void AOCharMovie::load_image(QString p_char, QString p_emote, QString emote_pref QList pathlist; pathlist = { ao_app->get_image_suffix(ao_app->get_character_path(p_char, emote_prefix + p_emote)), //Default path + ao_app->get_image_suffix(ao_app->get_character_path(p_char, emote_prefix + "/" + p_emote)),//Path check if it's categorized into a folder ao_app->get_character_path(p_char, p_emote + ".png"), //Non-animated path if emote_prefix fails ao_app->get_image_suffix(ao_app->get_theme_path("placeholder")), //Theme placeholder path ao_app->get_image_suffix(ao_app->get_default_theme_path("placeholder")), //Default theme placeholder path -- cgit From f30013f7f9d9ecb840948b99663e8b1e81a6971c Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Wed, 15 Jan 2020 16:06:27 +0300 Subject: i am REtArd Fixed a major bug that crashed the clients on chatting + broke a lot of assets because of a single `.` boi anywhere in the filepath. --- src/aocharmovie.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/aocharmovie.cpp') diff --git a/src/aocharmovie.cpp b/src/aocharmovie.cpp index 9bbb876..0ce5c86 100644 --- a/src/aocharmovie.cpp +++ b/src/aocharmovie.cpp @@ -50,6 +50,9 @@ void AOCharMovie::load_image(QString p_char, QString p_emote, QString emote_pref movie_delays.clear(); movie_effects.clear(); + if (!file_exists(emote_path)) + return; + m_reader->setFileName(emote_path); QPixmap f_pixmap = this->get_pixmap(m_reader->read()); int f_delay = m_reader->nextImageDelay(); -- cgit From 9b8f60061aebae849f5325189d5baf36db0c8c99 Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Sun, 8 Mar 2020 17:40:52 +0300 Subject: The Crispy:tm: update Make it so BG's and Characters will not be blurred when rescaled TODO: Make Qmovies ditch anti-aliasing during scaling as well Only apply crispy scaling if the size is 2x of the previous size or something --- src/aocharmovie.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/aocharmovie.cpp') diff --git a/src/aocharmovie.cpp b/src/aocharmovie.cpp index 0ce5c86..6cdcab2 100644 --- a/src/aocharmovie.cpp +++ b/src/aocharmovie.cpp @@ -240,7 +240,9 @@ QPixmap AOCharMovie::get_pixmap(QImage image) else f_pixmap = QPixmap::fromImage(image); // auto aspect_ratio = Qt::KeepAspectRatio; - auto transform_mode = Qt::SmoothTransformation; + auto transform_mode = Qt::FastTransformation; +// if () +// transform_mode = Qt::SmoothTransformation; f_pixmap = f_pixmap.scaledToHeight(f_h, transform_mode); this->resize(f_pixmap.size()); -- cgit From ce3269cc36485e44a85778b0d93b6bfc26f95eb1 Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Thu, 12 Mar 2020 00:47:39 +0300 Subject: Only use anti-aliasing when sprites are being downscaled, otherwise preserve crispyness:tm: --- src/aocharmovie.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/aocharmovie.cpp') diff --git a/src/aocharmovie.cpp b/src/aocharmovie.cpp index 6cdcab2..7bbdc1b 100644 --- a/src/aocharmovie.cpp +++ b/src/aocharmovie.cpp @@ -241,8 +241,8 @@ QPixmap AOCharMovie::get_pixmap(QImage image) f_pixmap = QPixmap::fromImage(image); // auto aspect_ratio = Qt::KeepAspectRatio; auto transform_mode = Qt::FastTransformation; -// if () -// transform_mode = Qt::SmoothTransformation; + if (f_pixmap.height() > f_h) //We are downscaling, use anti-aliasing. + transform_mode = Qt::SmoothTransformation; f_pixmap = f_pixmap.scaledToHeight(f_h, transform_mode); this->resize(f_pixmap.size()); -- cgit From c8e12558cdd3fd0769b81679ad09edf1f29b780f Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Fri, 22 May 2020 01:18:24 +0300 Subject: Clang-ify the code with this styling using Visual Studio Code: { BasedOnStyle: LLVM, UseTab: Never, IndentWidth: 4, TabWidth: 4, BreakBeforeBraces: Stroustrup, AllowShortIfStatementsOnASingleLine: false, IndentCaseLabels: false, ColumnLimit: 0, AccessModifierOffset: -4, NamespaceIndentation: All } (this is the Visual Studio preset with only "BreakBeforeBraces" changed from Allman to Stroustrup) --- src/aocharmovie.cpp | 393 +++++++++++++++++++++++++--------------------------- 1 file changed, 186 insertions(+), 207 deletions(-) (limited to 'src/aocharmovie.cpp') diff --git a/src/aocharmovie.cpp b/src/aocharmovie.cpp index 7bbdc1b..2963275 100644 --- a/src/aocharmovie.cpp +++ b/src/aocharmovie.cpp @@ -1,248 +1,230 @@ #include "aocharmovie.h" -#include "misc_functions.h" -#include "file_functions.h" #include "aoapplication.h" +#include "file_functions.h" +#include "misc_functions.h" AOCharMovie::AOCharMovie(QWidget *p_parent, AOApplication *p_ao_app) : QLabel(p_parent) { - ao_app = p_ao_app; - preanim_timer = new QTimer(this); - preanim_timer->setSingleShot(true); + ao_app = p_ao_app; + preanim_timer = new QTimer(this); + preanim_timer->setSingleShot(true); - ticker = new QTimer(this); - ticker->setTimerType(Qt::PreciseTimer); - ticker->setSingleShot(false); - connect(ticker, SIGNAL(timeout()), this, SLOT(movie_ticker())); + ticker = new QTimer(this); + ticker->setTimerType(Qt::PreciseTimer); + ticker->setSingleShot(false); + connect(ticker, SIGNAL(timeout()), this, SLOT(movie_ticker())); -// connect(m_movie, SIGNAL(frameChanged(int)), this, SLOT(frame_change(int))); - connect(preanim_timer, SIGNAL(timeout()), this, SLOT(preanim_done())); + // connect(m_movie, SIGNAL(frameChanged(int)), this, SLOT(frame_change(int))); + connect(preanim_timer, SIGNAL(timeout()), this, SLOT(preanim_done())); } void AOCharMovie::load_image(QString p_char, QString p_emote, QString emote_prefix) { #ifdef DEBUG_CHARMOVIE - actual_time.restart(); + actual_time.restart(); #endif - QString emote_path; - QList pathlist; - pathlist = { - ao_app->get_image_suffix(ao_app->get_character_path(p_char, emote_prefix + p_emote)), //Default path - ao_app->get_image_suffix(ao_app->get_character_path(p_char, emote_prefix + "/" + p_emote)),//Path check if it's categorized into a folder - ao_app->get_character_path(p_char, p_emote + ".png"), //Non-animated path if emote_prefix fails - ao_app->get_image_suffix(ao_app->get_theme_path("placeholder")), //Theme placeholder path - ao_app->get_image_suffix(ao_app->get_default_theme_path("placeholder")), //Default theme placeholder path - }; - - for (QString path : pathlist) - { - if (file_exists(path)) - { - emote_path = path; - break; - } - } - - this->clear(); - ticker->stop(); - preanim_timer->stop(); - movie_frames.clear(); - movie_delays.clear(); - movie_effects.clear(); - - if (!file_exists(emote_path)) - return; - - m_reader->setFileName(emote_path); - QPixmap f_pixmap = this->get_pixmap(m_reader->read()); - int f_delay = m_reader->nextImageDelay(); - - frame = 0; - max_frames = m_reader->imageCount(); - - this->set_frame(f_pixmap); - this->show(); - if (max_frames > 1) - { - movie_frames.append(f_pixmap); - movie_delays.append(f_delay); - } - - m_char = p_char; - m_emote = emote_prefix + p_emote; - - if (network_strings.size() > 0) //our FX overwritten by networked ones - this->load_network_effects(); - else //Use default ini FX - this->load_effects(); + QString emote_path; + QList pathlist; + pathlist = { + ao_app->get_image_suffix(ao_app->get_character_path(p_char, emote_prefix + p_emote)), //Default path + ao_app->get_image_suffix(ao_app->get_character_path(p_char, emote_prefix + "/" + p_emote)), //Path check if it's categorized into a folder + ao_app->get_character_path(p_char, p_emote + ".png"), //Non-animated path if emote_prefix fails + ao_app->get_image_suffix(ao_app->get_theme_path("placeholder")), //Theme placeholder path + ao_app->get_image_suffix(ao_app->get_default_theme_path("placeholder")), //Default theme placeholder path + }; + + for (QString path : pathlist) { + if (file_exists(path)) { + emote_path = path; + break; + } + } + + this->clear(); + ticker->stop(); + preanim_timer->stop(); + movie_frames.clear(); + movie_delays.clear(); + movie_effects.clear(); + + if (!file_exists(emote_path)) + return; + + m_reader->setFileName(emote_path); + QPixmap f_pixmap = this->get_pixmap(m_reader->read()); + int f_delay = m_reader->nextImageDelay(); + + frame = 0; + max_frames = m_reader->imageCount(); + + this->set_frame(f_pixmap); + this->show(); + if (max_frames > 1) { + movie_frames.append(f_pixmap); + movie_delays.append(f_delay); + } + + m_char = p_char; + m_emote = emote_prefix + p_emote; + + if (network_strings.size() > 0) //our FX overwritten by networked ones + this->load_network_effects(); + else //Use default ini FX + this->load_effects(); #ifdef DEBUG_CHARMOVIE - qDebug() << max_frames << "Setting image to " << emote_path << "Time taken to process image:" << actual_time.elapsed(); + qDebug() << max_frames << "Setting image to " << emote_path << "Time taken to process image:" << actual_time.elapsed(); - actual_time.restart(); + actual_time.restart(); #endif } void AOCharMovie::load_effects() { - movie_effects.clear(); - movie_effects.resize(max_frames); - for (int e_frame = 0; e_frame < max_frames; ++e_frame) - { - QString effect = ao_app->get_screenshake_frame(m_char, m_emote, e_frame); - if (effect != "") - { - movie_effects[e_frame].append("shake"); - } + movie_effects.clear(); + movie_effects.resize(max_frames); + for (int e_frame = 0; e_frame < max_frames; ++e_frame) { + QString effect = ao_app->get_screenshake_frame(m_char, m_emote, e_frame); + if (effect != "") { + movie_effects[e_frame].append("shake"); + } - effect = ao_app->get_flash_frame(m_char, m_emote, e_frame); - if (effect != "") - { - movie_effects[e_frame].append("flash"); - } + effect = ao_app->get_flash_frame(m_char, m_emote, e_frame); + if (effect != "") { + movie_effects[e_frame].append("flash"); + } - effect = ao_app->get_sfx_frame(m_char, m_emote, e_frame); - if (effect != "") - { - movie_effects[e_frame].append("sfx^"+effect); + effect = ao_app->get_sfx_frame(m_char, m_emote, e_frame); + if (effect != "") { + movie_effects[e_frame].append("sfx^" + effect); + } } - } } void AOCharMovie::load_network_effects() { - movie_effects.clear(); - movie_effects.resize(max_frames); - //Order is important!!! - QStringList effects_list = {"shake", "flash", "sfx^"}; - - //Determines which list is smaller - effects_list or network_strings - and uses it as basis for the loop. - //This way, incomplete network_strings would still be parsed, and excess/unaccounted for networked information is omitted. - int effects_size = qMin(effects_list.size(), network_strings.size()); - - for (int i = 0; i < effects_size; ++i) - { - QString netstring = network_strings.at(i); - QStringList emote_splits = netstring.split("^"); - foreach (QString emote, emote_splits) - { - QStringList parsed = emote.split("|"); - if (parsed.size() <= 0 || parsed.at(0) != m_emote) - continue; - foreach (QString frame_data, parsed) - { - QStringList frame_split = frame_data.split("="); - if (frame_split.size() <= 1) //We might still be hanging at the emote itself (entry 0). - continue; - int f_frame = frame_split.at(0).toInt(); - if (f_frame >= max_frames) - { - qDebug() << "Warning: out of bounds" << effects_list[i] << "frame" << f_frame << "out of" << max_frames << "for" << m_char << m_emote; - continue; - } - QString f_data = frame_split.at(1); - if (f_data != "") - { - QString effect = effects_list[i]; - if (effect == "sfx^") //Currently the only frame result that feeds us data, let's yank it in. - effect += f_data; - qDebug() << effect << f_data << "frame" << f_frame << "for" << m_char << m_emote; - movie_effects[f_frame].append(effect); + movie_effects.clear(); + movie_effects.resize(max_frames); + //Order is important!!! + QStringList effects_list = {"shake", "flash", "sfx^"}; + + //Determines which list is smaller - effects_list or network_strings - and uses it as basis for the loop. + //This way, incomplete network_strings would still be parsed, and excess/unaccounted for networked information is omitted. + int effects_size = qMin(effects_list.size(), network_strings.size()); + + for (int i = 0; i < effects_size; ++i) { + QString netstring = network_strings.at(i); + QStringList emote_splits = netstring.split("^"); + foreach (QString emote, emote_splits) { + QStringList parsed = emote.split("|"); + if (parsed.size() <= 0 || parsed.at(0) != m_emote) + continue; + foreach (QString frame_data, parsed) { + QStringList frame_split = frame_data.split("="); + if (frame_split.size() <= 1) //We might still be hanging at the emote itself (entry 0). + continue; + int f_frame = frame_split.at(0).toInt(); + if (f_frame >= max_frames) { + qDebug() << "Warning: out of bounds" << effects_list[i] << "frame" << f_frame << "out of" << max_frames << "for" << m_char << m_emote; + continue; + } + QString f_data = frame_split.at(1); + if (f_data != "") { + QString effect = effects_list[i]; + if (effect == "sfx^") //Currently the only frame result that feeds us data, let's yank it in. + effect += f_data; + qDebug() << effect << f_data << "frame" << f_frame << "for" << m_char << m_emote; + movie_effects[f_frame].append(effect); + } + } } - } } - } } void AOCharMovie::play() { - play_frame_effect(frame); - if (max_frames <= 1) - { - if (play_once) - ticker->start(60); - } - else - ticker->start(this->get_frame_delay(movie_delays[frame])); + play_frame_effect(frame); + if (max_frames <= 1) { + if (play_once) + ticker->start(60); + } + else + ticker->start(this->get_frame_delay(movie_delays[frame])); } void AOCharMovie::play_pre(QString p_char, QString p_emote, int duration) { - load_image(p_char, p_emote, ""); - //As much as I'd like to screw around with [Time] durations modifying the animation speed, I don't think I can reliably do that, - //not without looping through all frames in the image at least - which causes lag. So for now it simply ends the preanimation early instead. - play_once = true; - if (duration > 0) //It's -1 if there's no definition in [Time] for it. In which case, it will let the animation run out in full. Duration 0 does the same. - preanim_timer->start(duration * time_mod); //This timer will not fire if the animation finishes earlier than that - play(); + load_image(p_char, p_emote, ""); + //As much as I'd like to screw around with [Time] durations modifying the animation speed, I don't think I can reliably do that, + //not without looping through all frames in the image at least - which causes lag. So for now it simply ends the preanimation early instead. + play_once = true; + if (duration > 0) //It's -1 if there's no definition in [Time] for it. In which case, it will let the animation run out in full. Duration 0 does the same. + preanim_timer->start(duration * time_mod); //This timer will not fire if the animation finishes earlier than that + play(); } void AOCharMovie::play_talking(QString p_char, QString p_emote) { - play_once = false; - load_image(p_char, p_emote, "(b)"); - play(); + play_once = false; + load_image(p_char, p_emote, "(b)"); + play(); } void AOCharMovie::play_idle(QString p_char, QString p_emote) { - play_once = false; - load_image(p_char, p_emote, "(a)"); - play(); + play_once = false; + load_image(p_char, p_emote, "(a)"); + play(); } void AOCharMovie::play_frame_effect(int frame) { - if(frame < max_frames) - { - foreach (QString effect, movie_effects[frame]) - { - if(effect == "shake") - { - shake(); + if (frame < max_frames) { + foreach (QString effect, movie_effects[frame]) { + if (effect == "shake") { + shake(); #ifdef DEBUG_CHARMOVIE - qDebug() << "Attempting to play shake on frame" << frame; + qDebug() << "Attempting to play shake on frame" << frame; #endif - } + } - if(effect == "flash") - { - flash(); + if (effect == "flash") { + flash(); #ifdef DEBUG_CHARMOVIE - qDebug() << "Attempting to play flash on frame" << frame; + qDebug() << "Attempting to play flash on frame" << frame; #endif - } + } - if(effect.startsWith("sfx^")) - { - QString sfx = effect.section("^", 1); - play_sfx(sfx); + if (effect.startsWith("sfx^")) { + QString sfx = effect.section("^", 1); + play_sfx(sfx); #ifdef DEBUG_CHARMOVIE - qDebug() << "Attempting to play sfx" << sfx << "on frame" << frame; + qDebug() << "Attempting to play sfx" << sfx << "on frame" << frame; #endif - } + } + } } - } } void AOCharMovie::stop() { - //for all intents and purposes, stopping is the same as hiding. at no point do we want a frozen gif to display - ticker->stop(); - preanim_timer->stop(); - this->hide(); + //for all intents and purposes, stopping is the same as hiding. at no point do we want a frozen gif to display + ticker->stop(); + preanim_timer->stop(); + this->hide(); } QPixmap AOCharMovie::get_pixmap(QImage image) { QPixmap f_pixmap; - if(m_flipped) + if (m_flipped) f_pixmap = QPixmap::fromImage(image.mirrored(true, false)); else f_pixmap = QPixmap::fromImage(image); -// auto aspect_ratio = Qt::KeepAspectRatio; + // auto aspect_ratio = Qt::KeepAspectRatio; auto transform_mode = Qt::FastTransformation; if (f_pixmap.height() > f_h) //We are downscaling, use anti-aliasing. - transform_mode = Qt::SmoothTransformation; + transform_mode = Qt::SmoothTransformation; f_pixmap = f_pixmap.scaledToHeight(f_h, transform_mode); this->resize(f_pixmap.size()); @@ -253,64 +235,61 @@ QPixmap AOCharMovie::get_pixmap(QImage image) void AOCharMovie::set_frame(QPixmap f_pixmap) { this->setPixmap(f_pixmap); - QLabel::move(x + (f_w - f_pixmap.width())/2, y + (f_h - f_pixmap.height())); //Always center horizontally, always put at the bottom vertically + QLabel::move(x + (f_w - f_pixmap.width()) / 2, y + (f_h - f_pixmap.height())); //Always center horizontally, always put at the bottom vertically } void AOCharMovie::combo_resize(int w, int h) { - QSize f_size(w, h); - f_w = w; - f_h = h; - this->resize(f_size); + QSize f_size(w, h); + f_w = w; + f_h = h; + this->resize(f_size); } int AOCharMovie::get_frame_delay(int delay) { - return static_cast(double(delay) * double(speed/100)); + return static_cast(double(delay) * double(speed / 100)); } void AOCharMovie::move(int ax, int ay) { - x = ax; - y = ay; - QLabel::move(x, y); + x = ax; + y = ay; + QLabel::move(x, y); } void AOCharMovie::movie_ticker() { - ++frame; - if(frame >= max_frames) - { - if(play_once) - { - preanim_done(); - return; + ++frame; + if (frame >= max_frames) { + if (play_once) { + preanim_done(); + 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(); } - 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(); + qDebug() << frame << movie_delays[frame] << "actual time taken from last frame:" << actual_time.restart(); #endif - this->set_frame(movie_frames[frame]); - play_frame_effect(frame); - ticker->setInterval(this->get_frame_delay(movie_delays[frame])); + this->set_frame(movie_frames[frame]); + play_frame_effect(frame); + ticker->setInterval(this->get_frame_delay(movie_delays[frame])); } void AOCharMovie::preanim_done() { - ticker->stop(); - preanim_timer->stop(); - done(); + ticker->stop(); + preanim_timer->stop(); + done(); } -- cgit From 88de4cde0433ef5e606f38a2f1e6041f0d24a87e Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Fri, 22 May 2020 02:14:54 +0300 Subject: clang 2 electric boogaloo { BasedOnStyle: LLVM, BreakBeforeBraces: Stroustrup} --- src/aocharmovie.cpp | 426 ++++++++++++++++++++++++++++------------------------ 1 file changed, 227 insertions(+), 199 deletions(-) (limited to 'src/aocharmovie.cpp') diff --git a/src/aocharmovie.cpp b/src/aocharmovie.cpp index 2963275..252aab5 100644 --- a/src/aocharmovie.cpp +++ b/src/aocharmovie.cpp @@ -4,292 +4,320 @@ #include "file_functions.h" #include "misc_functions.h" -AOCharMovie::AOCharMovie(QWidget *p_parent, AOApplication *p_ao_app) : QLabel(p_parent) +AOCharMovie::AOCharMovie(QWidget *p_parent, AOApplication *p_ao_app) + : QLabel(p_parent) { - ao_app = p_ao_app; - preanim_timer = new QTimer(this); - preanim_timer->setSingleShot(true); - - ticker = new QTimer(this); - ticker->setTimerType(Qt::PreciseTimer); - ticker->setSingleShot(false); - connect(ticker, SIGNAL(timeout()), this, SLOT(movie_ticker())); - - // connect(m_movie, SIGNAL(frameChanged(int)), this, SLOT(frame_change(int))); - connect(preanim_timer, SIGNAL(timeout()), this, SLOT(preanim_done())); + ao_app = p_ao_app; + preanim_timer = new QTimer(this); + preanim_timer->setSingleShot(true); + + ticker = new QTimer(this); + ticker->setTimerType(Qt::PreciseTimer); + ticker->setSingleShot(false); + connect(ticker, SIGNAL(timeout()), this, SLOT(movie_ticker())); + + // connect(m_movie, SIGNAL(frameChanged(int)), this, + // SLOT(frame_change(int))); + connect(preanim_timer, SIGNAL(timeout()), this, SLOT(preanim_done())); } -void AOCharMovie::load_image(QString p_char, QString p_emote, QString emote_prefix) +void AOCharMovie::load_image(QString p_char, QString p_emote, + QString emote_prefix) { #ifdef DEBUG_CHARMOVIE - actual_time.restart(); + actual_time.restart(); #endif - QString emote_path; - QList pathlist; - pathlist = { - ao_app->get_image_suffix(ao_app->get_character_path(p_char, emote_prefix + p_emote)), //Default path - ao_app->get_image_suffix(ao_app->get_character_path(p_char, emote_prefix + "/" + p_emote)), //Path check if it's categorized into a folder - ao_app->get_character_path(p_char, p_emote + ".png"), //Non-animated path if emote_prefix fails - ao_app->get_image_suffix(ao_app->get_theme_path("placeholder")), //Theme placeholder path - ao_app->get_image_suffix(ao_app->get_default_theme_path("placeholder")), //Default theme placeholder path - }; - - for (QString path : pathlist) { - if (file_exists(path)) { - emote_path = path; - break; - } + QString emote_path; + QList pathlist; + pathlist = { + ao_app->get_image_suffix(ao_app->get_character_path( + p_char, emote_prefix + p_emote)), // Default path + ao_app->get_image_suffix(ao_app->get_character_path( + p_char, emote_prefix + "/" + + p_emote)), // Path check if it's categorized into a folder + ao_app->get_character_path( + p_char, p_emote + ".png"), // Non-animated path if emote_prefix fails + ao_app->get_image_suffix( + ao_app->get_theme_path("placeholder")), // Theme placeholder path + ao_app->get_image_suffix(ao_app->get_default_theme_path( + "placeholder")), // Default theme placeholder path + }; + + for (QString path : pathlist) { + if (file_exists(path)) { + emote_path = path; + break; } - - this->clear(); - ticker->stop(); - preanim_timer->stop(); - movie_frames.clear(); - movie_delays.clear(); - movie_effects.clear(); - - if (!file_exists(emote_path)) - return; - - m_reader->setFileName(emote_path); - QPixmap f_pixmap = this->get_pixmap(m_reader->read()); - int f_delay = m_reader->nextImageDelay(); - - frame = 0; - max_frames = m_reader->imageCount(); - - this->set_frame(f_pixmap); - this->show(); - if (max_frames > 1) { - movie_frames.append(f_pixmap); - movie_delays.append(f_delay); - } - - m_char = p_char; - m_emote = emote_prefix + p_emote; - - if (network_strings.size() > 0) //our FX overwritten by networked ones - this->load_network_effects(); - else //Use default ini FX - this->load_effects(); + } + + this->clear(); + ticker->stop(); + preanim_timer->stop(); + movie_frames.clear(); + movie_delays.clear(); + movie_effects.clear(); + + if (!file_exists(emote_path)) + return; + + m_reader->setFileName(emote_path); + QPixmap f_pixmap = this->get_pixmap(m_reader->read()); + int f_delay = m_reader->nextImageDelay(); + + frame = 0; + max_frames = m_reader->imageCount(); + + this->set_frame(f_pixmap); + this->show(); + if (max_frames > 1) { + movie_frames.append(f_pixmap); + movie_delays.append(f_delay); + } + + m_char = p_char; + m_emote = emote_prefix + p_emote; + + if (network_strings.size() > 0) // our FX overwritten by networked ones + this->load_network_effects(); + else // Use default ini FX + this->load_effects(); #ifdef DEBUG_CHARMOVIE - qDebug() << max_frames << "Setting image to " << emote_path << "Time taken to process image:" << actual_time.elapsed(); + qDebug() << max_frames << "Setting image to " << emote_path + << "Time taken to process image:" << actual_time.elapsed(); - actual_time.restart(); + actual_time.restart(); #endif } void AOCharMovie::load_effects() { - movie_effects.clear(); - movie_effects.resize(max_frames); - for (int e_frame = 0; e_frame < max_frames; ++e_frame) { - QString effect = ao_app->get_screenshake_frame(m_char, m_emote, e_frame); - if (effect != "") { - movie_effects[e_frame].append("shake"); - } + movie_effects.clear(); + movie_effects.resize(max_frames); + for (int e_frame = 0; e_frame < max_frames; ++e_frame) { + QString effect = ao_app->get_screenshake_frame(m_char, m_emote, e_frame); + if (effect != "") { + movie_effects[e_frame].append("shake"); + } - effect = ao_app->get_flash_frame(m_char, m_emote, e_frame); - if (effect != "") { - movie_effects[e_frame].append("flash"); - } + effect = ao_app->get_flash_frame(m_char, m_emote, e_frame); + if (effect != "") { + movie_effects[e_frame].append("flash"); + } - effect = ao_app->get_sfx_frame(m_char, m_emote, e_frame); - if (effect != "") { - movie_effects[e_frame].append("sfx^" + effect); - } + effect = ao_app->get_sfx_frame(m_char, m_emote, e_frame); + if (effect != "") { + movie_effects[e_frame].append("sfx^" + effect); } + } } void AOCharMovie::load_network_effects() { - movie_effects.clear(); - movie_effects.resize(max_frames); - //Order is important!!! - QStringList effects_list = {"shake", "flash", "sfx^"}; - - //Determines which list is smaller - effects_list or network_strings - and uses it as basis for the loop. - //This way, incomplete network_strings would still be parsed, and excess/unaccounted for networked information is omitted. - int effects_size = qMin(effects_list.size(), network_strings.size()); - - for (int i = 0; i < effects_size; ++i) { - QString netstring = network_strings.at(i); - QStringList emote_splits = netstring.split("^"); - foreach (QString emote, emote_splits) { - QStringList parsed = emote.split("|"); - if (parsed.size() <= 0 || parsed.at(0) != m_emote) - continue; - foreach (QString frame_data, parsed) { - QStringList frame_split = frame_data.split("="); - if (frame_split.size() <= 1) //We might still be hanging at the emote itself (entry 0). - continue; - int f_frame = frame_split.at(0).toInt(); - if (f_frame >= max_frames) { - qDebug() << "Warning: out of bounds" << effects_list[i] << "frame" << f_frame << "out of" << max_frames << "for" << m_char << m_emote; - continue; - } - QString f_data = frame_split.at(1); - if (f_data != "") { - QString effect = effects_list[i]; - if (effect == "sfx^") //Currently the only frame result that feeds us data, let's yank it in. - effect += f_data; - qDebug() << effect << f_data << "frame" << f_frame << "for" << m_char << m_emote; - movie_effects[f_frame].append(effect); - } - } + movie_effects.clear(); + movie_effects.resize(max_frames); + // Order is important!!! + QStringList effects_list = {"shake", "flash", "sfx^"}; + + // Determines which list is smaller - effects_list or network_strings - and + // uses it as basis for the loop. This way, incomplete network_strings would + // still be parsed, and excess/unaccounted for networked information is + // omitted. + int effects_size = qMin(effects_list.size(), network_strings.size()); + + for (int i = 0; i < effects_size; ++i) { + QString netstring = network_strings.at(i); + QStringList emote_splits = netstring.split("^"); + foreach (QString emote, emote_splits) { + QStringList parsed = emote.split("|"); + if (parsed.size() <= 0 || parsed.at(0) != m_emote) + continue; + foreach (QString frame_data, parsed) { + QStringList frame_split = frame_data.split("="); + if (frame_split.size() <= + 1) // We might still be hanging at the emote itself (entry 0). + continue; + int f_frame = frame_split.at(0).toInt(); + if (f_frame >= max_frames) { + qDebug() << "Warning: out of bounds" << effects_list[i] << "frame" + << f_frame << "out of" << max_frames << "for" << m_char + << m_emote; + continue; + } + QString f_data = frame_split.at(1); + if (f_data != "") { + QString effect = effects_list[i]; + if (effect == "sfx^") // Currently the only frame result that feeds us + // data, let's yank it in. + effect += f_data; + qDebug() << effect << f_data << "frame" << f_frame << "for" << m_char + << m_emote; + movie_effects[f_frame].append(effect); } + } } + } } void AOCharMovie::play() { - play_frame_effect(frame); - if (max_frames <= 1) { - if (play_once) - ticker->start(60); - } - else - ticker->start(this->get_frame_delay(movie_delays[frame])); + play_frame_effect(frame); + if (max_frames <= 1) { + if (play_once) + ticker->start(60); + } + else + ticker->start(this->get_frame_delay(movie_delays[frame])); } void AOCharMovie::play_pre(QString p_char, QString p_emote, int duration) { - load_image(p_char, p_emote, ""); - //As much as I'd like to screw around with [Time] durations modifying the animation speed, I don't think I can reliably do that, - //not without looping through all frames in the image at least - which causes lag. So for now it simply ends the preanimation early instead. - play_once = true; - if (duration > 0) //It's -1 if there's no definition in [Time] for it. In which case, it will let the animation run out in full. Duration 0 does the same. - preanim_timer->start(duration * time_mod); //This timer will not fire if the animation finishes earlier than that - play(); + load_image(p_char, p_emote, ""); + // As much as I'd like to screw around with [Time] durations modifying the + // animation speed, I don't think I can reliably do that, not without looping + // through all frames in the image at least - which causes lag. So for now it + // simply ends the preanimation early instead. + play_once = true; + if (duration > + 0) // It's -1 if there's no definition in [Time] for it. In which case, it + // will let the animation run out in full. Duration 0 does the same. + preanim_timer->start(duration * + time_mod); // This timer will not fire if the animation + // finishes earlier than that + play(); } void AOCharMovie::play_talking(QString p_char, QString p_emote) { - play_once = false; - load_image(p_char, p_emote, "(b)"); - play(); + play_once = false; + load_image(p_char, p_emote, "(b)"); + play(); } void AOCharMovie::play_idle(QString p_char, QString p_emote) { - play_once = false; - load_image(p_char, p_emote, "(a)"); - play(); + play_once = false; + load_image(p_char, p_emote, "(a)"); + play(); } void AOCharMovie::play_frame_effect(int frame) { - if (frame < max_frames) { - foreach (QString effect, movie_effects[frame]) { - if (effect == "shake") { - shake(); + if (frame < max_frames) { + foreach (QString effect, movie_effects[frame]) { + if (effect == "shake") { + shake(); #ifdef DEBUG_CHARMOVIE - qDebug() << "Attempting to play shake on frame" << frame; + qDebug() << "Attempting to play shake on frame" << frame; #endif - } + } - if (effect == "flash") { - flash(); + if (effect == "flash") { + flash(); #ifdef DEBUG_CHARMOVIE - qDebug() << "Attempting to play flash on frame" << frame; + qDebug() << "Attempting to play flash on frame" << frame; #endif - } + } - if (effect.startsWith("sfx^")) { - QString sfx = effect.section("^", 1); - play_sfx(sfx); + if (effect.startsWith("sfx^")) { + QString sfx = effect.section("^", 1); + play_sfx(sfx); #ifdef DEBUG_CHARMOVIE - qDebug() << "Attempting to play sfx" << sfx << "on frame" << frame; + qDebug() << "Attempting to play sfx" << sfx << "on frame" << frame; #endif - } - } + } } + } } void AOCharMovie::stop() { - //for all intents and purposes, stopping is the same as hiding. at no point do we want a frozen gif to display - ticker->stop(); - preanim_timer->stop(); - this->hide(); + // for all intents and purposes, stopping is the same as hiding. at no point + // do we want a frozen gif to display + ticker->stop(); + preanim_timer->stop(); + this->hide(); } QPixmap AOCharMovie::get_pixmap(QImage image) { - QPixmap f_pixmap; - if (m_flipped) - f_pixmap = QPixmap::fromImage(image.mirrored(true, false)); - else - f_pixmap = QPixmap::fromImage(image); - // auto aspect_ratio = Qt::KeepAspectRatio; - auto transform_mode = Qt::FastTransformation; - if (f_pixmap.height() > f_h) //We are downscaling, use anti-aliasing. - transform_mode = Qt::SmoothTransformation; - - f_pixmap = f_pixmap.scaledToHeight(f_h, transform_mode); - this->resize(f_pixmap.size()); - - return f_pixmap; + QPixmap f_pixmap; + if (m_flipped) + f_pixmap = QPixmap::fromImage(image.mirrored(true, false)); + else + f_pixmap = QPixmap::fromImage(image); + // auto aspect_ratio = Qt::KeepAspectRatio; + auto transform_mode = Qt::FastTransformation; + if (f_pixmap.height() > f_h) // We are downscaling, use anti-aliasing. + transform_mode = Qt::SmoothTransformation; + + f_pixmap = f_pixmap.scaledToHeight(f_h, transform_mode); + this->resize(f_pixmap.size()); + + return f_pixmap; } void AOCharMovie::set_frame(QPixmap f_pixmap) { - this->setPixmap(f_pixmap); - QLabel::move(x + (f_w - f_pixmap.width()) / 2, y + (f_h - f_pixmap.height())); //Always center horizontally, always put at the bottom vertically + this->setPixmap(f_pixmap); + QLabel::move( + x + (f_w - f_pixmap.width()) / 2, + y + (f_h - f_pixmap.height())); // Always center horizontally, always put + // at the bottom vertically } void AOCharMovie::combo_resize(int w, int h) { - QSize f_size(w, h); - f_w = w; - f_h = h; - this->resize(f_size); + QSize f_size(w, h); + f_w = w; + f_h = h; + this->resize(f_size); } int AOCharMovie::get_frame_delay(int delay) { - return static_cast(double(delay) * double(speed / 100)); + return static_cast(double(delay) * double(speed / 100)); } void AOCharMovie::move(int ax, int ay) { - x = ax; - y = ay; - QLabel::move(x, y); + x = ax; + y = ay; + QLabel::move(x, y); } void AOCharMovie::movie_ticker() { - ++frame; - if (frame >= max_frames) { - if (play_once) { - preanim_done(); - 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(); + ++frame; + if (frame >= max_frames) { + if (play_once) { + preanim_done(); + 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(); + qDebug() << frame << movie_delays[frame] + << "actual time taken from last frame:" << actual_time.restart(); #endif - this->set_frame(movie_frames[frame]); - play_frame_effect(frame); - ticker->setInterval(this->get_frame_delay(movie_delays[frame])); + this->set_frame(movie_frames[frame]); + play_frame_effect(frame); + ticker->setInterval(this->get_frame_delay(movie_delays[frame])); } void AOCharMovie::preanim_done() { - ticker->stop(); - preanim_timer->stop(); - done(); + ticker->stop(); + preanim_timer->stop(); + done(); } -- cgit