Removed app.options entirely, now rely on the handler

The advantage is that the menu entries are generated on demand, so they'll always be up to date irt language.

I think it would be better if the options_handler was in charge of showing the dialog too.

It would allow in-app menus and it will also avoid the careless unbounded copying.

But this first step preserves the previous behavior.
This commit is contained in:
Alex Duchesne 2024-12-17 13:03:08 -05:00
parent 92da1ec155
commit a8565b952c
12 changed files with 96 additions and 72 deletions

View File

@ -1570,6 +1570,7 @@ void rg_gui_options_menu(void)
#ifdef RG_ENABLE_NETWORKING
*opt++ = (rg_gui_option_t){0, _("Wi-Fi options"), NULL, RG_DIALOG_FLAG_NORMAL, &wifi_cb};
#endif
*opt++ = (rg_gui_option_t)RG_DIALOG_END;
}
// App settings that are shown only inside a game
else
@ -1579,14 +1580,9 @@ void rg_gui_options_menu(void)
*opt++ = (rg_gui_option_t){0, _("Filter"), "-", RG_DIALOG_FLAG_NORMAL, &filter_update_cb};
*opt++ = (rg_gui_option_t){0, _("Border"), "-", RG_DIALOG_FLAG_NORMAL, &border_update_cb};
*opt++ = (rg_gui_option_t){0, _("Speed"), "-", RG_DIALOG_FLAG_NORMAL, &speedup_update_cb};
*opt++ = (rg_gui_option_t)RG_DIALOG_END;
}
size_t extra_options = get_dialog_items_count(app->options);
for (size_t i = 0; i < extra_options; i++)
*opt++ = app->options[i];
*opt++ = (rg_gui_option_t)RG_DIALOG_END;
if (app->handlers.options)
app->handlers.options(options + get_dialog_items_count(options));

View File

@ -37,6 +37,11 @@ typedef struct
rg_stats_t statistics;
} panic_trace_t;
typedef struct
{
uint32_t magicWord;
} boot_config_t;
typedef struct
{
int32_t totalFrames, fullFrames, partFrames, ticks;
@ -78,6 +83,7 @@ static struct
// The trace will survive a software reset
static RTC_NOINIT_ATTR panic_trace_t panicTrace;
// static RTC_NOINIT_ATTR boot_config_t bootConfig;
static RTC_NOINIT_ATTR time_t rtcValue;
static bool panicTraceCleared = false;
static bool exitCalled = false;
@ -367,21 +373,20 @@ static void platform_init(void)
#endif
}
rg_app_t *rg_system_reinit(int sampleRate, const rg_handlers_t *handlers, const rg_gui_option_t *options)
rg_app_t *rg_system_reinit(int sampleRate, const rg_handlers_t *handlers, void *_unused)
{
if (!app.initialized)
return rg_system_init(sampleRate, handlers, options);
return rg_system_init(sampleRate, handlers, NULL);
app.sampleRate = sampleRate;
if (handlers)
app.handlers = *handlers;
app.options = options;
rg_audio_set_sample_rate(app.sampleRate);
return &app;
}
rg_app_t *rg_system_init(int sampleRate, const rg_handlers_t *handlers, const rg_gui_option_t *options)
rg_app_t *rg_system_init(int sampleRate, const rg_handlers_t *handlers, void *_unused)
{
RG_ASSERT(app.initialized == false, "rg_system_init() was already called.");
bool enterRecoveryMode = false;
@ -414,7 +419,6 @@ rg_app_t *rg_system_init(int sampleRate, const rg_handlers_t *handlers, const rg
.isRelease = false,
.logLevel = RG_LOG_DEBUG,
#endif
.options = options, // TO DO: We should make a copy of it?
};
// Do this very early, may be needed to enable serial console

View File

@ -185,7 +185,6 @@ typedef struct
int logLevel;
int saveSlot;
const char *romPath;
const rg_gui_option_t *options;
rg_handlers_t handlers;
bool initialized;
} rg_app_t;
@ -210,8 +209,8 @@ typedef struct
int freeStackMain;
} rg_stats_t;
rg_app_t *rg_system_init(int sampleRate, const rg_handlers_t *handlers, const rg_gui_option_t *options);
rg_app_t *rg_system_reinit(int sampleRate, const rg_handlers_t *handlers, const rg_gui_option_t *options);
rg_app_t *rg_system_init(int sampleRate, const rg_handlers_t *handlers, void *_unused);
rg_app_t *rg_system_reinit(int sampleRate, const rg_handlers_t *handlers, void *_unused);
void rg_system_panic(const char *context, const char *message) __attribute__((noreturn));
void rg_system_shutdown(void) __attribute__((noreturn));
void rg_system_sleep(void) __attribute__((noreturn));

