all repos — mgba @ 7bc834526a4475607b8a5d998b33cad6877ed6f7

mGBA Game Boy Advance Emulator

Qt: Ability to cap fast forward speed (fixes B#218)
Jeffrey Pfau jeffrey@endrift.com
Sat, 23 May 2015 22:59:07 -0700
commit

7bc834526a4475607b8a5d998b33cad6877ed6f7

parent

9085bbb8a4f0c40bbc4965bb2cf89343e940551a

M CHANGESCHANGES

@@ -17,6 +17,7 @@ - Memory inspector

- Screensaver can now be suspended while a game is running - Load/save the most recent savestate slot - Support varible speed (PWM) rumble + - Ability to cap fast forward speed Bugfixes: - ARM7: Fix SWI and IRQ timings - GBA Audio: Force audio FIFOs to 32-bit
M src/platform/qt/GameController.cppsrc/platform/qt/GameController.cpp

@@ -41,8 +41,10 @@ , m_audioThread(new QThread(this))

, m_audioProcessor(AudioProcessor::create()) , m_videoSync(VIDEO_SYNC) , m_audioSync(AUDIO_SYNC) + , m_fpsTarget(-1) , m_turbo(false) , m_turboForced(false) + , m_turboSpeed(-1) , m_inputController(nullptr) , m_multiplayer(nullptr) , m_stateSlot(1)

@@ -99,6 +101,7 @@ context->gba->luminanceSource = &controller->m_lux;

context->gba->rtcSource = &controller->m_rtc; context->gba->rumble = controller->m_inputController->rumble(); context->gba->rotationSource = controller->m_inputController->rotationSource(); + controller->m_fpsTarget = context->fpsTarget; controller->gameStarted(context); };

@@ -487,7 +490,11 @@ }

void GameController::setFPSTarget(float fps) { threadInterrupt(); + m_fpsTarget = fps; m_threadContext.fpsTarget = fps; + if (m_turbo && m_turboSpeed > 0) { + m_threadContext.fpsTarget *= m_turboSpeed; + } redoSamples(m_audioProcessor->getBufferSamples()); threadContinue(); QMetaObject::invokeMethod(m_audioProcessor, "inputParametersChanged");

@@ -577,9 +584,30 @@ return;

} m_turbo = set; m_turboForced = set && forced; + enableTurbo(); +} + +void GameController::setTurboSpeed(float ratio) { + m_turboSpeed = ratio; + enableTurbo(); +} + +void GameController::enableTurbo() { threadInterrupt(); - m_threadContext.sync.audioWait = set ? false : m_audioSync; - m_threadContext.sync.videoFrameWait = set ? false : m_videoSync; + if (!m_turbo) { + m_threadContext.fpsTarget = m_fpsTarget; + m_threadContext.sync.audioWait = m_audioSync; + m_threadContext.sync.videoFrameWait = m_videoSync; + redoSamples(m_audioProcessor->getBufferSamples()); + } else if (m_turboSpeed <= 0) { + m_threadContext.sync.audioWait = false; + m_threadContext.sync.videoFrameWait = false; + } else { + m_threadContext.fpsTarget = m_fpsTarget * m_turboSpeed; + m_threadContext.sync.audioWait = true; + m_threadContext.sync.videoFrameWait = false; + redoSamples(m_audioProcessor->getBufferSamples()); + } threadContinue(); }
M src/platform/qt/GameController.hsrc/platform/qt/GameController.h

@@ -121,6 +121,7 @@ void setFrameskip(int);

void setVolume(int); void setMute(bool); void setTurbo(bool, bool forced = true); + void setTurboSpeed(float ratio = -1); void setAVStream(GBAAVStream*); void clearAVStream(); void reloadAudioDriver();

@@ -151,6 +152,7 @@

private: void updateKeys(); void redoSamples(int samples); + void enableTurbo(); uint32_t* m_drawContext; GBAThread m_threadContext;

@@ -177,8 +179,10 @@ bool m_pauseAfterFrame;

bool m_videoSync; bool m_audioSync; + float m_fpsTarget; bool m_turbo; bool m_turboForced; + float m_turboSpeed; int m_stateSlot;
M src/platform/qt/Window.cppsrc/platform/qt/Window.cpp

@@ -787,6 +787,19 @@ turbo->setShortcut(tr("Shift+Tab"));

connect(turbo, SIGNAL(triggered(bool)), m_controller, SLOT(setTurbo(bool))); addControlledAction(emulationMenu, turbo, "fastForward"); + QMenu* ffspeedMenu = emulationMenu->addMenu(tr("Fast forward speed")); + ConfigOption* ffspeed = m_config->addOption("fastForwardRatio"); + ffspeed->connect([this](const QVariant& value) { + m_controller->setTurboSpeed(value.toFloat()); + }, this); + ffspeed->addValue(tr("Unbounded"), -1.0f, ffspeedMenu); + ffspeed->setValue(QVariant(-1.0f)); + ffspeedMenu->addSeparator(); + for (i = 2; i < 6; ++i) { + ffspeed->addValue(tr("%0x").arg(i), i, ffspeedMenu); + } + m_config->updateOption("fastForwardRatio"); + QAction* rewind = new QAction(tr("Re&wind"), emulationMenu); rewind->setShortcut(tr("`")); connect(rewind, SIGNAL(triggered()), m_controller, SLOT(rewind()));