Qt: Fix cancelling pausing before the frame ends

This commit is contained in:
Vicki Pfau 2020-11-17 22:52:44 -08:00
parent 61f8f14694
commit 67dae057ed
3 changed files with 28 additions and 16 deletions

View File

@ -59,6 +59,7 @@ Other fixes:
- Qt: Load/save bytes from memory viewer in the order visible (fixes mgba.io/i/1900)
- Qt: Fix running proxied video if it gets pushed to the main thread
- Qt: Fix game display sometimes disappearing after closing load/save state screen
- Qt: Fix cancelling pausing before the frame ends
- SM83: Simplify register pair access on big endian
- SM83: Disassemble STOP as one byte
Misc:

View File

@ -406,23 +406,25 @@ void CoreController::reset() {
}
void CoreController::setPaused(bool paused) {
if (paused == isPaused()) {
return;
}
QMutexLocker locker(&m_actionMutex);
if (paused) {
addFrameAction([this]() {
mCoreThreadPauseFromThread(&m_threadContext);
});
if (m_moreFrames < 0) {
m_moreFrames = 1;
}
} else {
mCoreThreadUnpause(&m_threadContext);
m_moreFrames = -1;
if (isPaused()) {
mCoreThreadUnpause(&m_threadContext);
}
}
}
void CoreController::frameAdvance() {
addFrameAction([this]() {
mCoreThreadPauseFromThread(&m_threadContext);
});
setPaused(false);
QMutexLocker locker(&m_actionMutex);
m_moreFrames = 1;
if (isPaused()) {
mCoreThreadUnpause(&m_threadContext);
}
}
void CoreController::addFrameAction(std::function<void ()> action) {
@ -947,11 +949,19 @@ void CoreController::finishFrame() {
memcpy(m_completeBuffer.data(), m_activeBuffer.constData(), width * height * BYTES_PER_PIXEL);
}
QMutexLocker locker(&m_actionMutex);
QList<std::function<void ()>> frameActions(m_frameActions);
m_frameActions.clear();
for (auto& action : frameActions) {
action();
{
QMutexLocker locker(&m_actionMutex);
QList<std::function<void ()>> frameActions(m_frameActions);
m_frameActions.clear();
for (auto& action : frameActions) {
action();
}
if (m_moreFrames > 0) {
--m_moreFrames;
if (!m_moreFrames) {
mCoreThreadPauseFromThread(&m_threadContext);
}
}
}
updateKeys();

View File

@ -213,6 +213,7 @@ private:
QList<std::function<void()>> m_resetActions;
QList<std::function<void()>> m_frameActions;
QMutex m_actionMutex{QMutex::Recursive};
int m_moreFrames = -1;
QMutex m_bufferMutex;
int m_activeKeys = 0;