summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Gallet <clement.gallet@ens-lyon.org>2024-02-23 17:17:41 +0100
committerClément Gallet <clement.gallet@ens-lyon.org>2024-02-23 17:17:41 +0100
commit3f65c4b951c2d8a1446a3afc996ba0f2a8e03f58 (patch)
tree5bc85d036993990a30c49d47ad96f5b929422f12
parent218e86aee865e930724d448ac5998b00e25df414 (diff)
Add rewind to RMB + wheel (#594)
-rw-r--r--CHANGELOG.md1
-rw-r--r--src/program/Context.h3
-rw-r--r--src/program/GameEvents.cpp20
-rw-r--r--src/program/GameLoop.cpp11
-rw-r--r--src/program/ui/InputEditorModel.cpp20
-rw-r--r--src/program/ui/InputEditorView.cpp17
6 files changed, 51 insertions, 21 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 90ef38a5..878d5fd8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,6 +20,7 @@
* Disable a dotnet speed check (#590)
* Hook getrandom()
* Implement mouse wheel input
+* RMB + wheel does advance and rewind frames (#594)
### Changed
diff --git a/src/program/Context.h b/src/program/Context.h
index 926f2e90..0c95af58 100644
--- a/src/program/Context.h
+++ b/src/program/Context.h
@@ -118,6 +118,9 @@ struct Context {
/* A frame number when the game pauses */
uint64_t pause_frame = 0;
+ /* A frame number that we are seeking to */
+ uint64_t seek_frame = 0;
+
/* Can we use incremental savestates? */
bool is_soft_dirty = false;
diff --git a/src/program/GameEvents.cpp b/src/program/GameEvents.cpp
index 436e7ffe..70d417e8 100644
--- a/src/program/GameEvents.cpp
+++ b/src/program/GameEvents.cpp
@@ -72,6 +72,15 @@ bool GameEvents::processEvent(GameEvents::EventType type, const HotKey &hk)
/* Advance a frame */
if (context->config.sc.running) {
context->config.sc.running = false;
+
+ /* Disable seeking */
+ if (context->seek_frame) {
+ context->seek_frame = 0;
+
+ /* Disable fast-forward */
+ context->config.sc.fastforward = false;
+ }
+
emit sharedConfigChanged();
context->config.sc_modified = true;
}
@@ -81,6 +90,15 @@ bool GameEvents::processEvent(GameEvents::EventType type, const HotKey &hk)
case HOTKEY_PLAYPAUSE:
/* Toggle between play and pause */
context->config.sc.running = !context->config.sc.running;
+
+ /* Disable seeking */
+ if (!context->config.sc.running && context->seek_frame) {
+ context->seek_frame = 0;
+
+ /* Disable fast-forward */
+ context->config.sc.fastforward = false;
+ }
+
emit sharedConfigChanged();
context->config.sc_modified = true;
return false;
@@ -230,7 +248,7 @@ bool GameEvents::processEvent(GameEvents::EventType type, const HotKey &hk)
/* Fast-forward to savestate frame */
context->config.sc.recording = SharedConfig::RECORDING_READ;
context->config.sc.movie_framecount = movie->inputs->nbFrames();
- context->pause_frame = movie->header->savestate_framecount;
+ context->seek_frame = movie->header->savestate_framecount;
context->config.sc.running = true;
context->config.sc_modified = true;
diff --git a/src/program/GameLoop.cpp b/src/program/GameLoop.cpp
index 0af26cf3..fcf21192 100644
--- a/src/program/GameLoop.cpp
+++ b/src/program/GameLoop.cpp
@@ -152,6 +152,17 @@ void GameLoop::start()
}
}
+ if (context->seek_frame == (context->framecount + 1)) {
+ /* Disable seek frame */
+ context->seek_frame = 0;
+
+ /* Pause and disable fast-forward */
+ context->config.sc.running = false;
+ context->config.sc.fastforward = false;
+ context->config.sc_modified = true;
+ emit sharedConfigChanged();
+ }
+
Lua::Callbacks::call(Lua::NamedLuaFunction::CallbackFrame);
endFrameMessages(ai);
diff --git a/src/program/ui/InputEditorModel.cpp b/src/program/ui/InputEditorModel.cpp
index 9ebea0e4..6f9fccdf 100644
--- a/src/program/ui/InputEditorModel.cpp
+++ b/src/program/ui/InputEditorModel.cpp
@@ -410,10 +410,10 @@ bool InputEditorModel::setData(const QModelIndex &index, const QVariant &value,
if (value.toInt() == ai.getInput(si))
return false;
- /* Update the pause frame if we changed an earlier frame */
- if ((context->pause_frame != 0) && !context->config.editor_rewind_seek
- && (row < context->pause_frame)) {
- context->pause_frame = row;
+ /* Update the seek frame if we changed an earlier frame */
+ if ((context->seek_frame) && !context->config.editor_rewind_seek
+ && (row < context->seek_frame)) {
+ context->seek_frame = row;
}
/* Modifying the movie is only performed by the main thread */
@@ -497,9 +497,9 @@ bool InputEditorModel::toggleInput(const QModelIndex &index)
}
/* Update the pause frame if we changed an earlier frame */
- if ((context->pause_frame != 0) && !context->config.editor_rewind_seek
- && (row < context->pause_frame)) {
- context->pause_frame = row;
+ if ((context->seek_frame) && !context->config.editor_rewind_seek
+ && (row < context->seek_frame)) {
+ context->seek_frame = row;
}
/* Modifying the movie is only performed by the main thread */
@@ -1066,11 +1066,11 @@ bool InputEditorModel::rewind(uint64_t framecount, bool toggle)
if (framecount > state_framecount) {
/* Seek to either the modified frame or the current frame */
if (toggle && context->config.editor_rewind_seek)
- context->pause_frame = current_framecount;
+ context->seek_frame = current_framecount;
else
- context->pause_frame = framecount;
+ context->seek_frame = framecount;
- /* Freeze scroll until pause_frame is reached */
+ /* Freeze scroll until seek_frame is reached */
freeze_scroll = true;
if (context->config.editor_rewind_fastforward)
diff --git a/src/program/ui/InputEditorView.cpp b/src/program/ui/InputEditorView.cpp
index d83487b1..ec29d4ed 100644
--- a/src/program/ui/InputEditorView.cpp
+++ b/src/program/ui/InputEditorView.cpp
@@ -219,19 +219,10 @@ void InputEditorView::update()
/* Check if scroll is frozen because of a rewind. Disable scroll freeze when
* reaching the paused frame. */
if (inputEditorModel->isScrollFreeze()) {
- static bool last_running = false;
- if (context->pause_frame == 0) {
+ if (context->seek_frame == 0) {
inputEditorModel->setScrollFreeze(false);
autoScroll = false;
}
- /* If user has paused during rewind, we must disable scroll freeze and
- * scroll to current frame if necessary */
- else if (!context->config.sc.running && last_running) {
- context->pause_frame = 0;
- inputEditorModel->setScrollFreeze(false);
- }
-
- last_running = context->config.sc.running;
if (inputEditorModel->isScrollFreeze())
return;
@@ -396,6 +387,12 @@ void InputEditorView::wheelEvent(QWheelEvent *event)
context->hotkey_released_queue.push(HOTKEY_FRAMEADVANCE);
}
}
+ else if (event->angleDelta().y() > 0) {
+ /* Only rewind when paused, which should prevent rewinding during the end
+ * of another rewind */
+ if (context->framecount > 0 && !context->config.sc.running)
+ inputEditorModel->rewind(context->framecount - 1, false);
+ }
event->accept();
}