aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriamgoofball <iamgoofball@gmail.com>2019-01-23 00:14:47 -0800
committeriamgoofball <iamgoofball@gmail.com>2019-01-23 00:14:47 -0800
commit13bc82094f76011eef371ece3b3894d7cc20eaf9 (patch)
treec5ea7960e853364993e6c2a430a7a46c95eec9a1
parenta7a614482e379ad13f8e0ca1e7f3e31c33bb1c21 (diff)
>>>>multi-threading the frame sfx/screenshake/flashes
-rw-r--r--include/aoapplication.h5
-rw-r--r--include/courtroom.h24
-rw-r--r--src/courtroom.cpp178
3 files changed, 143 insertions, 64 deletions
diff --git a/include/aoapplication.h b/include/aoapplication.h
index 7a5e633..22c6c23 100644
--- a/include/aoapplication.h
+++ b/include/aoapplication.h
@@ -23,6 +23,11 @@
#include <QStringList>
#include <QColor>
+#include <QtConcurrent/QtConcurrent>
+#include <QThread>
+#include <QThreadPool>
+#include <QFuture>
+
class NetworkManager;
class Lobby;
class Courtroom;
diff --git a/include/courtroom.h b/include/courtroom.h
index b746c6a..1c739b8 100644
--- a/include/courtroom.h
+++ b/include/courtroom.h
@@ -40,7 +40,7 @@
#include <QMap>
#include <QTextBrowser>
#include <QSpinBox>
-
+#include <QMovie>
#include <QDebug>
#include <QScrollBar>
#include <QRegExp>
@@ -53,7 +53,11 @@
#include <QPropertyAnimation>
#include <QTransform>
#include <QParallelAnimationGroup>
-
+#include <QtConcurrent/QtConcurrent>
+#include <QtConcurrent/QtConcurrentRun>
+#include <QThread>
+#include <QThreadPool>
+#include <QFuture>
#include <stack>
class AOApplication;
@@ -69,6 +73,16 @@ public:
void append_music(QString f_music){music_list.append(f_music);}
void append_area(QString f_area){area_list.append(f_area);}
void handle_failed_login();
+ QString threading_sfx = "";
+ QString threading_shake = "";
+ QString threading_flash = "";
+ QString threading_prefix = "";
+ //cid and this may differ in cases of ini-editing
+ QString current_char = "";
+ int current_emote = 0;
+ AOApplication *ao_app;
+ void mt_pre_framegetter(int frameNumber);
+ void mt_framegetter(int frameNumber);
void reset_music_list()
{
music_list.clear();
@@ -216,7 +230,6 @@ public:
~Courtroom();
private:
- AOApplication *ao_app;
int m_courtroom_width = 714;
int m_courtroom_height = 668;
@@ -232,7 +245,7 @@ private:
QPropertyAnimation *screenshake_animation;
QPropertyAnimation *chatbox_screenshake_animation;
QParallelAnimationGroup *screenshake_group;
- QImageReader *frame_emote_checker;
+ QMovie *frame_emote_checker;
// This is for inline message-colouring.
enum INLINE_COLOURS {
@@ -352,8 +365,6 @@ private:
//character id, which index of the char_list the player is
int m_cid = -1;
- //cid and this may differ in cases of ini-editing
- QString current_char = "";
int objection_state = 0;
int realization_state = 0;
@@ -373,7 +384,6 @@ private:
const int button_height = 60;
int current_emote_page = 0;
- int current_emote = 0;
int emote_columns = 5;
int emote_rows = 2;
int max_emotes_on_page = 10;
diff --git a/src/courtroom.cpp b/src/courtroom.cpp
index 537558f..19caa8d 100644
--- a/src/courtroom.cpp
+++ b/src/courtroom.cpp
@@ -1095,6 +1095,66 @@ void Courtroom::append_server_chatmessage(QString p_name, QString p_message, QSt
ui_server_chatlog->append_chatmessage(p_name, p_message, colour);
}
+class AOFrameThreadingBullshitPre : public QRunnable
+{
+public:
+ Courtroom *mycourt_fuck;
+ int my_frameNumber;
+ AOFrameThreadingBullshitPre(Courtroom *my_courtroom, int frameNumber){
+ mycourt_fuck = my_courtroom;
+ my_frameNumber = frameNumber;
+ }
+ void run()
+ {
+ qDebug() << my_frameNumber << " FRAME NUMBER" << " from" << QThread::currentThread();
+ QString sfx_to_play = mycourt_fuck->ao_app->get_frame_sfx_name(mycourt_fuck->current_char, mycourt_fuck->ao_app->get_pre_emote(mycourt_fuck->current_char, mycourt_fuck->current_emote), my_frameNumber);
+ QString screenshake_to_play = mycourt_fuck->ao_app->get_screenshake_frame(mycourt_fuck->current_char, mycourt_fuck->ao_app->get_pre_emote(mycourt_fuck->current_char, mycourt_fuck->current_emote), my_frameNumber);
+ QString realization_to_play = mycourt_fuck->ao_app->get_realization_frame(mycourt_fuck->current_char, mycourt_fuck->ao_app->get_pre_emote(mycourt_fuck->current_char, mycourt_fuck->current_emote), my_frameNumber);
+ if(sfx_to_play != "")
+ {
+ mycourt_fuck->threading_sfx += "|" + QString::number(my_frameNumber) + "=" + sfx_to_play;
+ }
+ if(screenshake_to_play != "")
+ {
+ mycourt_fuck->threading_shake += "|" + QString::number(my_frameNumber) + "=" + screenshake_to_play;
+ }
+ if(realization_to_play != "")
+ {
+ mycourt_fuck->threading_flash += "|" + QString::number(my_frameNumber) + "=" + realization_to_play;
+ }
+ }
+};
+
+
+class AOFrameThreadingBullshit : public QRunnable
+{
+public:
+ Courtroom *mycourt_fuck;
+ int my_frameNumber;
+ AOFrameThreadingBullshit(Courtroom *my_courtroom, int frameNumber){
+ mycourt_fuck = my_courtroom;
+ my_frameNumber = frameNumber;
+ }
+ void run()
+ {
+ QString sfx_to_play = mycourt_fuck->ao_app->get_frame_sfx_name(mycourt_fuck->current_char, mycourt_fuck->threading_prefix + mycourt_fuck->ao_app->get_emote(mycourt_fuck->current_char, mycourt_fuck->current_emote), my_frameNumber);
+ QString screenshake_to_play = mycourt_fuck->ao_app->get_screenshake_frame(mycourt_fuck->current_char, mycourt_fuck->threading_prefix + mycourt_fuck->ao_app->get_emote(mycourt_fuck->current_char, mycourt_fuck->current_emote), my_frameNumber);
+ QString realization_to_play = mycourt_fuck->ao_app->get_realization_frame(mycourt_fuck->current_char, mycourt_fuck->threading_prefix + mycourt_fuck->ao_app->get_emote(mycourt_fuck->current_char, mycourt_fuck->current_emote), my_frameNumber);
+ if(sfx_to_play != "")
+ {
+ mycourt_fuck->threading_sfx += "|" + QString::number(my_frameNumber) + "=" + sfx_to_play;
+ }
+ if(screenshake_to_play != "")
+ {
+ mycourt_fuck->threading_shake += "|" + QString::number(my_frameNumber) + "=" + screenshake_to_play;
+ }
+ if(realization_to_play != "")
+ {
+ mycourt_fuck->threading_flash += "|" + QString::number(my_frameNumber) + "=" + realization_to_play;
+ }
+ }
+};
+
void Courtroom::on_chat_return_pressed()
{
if (ui_ic_chat_message->text() == "" || is_muted)
@@ -1275,7 +1335,7 @@ void Courtroom::on_chat_return_pressed()
qDebug() << "Are we looping this? " << ao_app->get_sfx_looping(current_char, current_emote);
packet_contents.append(QString::number(screenshake_state));
qDebug() << "Are we screen shaking this one? " << screenshake_state;
-
+ qDebug() << "MAX THREAD COUNT " << QThreadPool::globalInstance()->maxThreadCount();
QString frame_screenshake = "";
QString frame_realization = "";
QString frame_sfx = "";
@@ -1295,77 +1355,86 @@ void Courtroom::on_chat_return_pressed()
QString preemote = ao_app->get_image_suffix(ao_app->get_character_path(current_char, ao_app->get_pre_emote(current_char, current_emote)));
QString talkemote_to_check = ao_app->get_image_suffix(ao_app->get_character_path(current_char, "(b)" + ao_app->get_emote(current_char, current_emote)));
QString idleemote_to_check = ao_app->get_image_suffix(ao_app->get_character_path(current_char, "(a)" + ao_app->get_emote(current_char, current_emote)));
- frame_emote_checker = new QImageReader(preemote);
+
+ frame_emote_checker = new QMovie(this);
+ frame_emote_checker->setFileName(preemote);
+ frame_emote_checker->jumpToFrame(0);
+ qDebug() << "Premote fuck: " << frame_emote_checker->frameCount();
+
preemote_sfx += ao_app->get_pre_emote(current_char, current_emote);
preemote_shake += ao_app->get_pre_emote(current_char, current_emote);
preemote_flash += ao_app->get_pre_emote(current_char, current_emote);
- for (int i = 0; i < frame_emote_checker->imageCount(); i++) {
- QString sfx_to_play = ao_app->get_frame_sfx_name(current_char, ao_app->get_pre_emote(current_char, current_emote), i);
- QString screenshake_to_play = ao_app->get_screenshake_frame(current_char, ao_app->get_pre_emote(current_char, current_emote), i);
- QString realization_to_play = ao_app->get_realization_frame(current_char, ao_app->get_pre_emote(current_char, current_emote), i);
- if(sfx_to_play != "")
- {
- preemote_sfx += "|" + QString::number(i) + "=" + sfx_to_play;
- }
- if(screenshake_to_play != "")
- {
- preemote_shake += "|" + QString::number(i) + "=" + screenshake_to_play;
- }
- if(realization_to_play != "")
- {
- preemote_flash += "|" + QString::number(i) + "=" + realization_to_play;
- }
+
+ threading_sfx = preemote_sfx;
+ threading_shake = preemote_shake;
+ threading_flash = preemote_flash;
+
+ for(int i=0; i < frame_emote_checker->frameCount(); i++){
+ AOFrameThreadingBullshitPre *testfuck = new AOFrameThreadingBullshitPre(this, i);
+ QThreadPool::globalInstance()->start(testfuck);
}
+ QThreadPool::globalInstance()->waitForDone();
+ preemote_sfx = threading_sfx;
+ preemote_shake = threading_shake;
+ preemote_flash = threading_flash;
preemote_sfx += "^";
preemote_shake += "^";
preemote_flash += "^";
delete frame_emote_checker;
+
+
+
talkemote_sfx += "(b)" + ao_app->get_emote(current_char, current_emote);
talkemote_shake += "(b)" + ao_app->get_emote(current_char, current_emote);
talkemote_flash += "(b)" + ao_app->get_emote(current_char, current_emote);
- frame_emote_checker = new QImageReader(talkemote_to_check);
- for (int i = 0; i < frame_emote_checker->imageCount(); i++) {
- QString sfx_to_play = ao_app->get_frame_sfx_name(current_char, "(b)" + ao_app->get_emote(current_char, current_emote), i);
- QString screenshake_to_play = ao_app->get_screenshake_frame(current_char, "(b)" + ao_app->get_emote(current_char, current_emote), i);
- QString realization_to_play = ao_app->get_realization_frame(current_char, "(b)" + ao_app->get_emote(current_char, current_emote), i);
- if(sfx_to_play != "")
- {
- talkemote_sfx += "|" + QString::number(i) + "=" + sfx_to_play;
- }
- if(screenshake_to_play != "")
- {
- talkemote_shake += "|" + QString::number(i) + "=" + screenshake_to_play;
- }
- if(realization_to_play != "")
- {
- talkemote_flash += "|" + QString::number(i) + "=" + realization_to_play;
- }
+
+ frame_emote_checker = new QMovie(this);
+ frame_emote_checker->setFileName(talkemote_to_check);
+ frame_emote_checker->jumpToFrame(0);
+ qDebug() << "TALK fuck: " << frame_emote_checker->frameCount();
+
+ threading_sfx = talkemote_sfx;
+ threading_shake = talkemote_shake;
+ threading_flash = talkemote_flash;
+ threading_prefix = QString("(b)");
+
+ for(int i=0; i < frame_emote_checker->frameCount(); i++){
+ AOFrameThreadingBullshit *testfuck = new AOFrameThreadingBullshit(this, i);
+ QThreadPool::globalInstance()->start(testfuck);
}
+ QThreadPool::globalInstance()->waitForDone();
+
+ talkemote_sfx = threading_sfx;
+ talkemote_shake = threading_shake;
+ talkemote_flash = threading_flash;
talkemote_sfx += "^";
talkemote_shake += "^";
talkemote_flash += "^";
delete frame_emote_checker;
+
+
+
idleemote_sfx += "(a)" + ao_app->get_emote(current_char, current_emote);
idleemote_shake += "(a)" + ao_app->get_emote(current_char, current_emote);
idleemote_flash += "(a)" + ao_app->get_emote(current_char, current_emote);
- frame_emote_checker = new QImageReader(idleemote_to_check);
- for (int i = 0; i < frame_emote_checker->imageCount(); i++) {
- QString sfx_to_play = ao_app->get_frame_sfx_name(current_char, "(a)" + ao_app->get_emote(current_char, current_emote), i);
- QString screenshake_to_play = ao_app->get_screenshake_frame(current_char, "(a)" + ao_app->get_emote(current_char, current_emote), i);
- QString realization_to_play = ao_app->get_realization_frame(current_char, "(a)" + ao_app->get_emote(current_char, current_emote), i);
- if(sfx_to_play != "")
- {
- idleemote_sfx += "|" + QString::number(i) + "=" + sfx_to_play;
- }
- if(screenshake_to_play != "")
- {
- idleemote_shake += "|" + QString::number(i) + "=" + screenshake_to_play;
- }
- if(realization_to_play != "")
- {
- idleemote_flash += "|" + QString::number(i) + "=" + realization_to_play;
- }
+
+ frame_emote_checker = new QMovie(this);
+ frame_emote_checker->setFileName(idleemote_to_check);
+ frame_emote_checker->jumpToFrame(0);
+ qDebug() << "idle fuck: " << frame_emote_checker->frameCount();
+
+ threading_sfx = idleemote_sfx;
+ threading_shake = idleemote_shake;
+ threading_flash = idleemote_flash;
+ threading_prefix = QString("(a)");
+ for(int i=0; i < frame_emote_checker->frameCount(); i++){
+ AOFrameThreadingBullshit *testfuck = new AOFrameThreadingBullshit(this, i);
+ QThreadPool::globalInstance()->start(testfuck);
}
+ QThreadPool::globalInstance()->waitForDone();
+ idleemote_sfx = threading_sfx;
+ idleemote_shake = threading_shake;
+ idleemote_flash = threading_flash;
delete frame_emote_checker;
frame_screenshake += preemote_shake;
@@ -1379,10 +1448,6 @@ void Courtroom::on_chat_return_pressed()
frame_sfx += preemote_sfx;
frame_sfx += talkemote_sfx;
frame_sfx += idleemote_sfx;
- qDebug() << "Final strings:";
- qDebug() << frame_screenshake;
- qDebug() << frame_realization;
- qDebug() << frame_sfx;
packet_contents.append(frame_screenshake);
packet_contents.append(frame_realization);
@@ -1390,7 +1455,6 @@ void Courtroom::on_chat_return_pressed()
}
ao_app->send_server_packet(new AOPacket("MS", packet_contents));
}
-
void Courtroom::handle_chatmessage(QStringList *p_contents)
{
// Instead of checking for whether a message has at least chatmessage_size