From 6afc00b4723a8141f9b014814fbc37bd4bfa3de9 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Wed, 15 Oct 2014 23:22:30 -0700 Subject: [PATCH] Move state loading/storing into GameController --- src/platform/qt/Display.cpp | 18 ++++++++++++++++++ src/platform/qt/Display.h | 2 ++ src/platform/qt/GameController.cpp | 15 +++++++++++++++ src/platform/qt/GameController.h | 3 +++ src/platform/qt/LoadSaveState.cpp | 7 ++----- src/platform/qt/Window.cpp | 1 + 6 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/platform/qt/Display.cpp b/src/platform/qt/Display.cpp index 566f83ba2..64b04f784 100644 --- a/src/platform/qt/Display.cpp +++ b/src/platform/qt/Display.cpp @@ -55,6 +55,12 @@ void Display::stopDrawing() { } } +void Display::forceDraw() { + if (m_drawThread) { + QMetaObject::invokeMethod(m_painter, "forceDraw", Qt::BlockingQueuedConnection); + } +} + void Display::initializeGL() { glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT); @@ -131,6 +137,18 @@ void Painter::draw() { m_gl->doneCurrent(); } +void Painter::forceDraw() { + m_gl->makeCurrent(); + glViewport(0, 0, m_size.width() * m_gl->devicePixelRatio(), m_size.height() * m_gl->devicePixelRatio()); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_backing); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + if (m_context->sync.videoFrameWait) { + glFlush(); + } + m_gl->swapBuffers(); + m_gl->doneCurrent(); +} + void Painter::stop() { m_drawTimer->stop(); delete m_drawTimer; diff --git a/src/platform/qt/Display.h b/src/platform/qt/Display.h index 77996f1d9..87082c2de 100644 --- a/src/platform/qt/Display.h +++ b/src/platform/qt/Display.h @@ -19,6 +19,7 @@ public: public slots: void startDrawing(const uint32_t* buffer, GBAThread* context); void stopDrawing(); + void forceDraw(); protected: virtual void initializeGL() override; @@ -40,6 +41,7 @@ public: void setBacking(const uint32_t*); public slots: + void forceDraw(); void draw(); void start(); void stop(); diff --git a/src/platform/qt/GameController.cpp b/src/platform/qt/GameController.cpp index 70455a5ba..8f3f22f15 100644 --- a/src/platform/qt/GameController.cpp +++ b/src/platform/qt/GameController.cpp @@ -7,6 +7,7 @@ extern "C" { #include "gba.h" #include "gba-audio.h" +#include "gba-serialize.h" #include "renderers/video-software.h" #include "util/vfs.h" } @@ -203,6 +204,20 @@ void GameController::setFPSTarget(float fps) { QMetaObject::invokeMethod(m_audioProcessor, "inputParametersChanged"); } +void GameController::loadState(int slot) { + GBAThreadInterrupt(&m_threadContext); + GBALoadState(m_threadContext.gba, m_threadContext.stateDir, slot); + GBAThreadContinue(&m_threadContext); + emit stateLoaded(&m_threadContext); + emit frameAvailable(m_drawContext); +} + +void GameController::saveState(int slot) { + GBAThreadInterrupt(&m_threadContext); + GBASaveState(m_threadContext.gba, m_threadContext.stateDir, slot, true); + GBAThreadContinue(&m_threadContext); +} + void GameController::updateKeys() { int activeKeys = m_activeKeys; #ifdef BUILD_SDL diff --git a/src/platform/qt/GameController.h b/src/platform/qt/GameController.h index e168ef49c..0705fda42 100644 --- a/src/platform/qt/GameController.h +++ b/src/platform/qt/GameController.h @@ -46,6 +46,7 @@ signals: void gameStopped(GBAThread*); void gamePaused(GBAThread*); void gameUnpaused(GBAThread*); + void stateLoaded(GBAThread*); void postLog(int level, const QString& log); @@ -59,6 +60,8 @@ public slots: void keyReleased(int key); void setAudioBufferSamples(int samples); void setFPSTarget(float fps); + void loadState(int slot); + void saveState(int slot); #ifdef BUILD_SDL private slots: diff --git a/src/platform/qt/LoadSaveState.cpp b/src/platform/qt/LoadSaveState.cpp index 2f27f3a57..23df83755 100644 --- a/src/platform/qt/LoadSaveState.cpp +++ b/src/platform/qt/LoadSaveState.cpp @@ -100,14 +100,11 @@ void LoadSaveState::loadState(int slot) { } void LoadSaveState::triggerState(int slot) { - GBAThread* thread = m_controller->thread(); - GBAThreadInterrupt(thread); if (m_mode == LoadSave::SAVE) { - GBASaveState(thread->gba, thread->stateDir, slot, true); + m_controller->saveState(slot); } else { - GBALoadState(thread->gba, thread->stateDir, slot); + m_controller->loadState(slot); } - GBAThreadContinue(thread); close(); } diff --git a/src/platform/qt/Window.cpp b/src/platform/qt/Window.cpp index beaf467db..e14c067d4 100644 --- a/src/platform/qt/Window.cpp +++ b/src/platform/qt/Window.cpp @@ -32,6 +32,7 @@ Window::Window(QWidget* parent) connect(m_controller, SIGNAL(gameStarted(GBAThread*)), this, SLOT(gameStarted(GBAThread*))); connect(m_controller, SIGNAL(gameStopped(GBAThread*)), m_display, SLOT(stopDrawing())); connect(m_controller, SIGNAL(gameStopped(GBAThread*)), this, SLOT(gameStopped())); + connect(m_controller, SIGNAL(stateLoaded(GBAThread*)), m_display, SLOT(forceDraw())); connect(m_controller, SIGNAL(postLog(int, const QString&)), m_logView, SLOT(postLog(int, const QString&))); 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()));