View File

@ -410,6 +410,13 @@ static void audioTask(void *arg)
}
}
static void options_handler(rg_gui_option_t *dest)
{
*dest++ = (rg_gui_option_t){0, _("Input"), "-", RG_DIALOG_FLAG_NORMAL, &input_select_cb};
*dest++ = (rg_gui_option_t){0, _("Crop"), "-", RG_DIALOG_FLAG_NORMAL, &crop_select_cb};
*dest++ = (rg_gui_option_t)RG_DIALOG_END;
}
void app_main(void)
{
const rg_handlers_t handlers = {
@ -418,15 +425,10 @@ void app_main(void)
.reset = &reset_handler,
.screenshot = &screenshot_handler,
.event = &event_handler,
};
const rg_gui_option_t options[] = {
{0, _("Input"), "-", RG_DIALOG_FLAG_NORMAL, &input_select_cb},
{0, _("Crop"), "-", RG_DIALOG_FLAG_NORMAL, &crop_select_cb},
// {0, "fMSX Menu", NULL, RG_DIALOG_FLAG_NORMAL, &fmsx_menu_cb},
RG_DIALOG_END,
.options = &options_handler,
};
app = rg_system_init(AUDIO_SAMPLE_RATE, &handlers, options);
app = rg_system_init(AUDIO_SAMPLE_RATE, &handlers, NULL);
// This is probably not right, but the emulator outputs 440 samples per frame??
rg_system_set_tick_rate(55);

View File

@ -189,6 +189,14 @@ static void event_handler(int event, void *arg)
}
}
static void options_handler(rg_gui_option_t *dest)
{
*dest++ = (rg_gui_option_t){0, _("YM2612 audio "), "-", RG_DIALOG_FLAG_NORMAL, &yfm_update_cb};
*dest++ = (rg_gui_option_t){0, _("SN76489 audio"), "-", RG_DIALOG_FLAG_NORMAL, &sn76489_update_cb};
*dest++ = (rg_gui_option_t){0, _("Z80 emulation"), "-", RG_DIALOG_FLAG_NORMAL, &z80_update_cb};
*dest++ = (rg_gui_option_t)RG_DIALOG_END;
}
void app_main(void)
{
const rg_handlers_t handlers = {
@ -197,15 +205,10 @@ void app_main(void)
.reset = &reset_handler,
.screenshot = &screenshot_handler,
.event = &event_handler,
};
const rg_gui_option_t options[] = {
{0, _("YM2612 audio "), "-", RG_DIALOG_FLAG_NORMAL, &yfm_update_cb},
{0, _("SN76489 audio"), "-", RG_DIALOG_FLAG_NORMAL, &sn76489_update_cb},
{0, _("Z80 emulation"), "-", RG_DIALOG_FLAG_NORMAL, &z80_update_cb},
RG_DIALOG_END
.options = &options_handler,
};
app = rg_system_init(AUDIO_SAMPLE_RATE / 2, &handlers, options);
app = rg_system_init(AUDIO_SAMPLE_RATE / 2, &handlers, NULL);
yfm_enabled = rg_settings_get_number(NS_APP, SETTING_YFM_EMULATION, 1);
sn76489_enabled = rg_settings_get_number(NS_APP, SETTING_SN76489_EMULATION, 0);

View File

@ -524,6 +524,12 @@ bool is_iwad(const char *path)
return header[0] == 'I' && header[1] == 'W';
}
static void options_handler(rg_gui_option_t *dest)
{
*dest++ = (rg_gui_option_t){0, _("Gamma Boost"), "-", RG_DIALOG_FLAG_NORMAL, &gamma_update_cb};
*dest++ = (rg_gui_option_t)RG_DIALOG_END;
}
void app_main()
{
const rg_handlers_t handlers = {
@ -532,13 +538,10 @@ void app_main()
.reset = &reset_handler,
.screenshot = &screenshot_handler,
.event = &event_handler,
};
const rg_gui_option_t options[] = {
{0, _("Gamma Boost"), "-", RG_DIALOG_FLAG_NORMAL, &gamma_update_cb},
RG_DIALOG_END
.options = &options_handler,
};
app = rg_system_init(AUDIO_SAMPLE_RATE, &handlers, options);
app = rg_system_init(AUDIO_SAMPLE_RATE, &handlers, NULL);
rg_system_set_tick_rate(TICRATE);
const rg_display_t *display = rg_display_get_info();

View File

@ -232,6 +232,15 @@ static void audio_callback(void *buffer, size_t length)
audio_time += rg_system_timer() - startTime;
}
static void options_handler(rg_gui_option_t *dest)
{
*dest++ = (rg_gui_option_t){0, _("Palette"), "-", RG_DIALOG_FLAG_NORMAL, &palette_update_cb};
*dest++ = (rg_gui_option_t){0, _("RTC config"), "-", RG_DIALOG_FLAG_NORMAL, &rtc_update_cb};
*dest++ = (rg_gui_option_t){0, _("SRAM autosave"), "-", RG_DIALOG_FLAG_NORMAL, &sram_autosave_cb};
*dest++ = (rg_gui_option_t){0, _("Enable BIOS"), "-", RG_DIALOG_FLAG_NORMAL, &enable_bios_cb};
*dest++ = (rg_gui_option_t)RG_DIALOG_END;
}
void gbc_main(void)
{
const rg_handlers_t handlers = {
@ -240,16 +249,10 @@ void gbc_main(void)
.reset = &reset_handler,
.screenshot = &screenshot_handler,
.event = &event_handler,
};
const rg_gui_option_t options[] = {
{0, _("Palette"), "-", RG_DIALOG_FLAG_NORMAL, &palette_update_cb},
{0, _("RTC config"), "-", RG_DIALOG_FLAG_NORMAL, &rtc_update_cb},
{0, _("SRAM autosave"), "-", RG_DIALOG_FLAG_NORMAL, &sram_autosave_cb},
{0, _("Enable BIOS"), "-", RG_DIALOG_FLAG_NORMAL, &enable_bios_cb},
RG_DIALOG_END
.options = &options_handler,
};
app = rg_system_reinit(AUDIO_SAMPLE_RATE, &handlers, options);
app = rg_system_reinit(AUDIO_SAMPLE_RATE, &handlers, NULL);
updates[0] = rg_surface_create(GB_WIDTH, GB_HEIGHT, RG_PIXEL_565_BE, MEM_ANY);
updates[1] = rg_surface_create(GB_WIDTH, GB_HEIGHT, RG_PIXEL_565_BE, MEM_ANY);

View File

@ -179,6 +179,12 @@ static bool reset_handler(bool hard)
return true;
}
static void options_handler(rg_gui_option_t *dest)
{
*dest++ = (rg_gui_option_t){0, _("Rotation"), (char *)"-", RG_DIALOG_FLAG_NORMAL, &rotation_cb};
*dest++ = (rg_gui_option_t)RG_DIALOG_END;
}
extern "C" void lynx_main(void)
{
const rg_handlers_t handlers = {
@ -192,12 +198,8 @@ extern "C" void lynx_main(void)
.options = NULL,
.about = NULL,
};
const rg_gui_option_t options[] = {
{0, _("Rotation"), (char *)"-", RG_DIALOG_FLAG_NORMAL, &rotation_cb},
RG_DIALOG_END
};
app = rg_system_reinit(AUDIO_SAMPLE_RATE, &handlers, options);
app = rg_system_reinit(AUDIO_SAMPLE_RATE, &handlers, NULL);
// the HANDY_SCREEN_WIDTH * HANDY_SCREEN_WIDTH is deliberate because of rotation
updates[0] = rg_surface_create(HANDY_SCREEN_WIDTH, HANDY_SCREEN_WIDTH, RG_PIXEL_565_BE, MEM_FAST);
@ -213,7 +215,7 @@ extern "C" void lynx_main(void)
}
gPrimaryFrameBuffer = (UBYTE*)currentUpdate->data;
gAudioBuffer = (SWORD*)malloc(AUDIO_BUFFER_LENGTH * 4);
gAudioBuffer = new SWORD[AUDIO_BUFFER_LENGTH * 2];
gAudioEnabled = 1;
if (app->bootFlags & RG_BOOT_RESUME)

