mirror of https://github.com/mgba-emu/mgba.git
Qt: Expose frame actions
This commit is contained in:
parent
5436d2576f
commit
4420054c1a
|
@ -203,10 +203,10 @@ CoreController::~CoreController() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const color_t* CoreController::drawContext() {
|
const color_t* CoreController::drawContext() {
|
||||||
QMutexLocker locker(&m_mutex);
|
|
||||||
if (m_hwaccel) {
|
if (m_hwaccel) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
QMutexLocker locker(&m_bufferMutex);
|
||||||
return reinterpret_cast<const color_t*>(m_completeBuffer.constData());
|
return reinterpret_cast<const color_t*>(m_completeBuffer.constData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -401,8 +401,7 @@ void CoreController::setPaused(bool paused) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (paused) {
|
if (paused) {
|
||||||
QMutexLocker locker(&m_mutex);
|
addFrameAction([this]() {
|
||||||
m_frameActions.append([this]() {
|
|
||||||
mCoreThreadPauseFromThread(&m_threadContext);
|
mCoreThreadPauseFromThread(&m_threadContext);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
@ -411,13 +410,17 @@ void CoreController::setPaused(bool paused) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoreController::frameAdvance() {
|
void CoreController::frameAdvance() {
|
||||||
QMutexLocker locker(&m_mutex);
|
addFrameAction([this]() {
|
||||||
m_frameActions.append([this]() {
|
|
||||||
mCoreThreadPauseFromThread(&m_threadContext);
|
mCoreThreadPauseFromThread(&m_threadContext);
|
||||||
});
|
});
|
||||||
setPaused(false);
|
setPaused(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CoreController::addFrameAction(std::function<void ()> action) {
|
||||||
|
QMutexLocker locker(&m_actionMutex);
|
||||||
|
m_frameActions.append(action);
|
||||||
|
}
|
||||||
|
|
||||||
void CoreController::setSync(bool sync) {
|
void CoreController::setSync(bool sync) {
|
||||||
if (sync) {
|
if (sync) {
|
||||||
m_threadContext.impl->sync.audioWait = m_audioSync;
|
m_threadContext.impl->sync.audioWait = m_audioSync;
|
||||||
|
@ -880,8 +883,8 @@ int CoreController::updateAutofire() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoreController::finishFrame() {
|
void CoreController::finishFrame() {
|
||||||
QMutexLocker locker(&m_mutex);
|
|
||||||
if (!m_hwaccel) {
|
if (!m_hwaccel) {
|
||||||
|
QMutexLocker locker(&m_bufferMutex);
|
||||||
memcpy(m_completeBuffer.data(), m_activeBuffer->constData(), m_activeBuffer->size());
|
memcpy(m_completeBuffer.data(), m_activeBuffer->constData(), m_activeBuffer->size());
|
||||||
|
|
||||||
// TODO: Generalize this to triple buffering?
|
// TODO: Generalize this to triple buffering?
|
||||||
|
@ -893,10 +896,13 @@ void CoreController::finishFrame() {
|
||||||
memcpy(m_activeBuffer->data(), m_completeBuffer.constData(), m_activeBuffer->size());
|
memcpy(m_activeBuffer->data(), m_completeBuffer.constData(), m_activeBuffer->size());
|
||||||
m_threadContext.core->setVideoBuffer(m_threadContext.core, reinterpret_cast<color_t*>(m_activeBuffer->data()), screenDimensions().width());
|
m_threadContext.core->setVideoBuffer(m_threadContext.core, reinterpret_cast<color_t*>(m_activeBuffer->data()), screenDimensions().width());
|
||||||
}
|
}
|
||||||
for (auto& action : m_frameActions) {
|
|
||||||
|
QMutexLocker locker(&m_actionMutex);
|
||||||
|
QList<std::function<void ()>> frameActions(m_frameActions);
|
||||||
|
m_frameActions.clear();
|
||||||
|
for (auto& action : frameActions) {
|
||||||
action();
|
action();
|
||||||
}
|
}
|
||||||
m_frameActions.clear();
|
|
||||||
updateKeys();
|
updateKeys();
|
||||||
|
|
||||||
QMetaObject::invokeMethod(this, "frameAvailable");
|
QMetaObject::invokeMethod(this, "frameAvailable");
|
||||||
|
|
|
@ -102,6 +102,8 @@ public:
|
||||||
bool audioSync() const { return m_audioSync; }
|
bool audioSync() const { return m_audioSync; }
|
||||||
bool videoSync() const { return m_videoSync; }
|
bool videoSync() const { return m_videoSync; }
|
||||||
|
|
||||||
|
void addFrameAction(std::function<void ()> callback);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void start();
|
void start();
|
||||||
void stop();
|
void stop();
|
||||||
|
@ -209,7 +211,8 @@ private:
|
||||||
|
|
||||||
QList<std::function<void()>> m_resetActions;
|
QList<std::function<void()>> m_resetActions;
|
||||||
QList<std::function<void()>> m_frameActions;
|
QList<std::function<void()>> m_frameActions;
|
||||||
QMutex m_mutex;
|
QMutex m_actionMutex{QMutex::Recursive};
|
||||||
|
QMutex m_bufferMutex;
|
||||||
|
|
||||||
int m_activeKeys = 0;
|
int m_activeKeys = 0;
|
||||||
bool m_autofire[32] = {};
|
bool m_autofire[32] = {};
|
||||||
|
|
Loading…
Reference in New Issue