Skip to content

Commit

Permalink
Add a binding to toggle the FPS counter.
Browse files Browse the repository at this point in the history
  • Loading branch information
Arignir committed Oct 8, 2024
1 parent c18093a commit 1641872
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 18 deletions.
12 changes: 8 additions & 4 deletions include/app/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ enum bind_actions {
BIND_EMULATOR_PAUSE,
BIND_EMULATOR_STOP,
BIND_EMULATOR_RESET,
BIND_EMULATOR_SHOW_FPS,
BIND_EMULATOR_SETTINGS,
BIND_EMULATOR_ALT_SPEED_HOLD,
BIND_EMULATOR_ALT_SPEED_TOGGLE,
BIND_EMULATOR_SETTINGS,
BIND_EMULATOR_QUICKSAVE_1,
BIND_EMULATOR_QUICKSAVE_2,
BIND_EMULATOR_QUICKSAVE_3,
Expand Down Expand Up @@ -160,6 +161,12 @@ struct settings {
// BIOS Path
char *bios_path;

// Skip BIOS
bool skip_bios;

// Show FPS
bool show_fps;

// Speed
// <= 0: Unlimited
// 1.0: 60fps
Expand All @@ -174,9 +181,6 @@ struct settings {
// etc.
float alt_speed;

// Skip BIOS
bool skip_bios;

// Backup storage
struct {
bool autodetect;
Expand Down
11 changes: 5 additions & 6 deletions source/app/bindings.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ app_bindings_setup_default(
app_bindings_keyboard_binding_build(&app->binds.keyboard[BIND_EMULATOR_RESET], SDL_GetKeyFromName("R"), true, false, false);
app_bindings_keyboard_binding_build(&app->binds.keyboard[BIND_EMULATOR_MUTE], SDL_GetKeyFromName("M"), true, false, false);
app_bindings_keyboard_binding_build(&app->binds.keyboard[BIND_EMULATOR_PAUSE], SDL_GetKeyFromName("P"), true, false, false);
app_bindings_keyboard_binding_build(&app->binds.keyboard[BIND_EMULATOR_SHOW_FPS], SDL_GetKeyFromName("F"), true, false, false);
app_bindings_keyboard_binding_build(&app->binds.keyboard[BIND_EMULATOR_SETTINGS], SDL_GetKeyFromName("Escape"), false, false, false);
app_bindings_keyboard_binding_build(&app->binds.keyboard[BIND_EMULATOR_SCREENSHOT], SDL_GetKeyFromName("F12"), false, false, false);
app_bindings_keyboard_binding_build(&app->binds.keyboard[BIND_EMULATOR_ALT_SPEED_HOLD], SDL_GetKeyFromName("Space"), false, false, false);
Expand Down Expand Up @@ -216,11 +217,10 @@ app_bindings_handle(

// Bindings that can be used both in and outside of a game
switch (bind) {
case BIND_EMULATOR_SETTINGS: {
app->ui.settings.open ^= true;
break;
};
default: break;
case BIND_EMULATOR_MUTE: app->settings.audio.mute ^= true; break;
case BIND_EMULATOR_SHOW_FPS: app->settings.emulation.show_fps ^= true; break;
case BIND_EMULATOR_SETTINGS: app->ui.settings.open ^= true; break;
default: break;
}

if (!app->emulation.is_started) {
Expand All @@ -229,7 +229,6 @@ app_bindings_handle(

// Bindings that can only be used in game.
switch (bind) {
case BIND_EMULATOR_MUTE: app->settings.audio.mute ^= 1; break;
case BIND_EMULATOR_SCREENSHOT: app_emulator_screenshot(app); break;
case BIND_EMULATOR_PAUSE: app->emulation.is_running ? app_emulator_pause(app) : app_emulator_run(app); break;
case BIND_EMULATOR_STOP: app_emulator_stop(app); break;
Expand Down
14 changes: 10 additions & 4 deletions source/app/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ app_config_load(
int b;
double d;

if (mjson_get_bool(data, data_len, "$.emulation.skip_bios", &b)) {
app->settings.emulation.skip_bios = b;
}

if (mjson_get_bool(data, data_len, "$.emulation.show_fps", &b)) {
app->settings.emulation.show_fps = b;
}

if (mjson_get_number(data, data_len, "$.emulation.speed", &d)) {
app->settings.emulation.speed = d;
}
Expand All @@ -99,10 +107,6 @@ app_config_load(
if (mjson_get_number(data, data_len, "$.emulation.gpio.type", &d)) {
app->settings.emulation.gpio_device.type = max(GPIO_MIN, min((int)d, GPIO_MAX));
}

if (mjson_get_bool(data, data_len, "$.emulation.skip_bios", &b)) {
app->settings.emulation.skip_bios = b;
}
}

// Video
Expand Down Expand Up @@ -294,6 +298,7 @@ app_config_save(
// Emulation
"emulation": {
"skip_bios": %B,
"show_fps": %B,
"speed": %g,
"alt_speed": %g,
"backup_storage": {
Expand Down Expand Up @@ -342,6 +347,7 @@ app_config_save(
app->file.recent_roms[8],
app->file.recent_roms[9],
(int)app->settings.emulation.skip_bios,
(int)app->settings.emulation.show_fps,
app->settings.emulation.speed,
app->settings.emulation.alt_speed,
(int)app->settings.emulation.backup_storage.autodetect,
Expand Down
9 changes: 7 additions & 2 deletions source/app/windows/menubar.c
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,13 @@ void
app_win_menubar_fps_counter(
struct app *app
) {
/* FPS Counter */
if (app->emulation.is_started && app->emulation.is_running && igGetWindowWidth() >= GBA_SCREEN_WIDTH * 2 * app->ui.scale) {
// FPS Counter
if (
app->settings.emulation.show_fps
&& app->emulation.is_started
&& app->emulation.is_running
&& igGetWindowWidth() >= GBA_SCREEN_WIDTH * 2 * app->ui.scale
) {
float spacing;
ImVec2 out;

Expand Down
23 changes: 21 additions & 2 deletions source/app/windows/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ char const * const binds_pretty_name[] = {
[BIND_EMULATOR_PAUSE] = "Pause",
[BIND_EMULATOR_STOP] = "Stop",
[BIND_EMULATOR_RESET] = "Reset",
[BIND_EMULATOR_SHOW_FPS] = "Show FPS",
[BIND_EMULATOR_SETTINGS] = "Settings",
[BIND_EMULATOR_ALT_SPEED_TOGGLE] = "Alt. Speed (Toggle)",
[BIND_EMULATOR_ALT_SPEED_HOLD] = "Alt. Speed (Hold)",
[BIND_EMULATOR_SETTINGS] = "Settings",
[BIND_EMULATOR_QUICKSAVE_1] = "Quicksave 1",
[BIND_EMULATOR_QUICKSAVE_2] = "Quicksave 2",
[BIND_EMULATOR_QUICKSAVE_3] = "Quicksave 3",
Expand Down Expand Up @@ -110,9 +111,10 @@ char const * const binds_slug[] = {
[BIND_EMULATOR_PAUSE] = "pause",
[BIND_EMULATOR_STOP] = "stop",
[BIND_EMULATOR_RESET] = "reset",
[BIND_EMULATOR_SHOW_FPS] = "show_fps",
[BIND_EMULATOR_SETTINGS] = "settings",
[BIND_EMULATOR_ALT_SPEED_TOGGLE] = "alternative_speed_toggle",
[BIND_EMULATOR_ALT_SPEED_HOLD] = "alternative_speed_hold",
[BIND_EMULATOR_SETTINGS] = "settings",
[BIND_EMULATOR_QUICKSAVE_1] = "quicksave_1",
[BIND_EMULATOR_QUICKSAVE_2] = "quicksave_2",
[BIND_EMULATOR_QUICKSAVE_3] = "quicksave_3",
Expand Down Expand Up @@ -329,6 +331,23 @@ app_win_settings_emulation(

igEndTable();
}

igSeparatorText("Misc");

if (igBeginTable("##EmulationSettingsMisc", 2, ImGuiTableFlags_None, (ImVec2){ .x = 0.f, .y = 0.f }, 0.f)) {
igTableSetupColumn("##EmulationSettingsMiscLabel", ImGuiTableColumnFlags_WidthFixed, vp->WorkSize.x / 5.f, 0);
igTableSetupColumn("##EmulationSettingsMiscValue", ImGuiTableColumnFlags_WidthStretch, 0.f, 0);

// Show FPS
igTableNextRow(ImGuiTableRowFlags_None, 0.f);
igTableNextColumn();
igTextWrapped("Show FPS");

igTableNextColumn();
igCheckbox("##ShowFPS", &app->settings.emulation.show_fps);

igEndTable();
}
}

static
Expand Down

0 comments on commit 1641872

Please sign in to comment.