Core: Add single config option reloading function

This commit is contained in:
Vicki Pfau 2019-06-30 11:25:40 -07:00
parent 4ea82f9e3a
commit cbc27f08f9
4 changed files with 111 additions and 27 deletions

View File

@ -68,6 +68,7 @@ struct mCore {
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);

View File

@ -224,6 +224,59 @@ static void _GBCoreLoadConfig(struct mCore* core, const struct mCoreConfig* conf
#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 @@ struct mCore* GBCoreCreate(void) {
core->supportsFeature = _GBCoreSupportsFeature;
core->setSync = _GBCoreSetSync;
core->loadConfig = _GBCoreLoadConfig;
core->reloadConfigOption = _GBCoreReloadConfigOption;
core->desiredVideoDimensions = _GBCoreDesiredVideoDimensions;
core->setVideoBuffer = _GBCoreSetVideoBuffer;
core->setVideoGLTex = _GBCoreSetVideoGLTex;

View File

@ -296,6 +296,59 @@ static void _GBACoreLoadConfig(struct mCore* core, const struct mCoreConfig* con
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 @@ struct mCore* GBACoreCreate(void) {
core->supportsFeature = _GBACoreSupportsFeature;
core->setSync = _GBACoreSetSync;
core->loadConfig = _GBACoreLoadConfig;
core->reloadConfigOption = _GBACoreReloadConfigOption;
core->desiredVideoDimensions = _GBACoreDesiredVideoDimensions;
core->setVideoBuffer = _GBACoreSetVideoBuffer;
core->setVideoGLTex = _GBACoreSetVideoGLTex;

View File

@ -922,33 +922,8 @@ void CoreController::updateFastForward() {
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)