Remove unnecessary QFile object add zip loading

This commit is contained in:
Jeffrey Pfau 2014-10-18 00:51:47 -07:00
parent d0b63162d5
commit 2b012ef0bc
2 changed files with 15 additions and 14 deletions

View File

@ -19,7 +19,7 @@ GameController::GameController(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 @@ void GameController::closeGame() {
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);
}

View File

@ -34,7 +34,7 @@ public:
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 @@ private:
GBAVideoSoftwareRenderer* m_renderer;
int m_activeKeys;
QFile* m_rom;
bool m_gameOpen;
QFile* m_bios;
QThread* m_audioThread;