From fcf764e3c6f62c2c3372da6854bab2493ed817c0 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sat, 22 Oct 2022 23:41:24 -0700 Subject: [PATCH] mGUI: Refactoring out common code --- src/feature/gui/gui-runner.c | 20 ++++++++++---------- src/feature/gui/gui-runner.h | 1 + src/platform/3ds/main.c | 5 +---- src/platform/psp2/main.c | 5 +---- src/platform/switch/main.c | 5 +---- src/platform/wii/main.c | 5 +---- 6 files changed, 15 insertions(+), 26 deletions(-) diff --git a/src/feature/gui/gui-runner.c b/src/feature/gui/gui-runner.c index 820f1cb07..2e837891f 100644 --- a/src/feature/gui/gui-runner.c +++ b/src/feature/gui/gui-runner.c @@ -456,11 +456,7 @@ void mGUIRun(struct mGUIRunner* runner, const char* path) { runner->setup(runner); } if (runner->config.port && runner->keySources) { - mLOG(GUI_RUNNER, DEBUG, "Loading key sources for %s...", runner->config.port); - size_t i; - for (i = 0; runner->keySources[i].id; ++i) { - mInputMapLoad(&runner->core->inputMap, runner->keySources[i].id, mCoreConfigGetInput(&runner->config)); - } + mGUILoadInputMaps(runner); } mLOG(GUI_RUNNER, DEBUG, "Reseting..."); runner->core->reset(runner->core); @@ -751,11 +747,7 @@ void mGUIRun(struct mGUIRunner* runner, const char* path) { void mGUIRunloop(struct mGUIRunner* runner) { if (runner->keySources) { - mLOG(GUI_RUNNER, DEBUG, "Loading key sources for %s...", runner->config.port); - size_t i; - for (i = 0; runner->keySources[i].id; ++i) { - mInputMapLoad(&runner->params.keyMap, runner->keySources[i].id, mCoreConfigGetInput(&runner->config)); - } + mGUILoadInputMaps(runner); } while (!runner->running || runner->running(runner)) { char path[PATH_MAX]; @@ -776,6 +768,14 @@ void mGUIRunloop(struct mGUIRunner* runner) { } } +void mGUILoadInputMaps(struct mGUIRunner* runner) { + mLOG(GUI_RUNNER, DEBUG, "Loading key sources for %s...", runner->config.port); + size_t i; + for (i = 0; runner->keySources[i].id; ++i) { + mInputMapLoad(&runner->params.keyMap, runner->keySources[i].id, mCoreConfigGetInput(&runner->config)); + } +} + #if defined(__3DS__) || defined(PSP2) bool mGUIGetRom(struct mGUIRunner* runner, char* out, size_t outLength) { #ifdef PSP2 diff --git a/src/feature/gui/gui-runner.h b/src/feature/gui/gui-runner.h index 860b96b99..fc8e85227 100644 --- a/src/feature/gui/gui-runner.h +++ b/src/feature/gui/gui-runner.h @@ -95,6 +95,7 @@ struct mGUIRunner { void mGUIInit(struct mGUIRunner*, const char* port); void mGUIDeinit(struct mGUIRunner*); +void mGUILoadInputMaps(struct mGUIRunner* runner); void mGUIRun(struct mGUIRunner*, const char* path); void mGUIRunloop(struct mGUIRunner*); diff --git a/src/platform/3ds/main.c b/src/platform/3ds/main.c index b19a0ca2f..5356130ce 100644 --- a/src/platform/3ds/main.c +++ b/src/platform/3ds/main.c @@ -1067,10 +1067,7 @@ int main(int argc, char* argv[]) { } if (initialPath[0] == '/' || useRomfs) { - size_t i; - for (i = 0; runner.keySources[i].id; ++i) { - mInputMapLoad(&runner.params.keyMap, runner.keySources[i].id, mCoreConfigGetInput(&runner.config)); - } + mGUILoadInputMaps(&runner); mGUIRun(&runner, initialPath); } else { mGUIRunloop(&runner); diff --git a/src/platform/psp2/main.c b/src/platform/psp2/main.c index d66ba8494..747535e25 100644 --- a/src/platform/psp2/main.c +++ b/src/platform/psp2/main.c @@ -282,10 +282,7 @@ int main() { scePowerSetArmClockFrequency(444); if (mGUIGetRom(&runner, initialPath, sizeof(initialPath))) { - size_t i; - for (i = 0; runner.keySources[i].id; ++i) { - mInputMapLoad(&runner.params.keyMap, runner.keySources[i].id, mCoreConfigGetInput(&runner.config)); - } + mGUILoadInputMaps(&runner); mGUIRun(&runner, initialPath); } else { mGUIRunloop(&runner); diff --git a/src/platform/switch/main.c b/src/platform/switch/main.c index 25b6f6eca..9f1e84563 100644 --- a/src/platform/switch/main.c +++ b/src/platform/switch/main.c @@ -1061,10 +1061,7 @@ int main(int argc, char* argv[]) { } if (argc > 1) { - size_t i; - for (i = 0; runner.keySources[i].id; ++i) { - mInputMapLoad(&runner.params.keyMap, runner.keySources[i].id, mCoreConfigGetInput(&runner.config)); - } + mGUILoadInputMaps(&runner); mGUIRun(&runner, argv[1]); } else { mGUIRunloop(&runner); diff --git a/src/platform/wii/main.c b/src/platform/wii/main.c index 36bb9abfc..312388347 100644 --- a/src/platform/wii/main.c +++ b/src/platform/wii/main.c @@ -653,10 +653,7 @@ int main(int argc, char* argv[]) { } if (argc > 1) { - size_t i; - for (i = 0; runner.keySources[i].id; ++i) { - mInputMapLoad(&runner.params.keyMap, runner.keySources[i].id, mCoreConfigGetInput(&runner.config)); - } + mGUILoadInputMaps(&runner); mGUIRun(&runner, argv[1]); } else { mGUIRunloop(&runner);