Core: Refactor GBADirectorySet into mDirectorySet
@@ -0,0 +1,35 @@
+/* Copyright (c) 2013-2015 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifndef DIRECTORIES_H +#define DIRECTORIES_H + +#include "util/common.h" + +#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 +struct VDir; + +struct mDirectorySet { + struct VDir* base; + struct VDir* archive; + struct VDir* save; + struct VDir* patch; + struct VDir* state; + struct VDir* screenshot; +}; + +void mDirectorySetInit(struct mDirectorySet* dirs); +void mDirectorySetDeinit(struct mDirectorySet* dirs); + +void mDirectorySetAttachBase(struct mDirectorySet* dirs, struct VDir* base); +void mDirectorySetDetachBase(struct mDirectorySet* dirs); + +struct VFile* mDirectorySetOpenPath(struct mDirectorySet* dirs, const char* path, bool (*filter)(struct VFile*)); + +struct GBAOptions; +void mDirectorySetMapOptions(struct mDirectorySet* dirs, const struct GBAOptions* opts); +#endif + +#endif
@@ -22,7 +22,7 @@ context->fname = 0;
context->save = 0; context->renderer = 0; #if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 - GBADirectorySetInit(&context->dirs); + mDirectorySetInit(&context->dirs); #endif memset(context->components, 0, sizeof(context->components));@@ -82,13 +82,13 @@ mappedMemoryFree(context->gba, 0);
mappedMemoryFree(context->cpu, 0); GBAConfigDeinit(&context->config); #if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 - GBADirectorySetDeinit(&context->dirs); + mDirectorySetDeinit(&context->dirs); #endif } bool GBAContextLoadROM(struct GBAContext* context, const char* path, bool autoloadSave) { #if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 - context->rom = GBADirectorySetOpenPath(&context->dirs, path, GBAIsROM); + context->rom = mDirectorySetOpenPath(&context->dirs, path, GBAIsROM); #else context->rom = VFileOpen(path, O_RDONLY); #endif@@ -102,7 +102,7 @@ if (autoloadSave) {
char dirname[PATH_MAX]; char basename[PATH_MAX]; separatePath(context->fname, dirname, basename, 0); - GBADirectorySetAttachBase(&context->dirs, VDirOpen(dirname)); + mDirectorySetAttachBase(&context->dirs, VDirOpen(dirname)); strncat(basename, ".sav", PATH_MAX - strlen(basename) - 1); context->save = context->dirs.save->openFile(context->dirs.save, basename, O_RDWR | O_CREAT); }@@ -115,7 +115,7 @@
void GBAContextUnloadROM(struct GBAContext* context) { GBAUnloadROM(context->gba); #if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 - GBADirectorySetDetachBase(&context->dirs); + mDirectorySetDetachBase(&context->dirs); #endif if (context->rom) { context->rom->close(context->rom);
@@ -8,8 +8,8 @@ #define CONTEXT_H
#include "util/common.h" +#include "core/directories.h" #include "gba/context/config.h" -#include "gba/context/directories.h" #include "gba/context/sync.h" #include "gba/input.h"@@ -22,7 +22,7 @@ const char* fname;
struct VFile* save; struct VFile* bios; #if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 - struct GBADirectorySet dirs; + struct mDirectorySet dirs; #endif struct ARMComponent* components[GBA_COMPONENT_MAX]; struct GBAConfig config;
@@ -9,7 +9,7 @@ #include "gba/context/config.h"
#include "util/vfs.h" #if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 -void GBADirectorySetInit(struct GBADirectorySet* dirs) { +void mDirectorySetInit(struct mDirectorySet* dirs) { dirs->base = 0; dirs->archive = 0; dirs->save = 0;@@ -18,8 +18,8 @@ dirs->state = 0;
dirs->screenshot = 0; } -void GBADirectorySetDeinit(struct GBADirectorySet* dirs) { - GBADirectorySetDetachBase(dirs); +void mDirectorySetDeinit(struct mDirectorySet* dirs) { + mDirectorySetDetachBase(dirs); if (dirs->archive) { dirs->archive->close(dirs->archive);@@ -47,7 +47,7 @@ dirs->screenshot = 0;
} } -void GBADirectorySetAttachBase(struct GBADirectorySet* dirs, struct VDir* base) { +void mDirectorySetAttachBase(struct mDirectorySet* dirs, struct VDir* base) { dirs->base = base; if (!dirs->save) { dirs->save = dirs->base;@@ -63,7 +63,7 @@ dirs->screenshot = dirs->base;
} } -void GBADirectorySetDetachBase(struct GBADirectorySet* dirs) { +void mDirectorySetDetachBase(struct mDirectorySet* dirs) { if (dirs->save == dirs->base) { dirs->save = 0; }@@ -83,7 +83,7 @@ dirs->base = 0;
} } -struct VFile* GBADirectorySetOpenPath(struct GBADirectorySet* dirs, const char* path, bool (*filter)(struct VFile*)) { +struct VFile* mDirectorySetOpenPath(struct mDirectorySet* dirs, const char* path, bool (*filter)(struct VFile*)) { dirs->archive = VDirOpenArchive(path); struct VFile* file; if (dirs->archive) {@@ -102,7 +102,7 @@ }
return file; } -void GBADirectorySetMapOptions(struct GBADirectorySet* dirs, const struct GBAOptions* opts) { +void mDirectorySetMapOptions(struct mDirectorySet* dirs, const struct GBAOptions* opts) { if (opts->savegamePath) { struct VDir* dir = VDirOpen(opts->savegamePath); if (dir) {
@@ -1,35 +0,0 @@
-/* Copyright (c) 2013-2015 Jeffrey Pfau - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef DIRECTORIES_H -#define DIRECTORIES_H - -#include "util/common.h" - -#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 -struct VDir; - -struct GBADirectorySet { - struct VDir* base; - struct VDir* archive; - struct VDir* save; - struct VDir* patch; - struct VDir* state; - struct VDir* screenshot; -}; - -void GBADirectorySetInit(struct GBADirectorySet* dirs); -void GBADirectorySetDeinit(struct GBADirectorySet* dirs); - -void GBADirectorySetAttachBase(struct GBADirectorySet* dirs, struct VDir* base); -void GBADirectorySetDetachBase(struct GBADirectorySet* dirs); - -struct VFile* GBADirectorySetOpenPath(struct GBADirectorySet* dirs, const char* path, bool (*filter)(struct VFile*)); - -struct GBAOptions; -void GBADirectorySetMapOptions(struct GBADirectorySet* dirs, const struct GBAOptions* opts); -#endif - -#endif
@@ -27,13 +27,13 @@
#ifndef DISABLE_THREADING static bool _reloadDirectories(struct GBAThread* threadContext) { - GBADirectorySetDetachBase(&threadContext->dirs); + mDirectorySetDetachBase(&threadContext->dirs); char basename[PATH_MAX]; if (threadContext->fname) { char dirname[PATH_MAX]; separatePath(threadContext->fname, dirname, basename, 0); - GBADirectorySetAttachBase(&threadContext->dirs, VDirOpen(dirname)); + mDirectorySetAttachBase(&threadContext->dirs, VDirOpen(dirname)); } else { return false; }@@ -402,7 +402,7 @@ }
threadContext->idleOptimization = opts->idleOptimization; - GBADirectorySetMapOptions(&threadContext->dirs, opts); + mDirectorySetMapOptions(&threadContext->dirs, opts); } void GBAMapArgumentsToContext(const struct GBAArguments* args, struct GBAThread* threadContext) {@@ -685,7 +685,7 @@ GBASyncSetVideoSync(&threadContext->sync, frameOn);
} void GBAThreadLoadROM(struct GBAThread* threadContext, const char* fname) { - threadContext->rom = GBADirectorySetOpenPath(&threadContext->dirs, fname, GBAIsROM); + threadContext->rom = mDirectorySetOpenPath(&threadContext->dirs, fname, GBAIsROM); } void GBAThreadReplaceROM(struct GBAThread* threadContext, const char* fname) {
@@ -8,9 +8,9 @@ #define GBA_THREAD_H
#include "util/common.h" +#include "core/directories.h" #include "gba/gba.h" #include "gba/input.h" -#include "gba/context/directories.h" #include "gba/context/overrides.h" #include "gba/context/sync.h"@@ -49,7 +49,7 @@ struct GBAVideoRenderer* renderer;
struct GBASIODriverSet sioDrivers; struct ARMDebugger* debugger; #if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 - struct GBADirectorySet dirs; + struct mDirectorySet dirs; #endif struct VFile* rom; struct VFile* save;
@@ -18,9 +18,9 @@
#include <ctime> extern "C" { +#include "core/directories.h" #include "gba/audio.h" #include "gba/context/config.h" -#include "gba/context/directories.h" #include "gba/gba.h" #include "gba/serialize.h" #include "gba/sharkport.h"@@ -78,7 +78,7 @@ m_threadContext.userData = this;
m_threadContext.rewindBufferCapacity = 0; m_threadContext.cheats = &m_cheatDevice; m_threadContext.logLevel = GBA_LOG_ALL; - GBADirectorySetInit(&m_threadContext.dirs); + mDirectorySetInit(&m_threadContext.dirs); m_lux.p = this; m_lux.sample = [](GBALuminanceSource* context) {@@ -216,7 +216,7 @@ disconnect();
clearMultiplayerController(); closeGame(); GBACheatDeviceDestroy(&m_cheatDevice); - GBADirectorySetDeinit(&m_threadContext.dirs); + mDirectorySetDeinit(&m_threadContext.dirs); delete m_renderer; delete[] m_drawContext; delete[] m_frontBuffer;@@ -256,7 +256,7 @@ setVolume(opts->volume);
setMute(opts->mute); threadInterrupt(); - GBADirectorySetMapOptions(&m_threadContext.dirs, opts); + mDirectorySetMapOptions(&m_threadContext.dirs, opts); m_threadContext.idleOptimization = opts->idleOptimization; threadContinue(); }
@@ -267,7 +267,7 @@ printf("The game crashed!\n");
} } free(context.debugger); - GBADirectorySetDeinit(&context.dirs); + mDirectorySetDeinit(&context.dirs); return didFail; }