all repos — mgba @ cbc27f08f9d4ea827c97f3e824f319f4104482ee

mGBA Game Boy Advance Emulator

Core: Add single config option reloading function
Vicki Pfau vi@endrift.com
Sun, 30 Jun 2019 11:25:40 -0700
commit

cbc27f08f9d4ea827c97f3e824f319f4104482ee

parent

4ea82f9e3ae326a1070162e8ab34f9e685cf1fc6

4 files changed, 111 insertions(+), 27 deletions(-)

jump to
M include/mgba/core/core.hinclude/mgba/core/core.h

@@ -68,6 +68,7 @@ bool (*supportsFeature)(const struct mCore*, enum mCoreFeature);

void (*setSync)(struct mCore*, struct mCoreSync*); void (*loadConfig)(struct mCore*, const struct mCoreConfig*); + void (*reloadConfigOption)(struct mCore*, const char* option, const struct mCoreConfig*); void (*desiredVideoDimensions)(struct mCore*, unsigned* width, unsigned* height); void (*setVideoBuffer)(struct mCore*, color_t* buffer, size_t stride);
M src/gb/core.csrc/gb/core.c

@@ -224,6 +224,59 @@ gbcore->overrides = mCoreConfigGetOverridesConst(config);

#endif } +static void _GBCoreReloadConfigOption(struct mCore* core, const char* option, const struct mCoreConfig* config) { + struct GB* gb = core->board; + if (!config) { + config = &core->config; + } + + if (!option) { + // Reload options from opts + if (core->opts.mute) { + gb->audio.masterVolume = 0; + } else { + gb->audio.masterVolume = core->opts.volume; + } + gb->video.frameskip = core->opts.frameskip; + return; + } + + int fakeBool; + if (strcmp("mute", option) == 0) { + if (mCoreConfigGetIntValue(config, "mute", &fakeBool)) { + core->opts.mute = fakeBool; + + if (core->opts.mute) { + gb->audio.masterVolume = 0; + } else { + gb->audio.masterVolume = core->opts.volume; + } + } + return; + } + if (strcmp("volume", option) == 0) { + if (mCoreConfigGetIntValue(config, "volume", &core->opts.volume) && !core->opts.mute) { + gb->audio.masterVolume = core->opts.volume; + } + return; + } + if (strcmp("frameskip", option) == 0) { + if (mCoreConfigGetIntValue(config, "frameskip", &core->opts.frameskip)) { + gb->video.frameskip = core->opts.frameskip; + } + return; + } + if (strcmp("allowOpposingDirections", option) == 0) { + if (config != &core->config) { + mCoreConfigCopyValue(&core->config, config, "allowOpposingDirections"); + } + if (mCoreConfigGetIntValue(config, "allowOpposingDirections", &fakeBool)) { + gb->allowOpposingDirections = fakeBool; + } + return; + } +} + static void _GBCoreDesiredVideoDimensions(struct mCore* core, unsigned* width, unsigned* height) { struct GB* gb = core->board; if (gb && (!(gb->model & GB_MODEL_SGB) || !gb->video.sgbBorders)) {

@@ -901,6 +954,7 @@ core->platform = _GBCorePlatform;

core->supportsFeature = _GBCoreSupportsFeature; core->setSync = _GBCoreSetSync; core->loadConfig = _GBCoreLoadConfig; + core->reloadConfigOption = _GBCoreReloadConfigOption; core->desiredVideoDimensions = _GBCoreDesiredVideoDimensions; core->setVideoBuffer = _GBCoreSetVideoBuffer; core->setVideoGLTex = _GBCoreSetVideoGLTex;
M src/gba/core.csrc/gba/core.c

@@ -296,6 +296,59 @@ mCoreConfigCopyValue(&core->config, config, "hwaccelVideo");

mCoreConfigCopyValue(&core->config, config, "videoScale"); } +static void _GBACoreReloadConfigOption(struct mCore* core, const char* option, const struct mCoreConfig* config) { + struct GBA* gba = core->board; + if (!config) { + config = &core->config; + } + + if (!option) { + // Reload options from opts + if (core->opts.mute) { + gba->audio.masterVolume = 0; + } else { + gba->audio.masterVolume = core->opts.volume; + } + gba->video.frameskip = core->opts.frameskip; + return; + } + + int fakeBool; + if (strcmp("mute", option) == 0) { + if (mCoreConfigGetIntValue(config, "mute", &fakeBool)) { + core->opts.mute = fakeBool; + + if (core->opts.mute) { + gba->audio.masterVolume = 0; + } else { + gba->audio.masterVolume = core->opts.volume; + } + } + return; + } + if (strcmp("volume", option) == 0) { + if (mCoreConfigGetIntValue(config, "volume", &core->opts.volume) && !core->opts.mute) { + gba->audio.masterVolume = core->opts.volume; + } + return; + } + if (strcmp("frameskip", option) == 0) { + if (mCoreConfigGetIntValue(config, "frameskip", &core->opts.frameskip)) { + gba->video.frameskip = core->opts.frameskip; + } + return; + } + if (strcmp("allowOpposingDirections", option) == 0) { + if (config != &core->config) { + mCoreConfigCopyValue(&core->config, config, "allowOpposingDirections"); + } + if (mCoreConfigGetIntValue(config, "allowOpposingDirections", &fakeBool)) { + gba->allowOpposingDirections = fakeBool; + } + return; + } +} + static void _GBACoreDesiredVideoDimensions(struct mCore* core, unsigned* width, unsigned* height) { #if defined(BUILD_GLES2) || defined(BUILD_GLES3) struct GBACore* gbacore = (struct GBACore*) core;

@@ -1021,6 +1074,7 @@ core->platform = _GBACorePlatform;

core->supportsFeature = _GBACoreSupportsFeature; core->setSync = _GBACoreSetSync; core->loadConfig = _GBACoreLoadConfig; + core->reloadConfigOption = _GBACoreReloadConfigOption; core->desiredVideoDimensions = _GBACoreDesiredVideoDimensions; core->setVideoBuffer = _GBACoreSetVideoBuffer; core->setVideoGLTex = _GBACoreSetVideoGLTex;
M src/platform/qt/CoreController.cppsrc/platform/qt/CoreController.cpp

@@ -922,33 +922,8 @@ m_threadContext.core->opts.mute = fakeBool;

m_threadContext.impl->sync.fpsTarget = m_fpsTarget; setSync(true); } - // XXX: Have a way of just updating volume - switch (platform()) { -#ifdef M_CORE_GBA - case PLATFORM_GBA: { - GBA* gba = static_cast<GBA*>(m_threadContext.core->board); - if (m_threadContext.core->opts.mute) { - gba->audio.masterVolume = 0; - } else { - gba->audio.masterVolume = m_threadContext.core->opts.volume; - } - break; - } -#endif -#ifdef M_CORE_GB - case PLATFORM_GB: { - GB* gb = static_cast<GB*>(m_threadContext.core->board); - if (m_threadContext.core->opts.mute) { - gb->audio.masterVolume = 0; - } else { - gb->audio.masterVolume = m_threadContext.core->opts.volume; - } - break; - } -#endif - default: - break; - } + + m_threadContext.core->reloadConfigOption(m_threadContext.core, NULL, NULL); } CoreController::Interrupter::Interrupter(CoreController* parent, bool fromThread)