mGUI: Refactoring out common code

This commit is contained in:
Vicki Pfau 2022-10-22 23:41:24 -07:00
parent 85e66155f2
commit fcf764e3c6
6 changed files with 15 additions and 26 deletions

View File

@ -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

View File

@ -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*);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);