diff --git a/cockatrice/src/client/network/replay_timeline_widget.cpp b/cockatrice/src/client/network/replay_timeline_widget.cpp index 28ae604b4..83b1abda0 100644 --- a/cockatrice/src/client/network/replay_timeline_widget.cpp +++ b/cockatrice/src/client/network/replay_timeline_widget.cpp @@ -16,25 +16,23 @@ ReplayTimelineWidget::ReplayTimelineWidget(QWidget *parent) connect(rewindBufferingTimer, &QTimer::timeout, this, &ReplayTimelineWidget::processRewind); } -const int ReplayTimelineWidget::binLength = 5000; - void ReplayTimelineWidget::setTimeline(const QList &_replayTimeline) { replayTimeline = _replayTimeline; histogram.clear(); - int binEndTime = binLength - 1; + int binEndTime = BIN_LENGTH - 1; int binValue = 0; for (int i : replayTimeline) { if (i > binEndTime) { histogram.append(binValue); if (binValue > maxBinValue) maxBinValue = binValue; - while (i > binEndTime + binLength) { + while (i > binEndTime + BIN_LENGTH) { histogram.append(0); - binEndTime += binLength; + binEndTime += BIN_LENGTH; } binValue = 1; - binEndTime += binLength; + binEndTime += BIN_LENGTH; } else ++binValue; } @@ -85,7 +83,7 @@ void ReplayTimelineWidget::skipToTime(int newTime, bool doRewindBuffering) newTime = maxTime; } - newTime -= newTime % 200; // Time should always be a multiple of 200 + newTime -= newTime % TIMER_INTERVAL_MS; // Time should always be a multiple of the interval const bool isBackwardsSkip = newTime < currentTime; currentTime = newTime; @@ -145,7 +143,7 @@ QSize ReplayTimelineWidget::minimumSizeHint() const void ReplayTimelineWidget::replayTimerTimeout() { - currentTime += 200; + currentTime += TIMER_INTERVAL_MS; processNewEvents(NORMAL_PLAYBACK); @@ -160,8 +158,8 @@ void ReplayTimelineWidget::processNewEvents(PlaybackMode playbackMode) Player::EventProcessingOptions options; // backwards skip => always skip reveal windows - // forwards skip => skip reveal windows that don't happen within 10 seconds of the target - if (playbackMode == BACKWARD_SKIP || currentTime - replayTimeline[currentEvent] > 10000) + // forwards skip => skip reveal windows that don't happen within a big skip of the target + if (playbackMode == BACKWARD_SKIP || currentTime - replayTimeline[currentEvent] > BIG_SKIP_MS) options |= Player::EventProcessingOption::SKIP_REVEAL_WINDOW; emit processNextEvent(options); @@ -176,12 +174,12 @@ void ReplayTimelineWidget::processNewEvents(PlaybackMode playbackMode) void ReplayTimelineWidget::setTimeScaleFactor(qreal _timeScaleFactor) { timeScaleFactor = _timeScaleFactor; - replayTimer->setInterval(static_cast(200 / timeScaleFactor)); + replayTimer->setInterval(static_cast(TIMER_INTERVAL_MS / timeScaleFactor)); } void ReplayTimelineWidget::startReplay() { - replayTimer->start(static_cast(200 / timeScaleFactor)); + replayTimer->start(static_cast(TIMER_INTERVAL_MS / timeScaleFactor)); } void ReplayTimelineWidget::stopReplay() diff --git a/cockatrice/src/client/network/replay_timeline_widget.h b/cockatrice/src/client/network/replay_timeline_widget.h index cd7077757..b4a0559a4 100644 --- a/cockatrice/src/client/network/replay_timeline_widget.h +++ b/cockatrice/src/client/network/replay_timeline_widget.h @@ -26,13 +26,15 @@ private: BACKWARD_SKIP }; - QTimer *replayTimer; + 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; QList replayTimeline; QList histogram; - static const int binLength; int maxBinValue, maxTime; qreal timeScaleFactor; int currentTime; @@ -47,6 +49,10 @@ private slots: void replayTimerTimeout(); public: + static constexpr int SMALL_SKIP_MS = 1000; + static constexpr int BIG_SKIP_MS = 10000; + static constexpr qreal FAST_FORWARD_SCALE_FACTOR = 10.0; + explicit ReplayTimelineWidget(QWidget *parent = nullptr); void setTimeline(const QList &_replayTimeline); QSize sizeHint() const override; diff --git a/cockatrice/src/client/tabs/tab_game.cpp b/cockatrice/src/client/tabs/tab_game.cpp index f16767a59..fa8e286ef 100644 --- a/cockatrice/src/client/tabs/tab_game.cpp +++ b/cockatrice/src/client/tabs/tab_game.cpp @@ -635,7 +635,7 @@ void TabGame::replayPlayButtonToggled(bool checked) void TabGame::replayFastForwardButtonToggled(bool checked) { - timelineWidget->setTimeScaleFactor(checked ? 10.0 : 1.0); + timelineWidget->setTimeScaleFactor(checked ? ReplayTimelineWidget::FAST_FORWARD_SCALE_FACTOR : 1.0); } /** @@ -1742,22 +1742,22 @@ void TabGame::createReplayDock() aReplaySkipForward = new QAction(timelineWidget); timelineWidget->addAction(aReplaySkipForward); connect(aReplaySkipForward, &QAction::triggered, this, - [=]() { timelineWidget->skipByAmount(SMALL_SKIP_AMOUNT_MS); }); + [=]() { timelineWidget->skipByAmount(ReplayTimelineWidget::SMALL_SKIP_MS); }); aReplaySkipBackward = new QAction(timelineWidget); timelineWidget->addAction(aReplaySkipBackward); connect(aReplaySkipBackward, &QAction::triggered, this, - [=]() { timelineWidget->skipByAmount(-SMALL_SKIP_AMOUNT_MS); }); + [=]() { timelineWidget->skipByAmount(-ReplayTimelineWidget::SMALL_SKIP_MS); }); aReplaySkipForwardBig = new QAction(timelineWidget); timelineWidget->addAction(aReplaySkipForwardBig); connect(aReplaySkipForwardBig, &QAction::triggered, this, - [=]() { timelineWidget->skipByAmount(BIG_SKIP_AMOUNT_MS); }); + [=]() { timelineWidget->skipByAmount(ReplayTimelineWidget::BIG_SKIP_MS); }); aReplaySkipBackwardBig = new QAction(timelineWidget); timelineWidget->addAction(aReplaySkipBackwardBig); connect(aReplaySkipBackwardBig, &QAction::triggered, this, - [=]() { timelineWidget->skipByAmount(-BIG_SKIP_AMOUNT_MS); }); + [=]() { timelineWidget->skipByAmount(-ReplayTimelineWidget::BIG_SKIP_MS); }); // buttons replayPlayButton = new QToolButton; diff --git a/cockatrice/src/client/tabs/tab_game.h b/cockatrice/src/client/tabs/tab_game.h index d3452bda5..561572eab 100644 --- a/cockatrice/src/client/tabs/tab_game.h +++ b/cockatrice/src/client/tabs/tab_game.h @@ -142,8 +142,6 @@ private: QStackedWidget *mainWidget; // Replay related members - static const int SMALL_SKIP_AMOUNT_MS = 1000; - static const int BIG_SKIP_AMOUNT_MS = 10000; GameReplay *replay; int currentReplayStep; QList replayTimeline;