View File

@ -179,6 +179,15 @@ static void nsf_draw_overlay(void)
}
static void options_handler(rg_gui_option_t *dest)
{
*dest++ = (rg_gui_option_t){0, _("Palette"), "-", RG_DIALOG_FLAG_NORMAL, &palette_update_cb};
*dest++ = (rg_gui_option_t){0, _("Overscan"), "-", RG_DIALOG_FLAG_NORMAL, &overscan_update_cb};
*dest++ = (rg_gui_option_t){0, _("Crop sides"), "-", RG_DIALOG_FLAG_NORMAL, &autocrop_update_cb};
*dest++ = (rg_gui_option_t){0, _("Sprite limit"), "-", RG_DIALOG_FLAG_NORMAL, &sprite_limit_cb};
*dest++ = (rg_gui_option_t)RG_DIALOG_END;
}
void nes_main(void)
{
const rg_handlers_t handlers = {
@ -187,16 +196,10 @@ void nes_main(void)
.reset = &reset_handler,
.event = &event_handler,
.screenshot = &screenshot_handler,
};
const rg_gui_option_t options[] = {
{0, _("Palette"), "-", RG_DIALOG_FLAG_NORMAL, &palette_update_cb},
{0, _("Overscan"), "-", RG_DIALOG_FLAG_NORMAL, &overscan_update_cb},
{0, _("Crop sides"), "-", RG_DIALOG_FLAG_NORMAL, &autocrop_update_cb},
{0, _("Sprite limit"), "-", RG_DIALOG_FLAG_NORMAL, &sprite_limit_cb},
RG_DIALOG_END
.options = &options_handler,
};
app = rg_system_reinit(AUDIO_SAMPLE_RATE, &handlers, options);
app = rg_system_reinit(AUDIO_SAMPLE_RATE, &handlers, NULL);
overscan = rg_settings_get_number(NS_APP, SETTING_OVERSCAN, 1);
autocrop = rg_settings_get_number(NS_APP, SETTING_AUTOCROP, 0);

View File

@ -181,6 +181,12 @@ static bool reset_handler(bool hard)
return true;
}
static void options_handler(rg_gui_option_t *dest)
{
*dest++ = (rg_gui_option_t){0, _("Overscan"), "-", RG_DIALOG_FLAG_NORMAL, &overscan_update_cb};
*dest++ = (rg_gui_option_t)RG_DIALOG_END;
}
void pce_main(void)
{
const rg_handlers_t handlers = {
@ -189,13 +195,10 @@ void pce_main(void)
.reset = &reset_handler,
.screenshot = &screenshot_handler,
.event = &event_handler,
};
const rg_gui_option_t options[] = {
{0, _("Overscan"), "-", RG_DIALOG_FLAG_NORMAL, &overscan_update_cb},
RG_DIALOG_END
.options = &options_handler,
};
app = rg_system_reinit(AUDIO_SAMPLE_RATE, &handlers, options);
app = rg_system_reinit(AUDIO_SAMPLE_RATE, &handlers, NULL);
overscan = rg_settings_get_number(NS_APP, SETTING_OVERSCAN, 1);
updates[0] = rg_surface_create(XBUF_WIDTH, XBUF_HEIGHT, RG_PIXEL_PAL565_BE, MEM_FAST);

View File

@ -93,6 +93,12 @@ static rg_gui_event_t palette_update_cb(rg_gui_option_t *opt, rg_gui_event_t eve
return RG_DIALOG_VOID;
}
static void options_handler(rg_gui_option_t *dest)
{
*dest++ = (rg_gui_option_t){0, _("Palette"), "-", RG_DIALOG_FLAG_NORMAL, &palette_update_cb};
*dest++ = (rg_gui_option_t)RG_DIALOG_END;
}
void sms_main(void)
{
const rg_handlers_t handlers = {
@ -101,13 +107,10 @@ void sms_main(void)
.reset = &reset_handler,
.screenshot = &screenshot_handler,
.event = &event_handler,
};
const rg_gui_option_t options[] = {
{0, _("Palette"), "-", RG_DIALOG_FLAG_NORMAL, &palette_update_cb},
RG_DIALOG_END
.options = &options_handler,
};
app = rg_system_reinit(AUDIO_SAMPLE_RATE, &handlers, options);
app = rg_system_reinit(AUDIO_SAMPLE_RATE, &handlers, NULL);
updates[0] = rg_surface_create(SMS_WIDTH, SMS_HEIGHT, RG_PIXEL_PAL565_BE, MEM_FAST);
updates[1] = rg_surface_create(SMS_WIDTH, SMS_HEIGHT, RG_PIXEL_PAL565_BE, MEM_FAST);

View File

@ -284,6 +284,14 @@ static void S9xAudioCallback(void)
}
#endif
static void options_handler(rg_gui_option_t *dest)
{
*dest++ = (rg_gui_option_t){0, _("Audio enable"), "-", RG_DIALOG_FLAG_NORMAL, &apu_toggle_cb};
*dest++ = (rg_gui_option_t){0, _("Audio filter"), "-", RG_DIALOG_FLAG_NORMAL, &lowpass_filter_cb};
*dest++ = (rg_gui_option_t){0, _("Controls"), "-", RG_DIALOG_FLAG_NORMAL, &menu_keymap_cb};
*dest++ = (rg_gui_option_t)RG_DIALOG_END;
}
void snes_main(void)
{
const rg_handlers_t handlers = {
@ -292,14 +300,9 @@ void snes_main(void)
.reset = &reset_handler,
.screenshot = &screenshot_handler,
.event = &event_handler,
.options = &options_handler,
};
const rg_gui_option_t options[] = {
{0, _("Audio enable"), "-", RG_DIALOG_FLAG_NORMAL, &apu_toggle_cb},
{0, _("Audio filter"), "-", RG_DIALOG_FLAG_NORMAL, &lowpass_filter_cb},
{0, _("Controls"), "-", RG_DIALOG_FLAG_NORMAL, &menu_keymap_cb},
RG_DIALOG_END,
};
app = rg_system_reinit(AUDIO_SAMPLE_RATE, &handlers, options);
app = rg_system_reinit(AUDIO_SAMPLE_RATE, &handlers, NULL);
apu_enabled = rg_settings_get_number(NS_APP, SETTING_APU_EMULATION, 1);