all repos — mgba @ f97ba6517b32f5043a833cd5f8defb30987a7086

mGBA Game Boy Advance Emulator

Qt: Expose rewind (fixes #136)
Jeffrey Pfau jeffrey@endrift.com
Mon, 05 Jan 2015 23:12:44 -0800
commit

f97ba6517b32f5043a833cd5f8defb30987a7086

parent

d6e24b20515510fab670f40b8d657cc43adc17fe

M CHANGESCHANGES

@@ -13,6 +13,7 @@ - Better audio resampling via blip-buf

- Game Pak overrides dialog for setting savetype and sensor values - Support for games using the tilt sensor - Remappable shortcuts for keyboard and gamepad + - Rewinding of emulation Bugfixes: - Qt: Fix issue with set frame sizes being the wrong height - Qt: Fix emulator crashing when full screen if a game is not running
M README.mdREADME.md

@@ -23,6 +23,7 @@ - Remappable controls for both keyboards and gamepads.

- Loading from ZIP files. - IPS and UPS patch support. - Game debugging via a command-line interface (not available with Qt port) and GDB remote support. +- Configurable emulation rewinding. ### Planned features
M src/platform/qt/GameController.cppsrc/platform/qt/GameController.cpp

@@ -298,6 +298,32 @@ setPaused(false);

m_pauseMutex.unlock(); } +void GameController::setRewind(bool enable, int capacity, int interval) { + if (m_gameOpen) { + threadInterrupt(); + GBARewindSettingsChanged(&m_threadContext, enable ? capacity : 0, enable ? interval : 0); + threadContinue(); + } else { + if (enable) { + m_threadContext.rewindBufferInterval = interval; + m_threadContext.rewindBufferCapacity = capacity; + } else { + m_threadContext.rewindBufferInterval = 0; + m_threadContext.rewindBufferCapacity = 0; + } + } +} + +void GameController::rewind(int states) { + threadInterrupt(); + if (!states) { + GBARewindAll(&m_threadContext); + } else { + GBARewind(&m_threadContext, states); + } + threadContinue(); +} + void GameController::keyPressed(int key) { int mappedKey = 1 << key; m_activeKeys |= mappedKey;
M src/platform/qt/GameController.hsrc/platform/qt/GameController.h

@@ -80,6 +80,8 @@ void closeGame();

void setPaused(bool paused); void reset(); void frameAdvance(); + void setRewind(bool enable, int capacity, int interval); + void rewind(int states = 0); void keyPressed(int key); void keyReleased(int key); void clearKeys();
M src/platform/qt/SettingsView.cppsrc/platform/qt/SettingsView.cpp

@@ -25,6 +25,7 @@ loadSetting("audioSync", m_ui.audioSync);

loadSetting("frameskip", m_ui.frameskip); loadSetting("fpsTarget", m_ui.fpsTarget); loadSetting("lockAspectRatio", m_ui.lockAspectRatio); + loadSetting("rewindEnable", m_ui.rewind); loadSetting("rewindBufferInterval", m_ui.rewindInterval); loadSetting("rewindBufferCapacity", m_ui.rewindCapacity); loadSetting("resampleVideo", m_ui.resampleVideo);

@@ -49,6 +50,7 @@ saveSetting("audioSync", m_ui.audioSync);

saveSetting("frameskip", m_ui.frameskip); saveSetting("fpsTarget", m_ui.fpsTarget); saveSetting("lockAspectRatio", m_ui.lockAspectRatio); + saveSetting("rewindEnable", m_ui.rewind); saveSetting("rewindBufferInterval", m_ui.rewindInterval); saveSetting("rewindBufferCapacity", m_ui.rewindCapacity); saveSetting("resampleVideo", m_ui.resampleVideo);
M src/platform/qt/SettingsView.uisrc/platform/qt/SettingsView.ui

@@ -244,9 +244,6 @@ </widget>

</item> <item row="13" column="1"> <widget class="QCheckBox" name="rewind"> - <property name="enabled"> - <bool>false</bool> - </property> <property name="text"> <string>Enable rewind</string> </property>
M src/platform/qt/Window.cppsrc/platform/qt/Window.cpp

@@ -144,6 +144,7 @@ m_controller->setFrameskip(opts->frameskip);

m_controller->setAudioSync(opts->audioSync); m_controller->setVideoSync(opts->videoSync); m_controller->setSkipBIOS(opts->skipBios); + m_controller->setRewind(opts->rewindEnable, opts->rewindBufferCapacity, opts->rewindBufferInterval); m_display->lockAspectRatio(opts->lockAspectRatio); m_display->filter(opts->resampleVideo);

@@ -522,6 +523,12 @@ turbo->setShortcut(tr("Shift+Tab"));

connect(turbo, SIGNAL(triggered(bool)), m_controller, SLOT(setTurbo(bool))); addControlledAction(emulationMenu, turbo, "fastForward"); + QAction* rewind = new QAction(tr("Re&wind"), emulationMenu); + rewind->setShortcut(tr("`")); + connect(rewind, SIGNAL(triggered()), m_controller, SLOT(rewind())); + m_gameActions.append(rewind); + addControlledAction(emulationMenu, rewind, "rewind"); + ConfigOption* videoSync = m_config->addOption("videoSync"); videoSync->addBoolean(tr("Sync to &video"), emulationMenu); videoSync->connect([this](const QVariant& value) { m_controller->setVideoSync(value.toBool()); });

@@ -648,6 +655,15 @@ #endif

ConfigOption* skipBios = m_config->addOption("skipBios"); skipBios->connect([this](const QVariant& value) { m_controller->setSkipBIOS(value.toBool()); }); + + ConfigOption* rewindEnable = m_config->addOption("rewindEnable"); + rewindEnable->connect([this](const QVariant& value) { m_controller->setRewind(value.toBool(), m_config->getOption("rewindBufferCapacity").toInt(), m_config->getOption("rewindBufferInterval").toInt()); }); + + ConfigOption* rewindBufferCapacity = m_config->addOption("rewindBufferCapacity"); + rewindBufferCapacity->connect([this](const QVariant& value) { m_controller->setRewind(m_config->getOption("rewindEnable").toInt(), value.toInt(), m_config->getOption("rewindBufferInterval").toInt()); }); + + ConfigOption* rewindBufferInterval = m_config->addOption("rewindBufferInterval"); + rewindBufferInterval->connect([this](const QVariant& value) { m_controller->setRewind(m_config->getOption("rewindEnable").toInt(), m_config->getOption("rewindBufferCapacity").toInt(), value.toInt()); }); QMenu* other = new QMenu(tr("Other"), this); m_shortcutController->addMenu(other);