mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-27 17:13:54 -07:00
move replay-related constants into ReplayTimelineWidget (#5166)
* move constants * make the existing static const into a constexpr
This commit is contained in:
parent
e894e78346
commit
f0fb77bade
4 changed files with 23 additions and 21 deletions
|
|
@ -16,25 +16,23 @@ ReplayTimelineWidget::ReplayTimelineWidget(QWidget *parent)
|
||||||
connect(rewindBufferingTimer, &QTimer::timeout, this, &ReplayTimelineWidget::processRewind);
|
connect(rewindBufferingTimer, &QTimer::timeout, this, &ReplayTimelineWidget::processRewind);
|
||||||
}
|
}
|
||||||
|
|
||||||
const int ReplayTimelineWidget::binLength = 5000;
|
|
||||||
|
|
||||||
void ReplayTimelineWidget::setTimeline(const QList<int> &_replayTimeline)
|
void ReplayTimelineWidget::setTimeline(const QList<int> &_replayTimeline)
|
||||||
{
|
{
|
||||||
replayTimeline = _replayTimeline;
|
replayTimeline = _replayTimeline;
|
||||||
histogram.clear();
|
histogram.clear();
|
||||||
int binEndTime = binLength - 1;
|
int binEndTime = BIN_LENGTH - 1;
|
||||||
int binValue = 0;
|
int binValue = 0;
|
||||||
for (int i : replayTimeline) {
|
for (int i : replayTimeline) {
|
||||||
if (i > binEndTime) {
|
if (i > binEndTime) {
|
||||||
histogram.append(binValue);
|
histogram.append(binValue);
|
||||||
if (binValue > maxBinValue)
|
if (binValue > maxBinValue)
|
||||||
maxBinValue = binValue;
|
maxBinValue = binValue;
|
||||||
while (i > binEndTime + binLength) {
|
while (i > binEndTime + BIN_LENGTH) {
|
||||||
histogram.append(0);
|
histogram.append(0);
|
||||||
binEndTime += binLength;
|
binEndTime += BIN_LENGTH;
|
||||||
}
|
}
|
||||||
binValue = 1;
|
binValue = 1;
|
||||||
binEndTime += binLength;
|
binEndTime += BIN_LENGTH;
|
||||||
} else
|
} else
|
||||||
++binValue;
|
++binValue;
|
||||||
}
|
}
|
||||||
|
|
@ -85,7 +83,7 @@ void ReplayTimelineWidget::skipToTime(int newTime, bool doRewindBuffering)
|
||||||
newTime = maxTime;
|
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;
|
const bool isBackwardsSkip = newTime < currentTime;
|
||||||
currentTime = newTime;
|
currentTime = newTime;
|
||||||
|
|
@ -145,7 +143,7 @@ QSize ReplayTimelineWidget::minimumSizeHint() const
|
||||||
|
|
||||||
void ReplayTimelineWidget::replayTimerTimeout()
|
void ReplayTimelineWidget::replayTimerTimeout()
|
||||||
{
|
{
|
||||||
currentTime += 200;
|
currentTime += TIMER_INTERVAL_MS;
|
||||||
|
|
||||||
processNewEvents(NORMAL_PLAYBACK);
|
processNewEvents(NORMAL_PLAYBACK);
|
||||||
|
|
||||||
|
|
@ -160,8 +158,8 @@ void ReplayTimelineWidget::processNewEvents(PlaybackMode playbackMode)
|
||||||
Player::EventProcessingOptions options;
|
Player::EventProcessingOptions options;
|
||||||
|
|
||||||
// backwards skip => always skip reveal windows
|
// backwards skip => always skip reveal windows
|
||||||
// forwards skip => skip reveal windows that don't happen within 10 seconds of the target
|
// forwards skip => skip reveal windows that don't happen within a big skip of the target
|
||||||
if (playbackMode == BACKWARD_SKIP || currentTime - replayTimeline[currentEvent] > 10000)
|
if (playbackMode == BACKWARD_SKIP || currentTime - replayTimeline[currentEvent] > BIG_SKIP_MS)
|
||||||
options |= Player::EventProcessingOption::SKIP_REVEAL_WINDOW;
|
options |= Player::EventProcessingOption::SKIP_REVEAL_WINDOW;
|
||||||
|
|
||||||
emit processNextEvent(options);
|
emit processNextEvent(options);
|
||||||
|
|
@ -176,12 +174,12 @@ void ReplayTimelineWidget::processNewEvents(PlaybackMode playbackMode)
|
||||||
void ReplayTimelineWidget::setTimeScaleFactor(qreal _timeScaleFactor)
|
void ReplayTimelineWidget::setTimeScaleFactor(qreal _timeScaleFactor)
|
||||||
{
|
{
|
||||||
timeScaleFactor = _timeScaleFactor;
|
timeScaleFactor = _timeScaleFactor;
|
||||||
replayTimer->setInterval(static_cast<int>(200 / timeScaleFactor));
|
replayTimer->setInterval(static_cast<int>(TIMER_INTERVAL_MS / timeScaleFactor));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReplayTimelineWidget::startReplay()
|
void ReplayTimelineWidget::startReplay()
|
||||||
{
|
{
|
||||||
replayTimer->start(static_cast<int>(200 / timeScaleFactor));
|
replayTimer->start(static_cast<int>(TIMER_INTERVAL_MS / timeScaleFactor));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReplayTimelineWidget::stopReplay()
|
void ReplayTimelineWidget::stopReplay()
|
||||||
|
|
|
||||||
|
|
@ -26,13 +26,15 @@ private:
|
||||||
BACKWARD_SKIP
|
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 BASE_REWIND_BUFFERING_TIMEOUT_MS = 180;
|
||||||
static constexpr int MAX_REWIND_BUFFERING_TIMEOUT_MS = 280;
|
static constexpr int MAX_REWIND_BUFFERING_TIMEOUT_MS = 280;
|
||||||
|
|
||||||
|
QTimer *replayTimer;
|
||||||
QTimer *rewindBufferingTimer;
|
QTimer *rewindBufferingTimer;
|
||||||
QList<int> replayTimeline;
|
QList<int> replayTimeline;
|
||||||
QList<int> histogram;
|
QList<int> histogram;
|
||||||
static const int binLength;
|
|
||||||
int maxBinValue, maxTime;
|
int maxBinValue, maxTime;
|
||||||
qreal timeScaleFactor;
|
qreal timeScaleFactor;
|
||||||
int currentTime;
|
int currentTime;
|
||||||
|
|
@ -47,6 +49,10 @@ private slots:
|
||||||
void replayTimerTimeout();
|
void replayTimerTimeout();
|
||||||
|
|
||||||
public:
|
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);
|
explicit ReplayTimelineWidget(QWidget *parent = nullptr);
|
||||||
void setTimeline(const QList<int> &_replayTimeline);
|
void setTimeline(const QList<int> &_replayTimeline);
|
||||||
QSize sizeHint() const override;
|
QSize sizeHint() const override;
|
||||||
|
|
|
||||||
|
|
@ -635,7 +635,7 @@ void TabGame::replayPlayButtonToggled(bool checked)
|
||||||
|
|
||||||
void TabGame::replayFastForwardButtonToggled(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);
|
aReplaySkipForward = new QAction(timelineWidget);
|
||||||
timelineWidget->addAction(aReplaySkipForward);
|
timelineWidget->addAction(aReplaySkipForward);
|
||||||
connect(aReplaySkipForward, &QAction::triggered, this,
|
connect(aReplaySkipForward, &QAction::triggered, this,
|
||||||
[=]() { timelineWidget->skipByAmount(SMALL_SKIP_AMOUNT_MS); });
|
[=]() { timelineWidget->skipByAmount(ReplayTimelineWidget::SMALL_SKIP_MS); });
|
||||||
|
|
||||||
aReplaySkipBackward = new QAction(timelineWidget);
|
aReplaySkipBackward = new QAction(timelineWidget);
|
||||||
timelineWidget->addAction(aReplaySkipBackward);
|
timelineWidget->addAction(aReplaySkipBackward);
|
||||||
connect(aReplaySkipBackward, &QAction::triggered, this,
|
connect(aReplaySkipBackward, &QAction::triggered, this,
|
||||||
[=]() { timelineWidget->skipByAmount(-SMALL_SKIP_AMOUNT_MS); });
|
[=]() { timelineWidget->skipByAmount(-ReplayTimelineWidget::SMALL_SKIP_MS); });
|
||||||
|
|
||||||
aReplaySkipForwardBig = new QAction(timelineWidget);
|
aReplaySkipForwardBig = new QAction(timelineWidget);
|
||||||
timelineWidget->addAction(aReplaySkipForwardBig);
|
timelineWidget->addAction(aReplaySkipForwardBig);
|
||||||
connect(aReplaySkipForwardBig, &QAction::triggered, this,
|
connect(aReplaySkipForwardBig, &QAction::triggered, this,
|
||||||
[=]() { timelineWidget->skipByAmount(BIG_SKIP_AMOUNT_MS); });
|
[=]() { timelineWidget->skipByAmount(ReplayTimelineWidget::BIG_SKIP_MS); });
|
||||||
|
|
||||||
aReplaySkipBackwardBig = new QAction(timelineWidget);
|
aReplaySkipBackwardBig = new QAction(timelineWidget);
|
||||||
timelineWidget->addAction(aReplaySkipBackwardBig);
|
timelineWidget->addAction(aReplaySkipBackwardBig);
|
||||||
connect(aReplaySkipBackwardBig, &QAction::triggered, this,
|
connect(aReplaySkipBackwardBig, &QAction::triggered, this,
|
||||||
[=]() { timelineWidget->skipByAmount(-BIG_SKIP_AMOUNT_MS); });
|
[=]() { timelineWidget->skipByAmount(-ReplayTimelineWidget::BIG_SKIP_MS); });
|
||||||
|
|
||||||
// buttons
|
// buttons
|
||||||
replayPlayButton = new QToolButton;
|
replayPlayButton = new QToolButton;
|
||||||
|
|
|
||||||
|
|
@ -142,8 +142,6 @@ private:
|
||||||
QStackedWidget *mainWidget;
|
QStackedWidget *mainWidget;
|
||||||
|
|
||||||
// Replay related members
|
// Replay related members
|
||||||
static const int SMALL_SKIP_AMOUNT_MS = 1000;
|
|
||||||
static const int BIG_SKIP_AMOUNT_MS = 10000;
|
|
||||||
GameReplay *replay;
|
GameReplay *replay;
|
||||||
int currentReplayStep;
|
int currentReplayStep;
|
||||||
QList<int> replayTimeline;
|
QList<int> replayTimeline;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue