From 315cbc09250c24e4131497ef6e6a666a46992bab Mon Sep 17 00:00:00 2001 From: RickyRister <42636155+RickyRister@users.noreply.github.com> Date: Wed, 11 Dec 2024 01:54:36 -0800 Subject: [PATCH] fix remaining wonkiness with rewind buffering in replays (#5235) --- .../client/network/replay_timeline_widget.cpp | 21 +++++++++++-------- .../client/network/replay_timeline_widget.h | 4 +++- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/cockatrice/src/client/network/replay_timeline_widget.cpp b/cockatrice/src/client/network/replay_timeline_widget.cpp index c5197c2a6..6517856cd 100644 --- a/cockatrice/src/client/network/replay_timeline_widget.cpp +++ b/cockatrice/src/client/network/replay_timeline_widget.cpp @@ -6,7 +6,8 @@ #include ReplayTimelineWidget::ReplayTimelineWidget(QWidget *parent) - : QWidget(parent), maxBinValue(1), maxTime(1), timeScaleFactor(1.0), currentTime(0), currentEvent(0) + : QWidget(parent), maxBinValue(1), maxTime(1), timeScaleFactor(1.0), currentVisualTime(0), currentProcessedTime(0), + currentEvent(0) { replayTimer = new QTimer(this); connect(replayTimer, SIGNAL(timeout()), this, SLOT(replayTimerTimeout())); @@ -58,7 +59,7 @@ void ReplayTimelineWidget::paintEvent(QPaintEvent * /* event */) painter.fillPath(path, Qt::black); const QColor barColor = QColor::fromHsv(120, 255, 255, 100); - quint64 w = (quint64)(width() - 1) * (quint64)currentTime / maxTime; + quint64 w = (quint64)(width() - 1) * (quint64)currentVisualTime / maxTime; painter.fillRect(0, 0, static_cast(w), height() - 1, barColor); } @@ -85,8 +86,8 @@ void ReplayTimelineWidget::skipToTime(int newTime, bool doRewindBuffering) newTime -= newTime % TIMER_INTERVAL_MS; // Time should always be a multiple of the interval - const bool isBackwardsSkip = newTime < currentTime; - currentTime = newTime; + const bool isBackwardsSkip = newTime < currentProcessedTime; + currentVisualTime = newTime; if (isBackwardsSkip) { handleBackwardsSkip(doRewindBuffering); @@ -136,23 +137,25 @@ QSize ReplayTimelineWidget::minimumSizeHint() const void ReplayTimelineWidget::replayTimerTimeout() { - currentTime += TIMER_INTERVAL_MS; + currentVisualTime += TIMER_INTERVAL_MS; processNewEvents(NORMAL_PLAYBACK); - if (!(currentTime % 1000)) + if (!(currentVisualTime % 1000)) update(); } /// Processes all unprocessed events up to the current time. void ReplayTimelineWidget::processNewEvents(PlaybackMode playbackMode) { - while ((currentEvent < replayTimeline.size()) && (replayTimeline[currentEvent] < currentTime)) { + currentProcessedTime = currentVisualTime; + + while ((currentEvent < replayTimeline.size()) && (replayTimeline[currentEvent] < currentProcessedTime)) { Player::EventProcessingOptions options; // backwards skip => always skip reveal windows // 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) + if (playbackMode == BACKWARD_SKIP || currentProcessedTime - replayTimeline[currentEvent] > BIG_SKIP_MS) options |= Player::EventProcessingOption::SKIP_REVEAL_WINDOW; // backwards skip => always skip tap animation @@ -186,5 +189,5 @@ void ReplayTimelineWidget::stopReplay() void ReplayTimelineWidget::skipByAmount(int amount) { - skipToTime(currentTime + amount, true); + skipToTime(currentVisualTime + amount, amount < 0); } \ No newline at end of file diff --git a/cockatrice/src/client/network/replay_timeline_widget.h b/cockatrice/src/client/network/replay_timeline_widget.h index 68f70fa65..9676e7b47 100644 --- a/cockatrice/src/client/network/replay_timeline_widget.h +++ b/cockatrice/src/client/network/replay_timeline_widget.h @@ -35,7 +35,9 @@ private: QList histogram; int maxBinValue, maxTime; qreal timeScaleFactor; - int currentTime; + int currentVisualTime; // time currently displayed by the timeline + int currentProcessedTime; // time that events are currently processed up to. Could differ from visual time due to + // rewind buffering int currentEvent; void skipToTime(int newTime, bool doRewindBuffering);