Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rewind speed feature #2902

Merged
merged 2 commits into from
Apr 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/mgba/core/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ struct mCoreOptions {
int frameskip;
bool rewindEnable;
int rewindBufferCapacity;
int rewindRatio;
martinmurtiono marked this conversation as resolved.
Show resolved Hide resolved
float fpsTarget;
size_t audioBuffers;
unsigned sampleRate;
Expand Down
1 change: 1 addition & 0 deletions include/mgba/core/rewind.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct mCoreRewindContext {
size_t size;
struct VFile* previousState;
struct VFile* currentState;
int rewindFrameCounter;

#ifndef DISABLE_THREADING
bool onThread;
Expand Down
2 changes: 2 additions & 0 deletions src/core/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ void mCoreConfigMap(const struct mCoreConfig* config, struct mCoreOptions* opts)
_lookupIntValue(config, "frameskip", &opts->frameskip);
_lookupIntValue(config, "volume", &opts->volume);
_lookupIntValue(config, "rewindBufferCapacity", &opts->rewindBufferCapacity);
_lookupIntValue(config, "rewindRatio", &opts->rewindRatio);
martinmurtiono marked this conversation as resolved.
Show resolved Hide resolved
_lookupFloatValue(config, "fpsTarget", &opts->fpsTarget);
unsigned audioBuffers;
if (_lookupUIntValue(config, "audioBuffers", &audioBuffers)) {
Expand Down Expand Up @@ -448,6 +449,7 @@ void mCoreConfigLoadDefaults(struct mCoreConfig* config, const struct mCoreOptio
ConfigurationSetIntValue(&config->defaultsTable, 0, "frameskip", opts->frameskip);
ConfigurationSetIntValue(&config->defaultsTable, 0, "rewindEnable", opts->rewindEnable);
ConfigurationSetIntValue(&config->defaultsTable, 0, "rewindBufferCapacity", opts->rewindBufferCapacity);
ConfigurationSetIntValue(&config->defaultsTable, 0, "rewindRatio", opts->rewindRatio);
martinmurtiono marked this conversation as resolved.
Show resolved Hide resolved
ConfigurationSetFloatValue(&config->defaultsTable, 0, "fpsTarget", opts->fpsTarget);
ConfigurationSetUIntValue(&config->defaultsTable, 0, "audioBuffers", opts->audioBuffers);
ConfigurationSetUIntValue(&config->defaultsTable, 0, "sampleRate", opts->sampleRate);
Expand Down
1 change: 1 addition & 0 deletions src/core/rewind.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ void mCoreRewindContextInit(struct mCoreRewindContext* context, size_t entries,
context->previousState = VFileMemChunk(0, 0);
context->currentState = VFileMemChunk(0, 0);
context->size = 0;
context->rewindFrameCounter = 0;
#ifndef DISABLE_THREADING
context->onThread = onThread;
context->ready = false;
Expand Down
5 changes: 4 additions & 1 deletion src/core/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ void _frameStarted(void* context) {
}
if (thread->core->opts.rewindEnable && thread->core->opts.rewindBufferCapacity > 0) {
if (!thread->impl->rewinding || !mCoreRewindRestore(&thread->impl->rewind, thread->core)) {
mCoreRewindAppend(&thread->impl->rewind, thread->core);
if (thread->impl->rewind.rewindFrameCounter % thread->core->opts.rewindRatio == 0) {
mCoreRewindAppend(&thread->impl->rewind, thread->core);
}
thread->impl->rewind.rewindFrameCounter++;
martinmurtiono marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/platform/qt/ConfigController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ ConfigController::ConfigController(QObject* parent)
m_opts.logLevel = mLOG_WARN | mLOG_ERROR | mLOG_FATAL;
m_opts.rewindEnable = false;
m_opts.rewindBufferCapacity = 300;
m_opts.rewindRatio = 1;
martinmurtiono marked this conversation as resolved.
Show resolved Hide resolved
m_opts.useBios = true;
m_opts.suspendScreensaver = true;
m_opts.lockAspectRatio = true;
Expand Down
2 changes: 2 additions & 0 deletions src/platform/qt/SettingsView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ void SettingsView::updateConfig() {
saveSetting("fastForwardMute", m_ui.muteFf);
saveSetting("rewindEnable", m_ui.rewind);
saveSetting("rewindBufferCapacity", m_ui.rewindCapacity);
saveSetting("rewindRatio", m_ui.rewindRatio);
martinmurtiono marked this conversation as resolved.
Show resolved Hide resolved
saveSetting("resampleVideo", m_ui.resampleVideo);
saveSetting("allowOpposingDirections", m_ui.allowOpposingDirections);
saveSetting("suspendScreensaver", m_ui.suspendScreensaver);
Expand Down Expand Up @@ -708,6 +709,7 @@ void SettingsView::reloadConfig() {
loadSetting("fastForwardMute", m_ui.muteFf, m_ui.mute->isChecked());
loadSetting("rewindEnable", m_ui.rewind);
loadSetting("rewindBufferCapacity", m_ui.rewindCapacity);
loadSetting("rewindRatio", m_ui.rewindRatio);
martinmurtiono marked this conversation as resolved.
Show resolved Hide resolved
loadSetting("resampleVideo", m_ui.resampleVideo);
loadSetting("allowOpposingDirections", m_ui.allowOpposingDirections);
loadSetting("suspendScreensaver", m_ui.suspendScreensaver);
Expand Down
42 changes: 36 additions & 6 deletions src/platform/qt/SettingsView.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1195,21 +1195,51 @@
</item>
</layout>
</item>
<item row="6" column="0" colspan="2">
<item row="6" column="0">
<widget class="QLabel" name="label_54">
<property name="text">
<string>Rewind speed:</string>
</property>
</widget>
</item>
<item row="6" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_23">
<item>
<widget class="QDoubleSpinBox" name="rewindRatio">
martinmurtiono marked this conversation as resolved.
Show resolved Hide resolved
<property name="suffix">
<string notr="true">×</string>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>10</number>
</property>
<property name="singleStep">
<number>1</number>
</property>
<property name="value">
<number>1</number>
</property>
</widget>
</item>
</layout>
</item>
<item row="7" column="0" colspan="2">
<widget class="Line" name="line_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="7" column="0">
<item row="8" column="0">
<widget class="QLabel" name="label_15">
<property name="text">
<string>Idle loops:</string>
</property>
</widget>
</item>
<item row="7" column="1">
<item row="8" column="1">
<widget class="QComboBox" name="idleOptimization">
<item>
<property name="text">
Expand All @@ -1228,21 +1258,21 @@
</item>
</widget>
</item>
<item row="8" column="1">
<item row="9" column="1">
<widget class="QCheckBox" name="preload">
<property name="text">
<string>Preload entire ROM into memory</string>
</property>
</widget>
</item>
<item row="9" column="1">
<item row="10" column="1">
<widget class="QCheckBox" name="forceGbp">
<property name="text">
<string>Enable Game Boy Player features by default</string>
</property>
</widget>
</item>
<item row="10" column="1">
<item row="11" column="1">
<widget class="QCheckBox" name="vbaBugCompat">
<property name="text">
<string>Enable VBA bug compatibility in ROM hacks</string>
Expand Down
5 changes: 5 additions & 0 deletions src/platform/qt/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1813,6 +1813,11 @@ void Window::setupOptions() {
reloadConfig();
}, this);

ConfigOption* rewindRatio = m_config->addOption("rewindRatio");
martinmurtiono marked this conversation as resolved.
Show resolved Hide resolved
rewindRatio->connect([this](const QVariant&) {
reloadConfig();
}, this);

ConfigOption* allowOpposingDirections = m_config->addOption("allowOpposingDirections");
allowOpposingDirections->connect([this](const QVariant&) {
reloadConfig();
Expand Down
1 change: 1 addition & 0 deletions src/platform/sdl/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ int main(int argc, char** argv) {
.useBios = true,
.rewindEnable = true,
.rewindBufferCapacity = 600,
.rewindRatio = 1,
martinmurtiono marked this conversation as resolved.
Show resolved Hide resolved
.audioBuffers = 1024,
.videoSync = false,
.audioSync = true,
Expand Down