Move state loading/storing into GameController

This commit is contained in:
Jeffrey Pfau 2014-10-15 23:22:30 -07:00
parent ad37ae3d61
commit 6afc00b472
6 changed files with 41 additions and 5 deletions

View File

@ -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;

View File

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

View File

@ -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

View File

@ -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:

View File

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

View File

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