From a39de270cd0d2ecb7c88589e09d74958dbacf0c9 Mon Sep 17 00:00:00 2001 From: RickyRister <42636155+RickyRister@users.noreply.github.com> Date: Sun, 8 Dec 2024 18:25:10 -0800 Subject: [PATCH] make rewind buffering timeout configurable (#5227) * update settingsCache * implement thing * add new setting to window * rename setting * make it compile on qt5 * fix typo * somehow changing the order here fixes a bug? The loaded value was getting clamped to 99 --- .../client/network/replay_timeline_widget.cpp | 9 +-------- .../src/client/network/replay_timeline_widget.h | 3 --- cockatrice/src/dialogs/dlg_settings.cpp | 17 +++++++++++++++++ cockatrice/src/dialogs/dlg_settings.h | 3 +++ cockatrice/src/settings/cache_settings.cpp | 7 +++++++ cockatrice/src/settings/cache_settings.h | 6 ++++++ dbconverter/src/mocks.cpp | 3 +++ tests/carddatabase/mocks.cpp | 3 +++ 8 files changed, 40 insertions(+), 11 deletions(-) diff --git a/cockatrice/src/client/network/replay_timeline_widget.cpp b/cockatrice/src/client/network/replay_timeline_widget.cpp index deb77d623..c5197c2a6 100644 --- a/cockatrice/src/client/network/replay_timeline_widget.cpp +++ b/cockatrice/src/client/network/replay_timeline_widget.cpp @@ -106,20 +106,13 @@ void ReplayTimelineWidget::handleBackwardsSkip(bool doRewindBuffering) // The rewind only happens once the timer runs out. // If another backwards skip happens, the timer will just get reset instead of rewinding. rewindBufferingTimer->stop(); - rewindBufferingTimer->start(calcRewindBufferingTimeout()); + rewindBufferingTimer->start(SettingsCache::instance().getRewindBufferingMs()); } else { // otherwise, process the rewind immediately processRewind(); } } -/// The timeout scales based on the current event number, up to a limit -int ReplayTimelineWidget::calcRewindBufferingTimeout() const -{ - int extraTime = currentEvent / 100; - return std::min(BASE_REWIND_BUFFERING_TIMEOUT_MS + extraTime, MAX_REWIND_BUFFERING_TIMEOUT_MS); -} - void ReplayTimelineWidget::processRewind() { // stop any queued-up rewinds diff --git a/cockatrice/src/client/network/replay_timeline_widget.h b/cockatrice/src/client/network/replay_timeline_widget.h index b4a0559a4..68f70fa65 100644 --- a/cockatrice/src/client/network/replay_timeline_widget.h +++ b/cockatrice/src/client/network/replay_timeline_widget.h @@ -28,8 +28,6 @@ private: static constexpr int TIMER_INTERVAL_MS = 200; static constexpr int BIN_LENGTH = 5000; - static constexpr int BASE_REWIND_BUFFERING_TIMEOUT_MS = 180; - static constexpr int MAX_REWIND_BUFFERING_TIMEOUT_MS = 280; QTimer *replayTimer; QTimer *rewindBufferingTimer; @@ -42,7 +40,6 @@ private: void skipToTime(int newTime, bool doRewindBuffering); void handleBackwardsSkip(bool doRewindBuffering); - int calcRewindBufferingTimeout() const; void processRewind(); void processNewEvents(PlaybackMode playbackMode); private slots: diff --git a/cockatrice/src/dialogs/dlg_settings.cpp b/cockatrice/src/dialogs/dlg_settings.cpp index babe49213..121b10454 100644 --- a/cockatrice/src/dialogs/dlg_settings.cpp +++ b/cockatrice/src/dialogs/dlg_settings.cpp @@ -508,12 +508,26 @@ UserInterfaceSettingsPage::UserInterfaceSettingsPage() deckEditorGroupBox = new QGroupBox; deckEditorGroupBox->setLayout(deckEditorGrid); + // replay settings + rewindBufferingMsBox.setRange(0, 9999); + rewindBufferingMsBox.setValue(SettingsCache::instance().getRewindBufferingMs()); + connect(&rewindBufferingMsBox, qOverload(&QSpinBox::valueChanged), &SettingsCache::instance(), + &SettingsCache::setRewindBufferingMs); + + auto *replayGrid = new QGridLayout; + replayGrid->addWidget(&rewindBufferingMsLabel, 0, 0, 1, 1); + replayGrid->addWidget(&rewindBufferingMsBox, 0, 1, 1, 1); + + replayGroupBox = new QGroupBox; + replayGroupBox->setLayout(replayGrid); + // putting it all together auto *mainLayout = new QVBoxLayout; mainLayout->addWidget(generalGroupBox); mainLayout->addWidget(notificationsGroupBox); mainLayout->addWidget(animationGroupBox); mainLayout->addWidget(deckEditorGroupBox); + mainLayout->addWidget(replayGroupBox); mainLayout->addStretch(); setLayout(mainLayout); @@ -544,6 +558,9 @@ void UserInterfaceSettingsPage::retranslateUi() tapAnimationCheckBox.setText(tr("&Tap/untap animation")); deckEditorGroupBox->setTitle(tr("Deck editor settings")); openDeckInNewTabCheckBox.setText(tr("Always open deck in new tab")); + replayGroupBox->setTitle(tr("Replay settings")); + rewindBufferingMsLabel.setText(tr("Buffer time for backwards skip via shortcut:")); + rewindBufferingMsBox.setSuffix(tr(" ms")); } DeckEditorSettingsPage::DeckEditorSettingsPage() diff --git a/cockatrice/src/dialogs/dlg_settings.h b/cockatrice/src/dialogs/dlg_settings.h index fdd114274..f98daf83e 100644 --- a/cockatrice/src/dialogs/dlg_settings.h +++ b/cockatrice/src/dialogs/dlg_settings.h @@ -125,10 +125,13 @@ private: QCheckBox useTearOffMenusCheckBox; QCheckBox tapAnimationCheckBox; QCheckBox openDeckInNewTabCheckBox; + QLabel rewindBufferingMsLabel; + QSpinBox rewindBufferingMsBox; QGroupBox *generalGroupBox; QGroupBox *notificationsGroupBox; QGroupBox *animationGroupBox; QGroupBox *deckEditorGroupBox; + QGroupBox *replayGroupBox; public: UserInterfaceSettingsPage(); diff --git a/cockatrice/src/settings/cache_settings.cpp b/cockatrice/src/settings/cache_settings.cpp index 3a75af782..4386e10b8 100644 --- a/cockatrice/src/settings/cache_settings.cpp +++ b/cockatrice/src/settings/cache_settings.cpp @@ -245,6 +245,7 @@ SettingsCache::SettingsCache() minPlayersForMultiColumnLayout = settings->value("interface/min_players_multicolumn", 4).toInt(); tapAnimation = settings->value("cards/tapanimation", true).toBool(); openDeckInNewTab = settings->value("editor/openDeckInNewTab", false).toBool(); + rewindBufferingMs = settings->value("replay/rewindBufferingMs", 200).toInt(); chatMention = settings->value("chat/mention", true).toBool(); chatMentionCompleter = settings->value("chat/mentioncompleter", true).toBool(); chatMentionForeground = settings->value("chat/mentionforeground", true).toBool(); @@ -545,6 +546,12 @@ void SettingsCache::setOpenDeckInNewTab(QT_STATE_CHANGED_T _openDeckInNewTab) settings->setValue("editor/openDeckInNewTab", openDeckInNewTab); } +void SettingsCache::setRewindBufferingMs(int _rewindBufferingMs) +{ + rewindBufferingMs = _rewindBufferingMs; + settings->setValue("replay/rewindBufferingMs", rewindBufferingMs); +} + void SettingsCache::setChatMention(QT_STATE_CHANGED_T _chatMention) { chatMention = static_cast(_chatMention); diff --git a/cockatrice/src/settings/cache_settings.h b/cockatrice/src/settings/cache_settings.h index 77e826412..1d4b9ecdd 100644 --- a/cockatrice/src/settings/cache_settings.h +++ b/cockatrice/src/settings/cache_settings.h @@ -103,6 +103,7 @@ private: int minPlayersForMultiColumnLayout; bool tapAnimation; bool openDeckInNewTab; + int rewindBufferingMs; bool chatMention; bool chatMentionCompleter; QString chatMentionColor; @@ -312,6 +313,10 @@ public: { return openDeckInNewTab; } + int getRewindBufferingMs() const + { + return rewindBufferingMs; + } bool getChatMention() const { return chatMention; @@ -566,6 +571,7 @@ public slots: void setMinPlayersForMultiColumnLayout(int _minPlayersForMultiColumnLayout); void setTapAnimation(QT_STATE_CHANGED_T _tapAnimation); void setOpenDeckInNewTab(QT_STATE_CHANGED_T _openDeckInNewTab); + void setRewindBufferingMs(int _rewindBufferingMs); void setChatMention(QT_STATE_CHANGED_T _chatMention); void setChatMentionCompleter(QT_STATE_CHANGED_T _chatMentionCompleter); void setChatMentionForeground(QT_STATE_CHANGED_T _chatMentionForeground); diff --git a/dbconverter/src/mocks.cpp b/dbconverter/src/mocks.cpp index e13db95ff..0de1efb35 100644 --- a/dbconverter/src/mocks.cpp +++ b/dbconverter/src/mocks.cpp @@ -166,6 +166,9 @@ void SettingsCache::setTapAnimation(QT_STATE_CHANGED_T /* _tapAnimation */) void SettingsCache::setOpenDeckInNewTab(QT_STATE_CHANGED_T /* _openDeckInNewTab */) { } +void SettingsCache::setRewindBufferingMs(int /* _rewindBufferingMs */) +{ +} void SettingsCache::setChatMention(QT_STATE_CHANGED_T /* _chatMention */) { } diff --git a/tests/carddatabase/mocks.cpp b/tests/carddatabase/mocks.cpp index 0eed998b3..c7c7b5976 100644 --- a/tests/carddatabase/mocks.cpp +++ b/tests/carddatabase/mocks.cpp @@ -170,6 +170,9 @@ void SettingsCache::setTapAnimation(QT_STATE_CHANGED_T /* _tapAnimation */) void SettingsCache::setOpenDeckInNewTab(QT_STATE_CHANGED_T /* _openDeckInNewTab */) { } +void SettingsCache::setRewindBufferingMs(int /* _rewindBufferingMs */) +{ +} void SettingsCache::setChatMention(QT_STATE_CHANGED_T /* _chatMention */) { }