all repos — mgba @ 2b012ef0bccfcc294d1c27efa69665430a35eb32

mGBA Game Boy Advance Emulator

Remove unnecessary QFile object add zip loading
Jeffrey Pfau jeffrey@endrift.com
Sat, 18 Oct 2014 00:51:47 -0700
commit

2b012ef0bccfcc294d1c27efa69665430a35eb32

parent

d0b63162d590ce2e185f6f35b587244a9b7e5851

2 files changed, 15 insertions(+), 14 deletions(-)

jump to
M src/platform/qt/GameController.cppsrc/platform/qt/GameController.cpp

@@ -19,7 +19,7 @@ : QObject(parent)

, m_drawContext(new uint32_t[256 * 256]) , m_threadContext() , m_activeKeys(0) - , m_rom(nullptr) + , m_gameOpen(false) , m_audioThread(new QThread(this)) , m_audioProcessor(new AudioProcessor) {

@@ -117,22 +117,26 @@ void GameController::loadGame(const QString& path) {

closeGame(); m_threadContext.sync.videoFrameWait = 0; m_threadContext.sync.audioWait = 1; - m_rom = new QFile(path); - if (!m_rom->open(QIODevice::ReadOnly)) { - delete m_rom; - m_rom = nullptr; + QFile file(path); + if (!file.open(QIODevice::ReadOnly)) { + return; } + file.close(); + m_gameOpen = true; m_pauseAfterFrame = false; - m_threadContext.rom = VFileFromFD(m_rom->handle()); m_threadContext.fname = strdup(path.toLocal8Bit().constData()); + m_threadContext.rom = VFileOpen(m_threadContext.fname, O_RDONLY); +#if ENABLE_LIBZIP + m_threadContext.gameDir = VDirOpenZip(m_threadContext.fname, 0); +#endif GBAThreadStart(&m_threadContext); } void GameController::closeGame() { - if (!m_rom) { + if (!m_gameOpen) { return; } GBAThreadEnd(&m_threadContext);

@@ -141,11 +145,8 @@ if (m_threadContext.fname) {

free(const_cast<char*>(m_threadContext.fname)); m_threadContext.fname = nullptr; } - if (m_rom) { - m_rom->close(); - delete m_rom; - m_rom = nullptr; - } + + m_gameOpen = false; emit gameStopped(&m_threadContext); }
M src/platform/qt/GameController.hsrc/platform/qt/GameController.h

@@ -34,7 +34,7 @@ const uint32_t* drawContext() const { return m_drawContext; }

GBAThread* thread() { return &m_threadContext; } bool isPaused(); - bool isLoaded() { return m_rom; } + bool isLoaded() { return m_gameOpen; } #ifdef USE_GDB_STUB ARMDebugger* debugger();

@@ -81,7 +81,7 @@ GBAThread m_threadContext;

GBAVideoSoftwareRenderer* m_renderer; int m_activeKeys; - QFile* m_rom; + bool m_gameOpen; QFile* m_bios; QThread* m_audioThread;