Game resets when loading a patch or BIOS
Jeffrey Pfau jeffrey@endrift.com
Fri, 24 Oct 2014 01:57:18 -0700
2 files changed,
27 insertions(+),
9 deletions(-)
M
src/platform/qt/GameController.cpp
→
src/platform/qt/GameController.cpp
@@ -119,8 +119,6 @@ }
void GameController::loadGame(const QString& path, bool dirmode) { closeGame(); - m_threadContext.sync.videoFrameWait = m_videoSync; - m_threadContext.sync.audioWait = m_audioSync; if (!dirmode) { QFile file(path); if (!file.open(QIODevice::ReadOnly)) {@@ -128,12 +126,22 @@ return;
} file.close(); } + + m_fname = path; + m_dirmode = dirmode; + openGame(); +} + +void GameController::openGame() { m_gameOpen = true; m_pauseAfterFrame = false; - m_threadContext.fname = strdup(path.toLocal8Bit().constData()); - if (dirmode) { + m_threadContext.sync.videoFrameWait = m_videoSync; + m_threadContext.sync.audioWait = m_audioSync; + + m_threadContext.fname = m_fname.toLocal8Bit().constData(); + if (m_dirmode) { m_threadContext.gameDir = VDirOpen(m_threadContext.fname); m_threadContext.stateDir = m_threadContext.gameDir; } else {@@ -151,15 +159,25 @@ if (!m_patch.isNull()) {
m_threadContext.patch = VFileOpen(m_patch.toLocal8Bit().constData(), O_RDONLY); } - GBAThreadStart(&m_threadContext); + if (!GBAThreadStart(&m_threadContext)) { + m_gameOpen = false; + } } void GameController::loadBIOS(const QString& path) { m_bios = path; + if (m_gameOpen) { + closeGame(); + openGame(); + } } void GameController::loadPatch(const QString& path) { m_patch = path; + if (m_gameOpen) { + closeGame(); + openGame(); + } } void GameController::closeGame() {@@ -168,10 +186,6 @@ return;
} GBAThreadEnd(&m_threadContext); GBAThreadJoin(&m_threadContext); - if (m_threadContext.fname) { - free(const_cast<char*>(m_threadContext.fname)); - m_threadContext.fname = nullptr; - } m_gameOpen = false; emit gameStopped(&m_threadContext);
M
src/platform/qt/GameController.h
→
src/platform/qt/GameController.h
@@ -58,6 +58,7 @@ public slots:
void loadGame(const QString& path, bool dirmode = false); void loadBIOS(const QString& path); void loadPatch(const QString& path); + void openGame(); void closeGame(); void setPaused(bool paused); void reset();@@ -90,6 +91,9 @@ GBAVideoSoftwareRenderer* m_renderer;
int m_activeKeys; bool m_gameOpen; + bool m_dirmode; + + QString m_fname; QString m_bios; QString m_patch;