mirror of
https://github.com/libretro/RetroArch
synced 2025-02-27 00:40:20 +00:00
Refactor away some functions
This commit is contained in:
parent
3de0718e3f
commit
668373f9f8
31
driver.c
31
driver.c
@ -149,21 +149,21 @@ int find_driver_index(const char * label, const char *drv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool find_first_driver(const char *label, char *s, size_t len)
|
||||
static bool driver_find_first(const char *label, char *s, size_t len)
|
||||
{
|
||||
find_driver_nonempty(label, 0, s, len);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* find_prev_driver:
|
||||
* driver_find_prev:
|
||||
* @label : string of driver type to be found.
|
||||
* @s : identifier of driver to be found.
|
||||
* @len : size of @s.
|
||||
*
|
||||
* Find previous driver in driver array.
|
||||
**/
|
||||
bool find_prev_driver(const char *label, char *s, size_t len)
|
||||
static bool driver_find_prev(const char *label, char *s, size_t len)
|
||||
{
|
||||
int i = find_driver_index(label, s);
|
||||
if (i > 0)
|
||||
@ -178,14 +178,14 @@ bool find_prev_driver(const char *label, char *s, size_t len)
|
||||
}
|
||||
|
||||
/**
|
||||
* find_next_driver:
|
||||
* driver_find_next:
|
||||
* @label : string of driver type to be found.
|
||||
* @s : identifier of driver to be found.
|
||||
* @len : size of @s.
|
||||
*
|
||||
* Find next driver in driver array.
|
||||
**/
|
||||
bool find_next_driver(const char *label, char *s, size_t len)
|
||||
bool driver_find_next(const char *label, char *s, size_t len)
|
||||
{
|
||||
int i = find_driver_index(label, s);
|
||||
if (i >= 0 && !string_is_equal(s, "null"))
|
||||
@ -475,6 +475,27 @@ bool driver_ctl(enum driver_ctl_state state, void *data)
|
||||
return driver_update_system_av_info(*info);
|
||||
}
|
||||
return false;
|
||||
case RARCH_DRIVER_CTL_FIND_FIRST:
|
||||
{
|
||||
driver_ctx_info_t *drv = (driver_ctx_info_t*)data;
|
||||
if (!drv)
|
||||
return false;
|
||||
return driver_find_first(drv->label, drv->s, drv->len);
|
||||
}
|
||||
case RARCH_DRIVER_CTL_FIND_PREV:
|
||||
{
|
||||
driver_ctx_info_t *drv = (driver_ctx_info_t*)data;
|
||||
if (!drv)
|
||||
return false;
|
||||
return driver_find_prev(drv->label, drv->s, drv->len);
|
||||
}
|
||||
case RARCH_DRIVER_CTL_FIND_NEXT:
|
||||
{
|
||||
driver_ctx_info_t *drv = (driver_ctx_info_t*)data;
|
||||
if (!drv)
|
||||
return false;
|
||||
return driver_find_next(drv->label, drv->s, drv->len);
|
||||
}
|
||||
case RARCH_DRIVER_CTL_NONE:
|
||||
default:
|
||||
break;
|
||||
|
41
driver.h
41
driver.h
@ -201,9 +201,22 @@ enum driver_ctl_state
|
||||
/* Update the system Audio/Video information.
|
||||
* Will reinitialize audio/video drivers.
|
||||
* Used by RETRO_ENVIRONMENT_SET_SYSTEM_AV_INFO. */
|
||||
RARCH_DRIVER_CTL_UPDATE_SYSTEM_AV_INFO
|
||||
RARCH_DRIVER_CTL_UPDATE_SYSTEM_AV_INFO,
|
||||
|
||||
RARCH_DRIVER_CTL_FIND_FIRST,
|
||||
|
||||
RARCH_DRIVER_CTL_FIND_PREV,
|
||||
|
||||
RARCH_DRIVER_CTL_FIND_NEXT
|
||||
};
|
||||
|
||||
typedef struct driver_ctx_info
|
||||
{
|
||||
const char *label;
|
||||
char *s;
|
||||
size_t len;
|
||||
} driver_ctx_info_t;
|
||||
|
||||
|
||||
/* TODO/FIXME - comment needs to be moved to each respective driver */
|
||||
|
||||
@ -220,32 +233,6 @@ enum driver_ctl_state
|
||||
* Typically, if a driver intends to make use of this, it should
|
||||
* set this to true at the end of its 'init' function. */
|
||||
|
||||
bool find_first_driver(const char *label, char *s, size_t len);
|
||||
|
||||
/**
|
||||
* find_prev_driver:
|
||||
* @label : string of driver type to be found.
|
||||
* @s : identifier of driver to be found.
|
||||
* @len : size of @s.
|
||||
*
|
||||
* Find previous driver in driver array.
|
||||
*
|
||||
* Returns: true (1) if successful, otherwise false (0).
|
||||
**/
|
||||
bool find_prev_driver(const char *label, char *s, size_t len);
|
||||
|
||||
/**
|
||||
* find_next_driver:
|
||||
* @label : string of driver type to be found.
|
||||
* @s : identifier of driver to be found.
|
||||
* @len : size of @.
|
||||
*
|
||||
* Find next driver in driver array.
|
||||
*
|
||||
* Returns: true (1) if successful, otherwise false (0).
|
||||
**/
|
||||
bool find_next_driver(const char *label, char *s, size_t len);
|
||||
|
||||
/**
|
||||
* find_driver_index:
|
||||
* @label : string of driver type to be found.
|
||||
|
@ -789,12 +789,18 @@ static int setting_fraction_action_right_default(
|
||||
static int setting_string_action_left_driver(void *data,
|
||||
bool wraparound)
|
||||
{
|
||||
driver_ctx_info_t drv;
|
||||
rarch_setting_t *setting = (rarch_setting_t*)data;
|
||||
|
||||
if (!setting)
|
||||
return -1;
|
||||
|
||||
find_prev_driver(setting->name, setting->value.string, setting->size);
|
||||
drv.label = setting->name;
|
||||
drv.s = setting->value.string;
|
||||
drv.len = setting->size;
|
||||
|
||||
if (!driver_ctl(RARCH_DRIVER_CTL_FIND_PREV, &drv))
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -802,17 +808,27 @@ static int setting_string_action_left_driver(void *data,
|
||||
static int setting_string_action_right_driver(void *data,
|
||||
bool wraparound)
|
||||
{
|
||||
driver_ctx_info_t drv;
|
||||
rarch_setting_t *setting = (rarch_setting_t*)data;
|
||||
|
||||
if (!setting)
|
||||
return -1;
|
||||
|
||||
if (!find_next_driver(setting->name, setting->value.string, setting->size))
|
||||
drv.label = setting->name;
|
||||
drv.s = setting->value.string;
|
||||
drv.len = setting->size;
|
||||
|
||||
if (!driver_ctl(RARCH_DRIVER_CTL_FIND_NEXT, &drv))
|
||||
{
|
||||
settings_t *settings = config_get_ptr();
|
||||
|
||||
if (settings && settings->menu.navigation.wraparound.setting_enable)
|
||||
find_first_driver(setting->name, setting->value.string, setting->size);
|
||||
{
|
||||
drv.label = setting->name;
|
||||
drv.s = setting->value.string;
|
||||
drv.len = setting->size;
|
||||
driver_ctl(RARCH_DRIVER_CTL_FIND_FIRST, &drv);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user