mirror of https://github.com/mgba-emu/mgba.git
Move state loading/storing into GameController
This commit is contained in:
parent
ad37ae3d61
commit
6afc00b472
|
@ -55,6 +55,12 @@ void Display::stopDrawing() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Display::forceDraw() {
|
||||||
|
if (m_drawThread) {
|
||||||
|
QMetaObject::invokeMethod(m_painter, "forceDraw", Qt::BlockingQueuedConnection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Display::initializeGL() {
|
void Display::initializeGL() {
|
||||||
glClearColor(0, 0, 0, 0);
|
glClearColor(0, 0, 0, 0);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
@ -131,6 +137,18 @@ void Painter::draw() {
|
||||||
m_gl->doneCurrent();
|
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() {
|
void Painter::stop() {
|
||||||
m_drawTimer->stop();
|
m_drawTimer->stop();
|
||||||
delete m_drawTimer;
|
delete m_drawTimer;
|
||||||
|
|
|
@ -19,6 +19,7 @@ public:
|
||||||
public slots:
|
public slots:
|
||||||
void startDrawing(const uint32_t* buffer, GBAThread* context);
|
void startDrawing(const uint32_t* buffer, GBAThread* context);
|
||||||
void stopDrawing();
|
void stopDrawing();
|
||||||
|
void forceDraw();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void initializeGL() override;
|
virtual void initializeGL() override;
|
||||||
|
@ -40,6 +41,7 @@ public:
|
||||||
void setBacking(const uint32_t*);
|
void setBacking(const uint32_t*);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
void forceDraw();
|
||||||
void draw();
|
void draw();
|
||||||
void start();
|
void start();
|
||||||
void stop();
|
void stop();
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "gba.h"
|
#include "gba.h"
|
||||||
#include "gba-audio.h"
|
#include "gba-audio.h"
|
||||||
|
#include "gba-serialize.h"
|
||||||
#include "renderers/video-software.h"
|
#include "renderers/video-software.h"
|
||||||
#include "util/vfs.h"
|
#include "util/vfs.h"
|
||||||
}
|
}
|
||||||
|
@ -203,6 +204,20 @@ void GameController::setFPSTarget(float fps) {
|
||||||
QMetaObject::invokeMethod(m_audioProcessor, "inputParametersChanged");
|
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() {
|
void GameController::updateKeys() {
|
||||||
int activeKeys = m_activeKeys;
|
int activeKeys = m_activeKeys;
|
||||||
#ifdef BUILD_SDL
|
#ifdef BUILD_SDL
|
||||||
|
|
|
@ -46,6 +46,7 @@ signals:
|
||||||
void gameStopped(GBAThread*);
|
void gameStopped(GBAThread*);
|
||||||
void gamePaused(GBAThread*);
|
void gamePaused(GBAThread*);
|
||||||
void gameUnpaused(GBAThread*);
|
void gameUnpaused(GBAThread*);
|
||||||
|
void stateLoaded(GBAThread*);
|
||||||
|
|
||||||
void postLog(int level, const QString& log);
|
void postLog(int level, const QString& log);
|
||||||
|
|
||||||
|
@ -59,6 +60,8 @@ public slots:
|
||||||
void keyReleased(int key);
|
void keyReleased(int key);
|
||||||
void setAudioBufferSamples(int samples);
|
void setAudioBufferSamples(int samples);
|
||||||
void setFPSTarget(float fps);
|
void setFPSTarget(float fps);
|
||||||
|
void loadState(int slot);
|
||||||
|
void saveState(int slot);
|
||||||
|
|
||||||
#ifdef BUILD_SDL
|
#ifdef BUILD_SDL
|
||||||
private slots:
|
private slots:
|
||||||
|
|
|
@ -100,14 +100,11 @@ void LoadSaveState::loadState(int slot) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadSaveState::triggerState(int slot) {
|
void LoadSaveState::triggerState(int slot) {
|
||||||
GBAThread* thread = m_controller->thread();
|
|
||||||
GBAThreadInterrupt(thread);
|
|
||||||
if (m_mode == LoadSave::SAVE) {
|
if (m_mode == LoadSave::SAVE) {
|
||||||
GBASaveState(thread->gba, thread->stateDir, slot, true);
|
m_controller->saveState(slot);
|
||||||
} else {
|
} else {
|
||||||
GBALoadState(thread->gba, thread->stateDir, slot);
|
m_controller->loadState(slot);
|
||||||
}
|
}
|
||||||
GBAThreadContinue(thread);
|
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ Window::Window(QWidget* parent)
|
||||||
connect(m_controller, SIGNAL(gameStarted(GBAThread*)), this, SLOT(gameStarted(GBAThread*)));
|
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*)), m_display, SLOT(stopDrawing()));
|
||||||
connect(m_controller, SIGNAL(gameStopped(GBAThread*)), this, SLOT(gameStopped()));
|
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(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(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(shutdown()), m_display, SLOT(stopDrawing()));
|
||||||
|
|
Loading…
Reference in New Issue