diff options
| -rw-r--r-- | .github/labeler.yml | 8 | ||||
| -rw-r--r-- | .github/workflows/clang-tidy-review.yml | 70 | ||||
| -rw-r--r-- | Attorney_Online.pro | 2 | ||||
| -rw-r--r-- | include/aoapplication.h | 4 | ||||
| -rw-r--r-- | include/chatlogpiece.h | 20 | ||||
| -rw-r--r-- | include/courtroom.h | 5 | ||||
| -rw-r--r-- | include/datatypes.h | 7 | ||||
| -rw-r--r-- | include/demoserver.h | 1 | ||||
| -rw-r--r-- | include/networkmanager.h | 2 | ||||
| -rw-r--r-- | src/aooptionsdialog.cpp | 4 | ||||
| -rw-r--r-- | src/charselect.cpp | 2 | ||||
| -rw-r--r-- | src/chatlogpiece.cpp | 20 | ||||
| -rw-r--r-- | src/courtroom.cpp | 139 | ||||
| -rw-r--r-- | src/demoserver.cpp | 60 | ||||
| -rw-r--r-- | src/packet_distribution.cpp | 36 | ||||
| -rw-r--r-- | src/text_file_functions.cpp | 4 |
16 files changed, 270 insertions, 114 deletions
diff --git a/.github/labeler.yml b/.github/labeler.yml deleted file mode 100644 index 56c4cc7..0000000 --- a/.github/labeler.yml +++ /dev/null @@ -1,8 +0,0 @@ -translation: - - resource/translations/* - -content: - - base/**/* - -good_luck: - - src/courtroom.cpp diff --git a/.github/workflows/clang-tidy-review.yml b/.github/workflows/clang-tidy-review.yml new file mode 100644 index 0000000..4701f6b --- /dev/null +++ b/.github/workflows/clang-tidy-review.yml @@ -0,0 +1,70 @@ +name: clang-tidy-review + +on: [pull_request] + +jobs: + compile: + name: ${{matrix.buildname}} + runs-on: ${{matrix.os}} + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-latest + buildname: 'clang-tidy' + triplet: x64-linux + compiler: clang_64 + qt: '5.15.2' + + steps: + - uses: actions/checkout@v2 + + - name: Restore Qt cache + uses: actions/cache@v2.1.7 + id: cache-qt + with: + path: ${{github.workspace}}/Qt/${{matrix.qt}} + key: ${{matrix.os}}-qt-${{matrix.qt}}-cache + + - name: Install Qt + uses: jurplel/install-qt-action@v2 + with: + version: ${{matrix.qt}} + dir: ${{github.workspace}} + cached: ${{steps.cache-qt.outputs.cache-hit}} + aqtversion: '==1.1.2' + + - name: Install Catch2 + shell: bash + run: | + curl -L https://github.com/catchorg/Catch2/archive/v2.13.4.tar.gz -o catch2.tar.gz + tar xvf catch2.tar.gz + cd Catch2-2.13.4 + cmake -Bbuild -H. -DBUILD_TESTING=OFF + sudo cmake --build build/ --target install + + - name: Use CMake 3.20.1 + uses: lukka/get-cmake@v3.20.1 + + - name: Generate compile_commands.json + uses: lukka/run-cmake@v3 + with: + cmakeListsOrSettingsJson: CMakeListsTxtAdvanced + cmakeListsTxtPath: '${{github.workspace}}/CMakeLists.txt' + buildDirectory: '${{github.workspace}}/build' + cmakeAppendedArgs: >- + -DCMAKE_GLOBAL_AUTOGEN_TARGET=ON + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + -DENABLE_CLAZY:BOOL=ON + buildWithCMakeArgs: >- + --target autogen + + - uses: ZedThree/clang-tidy-review@v0.8.2 + id: review + with: + build_dir: 'build' + clang_tidy_checks: '-*,performance-*,readability-*,bugprone-*,clang-analyzer-*,cppcoreguidelines-*,mpi-*,misc-*,-cppcoreguidelines-owning-memory,-cppcoreguidelines-pro-bounds-constant-array-index,-cppcoreguidelines-init-variables,-cppcoreguidelines-pro-type-member-init,-cppcoreguidelines-avoid-magic-numbers' + apt_packages: 'pkg-config,libzip-dev,libglu1-mesa-dev,libpulse-dev' + # If there are any comments, fail the check + - if: steps.review.outputs.total_comments > 0 + run: exit 1 diff --git a/Attorney_Online.pro b/Attorney_Online.pro index abca0fb..c21c7de 100644 --- a/Attorney_Online.pro +++ b/Attorney_Online.pro @@ -3,7 +3,7 @@ QT += core gui widgets network TARGET = Attorney_Online TEMPLATE = app -VERSION = 2.9.1.0 +VERSION = 2.10.0.0 INCLUDEPATH += $$PWD/include DESTDIR = $$PWD/bin diff --git a/include/aoapplication.h b/include/aoapplication.h index c094a33..ecd3180 100644 --- a/include/aoapplication.h +++ b/include/aoapplication.h @@ -553,8 +553,8 @@ public: private: const int RELEASE = 2; - const int MAJOR_VERSION = 9; - const int MINOR_VERSION = 1; + const int MAJOR_VERSION = 10; + const int MINOR_VERSION = 0; QVector<server_type> server_list; QVector<server_type> favorite_list; diff --git a/include/chatlogpiece.h b/include/chatlogpiece.h index da78d0d..df6ccd0 100644 --- a/include/chatlogpiece.h +++ b/include/chatlogpiece.h @@ -10,17 +10,18 @@ class chatlogpiece { public: chatlogpiece(); chatlogpiece(QString p_name, QString p_showname, QString p_message, - QString p_action,int color); + QString p_action,int color, bool selfname); chatlogpiece(QString p_name, QString p_showname, QString p_message, - QString p_action, int color, QDateTime p_datetime); + QString p_action, int color, bool selfname, QDateTime p_datetime); - QString get_name(); - QString get_showname(); - QString get_message(); - QString get_action(); - QDateTime get_datetime(); - QString get_datetime_as_string(); - int get_chat_color(); + QString get_name() { return name; }; + QString get_showname() { return showname; }; + QString get_message() { return message; }; + QString get_action() { return action; }; + bool get_selfname() const { return selfname; }; + QDateTime get_datetime() { return datetime; }; + QString get_datetime_as_string() { return datetime.toString(); }; + int get_chat_color() const { return color; }; QString get_full(); private: @@ -28,6 +29,7 @@ private: QString showname; QString message; QString action; + bool selfname; QDateTime datetime; int color; }; diff --git a/include/courtroom.h b/include/courtroom.h index 3b56c77..bf688b5 100644 --- a/include/courtroom.h +++ b/include/courtroom.h @@ -73,6 +73,7 @@ public: void append_evidence(evi_type p_evi) { evidence_list.append(p_evi); } void append_music(QString f_music) { music_list.append(f_music); } void append_area(QString f_area) { area_list.append(f_area); } + void clear_chars() { char_list.clear(); } void clear_music() { music_list.clear(); } void clear_areas() { area_list.clear(); } @@ -278,14 +279,14 @@ public: int default_color = 0); void log_ic_text(QString p_name, QString p_showname, QString p_message, - QString p_action = "", int p_color = 0); + QString p_action = "", int p_color = 0, bool p_selfname = false); // adds text to the IC chatlog. p_name first as bold then p_text then a newlin // this function keeps the chatlog scrolled to the top unless there's text // selected // or the user isn't already scrolled to the top void append_ic_text(QString p_text, QString p_name = "", QString action = "", - int color = 0, QDateTime timestamp = QDateTime::currentDateTime()); + int color = 0, bool selfname = false, QDateTime timestamp = QDateTime::currentDateTime()); // prints who played the song to IC chat and plays said song(if found on local // filesystem) takes in a list where the first element is the song name and diff --git a/include/datatypes.h b/include/datatypes.h index ebf2e38..2f03d39 100644 --- a/include/datatypes.h +++ b/include/datatypes.h @@ -101,6 +101,13 @@ enum CHAT_MESSAGE { EFFECTS }; +enum EMOTE_MOD { + IDLE = 0, + PREANIM = 1, + ZOOM = 5, + PREANIM_ZOOM = 6, +}; + enum MUSIC_EFFECT { FADE_IN = 1, FADE_OUT = 2, SYNC_POS = 4 }; #endif // DATATYPES_H diff --git a/include/demoserver.h b/include/demoserver.h index cadc52d..d355ddb 100644 --- a/include/demoserver.h +++ b/include/demoserver.h @@ -31,6 +31,7 @@ private: QTcpSocket* client_sock = nullptr; bool client_connected = false; bool partial_packet = false; + bool debug_mode = false; QString temp_packet = ""; QQueue<QString> demo_data; QString sc_packet; diff --git a/include/networkmanager.h b/include/networkmanager.h index 1e1a60b..26a61f2 100644 --- a/include/networkmanager.h +++ b/include/networkmanager.h @@ -33,7 +33,7 @@ public: const QString DEFAULT_MS_BASEURL = "https://servers.aceattorneyonline.com"; QString ms_baseurl = DEFAULT_MS_BASEURL; - const int heartbeat_interval = 60 * 5; + const int heartbeat_interval = 60 * 5 * 1000; bool partial_packet = false; QString temp_packet = ""; diff --git a/src/aooptionsdialog.cpp b/src/aooptionsdialog.cpp index 589bc92..6af93ed 100644 --- a/src/aooptionsdialog.cpp +++ b/src/aooptionsdialog.cpp @@ -751,10 +751,10 @@ AOOptionsDialog::AOOptionsDialog(QWidget *parent, AOApplication *p_ao_app) ui_audio_layout->setWidget(row, QFormLayout::LabelRole, ui_bliprate_lbl); ui_bliprate_spinbox = new QSpinBox(ui_audio_widget); - ui_bliprate_spinbox->setMinimum(1); + ui_bliprate_spinbox->setMinimum(0); ui_bliprate_spinbox->setToolTip( tr("Play a blip sound \"once per every X symbols\", where " - "X is the blip rate.")); + "X is the blip rate. 0 plays a blip sound only once.")); ui_audio_layout->setWidget(row, QFormLayout::FieldRole, ui_bliprate_spinbox); diff --git a/src/charselect.cpp b/src/charselect.cpp index ea0a4c4..dce675a 100644 --- a/src/charselect.cpp +++ b/src/charselect.cpp @@ -243,6 +243,7 @@ void Courtroom::character_loading_finished() delete item; } ui_char_button_list.clear(); + ui_char_list->clear(); } // First, we'll make all the character buttons in the very beginning. @@ -305,7 +306,6 @@ void Courtroom::character_loading_finished() } } ui_char_list->expandAll(); - filter_character_list(); } void Courtroom::filter_character_list() diff --git a/src/chatlogpiece.cpp b/src/chatlogpiece.cpp index f4cb225..64ffefe 100644 --- a/src/chatlogpiece.cpp +++ b/src/chatlogpiece.cpp @@ -11,18 +11,19 @@ chatlogpiece::chatlogpiece() } chatlogpiece::chatlogpiece(QString p_name, QString p_showname, - QString p_message, QString p_action, int p_color) + QString p_message, QString p_action, int p_color, bool p_selfname) { name = p_name; showname = p_showname; message = p_message; action = p_action; color = p_color; + selfname = p_selfname; datetime = QDateTime::currentDateTimeUtc(); } chatlogpiece::chatlogpiece(QString p_name, QString p_showname, - QString p_message, QString p_action, int p_color, + QString p_message, QString p_action, int p_color, bool p_selfname, QDateTime p_datetime) { name = p_name; @@ -30,23 +31,10 @@ chatlogpiece::chatlogpiece(QString p_name, QString p_showname, message = p_message; action = p_action; color = p_color; + selfname = p_selfname; datetime = p_datetime.toUTC(); } -QString chatlogpiece::get_name() { return name; } - -QString chatlogpiece::get_showname() { return showname; } - -QString chatlogpiece::get_message() { return message; } - -QDateTime chatlogpiece::get_datetime() { return datetime; } - -QString chatlogpiece::get_action() { return action; } - -QString chatlogpiece::get_datetime_as_string() { return datetime.toString(); } - -int chatlogpiece::get_chat_color() { return color; } - QString chatlogpiece::get_full() { QString full = "["; diff --git a/src/courtroom.cpp b/src/courtroom.cpp index b972e00..0afbeb2 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -725,8 +725,9 @@ void Courtroom::set_widgets() log_margin = ao_app->get_log_margin(); log_timestamp = ao_app->get_log_timestamp(); log_timestamp_format = ao_app->get_log_timestamp_format(); - if (regenerate) + if (regenerate) { regenerate_ic_chatlog(); + } set_size_and_pos(ui_ic_chatlog, "ic_chatlog"); ui_ic_chatlog->setFrameShape(QFrame::NoFrame); @@ -1309,13 +1310,13 @@ void Courtroom::done_received() if (char_list.size() > 0) { - set_char_select_page(); set_char_select(); } else { update_character(m_cid); enter_courtroom(); + set_courtroom_size(); } set_mute_list(); @@ -1869,30 +1870,72 @@ void Courtroom::on_chat_return_pressed() packet_contents.append(f_side); - packet_contents.append(get_char_sfx()); - int f_emote_mod = ao_app->get_emote_mod(current_char, current_emote); + QString f_sfx = "1"; +// EMOTE MOD OVERRIDES: + // Emote_mod 2 is only used by objection check later, having it in the char.ini does nothing + if (f_emote_mod == 2) { + f_emote_mod = PREANIM; + } + // No clue what emote_mod 3 is even supposed to be. + if (f_emote_mod == 3) { + f_emote_mod = IDLE; + } + // Emote_mod 4 seems to be a legacy bugfix that just refers it to emote_mod 5 which is zoom emote + if (f_emote_mod == 4) { + f_emote_mod = ZOOM; + } + // If we have "pre" on, and immediate is not checked + if (ui_pre->isChecked() && !ui_immediate->isChecked()) { + // Turn idle into preanim + if (f_emote_mod == IDLE) { + f_emote_mod = PREANIM; + } + // Turn zoom into preanim zoom + else if (f_emote_mod == ZOOM && ao_app->prezoom_enabled) { + f_emote_mod = PREANIM_ZOOM; + } + // Play the sfx + f_sfx = get_char_sfx(); + } + // If we have "pre" off, or immediate is checked + else { + // Turn preanim into idle + if (f_emote_mod == PREANIM) { + f_emote_mod = IDLE; + } + // Turn preanim zoom into zoom + else if (f_emote_mod == PREANIM_ZOOM) { + f_emote_mod = ZOOM; + } - // needed or else legacy won't understand what we're saying - if (objection_state > 0 && ui_pre->isChecked()) { - if (f_emote_mod == 4 || f_emote_mod == 5) - f_emote_mod = 6; - else - f_emote_mod = 2; + // Play the sfx if pre is checked + if (ui_pre->isChecked()) { + f_sfx = get_char_sfx(); + } } - else if (ui_pre->isChecked() && !ui_immediate->isChecked()) { - if (f_emote_mod == 0) - f_emote_mod = 1; - else if (f_emote_mod == 5 && ao_app->prezoom_enabled) - f_emote_mod = 6; + +// TODO: deprecate this garbage. See https://github.com/AttorneyOnline/AO2-Client/issues/692 + // If our objection is enabled + if (objection_state > 0) { + // Turn preanim zoom emote mod into non-pre + if (f_emote_mod == ZOOM) { + f_emote_mod = PREANIM_ZOOM; + } + // Turn it into preanim objection emote mod + else { + f_emote_mod = 2; + } + // Play the sfx + f_sfx = get_char_sfx(); } - else { - if (f_emote_mod == 1) - f_emote_mod = 0; - else if (f_emote_mod == 4) - f_emote_mod = 5; + + // Custom sfx override via sound list dropdown. + if (!custom_sfx.isEmpty() || ui_sfx_dropdown->currentIndex() != 0) { + f_sfx = get_char_sfx(); } + packet_contents.append(f_sfx); packet_contents.append(QString::number(f_emote_mod)); packet_contents.append(QString::number(m_cid)); @@ -2058,7 +2101,7 @@ void Courtroom::reset_ui() ui_screenshake->set_image("screenshake"); ui_evidence_present->set_image("present"); - if (ui_pre->isChecked() && !ao_app->is_stickysounds_enabled()) { + if (!ao_app->is_stickysounds_enabled()) { ui_sfx_dropdown->setCurrentIndex(0); ui_sfx_remove->hide(); custom_sfx = ""; @@ -2205,6 +2248,8 @@ void Courtroom::log_chatmessage(QString f_message, int f_char_id, QString f_show if (f_displayname.trimmed().isEmpty()) f_displayname = f_showname; + bool selfname = f_char_id == m_cid; + if (log_ic_actions) { // Check if a custom objection is in use int objection_mod = 0; @@ -2253,13 +2298,13 @@ void Courtroom::log_chatmessage(QString f_message, int f_char_id, QString f_show } switch (f_log_mode) { case IO_ONLY: - log_ic_text(f_char, f_displayname, shout_message, tr("shouts")); + log_ic_text(f_char, f_displayname, shout_message, tr("shouts"), 0, selfname); break; case DISPLAY_AND_IO: - log_ic_text(f_char, f_displayname, shout_message, tr("shouts")); + log_ic_text(f_char, f_displayname, shout_message, tr("shouts"), 0, selfname); [[fallthrough]]; case DISPLAY_ONLY: - append_ic_text(shout_message, f_displayname, tr("shouts")); + append_ic_text(shout_message, f_displayname, tr("shouts"), 0, selfname); break; } } @@ -2270,13 +2315,13 @@ void Courtroom::log_chatmessage(QString f_message, int f_char_id, QString f_show QString f_evi_name = local_evidence_list.at(f_evi_id - 1).name; switch (f_log_mode) { case IO_ONLY: - log_ic_text(f_showname, f_displayname, f_evi_name, tr("has presented evidence")); + log_ic_text(f_showname, f_displayname, f_evi_name, tr("has presented evidence"), 0, selfname); break; case DISPLAY_AND_IO: - log_ic_text(f_showname, f_displayname, f_evi_name, tr("has presented evidence")); + log_ic_text(f_showname, f_displayname, f_evi_name, tr("has presented evidence"), 0, selfname); [[fallthrough]]; case DISPLAY_ONLY: - append_ic_text(f_evi_name, f_displayname, tr("has presented evidence")); + append_ic_text(f_evi_name, f_displayname, tr("has presented evidence"), 0, selfname); break; } } @@ -2290,13 +2335,13 @@ void Courtroom::log_chatmessage(QString f_message, int f_char_id, QString f_show return; // Skip adding message switch (f_log_mode) { case IO_ONLY: - log_ic_text(f_showname, f_displayname, f_message, "",f_color); + log_ic_text(f_showname, f_displayname, f_message, "", f_color, selfname); break; case DISPLAY_AND_IO: - log_ic_text(f_showname, f_displayname, f_message, "",f_color); + log_ic_text(f_showname, f_displayname, f_message, "", f_color, selfname); [[fallthrough]]; case DISPLAY_ONLY: - append_ic_text(f_message, f_displayname, "",f_color); + append_ic_text(f_message, f_displayname, "", f_color, selfname); break; } if (!ui_showname_enable->isChecked()) @@ -2501,6 +2546,7 @@ void Courtroom::handle_emote_mod(int emote_mod, bool p_immediate) // If immediate is not ticked on... if (!p_immediate) { + play_sfx(); // Skip preanim. handle_ic_speaking(); } @@ -3104,9 +3150,9 @@ QString Courtroom::filter_ic_text(QString p_text, bool html, int target_pos, } void Courtroom::log_ic_text(QString p_name, QString p_showname, - QString p_message, QString p_action, int p_color) + QString p_message, QString p_action, int p_color, bool p_selfname) { - chatlogpiece log_entry(p_name, p_showname, p_message, p_action, p_color); + chatlogpiece log_entry(p_name, p_showname, p_message, p_action, p_color, p_selfname); ic_chatlog_history.append(log_entry); if (ao_app->get_text_logging_enabled() && !ao_app->log_filename.isEmpty()) ao_app->append_to_file(log_entry.get_full(), ao_app->log_filename, true); @@ -3118,16 +3164,22 @@ void Courtroom::log_ic_text(QString p_name, QString p_showname, } void Courtroom::append_ic_text(QString p_text, QString p_name, QString p_action, - int color, QDateTime timestamp) + int color, bool selfname, QDateTime timestamp) { last_ic_message = p_name + ":" + p_text; QTextCharFormat bold; QTextCharFormat normal; QTextCharFormat italics; + QTextCharFormat own_name; + QTextCharFormat other_name; QTextBlockFormat format; bold.setFontWeight(QFont::Bold); normal.setFontWeight(QFont::Normal); italics.setFontItalic(true); + own_name.setFontWeight(QFont::Bold); + own_name.setForeground(ao_app->get_color("ic_chatlog_selfname_color", "courtroom_fonts.ini")); + other_name.setFontWeight(QFont::Bold); + other_name.setForeground(ao_app->get_color("ic_chatlog_showname_color", "courtroom_fonts.ini")); format.setTopMargin(log_margin); const QTextCursor old_cursor = ui_ic_chatlog->textCursor(); const int old_scrollbar_value = ui_ic_chatlog->verticalScrollBar()->value(); @@ -3155,7 +3207,8 @@ void Courtroom::append_ic_text(QString p_text, QString p_name, QString p_action, } // Format the name of the actor - ui_ic_chatlog->textCursor().insertText(p_name, bold); + QTextCharFormat name_format = selfname ? own_name : other_name; + ui_ic_chatlog->textCursor().insertText(p_name, name_format); // Special case for stopping the music if (p_action == tr("has stopped the music")) { ui_ic_chatlog->textCursor().insertText(" " + p_action + ".", normal); @@ -3623,7 +3676,7 @@ void Courtroom::chat_tick() // ! ! ! ! // where ! is the blip sound int b_rate = blip_rate; - // Earrape prevention without using timers, this method is more consistent. + // Overwhelming blip spam prevention, this method is more consistent than timers if (msg_delay != 0 && msg_delay <= 25) { // The default blip speed is 40ms, and if current msg_delay is 25ms, // the formula will result in the blip rate of: @@ -3634,7 +3687,7 @@ void Courtroom::chat_tick() qMax(b_rate, qRound(static_cast<float>(text_crawl) / msg_delay)); } - if (blip_ticker % b_rate == 0) { + if ((blip_rate <= 0 && blip_ticker < 1) || (b_rate > 0 && blip_ticker % b_rate == 0)) { // ignoring white space unless blank_blip is enabled. if (!formatting_char && (f_character != ' ' || blank_blip)) { blip_player->blip_tick(); @@ -3894,13 +3947,14 @@ void Courtroom::handle_song(QStringList *p_contents) } } if (!mute_map.value(n_char)) { + bool selfname = n_char == m_cid; if (is_stop) { - log_ic_text(str_char, str_show, "", tr("has stopped the music")); - append_ic_text("", str_show, tr("has stopped the music")); + log_ic_text(str_char, str_show, "", tr("has stopped the music"), 0, selfname); + append_ic_text("", str_show, tr("has stopped the music"), 0, selfname); } else { - log_ic_text(str_char, str_show, f_song, tr("has played a song")); - append_ic_text(f_song_clear, str_show, tr("has played a song")); + log_ic_text(str_char, str_show, f_song, tr("has played a song"), 0, selfname); + append_ic_text(f_song_clear, str_show, tr("has played a song"), 0, selfname); } } } @@ -4636,8 +4690,9 @@ QString Courtroom::get_char_sfx() if (!custom_sfx.isEmpty()) return custom_sfx; int index = ui_sfx_dropdown->currentIndex(); - if (index == 0) // Default + if (index == 0) { // Default return ao_app->get_sfx_name(current_char, current_emote); + } if (index == 1) // Nothing return "1"; QString sfx = sound_list[index-2].split("=")[0].trimmed(); @@ -5376,7 +5431,7 @@ void Courtroom::regenerate_ic_chatlog() append_ic_text(message, name, item.get_action(), item.get_chat_color(), - item.get_datetime().toLocalTime()); + item.get_selfname(), item.get_datetime().toLocalTime()); } } diff --git a/src/demoserver.cpp b/src/demoserver.cpp index 800d282..c4f8c15 100644 --- a/src/demoserver.cpp +++ b/src/demoserver.cpp @@ -233,9 +233,39 @@ void DemoServer::handle_packet(AOPacket packet) QString packet = "CT#DEMO#" + tr("min_wait is deprecated. Use the client Settings for minimum wait instead!") + "#1#%"; client_sock->write(packet.toUtf8()); } + else if (contents[1].startsWith("/debug")) + { + QStringList args = contents[1].split(" "); + if (args.size() > 1) + { + bool ok; + int toggle = args.at(1).toInt(&ok); + if (ok && (toggle == 0 || toggle == 1)) { + debug_mode = toggle == 1; + QString packet = "CT#DEMO#" + tr("Setting debug mode to %1").arg(static_cast<int>(debug_mode)) + "#1#%"; + client_sock->write(packet.toUtf8()); + // Debug mode disabled? + if (!debug_mode) { + // Reset the timer + client_sock->write("TI#4#1#0#%"); + client_sock->write("TI#4#3#0#%"); + } + } + else + { + QString packet = "CT#DEMO#" + tr("Valid values are 1 or 0!") + "#1#%"; + client_sock->write(packet.toUtf8()); + } + } + else + { + QString packet = "CT#DEMO#" + tr("Set debug mode using /debug 1 to enable, and /debug 0 to disable, which will use the fifth timer (TI#4) to show the remaining time until next demo line.") + "#1#%"; + client_sock->write(packet.toUtf8()); + } + } else if (contents[1].startsWith("/help")) { - QString packet = "CT#DEMO#" + tr("Available commands:\nload, reload, play, pause, max_wait, help") + "#1#%"; + QString packet = "CT#DEMO#" + tr("Available commands:\nload, reload, play, pause, max_wait, debug, help") + "#1#%"; client_sock->write(packet.toUtf8()); } } @@ -321,8 +351,8 @@ void DemoServer::reset_state() client_sock->write("LE##%"); // Reset timers - client_sock->write("TI#0#3#0#%"); client_sock->write("TI#0#1#0#%"); + client_sock->write("TI#0#3#0#%"); client_sock->write("TI#1#1#0#%"); client_sock->write("TI#1#3#0#%"); client_sock->write("TI#2#1#0#%"); @@ -359,19 +389,25 @@ void DemoServer::playback() AOPacket wait_packet = AOPacket(current_packet); int duration = wait_packet.get_contents().at(0).toInt(); - if (max_wait != -1) { - if (duration + elapsed_time > max_wait) { - duration = qMax(0, max_wait - elapsed_time); - // Skip the difference on the timers - emit skip_timers(wait_packet.get_contents().at(0).toInt() - duration); - } - else if (timer->interval() != 0 && duration + elapsed_time > timer->interval()) { - duration = qMax(0, timer->interval() - elapsed_time); - emit skip_timers(wait_packet.get_contents().at(0).toInt() - duration); - } + // Max wait reached + if (max_wait != -1 && duration + elapsed_time > max_wait) { + duration = qMax(0, max_wait - elapsed_time); + qDebug() << "Max_wait of " << max_wait << " reached. Forcing duration to " << duration << "ms"; + // Skip the difference on the timers + emit skip_timers(wait_packet.get_contents().at(0).toInt() - duration); + } + // Manual user skip, such as with > + else if (timer->remainingTime() > 0) { + qDebug() << "Timer of interval " << timer->interval() << " is being skipped. Forcing to skip " << timer->remainingTime() << "ms on TI# clocks"; + emit skip_timers(timer->remainingTime()); } elapsed_time += duration; timer->start(duration); + if (debug_mode) { + client_sock->write("TI#4#2#%"); + QString debug_timer = "TI#4#0#" + QString::number(duration) + "#%"; + client_sock->write(debug_timer.toUtf8()); + } } else { QString end_packet = "CT#DEMO#" + tr("Reached the end of the demo file. Send /play or > in OOC to restart, or /load to open a new file.") + "#1#%"; diff --git a/src/packet_distribution.cpp b/src/packet_distribution.cpp index 0ddadd8..0fe25dc 100644 --- a/src/packet_distribution.cpp +++ b/src/packet_distribution.cpp @@ -240,9 +240,9 @@ void AOApplication::server_packet_received(AOPacket *p_packet) } else if (header == "SC") { - if (!courtroom_constructed || courtroom_loaded) + if (!courtroom_constructed) goto end; - + w_courtroom->clear_chars(); for (int n_element = 0; n_element < f_contents.size(); ++n_element) { QStringList sub_elements = f_contents.at(n_element).split("&"); @@ -256,24 +256,28 @@ void AOApplication::server_packet_received(AOPacket *p_packet) // temporary. the CharsCheck packet sets this properly f_char.taken = false; - ++loaded_chars; - - w_lobby->set_loading_text(tr("Loading chars:\n%1/%2") - .arg(QString::number(loaded_chars)) - .arg(QString::number(char_list_size))); - w_courtroom->append_char(f_char); - int total_loading_size = - char_list_size * 2 + evidence_list_size + music_list_size; - int loading_value = int( - ((loaded_chars + generated_chars + loaded_music + loaded_evidence) / - static_cast<double>(total_loading_size)) * - 100); - w_lobby->set_loading_value(loading_value); + if (!courtroom_loaded) { + ++loaded_chars; + w_lobby->set_loading_text(tr("Loading chars:\n%1/%2") + .arg(QString::number(loaded_chars)) + .arg(QString::number(char_list_size))); + + int total_loading_size = + char_list_size * 2 + evidence_list_size + music_list_size; + int loading_value = int( + ((loaded_chars + generated_chars + loaded_music + loaded_evidence) / + static_cast<double>(total_loading_size)) * + 100); + w_lobby->set_loading_value(loading_value); + } } - send_server_packet(new AOPacket("RM#%")); + if (!courtroom_loaded) + send_server_packet(new AOPacket("RM#%")); + else + w_courtroom->character_loading_finished(); append_to_demofile(f_packet_encoded); } else if (header == "SM") { diff --git a/src/text_file_functions.cpp b/src/text_file_functions.cpp index a0caf9b..e3a285d 100644 --- a/src/text_file_functions.cpp +++ b/src/text_file_functions.cpp @@ -10,8 +10,8 @@ int AOApplication::read_blip_rate() { int result = configini->value("blip_rate", 2).toInt(); - if (result < 1) - return 1; + if (result < 0) + return 0; return result; } |
