From adb54370497dd9cfab48bcd3803774a6d837afc5 Mon Sep 17 00:00:00 2001 From: in1tiate Date: Mon, 18 Jul 2022 05:46:42 -0500 Subject: [PATCH 01/11] Major cleanup of screenshake code --- include/courtroom.h | 1 + src/courtroom.cpp | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/include/courtroom.h b/include/courtroom.h index deabb4601..4d18ab48c 100644 --- a/include/courtroom.h +++ b/include/courtroom.h @@ -51,6 +51,7 @@ #include #include #include +#include #include #include #include diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 563c5cc1f..faceaf05e 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -2609,33 +2609,33 @@ void Courtroom::do_screenshake() // This way, the animation is reset in such a way that last played screenshake // would return to its "final frame" properly. This properly resets all UI // elements without having to bother keeping track of "origin" positions. - // Works great wit the chat text being detached from the chat box! + // Works great with the chat text being detached from the chat box! screenshake_animation_group->setCurrentTime( screenshake_animation_group->duration()); screenshake_animation_group->clear(); - QList affected_list = {ui_vp_background, ui_vp_player_char, + const QList &affected_list = {ui_vp_background, ui_vp_player_char, ui_vp_sideplayer_char, ui_vp_chatbox}; // I would prefer if this was its own "shake" function to be honest. - foreach (QWidget *ui_element, affected_list) { + for (QWidget *ui_element : affected_list) { QPropertyAnimation *screenshake_animation = new QPropertyAnimation(ui_element, "pos", this); QPoint pos_default = QPoint(ui_element->x(), ui_element->y()); int duration = 300; // How long does the screenshake last int frequency = 20; // How often in ms is there a "jolt" frame - int maxframes = duration / frequency; - int max_x = 7; // Max deviation from origin on x axis - int max_y = 7; // Max deviation from origin on y axis + // Maximum deviation from the origin position. This is 7 pixels for a 256x192 viewport, + // so we scale that value in accordance with the current viewport height so the shake + // is roughly the same intensity regardless of viewport size. Done as a float operation for maximum accuracy. + int max_deviation = 7 * (float(ui_viewport->height()) / 192); + int maxframes = 15; // duration / frequency; screenshake_animation->setDuration(duration); for (int frame = 0; frame < maxframes; frame++) { double fraction = double(frame * frequency) / duration; - int rng = qrand(); // QRandomGenerator::global()->generate(); - int rand_x = max_x - (int(rng) % (max_x * 2)); - int rand_y = max_y - (int(rng + 100) % (max_y * 2)); - screenshake_animation->setKeyValueAt( - fraction, QPoint(pos_default.x() + rand_x, pos_default.y() + rand_y)); + int rand_x = QRandomGenerator::system()->bounded(-max_deviation, max_deviation); + int rand_y = QRandomGenerator::system()->bounded(-max_deviation, max_deviation); + screenshake_animation->setKeyValueAt(fraction, QPoint(pos_default.x() + rand_x, pos_default.y() + rand_y)); } screenshake_animation->setEndValue(pos_default); screenshake_animation->setEasingCurve(QEasingCurve::Linear); From c306a259ab213a3584322c0b17d3271484f78757 Mon Sep 17 00:00:00 2001 From: in1tiate Date: Mon, 18 Jul 2022 06:58:59 -0500 Subject: [PATCH 02/11] Add pre-5.10 support for screenshake math --- src/courtroom.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/courtroom.cpp b/src/courtroom.cpp index faceaf05e..cbb2dec90 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -2633,8 +2633,14 @@ void Courtroom::do_screenshake() screenshake_animation->setDuration(duration); for (int frame = 0; frame < maxframes; frame++) { double fraction = double(frame * frequency) / duration; +#if QT_VERSION > QT_VERSION_CHECK(5, 10, 0) int rand_x = QRandomGenerator::system()->bounded(-max_deviation, max_deviation); int rand_y = QRandomGenerator::system()->bounded(-max_deviation, max_deviation); +#else + // Ugly pre-5.10 STLpilled way of getting random negative numbers, for older distributions + int rand_x = (qrand() % (max_deviation * 2)) - max_deviation; + int rand_y = (qrand() % (max_deviation * 2)) - max_deviation; +#endif screenshake_animation->setKeyValueAt(fraction, QPoint(pos_default.x() + rand_x, pos_default.y() + rand_y)); } screenshake_animation->setEndValue(pos_default); From 0e78b2bf01e80f7db1092e22001f494696b504a7 Mon Sep 17 00:00:00 2001 From: in1tiate Date: Mon, 18 Jul 2022 07:18:34 -0500 Subject: [PATCH 03/11] more compat, uglier too --- include/courtroom.h | 4 +++- src/courtroom.cpp | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/courtroom.h b/include/courtroom.h index 4d18ab48c..22757841d 100644 --- a/include/courtroom.h +++ b/include/courtroom.h @@ -51,7 +51,9 @@ #include #include #include -#include +#if QT_VERSION > QT_VERSION_CHECK(5, 10, 0) +#include //added in Qt 5.10 +#endif #include #include #include diff --git a/src/courtroom.cpp b/src/courtroom.cpp index cbb2dec90..f67ab752e 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -2638,8 +2638,9 @@ void Courtroom::do_screenshake() int rand_y = QRandomGenerator::system()->bounded(-max_deviation, max_deviation); #else // Ugly pre-5.10 STLpilled way of getting random negative numbers, for older distributions - int rand_x = (qrand() % (max_deviation * 2)) - max_deviation; - int rand_y = (qrand() % (max_deviation * 2)) - max_deviation; + int range = (max_deviation) - (-max_deviation) + 1; + int rand_x = -max_deviation+int(range*qrand()/(RAND_MAX+1.0)); + int rand_y = -max_deviation+int(range*qrand()/(RAND_MAX+1.0)); #endif screenshake_animation->setKeyValueAt(fraction, QPoint(pos_default.x() + rand_x, pos_default.y() + rand_y)); } From ea4e9c94080d3ef6e229ba5e58dc0992026a764d Mon Sep 17 00:00:00 2001 From: in1tiate Date: Mon, 18 Jul 2022 07:40:27 -0500 Subject: [PATCH 04/11] add surprise tool --- src/courtroom.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/courtroom.cpp b/src/courtroom.cpp index f67ab752e..14877aa92 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -2601,6 +2601,11 @@ void Courtroom::handle_ic_message() } } +#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0) +// It's a surprise tool that will help us later. +inline double NegRand() { return 2*(qrand()/(float)RAND_MAX)-1; } // Returns random double between -1 and 1 +#endif + void Courtroom::do_screenshake() { if (!ao_app->is_shake_enabled()) @@ -2633,14 +2638,12 @@ void Courtroom::do_screenshake() screenshake_animation->setDuration(duration); for (int frame = 0; frame < maxframes; frame++) { double fraction = double(frame * frequency) / duration; -#if QT_VERSION > QT_VERSION_CHECK(5, 10, 0) +#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0) + int rand_x = max_deviation*NegRand() + 1; + int rand_y = max_deviation*NegRand() + 1; +#else int rand_x = QRandomGenerator::system()->bounded(-max_deviation, max_deviation); int rand_y = QRandomGenerator::system()->bounded(-max_deviation, max_deviation); -#else - // Ugly pre-5.10 STLpilled way of getting random negative numbers, for older distributions - int range = (max_deviation) - (-max_deviation) + 1; - int rand_x = -max_deviation+int(range*qrand()/(RAND_MAX+1.0)); - int rand_y = -max_deviation+int(range*qrand()/(RAND_MAX+1.0)); #endif screenshake_animation->setKeyValueAt(fraction, QPoint(pos_default.x() + rand_x, pos_default.y() + rand_y)); } From cbee9cd1d275ce49368846e4503d7d54e3bb7a5a Mon Sep 17 00:00:00 2001 From: in1tiate Date: Tue, 19 Jul 2022 05:34:25 -0500 Subject: [PATCH 05/11] we don't need inline functions --- src/courtroom.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 14877aa92..79d5028fd 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -2601,11 +2601,6 @@ void Courtroom::handle_ic_message() } } -#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0) -// It's a surprise tool that will help us later. -inline double NegRand() { return 2*(qrand()/(float)RAND_MAX)-1; } // Returns random double between -1 and 1 -#endif - void Courtroom::do_screenshake() { if (!ao_app->is_shake_enabled()) @@ -2639,8 +2634,8 @@ void Courtroom::do_screenshake() for (int frame = 0; frame < maxframes; frame++) { double fraction = double(frame * frequency) / duration; #if QT_VERSION < QT_VERSION_CHECK(5, 10, 0) - int rand_x = max_deviation*NegRand() + 1; - int rand_y = max_deviation*NegRand() + 1; + int rand_x = max_deviation * (2 * (qrand() / (float)RAND_MAX) - 1) + 1; + int rand_y = max_deviation * (2 * (qrand() / (float)RAND_MAX) - 1) + 1; #else int rand_x = QRandomGenerator::system()->bounded(-max_deviation, max_deviation); int rand_y = QRandomGenerator::system()->bounded(-max_deviation, max_deviation); From e673c06e2de41b688a1587137cc39e023f4a7ddf Mon Sep 17 00:00:00 2001 From: in1tiate Date: Tue, 19 Jul 2022 05:35:50 -0500 Subject: [PATCH 06/11] only run qsrand on old versions --- src/courtroom.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 79d5028fd..16274fe32 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -8,8 +8,9 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ~Qt::WindowMaximizeButtonHint); ao_app->initBASS(); - +#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0) // Needed for pre-5.10 RNG stuff qsrand(static_cast(QDateTime::currentMSecsSinceEpoch() / 1000)); +#endif keepalive_timer = new QTimer(this); keepalive_timer->start(45000); From c1ca74d6241f2ae75d50f8ce0e4140a8325f6b9b Mon Sep 17 00:00:00 2001 From: in1tiate Date: Tue, 19 Jul 2022 05:48:04 -0500 Subject: [PATCH 07/11] Squash compiler warnings --- src/courtroom.cpp | 9 +++++++++ src/demoserver.cpp | 4 ++++ src/discord_rich_presence.cpp | 3 +++ src/networkmanager.cpp | 5 ++++- 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 16274fe32..fdd23a1f7 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -4080,6 +4080,11 @@ void Courtroom::mod_called(QString p_ip) void Courtroom::case_called(QString msg, bool def, bool pro, bool jud, bool jur, bool steno) { + Q_UNUSED(def); + Q_UNUSED(pro); + Q_UNUSED(jud); + Q_UNUSED(jur); + Q_UNUSED(steno); if (ui_casing->isChecked()) { ui_server_chatlog->append(msg); modcall_player->play(ao_app->get_court_sfx("case_call")); @@ -4891,7 +4896,11 @@ void Courtroom::music_random() } if (clist.length() == 0) return; +#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0) on_music_list_double_clicked(clist.at(qrand() % clist.length()), 1); +#else + on_music_list_double_clicked(clist.at(QRandomGenerator::global()->bounded(0, clist.length())), 1); +#endif } void Courtroom::music_list_expand_all() { ui_music_list->expandAll(); } diff --git a/src/demoserver.cpp b/src/demoserver.cpp index c4f8c1582..0aefc0cc5 100644 --- a/src/demoserver.cpp +++ b/src/demoserver.cpp @@ -95,7 +95,11 @@ void DemoServer::recv_data() } QStringList packet_list = +#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) in_data.split("%", QString::SplitBehavior(QString::SkipEmptyParts)); +#else + in_data.split("%", Qt::SkipEmptyParts); +#endif for (const QString &packet : packet_list) { AOPacket ao_packet(packet); diff --git a/src/discord_rich_presence.cpp b/src/discord_rich_presence.cpp index cd3a475aa..81e5a86c2 100644 --- a/src/discord_rich_presence.cpp +++ b/src/discord_rich_presence.cpp @@ -106,11 +106,14 @@ void Discord::state_lobby() {} void Discord::state_server(std::string name, std::string server_id) { + Q_UNUSED(name); + Q_UNUSED(server_id); qDebug() << "Discord RPC: Setting server state"; } void Discord::state_character(std::string name) { + Q_UNUSED(name); qDebug() << "Discord RPC: Setting character state"; } diff --git a/src/networkmanager.cpp b/src/networkmanager.cpp index 7e039d21e..27b3e01ae 100644 --- a/src/networkmanager.cpp +++ b/src/networkmanager.cpp @@ -240,8 +240,11 @@ void NetworkManager::handle_server_packet(const QString& p_data) partial_packet = false; } } - +#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) const QStringList packet_list = in_data.split("%", QString::SkipEmptyParts); +#else + const QStringList packet_list = in_data.split("%", Qt::SkipEmptyParts); +#endif for (const QString &packet : packet_list) { AOPacket *f_packet = new AOPacket(packet); From 2455a0b404ee85ab168d26ae5844be0fdb25a8eb Mon Sep 17 00:00:00 2001 From: in1tiate Date: Tue, 19 Jul 2022 05:52:22 -0500 Subject: [PATCH 08/11] >= not > please --- include/courtroom.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/courtroom.h b/include/courtroom.h index 22757841d..3b4e02fea 100644 --- a/include/courtroom.h +++ b/include/courtroom.h @@ -51,7 +51,7 @@ #include #include #include -#if QT_VERSION > QT_VERSION_CHECK(5, 10, 0) +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) #include //added in Qt 5.10 #endif #include From f27820370d52cd7a452937f226e0625e175d207e Mon Sep 17 00:00:00 2001 From: in1tiate Date: Tue, 19 Jul 2022 05:35:50 -0500 Subject: [PATCH 09/11] only run qsrand on old versions --- src/courtroom.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 1884c7c81..ae104ddb9 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -8,8 +8,9 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ~Qt::WindowMaximizeButtonHint); ao_app->initBASS(); - +#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0) // Needed for pre-5.10 RNG stuff qsrand(static_cast(QDateTime::currentMSecsSinceEpoch() / 1000)); +#endif keepalive_timer = new QTimer(this); keepalive_timer->start(45000); From 0b0feddde9829ebbe495359c0a3c9752aba03629 Mon Sep 17 00:00:00 2001 From: in1tiate Date: Tue, 19 Jul 2022 05:48:04 -0500 Subject: [PATCH 10/11] Squash compiler warnings --- src/courtroom.cpp | 9 +++++++++ src/demoserver.cpp | 4 ++++ src/discord_rich_presence.cpp | 3 +++ src/networkmanager.cpp | 5 ++++- 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/courtroom.cpp b/src/courtroom.cpp index ae104ddb9..c8d58257d 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -4143,6 +4143,11 @@ void Courtroom::mod_called(QString p_ip) void Courtroom::case_called(QString msg, bool def, bool pro, bool jud, bool jur, bool steno) { + Q_UNUSED(def); + Q_UNUSED(pro); + Q_UNUSED(jud); + Q_UNUSED(jur); + Q_UNUSED(steno); if (ui_casing->isChecked()) { ui_server_chatlog->append(msg); modcall_player->play(ao_app->get_court_sfx("case_call")); @@ -4962,7 +4967,11 @@ void Courtroom::music_random() } if (clist.length() == 0) return; +#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0) on_music_list_double_clicked(clist.at(qrand() % clist.length()), 1); +#else + on_music_list_double_clicked(clist.at(QRandomGenerator::global()->bounded(0, clist.length())), 1); +#endif } void Courtroom::music_list_expand_all() { ui_music_list->expandAll(); } diff --git a/src/demoserver.cpp b/src/demoserver.cpp index c4f8c1582..0aefc0cc5 100644 --- a/src/demoserver.cpp +++ b/src/demoserver.cpp @@ -95,7 +95,11 @@ void DemoServer::recv_data() } QStringList packet_list = +#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) in_data.split("%", QString::SplitBehavior(QString::SkipEmptyParts)); +#else + in_data.split("%", Qt::SkipEmptyParts); +#endif for (const QString &packet : packet_list) { AOPacket ao_packet(packet); diff --git a/src/discord_rich_presence.cpp b/src/discord_rich_presence.cpp index cd3a475aa..81e5a86c2 100644 --- a/src/discord_rich_presence.cpp +++ b/src/discord_rich_presence.cpp @@ -106,11 +106,14 @@ void Discord::state_lobby() {} void Discord::state_server(std::string name, std::string server_id) { + Q_UNUSED(name); + Q_UNUSED(server_id); qDebug() << "Discord RPC: Setting server state"; } void Discord::state_character(std::string name) { + Q_UNUSED(name); qDebug() << "Discord RPC: Setting character state"; } diff --git a/src/networkmanager.cpp b/src/networkmanager.cpp index 7e039d21e..27b3e01ae 100644 --- a/src/networkmanager.cpp +++ b/src/networkmanager.cpp @@ -240,8 +240,11 @@ void NetworkManager::handle_server_packet(const QString& p_data) partial_packet = false; } } - +#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) const QStringList packet_list = in_data.split("%", QString::SkipEmptyParts); +#else + const QStringList packet_list = in_data.split("%", Qt::SkipEmptyParts); +#endif for (const QString &packet : packet_list) { AOPacket *f_packet = new AOPacket(packet); From b46f8c97aa88595395c1637b90f372db1c240586 Mon Sep 17 00:00:00 2001 From: in1tiate Date: Tue, 19 Jul 2022 05:52:22 -0500 Subject: [PATCH 11/11] >= not > please --- include/courtroom.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/courtroom.h b/include/courtroom.h index 0c53c959f..cc52f930d 100644 --- a/include/courtroom.h +++ b/include/courtroom.h @@ -52,7 +52,7 @@ #include #include #include -#if QT_VERSION > QT_VERSION_CHECK(5, 10, 0) +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) #include //added in Qt 5.10 #endif #include