mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-21 17:15:09 -07:00
[Replay] Implement option to skip empty sections (#7069)
Some checks are pending
Build Desktop / Configure (push) Waiting to run
Build Desktop / Debian 13 (push) Blocked by required conditions
Build Desktop / Debian 12 (push) Blocked by required conditions
Build Desktop / Fedora 44 (push) Blocked by required conditions
Build Desktop / Fedora 43 (push) Blocked by required conditions
Build Desktop / Servatrice_Debian 12 (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 (push) Blocked by required conditions
Build Desktop / Ubuntu 24.04 (push) Blocked by required conditions
Build Desktop / Arch (push) Blocked by required conditions
Build Desktop / macOS 14 (push) Blocked by required conditions
Build Desktop / macOS 15 (push) Blocked by required conditions
Build Desktop / macOS 13 Intel (push) Blocked by required conditions
Build Desktop / macOS 15 Debug (push) Blocked by required conditions
Build Desktop / Windows 10 (push) Blocked by required conditions
Build Docker Image / amd64 & arm64 (push) Waiting to run
Some checks are pending
Build Desktop / Configure (push) Waiting to run
Build Desktop / Debian 13 (push) Blocked by required conditions
Build Desktop / Debian 12 (push) Blocked by required conditions
Build Desktop / Fedora 44 (push) Blocked by required conditions
Build Desktop / Fedora 43 (push) Blocked by required conditions
Build Desktop / Servatrice_Debian 12 (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 (push) Blocked by required conditions
Build Desktop / Ubuntu 24.04 (push) Blocked by required conditions
Build Desktop / Arch (push) Blocked by required conditions
Build Desktop / macOS 14 (push) Blocked by required conditions
Build Desktop / macOS 15 (push) Blocked by required conditions
Build Desktop / macOS 13 Intel (push) Blocked by required conditions
Build Desktop / macOS 15 Debug (push) Blocked by required conditions
Build Desktop / Windows 10 (push) Blocked by required conditions
Build Docker Image / amd64 & arm64 (push) Waiting to run
* add settings * [Replay] Implement option to skip empty sections * correct starting offset
This commit is contained in:
parent
46bdb6df32
commit
c08dc780a7
8 changed files with 95 additions and 0 deletions
|
|
@ -3,9 +3,11 @@
|
|||
#include "../../../client/settings/cache_settings.h"
|
||||
|
||||
#include <QTimer>
|
||||
#include <libcockatrice/protocol/get_pb_extension.h>
|
||||
#include <libcockatrice/settings/interface_settings.h>
|
||||
|
||||
static constexpr int TIMER_INTERVAL_MS = 200;
|
||||
static constexpr int EMPTY_SECTION_MARGIN_MS = 500;
|
||||
|
||||
static QList<int> createReplayTimeline(const GameReplay *replay)
|
||||
{
|
||||
|
|
@ -119,6 +121,10 @@ void ReplayManager::replayTimerTimeout()
|
|||
processNewEvents(NORMAL_PLAYBACK);
|
||||
|
||||
timeChanged(currentVisualTime);
|
||||
|
||||
if (skipEmptySections) {
|
||||
handleSkipEmptySection();
|
||||
}
|
||||
}
|
||||
|
||||
/** @brief Processes all unprocessed events up to the current time. */
|
||||
|
|
@ -149,6 +155,51 @@ void ReplayManager::processNewEvents(PlaybackMode playbackMode)
|
|||
}
|
||||
}
|
||||
|
||||
static bool hasMeaningfulEvent(const GameEventContainer &cont)
|
||||
{
|
||||
const int eventListSize = cont.event_list_size();
|
||||
for (int i = 0; i < eventListSize; ++i) {
|
||||
const GameEvent &event = cont.event_list(i);
|
||||
const auto eventType = static_cast<GameEvent::GameEventType>(getPbExtension(event));
|
||||
|
||||
if (eventType != GameEvent::PLAYER_PROPERTIES_CHANGED) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ReplayManager::handleSkipEmptySection()
|
||||
{
|
||||
if (currentEvent == replayTimeline.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// find most recent meaningful event
|
||||
int prevEvent = std::max(0, currentEvent - 1);
|
||||
for (; prevEvent > 0 && !hasMeaningfulEvent(replay->event_list(prevEvent)); --prevEvent) {
|
||||
}
|
||||
|
||||
int prevEventTime = replayTimeline.value(prevEvent);
|
||||
if (currentVisualTime - prevEventTime <= EMPTY_SECTION_MARGIN_MS) {
|
||||
return;
|
||||
}
|
||||
|
||||
// find next earliest meaningful event
|
||||
int nextEvent = currentEvent;
|
||||
for (; nextEvent < replayTimeline.size() - 1 && !hasMeaningfulEvent(replay->event_list(nextEvent)); ++nextEvent) {
|
||||
}
|
||||
|
||||
int nextEventTime = replayTimeline.value(nextEvent);
|
||||
if (nextEventTime - currentVisualTime <= EMPTY_SECTION_MARGIN_MS) {
|
||||
return;
|
||||
}
|
||||
|
||||
// skip forward if we're not within margin of either event
|
||||
skipToTime(nextEventTime - EMPTY_SECTION_MARGIN_MS, false);
|
||||
}
|
||||
|
||||
void ReplayManager::setTimeScaleFactor(qreal _timeScaleFactor)
|
||||
{
|
||||
timeScaleFactor = _timeScaleFactor;
|
||||
|
|
@ -156,6 +207,11 @@ void ReplayManager::setTimeScaleFactor(qreal _timeScaleFactor)
|
|||
replayTimer->setInterval(interval);
|
||||
}
|
||||
|
||||
void ReplayManager::setSkipEmptySections(bool value)
|
||||
{
|
||||
skipEmptySections = value;
|
||||
}
|
||||
|
||||
void ReplayManager::startReplay()
|
||||
{
|
||||
replayTimer->start();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue