all repos — mgba @ 6afc00b4723a8141f9b014814fbc37bd4bfa3de9

mGBA Game Boy Advance Emulator

Move state loading/storing into GameController
Jeffrey Pfau jeffrey@endrift.com
Wed, 15 Oct 2014 23:22:30 -0700
commit

6afc00b4723a8141f9b014814fbc37bd4bfa3de9

parent

ad37ae3d61326865a190f4b866800474c30ebadd

M src/platform/qt/Display.cppsrc/platform/qt/Display.cpp

@@ -55,6 +55,12 @@ m_drawThread = nullptr;

} } +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);

@@ -127,6 +133,18 @@ glFlush();

} } GBASyncWaitFrameEnd(&m_context->sync); + m_gl->swapBuffers(); + 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(); }
M src/platform/qt/Display.hsrc/platform/qt/Display.h

@@ -19,6 +19,7 @@

public slots: void startDrawing(const uint32_t* buffer, GBAThread* context); void stopDrawing(); + void forceDraw(); protected: virtual void initializeGL() override;

@@ -40,6 +41,7 @@ void setContext(GBAThread*);

void setBacking(const uint32_t*); public slots: + void forceDraw(); void draw(); void start(); void stop();
M src/platform/qt/GameController.cppsrc/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" }

@@ -201,6 +202,20 @@ GBAThreadInterrupt(&m_threadContext);

m_threadContext.fpsTarget = fps; GBAThreadContinue(&m_threadContext); 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() {
M src/platform/qt/GameController.hsrc/platform/qt/GameController.h

@@ -46,6 +46,7 @@ void gameStarted(GBAThread*);

void gameStopped(GBAThread*); void gamePaused(GBAThread*); void gameUnpaused(GBAThread*); + void stateLoaded(GBAThread*); void postLog(int level, const QString& log);

@@ -59,6 +60,8 @@ void keyPressed(int key);

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:
M src/platform/qt/LoadSaveState.cppsrc/platform/qt/LoadSaveState.cpp

@@ -100,14 +100,11 @@ m_slots[slot]->setShortcut(QString::number(slot + 1));

} 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(); }
M src/platform/qt/Window.cppsrc/platform/qt/Window.cpp

@@ -32,6 +32,7 @@ setCentralWidget(m_display);

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()));