Add FPS target options
Jeffrey Pfau jeffrey@endrift.com
Tue, 22 Jul 2014 03:14:28 -0700
7 files changed,
39 insertions(+),
1 deletions(-)
M
src/platform/qt/AudioDevice.cpp
→
src/platform/qt/AudioDevice.cpp
@@ -20,7 +20,7 @@ if (!GBAThreadHasStarted(m_context)) {
return; } // TODO: make this thread-safe - m_ratio = GBAAudioCalculateRatio(&m_context->gba->audio, 60, format.sampleRate()); + m_ratio = GBAAudioCalculateRatio(&m_context->gba->audio, m_context->fpsTarget, format.sampleRate()); } void AudioDevice::setInput(GBAThread* input) {
M
src/platform/qt/AudioProcessor.cpp
→
src/platform/qt/AudioProcessor.cpp
@@ -61,3 +61,7 @@ void AudioProcessor::setBufferSamples(int samples) {
QAudioFormat format = m_audioOutput->format(); m_audioOutput->setBufferSize(samples * format.channelCount() * format.sampleSize() / 8); } + +void AudioProcessor::inputParametersChanged() { + m_device->setFormat(m_audioOutput->format()); +}
M
src/platform/qt/AudioProcessor.h
→
src/platform/qt/AudioProcessor.h
@@ -23,6 +23,7 @@ void start();
void pause(); void setBufferSamples(int samples); + void inputParametersChanged(); private: GBAThread* m_context;
M
src/platform/qt/GameController.cpp
→
src/platform/qt/GameController.cpp
@@ -181,6 +181,13 @@ GBAThreadContinue(&m_threadContext);
QMetaObject::invokeMethod(m_audioProcessor, "setBufferSamples", Q_ARG(int, samples)); } +void GameController::setFPSTarget(float fps) { + GBAThreadInterrupt(&m_threadContext); + m_threadContext.fpsTarget = fps; + GBAThreadContinue(&m_threadContext); + QMetaObject::invokeMethod(m_audioProcessor, "inputParametersChanged"); +} + void GameController::updateKeys() { int activeKeys = m_activeKeys; #ifdef BUILD_SDL
M
src/platform/qt/GameController.h
→
src/platform/qt/GameController.h
@@ -55,6 +55,7 @@ void frameAdvance();
void keyPressed(int key); void keyReleased(int key); void setAudioBufferSamples(int samples); + void setFPSTarget(float fps); #ifdef BUILD_SDL private slots:
M
src/platform/qt/Window.cpp
→
src/platform/qt/Window.cpp
@@ -29,6 +29,7 @@ connect(m_controller, SIGNAL(gameStopped(GBAThread*)), this, SLOT(gameStopped()));
connect(this, SIGNAL(startDrawing(const uint32_t*, GBAThread*)), m_display, SLOT(startDrawing(const uint32_t*, GBAThread*)), Qt::QueuedConnection); connect(this, SIGNAL(shutdown()), m_display, SLOT(stopDrawing())); connect(this, SIGNAL(audioBufferSamplesChanged(int)), m_controller, SLOT(setAudioBufferSamples(int))); + connect(this, SIGNAL(fpsTargetChanged(float)), m_controller, SLOT(setFPSTarget(float))); setupMenu(menuBar()); }@@ -166,6 +167,29 @@ frameAdvance->setShortcut(tr("Ctrl+N"));
connect(frameAdvance, SIGNAL(triggered()), m_controller, SLOT(frameAdvance())); m_gameActions.append(frameAdvance); emulationMenu->addAction(frameAdvance); + + QMenu* target = emulationMenu->addMenu("FPS target"); + QAction* setTarget = new QAction(tr("15"), nullptr); + connect(setTarget, &QAction::triggered, [this]() { emit fpsTargetChanged(15); }); + target->addAction(setTarget); + setTarget = new QAction(tr("30"), nullptr); + connect(setTarget, &QAction::triggered, [this]() { emit fpsTargetChanged(30); }); + target->addAction(setTarget); + setTarget = new QAction(tr("45"), nullptr); + connect(setTarget, &QAction::triggered, [this]() { emit fpsTargetChanged(45); }); + target->addAction(setTarget); + setTarget = new QAction(tr("60"), nullptr); + connect(setTarget, &QAction::triggered, [this]() { emit fpsTargetChanged(60); }); + target->addAction(setTarget); + setTarget = new QAction(tr("90"), nullptr); + connect(setTarget, &QAction::triggered, [this]() { emit fpsTargetChanged(90); }); + target->addAction(setTarget); + setTarget = new QAction(tr("120"), nullptr); + connect(setTarget, &QAction::triggered, [this]() { emit fpsTargetChanged(120); }); + target->addAction(setTarget); + setTarget = new QAction(tr("240"), nullptr); + connect(setTarget, &QAction::triggered, [this]() { emit fpsTargetChanged(240); }); + target->addAction(setTarget); QMenu* soundMenu = menubar->addMenu(tr("&Sound")); QMenu* buffersMenu = soundMenu->addMenu(tr("Buffer &size"));
M
src/platform/qt/Window.h
→
src/platform/qt/Window.h
@@ -40,6 +40,7 @@ virtual void closeEvent(QCloseEvent*) override;
signals: void audioBufferSamplesChanged(int samples); + void fpsTargetChanged(float target); private slots: void gameStarted(GBAThread*);