Skip to content

Commit

Permalink
Split the settings in a new structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
Arignir committed Mar 16, 2024
1 parent 5ece4a4 commit 1beefe2
Show file tree
Hide file tree
Showing 17 changed files with 274 additions and 233 deletions.
125 changes: 78 additions & 47 deletions include/app/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ enum bind_actions {
extern char const * const binds_pretty_name[];
extern char const * const binds_slug[];

enum ui_notification_kind {
enum app_notification_kind {
UI_NOTIFICATION_INFO,
UI_NOTIFICATION_SUCCESS,
UI_NOTIFICATION_ERROR,
Expand All @@ -143,22 +143,92 @@ enum menu_kind {
MENU_MAX,
};

struct ui_notification {
enum ui_notification_kind kind;
struct app_notification {
enum app_notification_kind kind;
char *msg;
uint64_t timeout;
uint64_t fade_time_start;
struct ui_notification *next;
struct app_notification *next;
};

struct app_config {
struct settings {
struct {
// BIOS Path
char *bios_path;

// Fast forward
bool fast_forward;

// Speed
float speed;

// Skip BIOS
bool skip_bios;

// Automatically pause the game when the window looses focus
bool auto_pause;

// Pause immediately after resetting the game
bool pause_on_reset;

// Backup storage
struct {
bool autodetect;
enum backup_storage_types type;
} backup_storage;

// GPIO
struct {
bool autodetect;
enum gpio_device_types type;
} gpio_device;
} emulation;

struct {
// Display size
uint32_t display_size;

// Aspect Ratio (Black borders, Auto-Resize, etc.)
enum aspect_ratio aspect_ratio;

// VSync
bool vsync;

// Texture Filter (Linear, Nearest)
enum texture_filter_kind texture_filter;

// Color Filter (Color Correction)
enum pixel_color_filter_kind pixel_color_filter;

// Pixel Scaling Filter (LCD Grid, xBRZ, etc.)
enum pixel_scaling_filter_kind pixel_scaling_filter;

/*
** Debug
*/

// Enable BG Layer X
bool enable_bg_layers[4];

// Enable OAM (Sprites)
bool enable_oam;
} video;

struct {
// Mute all the emulator's sounds
bool mute;

// Level of the sound (0.0 to 1.0)
float level;

/*
** Debug
*/

// Enable PSG Channel X
bool enable_psg_channels[4];

// Enable FIFO Channel
bool enable_fifo_channels[2];
} audio;
};
Expand Down Expand Up @@ -188,33 +258,6 @@ struct app {
// Current FPS
uint32_t fps;

// Fast forward
bool fast_forward;

// Speed
float speed;

// Skip BIOS
bool skip_bios;

// Automatically pause the game when the window looses focus
bool auto_pause;

// Pause immediately after resetting the game
bool pause_on_reset;

// Backup storage
struct {
bool autodetect;
enum backup_storage_types type;
} backup_storage;

// GPIO
struct {
bool autodetect;
enum gpio_device_types type;
} gpio_device;

// The current quicksave request
struct {
bool enabled;
Expand Down Expand Up @@ -271,7 +314,6 @@ struct app {
char *sys_pictures_dir_path;
char *sys_config_path;

char *bios_path;
char *recent_roms[MAX_RECENT_ROMS];

struct {
Expand All @@ -284,17 +326,6 @@ struct app {
} file;

struct {
uint32_t display_size;
enum aspect_ratio aspect_ratio;
bool vsync;
enum texture_filter_kind texture_filter;
enum pixel_color_filter_kind pixel_color_filter;
enum pixel_scaling_filter_kind pixel_scaling_filter;
} video;

struct {
bool mute;
float level;
uint32_t resample_frequency;
} audio;

Expand Down Expand Up @@ -371,7 +402,7 @@ struct app {
} keybindings_editor;
} settings;

struct ui_notification *notifications;
struct app_notification *notifications;
} ui;

struct {
Expand All @@ -381,7 +412,7 @@ struct app {
SDL_GameControllerButton controller_alt[BIND_MAX];
} binds;

struct app_config config;
struct settings settings;

#if WITH_DEBUGGER
struct {
Expand Down Expand Up @@ -445,7 +476,7 @@ void app_win_game(struct app *app);
void app_win_menubar(struct app *app);

/* app/windows/notif.c */
void app_new_notification(struct app *app, enum ui_notification_kind, char const *msg, ...);
void app_new_notification(struct app *app, enum app_notification_kind, char const *msg, ...);
void app_win_notifications(struct app *app);

/* app/windows/settings.c */
Expand Down
2 changes: 1 addition & 1 deletion include/gba/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct message_reset {

struct message_settings {
struct event_header header;
struct emulation_settings settings;
struct gba_settings settings;
};

struct message_key {
Expand Down
6 changes: 3 additions & 3 deletions include/gba/gba.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ struct shared_data {
/*
** Settings that can be altered while the game is running.
*/
struct emulation_settings {
struct gba_settings {
// Fast forward
bool fast_forward;

Expand Down Expand Up @@ -116,7 +116,7 @@ struct gba {
struct shared_data shared_data;

// A set of settings the frontend can update during the emulator's execution (speed, etc.)
struct emulation_settings settings;
struct gba_settings settings;

// The different components of the GBA
struct core core;
Expand Down Expand Up @@ -163,7 +163,7 @@ struct launch_config {
} backup_storage;

// Initial value for all runtime-settings (speed, etc.)
struct emulation_settings settings;
struct gba_settings settings;
};

struct notification;
Expand Down
10 changes: 5 additions & 5 deletions source/app/bindings.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ app_bindings_handle(
case BIND_GBA_SELECT: app_emulator_key(app, KEY_SELECT, pressed); break;
case BIND_GBA_START: app_emulator_key(app, KEY_START, pressed); break;
case BIND_EMULATOR_FAST_FORWARD_HOLD: {
app->emulation.fast_forward = pressed;
app->settings.emulation.fast_forward = pressed;
app_emulator_settings(app);
break;
};
Expand All @@ -155,7 +155,7 @@ app_bindings_handle(

/* Bindings that cannot be used outside of a game */
switch (bind) {
case BIND_EMULATOR_MUTE: app->audio.mute ^= 1; break;
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 All @@ -176,13 +176,13 @@ app_bindings_handle(
4.00f,
5.00f,
};
app->emulation.fast_forward = false;
app->emulation.speed = speeds[bind - BIND_EMULATOR_SPEED_X0_25];
app->settings.emulation.fast_forward = false;
app->settings.emulation.speed = speeds[bind - BIND_EMULATOR_SPEED_X0_25];
app_emulator_settings(app);
break;
};
case BIND_EMULATOR_FAST_FORWARD_TOGGLE: {
app->emulation.fast_forward ^= true;
app->settings.emulation.fast_forward ^= true;
app_emulator_settings(app);
break;
}
Expand Down

0 comments on commit 1beefe2

Please sign in to comment.