mirror of https://github.com/mgba-emu/mgba.git
Add frame advance
This commit is contained in:
parent
1eeeb36015
commit
2f98f542e5
|
@ -32,6 +32,12 @@ GameController::GameController(QObject* parent)
|
||||||
};
|
};
|
||||||
m_threadContext.frameCallback = [] (GBAThread* context) {
|
m_threadContext.frameCallback = [] (GBAThread* context) {
|
||||||
GameController* controller = static_cast<GameController*>(context->userData);
|
GameController* controller = static_cast<GameController*>(context->userData);
|
||||||
|
controller->m_pauseMutex.lock();
|
||||||
|
if (controller->m_pauseAfterFrame) {
|
||||||
|
GBAThreadPause(context);
|
||||||
|
controller->m_pauseAfterFrame = false;
|
||||||
|
}
|
||||||
|
controller->m_pauseMutex.unlock();
|
||||||
controller->frameAvailable(controller->m_drawContext);
|
controller->frameAvailable(controller->m_drawContext);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -48,6 +54,9 @@ void GameController::loadGame(const QString& path) {
|
||||||
delete m_rom;
|
delete m_rom;
|
||||||
m_rom = 0;
|
m_rom = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_pauseAfterFrame = false;
|
||||||
|
|
||||||
m_threadContext.fd = m_rom->handle();
|
m_threadContext.fd = m_rom->handle();
|
||||||
m_threadContext.fname = path.toLocal8Bit().constData();
|
m_threadContext.fname = path.toLocal8Bit().constData();
|
||||||
GBAThreadStart(&m_threadContext);
|
GBAThreadStart(&m_threadContext);
|
||||||
|
@ -65,6 +74,13 @@ void GameController::setPaused(bool paused) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameController::frameAdvance() {
|
||||||
|
m_pauseMutex.lock();
|
||||||
|
m_pauseAfterFrame = true;
|
||||||
|
setPaused(false);
|
||||||
|
m_pauseMutex.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
void GameController::keyPressed(int key) {
|
void GameController::keyPressed(int key) {
|
||||||
int mappedKey = 1 << key;
|
int mappedKey = 1 << key;
|
||||||
m_threadContext.activeKeys |= mappedKey;
|
m_threadContext.activeKeys |= mappedKey;
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QMutex>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
#include "AudioDevice.h"
|
#include "AudioDevice.h"
|
||||||
|
@ -32,6 +33,7 @@ signals:
|
||||||
public slots:
|
public slots:
|
||||||
void loadGame(const QString& path);
|
void loadGame(const QString& path);
|
||||||
void setPaused(bool paused);
|
void setPaused(bool paused);
|
||||||
|
void frameAdvance();
|
||||||
void keyPressed(int key);
|
void keyPressed(int key);
|
||||||
void keyReleased(int key);
|
void keyReleased(int key);
|
||||||
|
|
||||||
|
@ -45,6 +47,9 @@ private:
|
||||||
|
|
||||||
QFile* m_rom;
|
QFile* m_rom;
|
||||||
QFile* m_bios;
|
QFile* m_bios;
|
||||||
|
|
||||||
|
QMutex m_pauseMutex;
|
||||||
|
bool m_pauseAfterFrame;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,4 +119,11 @@ void Window::setupMenu(QMenuBar* menubar) {
|
||||||
connect(pause, SIGNAL(triggered(bool)), m_controller, SLOT(setPaused(bool)));
|
connect(pause, SIGNAL(triggered(bool)), m_controller, SLOT(setPaused(bool)));
|
||||||
m_gameActions.append(pause);
|
m_gameActions.append(pause);
|
||||||
emulationMenu->addAction(pause);
|
emulationMenu->addAction(pause);
|
||||||
|
|
||||||
|
QAction* frameAdvance = new QAction(tr("&Next frame"), 0);
|
||||||
|
frameAdvance->setShortcut(tr("Ctrl+N"));
|
||||||
|
frameAdvance->setDisabled(true);
|
||||||
|
connect(frameAdvance, SIGNAL(triggered()), m_controller, SLOT(frameAdvance()));
|
||||||
|
m_gameActions.append(frameAdvance);
|
||||||
|
emulationMenu->addAction(frameAdvance);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue