mirror of
https://github.com/libretro/RetroArch
synced 2025-02-06 18:40:49 +00:00
input_autoconfigure_connect - have boolean return value
- task_autodetect.c - cleanups, try to do less with generic error labels and gotos, etc.
This commit is contained in:
parent
81de36e1ff
commit
fa9e56d824
@ -244,9 +244,7 @@ static bool input_autoconfigure_scan_config_files_external(
|
||||
continue;
|
||||
|
||||
/* Load autoconfig file */
|
||||
config = config_file_new_from_path_to_string(config_file_path);
|
||||
|
||||
if (!config)
|
||||
if (!(config = config_file_new_from_path_to_string(config_file_path)))
|
||||
continue;
|
||||
|
||||
/* Check for a match */
|
||||
@ -369,9 +367,7 @@ static void cb_input_autoconfigure_connect(
|
||||
if (!task)
|
||||
return;
|
||||
|
||||
autoconfig_handle = (autoconfig_handle_t*)task->state;
|
||||
|
||||
if (!autoconfig_handle)
|
||||
if (!(autoconfig_handle = (autoconfig_handle_t*)task->state))
|
||||
return;
|
||||
|
||||
/* Use local copy of port index for brevity... */
|
||||
@ -450,14 +446,24 @@ static void input_autoconfigure_connect_handler(retro_task_t *task)
|
||||
task_title[0] = '\0';
|
||||
|
||||
if (!task)
|
||||
goto task_finished;
|
||||
return;
|
||||
|
||||
autoconfig_handle = (autoconfig_handle_t*)task->state;
|
||||
|
||||
if (!autoconfig_handle ||
|
||||
string_is_empty(autoconfig_handle->device_info.name) ||
|
||||
!autoconfig_handle->autoconfig_enabled)
|
||||
goto task_finished;
|
||||
{
|
||||
task_set_finished(task, true);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Get display name for task status message */
|
||||
device_display_name = autoconfig_handle->device_info.display_name;
|
||||
if (string_is_empty(device_display_name))
|
||||
device_display_name = autoconfig_handle->device_info.name;
|
||||
if (string_is_empty(device_display_name))
|
||||
device_display_name = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE);
|
||||
|
||||
/* Annoyingly, we have to scan all the autoconfig
|
||||
* files (and in-built configs) in a single shot
|
||||
@ -469,63 +475,58 @@ static void input_autoconfigure_connect_handler(retro_task_t *task)
|
||||
/* Scan in order of preference:
|
||||
* - External autoconfig files
|
||||
* - Internal autoconfig definitions */
|
||||
match_found = input_autoconfigure_scan_config_files_external(
|
||||
autoconfig_handle);
|
||||
|
||||
if (!match_found)
|
||||
match_found = input_autoconfigure_scan_config_files_internal(
|
||||
autoconfig_handle);
|
||||
|
||||
/* If no match was found, attempt to use
|
||||
* fallback mapping
|
||||
* > Only enabled for certain drivers */
|
||||
if (!match_found)
|
||||
if (!(match_found = input_autoconfigure_scan_config_files_external(
|
||||
autoconfig_handle)))
|
||||
{
|
||||
const char *fallback_device_name = NULL;
|
||||
|
||||
/* Preset fallback device names - must match
|
||||
* those set in 'input_autodetect_builtin.c' */
|
||||
if (string_is_equal(autoconfig_handle->device_info.joypad_driver,
|
||||
"android"))
|
||||
fallback_device_name = "Android Gamepad";
|
||||
else if (string_is_equal(autoconfig_handle->device_info.joypad_driver,
|
||||
"xinput"))
|
||||
fallback_device_name = "XInput Controller";
|
||||
else if (string_is_equal(autoconfig_handle->device_info.joypad_driver,
|
||||
"sdl2"))
|
||||
fallback_device_name = "Standard Gamepad";
|
||||
|
||||
if (!string_is_empty(fallback_device_name) &&
|
||||
!string_is_equal(autoconfig_handle->device_info.name,
|
||||
fallback_device_name))
|
||||
if (!(match_found = input_autoconfigure_scan_config_files_internal(
|
||||
autoconfig_handle)))
|
||||
{
|
||||
char *name_backup = strdup(autoconfig_handle->device_info.name);
|
||||
/* If no match was found, attempt to use
|
||||
* fallback mapping
|
||||
* > Only enabled for certain drivers */
|
||||
const char *fallback_device_name = NULL;
|
||||
|
||||
strlcpy(autoconfig_handle->device_info.name,
|
||||
fallback_device_name,
|
||||
sizeof(autoconfig_handle->device_info.name));
|
||||
/* Preset fallback device names - must match
|
||||
* those set in 'input_autodetect_builtin.c' */
|
||||
if (string_is_equal(
|
||||
autoconfig_handle->device_info.joypad_driver,
|
||||
"android"))
|
||||
fallback_device_name = "Android Gamepad";
|
||||
else if (string_is_equal(
|
||||
autoconfig_handle->device_info.joypad_driver,
|
||||
"xinput"))
|
||||
fallback_device_name = "XInput Controller";
|
||||
else if (string_is_equal(
|
||||
autoconfig_handle->device_info.joypad_driver,
|
||||
"sdl2"))
|
||||
fallback_device_name = "Standard Gamepad";
|
||||
|
||||
/* This is not a genuine match - leave
|
||||
* match_found set to 'false' regardless
|
||||
* of the outcome */
|
||||
input_autoconfigure_scan_config_files_internal(
|
||||
autoconfig_handle);
|
||||
if (!string_is_empty(fallback_device_name) &&
|
||||
!string_is_equal(autoconfig_handle->device_info.name,
|
||||
fallback_device_name))
|
||||
{
|
||||
char *name_backup = strdup(autoconfig_handle->device_info.name);
|
||||
|
||||
strlcpy(autoconfig_handle->device_info.name,
|
||||
name_backup,
|
||||
sizeof(autoconfig_handle->device_info.name));
|
||||
strlcpy(autoconfig_handle->device_info.name,
|
||||
fallback_device_name,
|
||||
sizeof(autoconfig_handle->device_info.name));
|
||||
|
||||
free(name_backup);
|
||||
name_backup = NULL;
|
||||
/* This is not a genuine match - leave
|
||||
* match_found set to 'false' regardless
|
||||
* of the outcome */
|
||||
input_autoconfigure_scan_config_files_internal(
|
||||
autoconfig_handle);
|
||||
|
||||
strlcpy(autoconfig_handle->device_info.name,
|
||||
name_backup,
|
||||
sizeof(autoconfig_handle->device_info.name));
|
||||
|
||||
free(name_backup);
|
||||
name_backup = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Get display name for task status message */
|
||||
device_display_name = autoconfig_handle->device_info.display_name;
|
||||
if (string_is_empty(device_display_name))
|
||||
device_display_name = autoconfig_handle->device_info.name;
|
||||
if (string_is_empty(device_display_name))
|
||||
device_display_name = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE);
|
||||
|
||||
/* Generate task status message
|
||||
* > Note that 'connection successful' messages
|
||||
@ -564,10 +565,7 @@ static void input_autoconfigure_connect_handler(retro_task_t *task)
|
||||
if (!string_is_empty(task_title))
|
||||
task_set_title(task, strdup(task_title));
|
||||
|
||||
task_finished:
|
||||
|
||||
if (task)
|
||||
task_set_finished(task, true);
|
||||
task_set_finished(task, true);
|
||||
}
|
||||
|
||||
static bool autoconfigure_connect_finder(retro_task_t *task, void *user_data)
|
||||
@ -581,15 +579,14 @@ static bool autoconfigure_connect_finder(retro_task_t *task, void *user_data)
|
||||
if (task->handler != input_autoconfigure_connect_handler)
|
||||
return false;
|
||||
|
||||
autoconfig_handle = (autoconfig_handle_t*)task->state;
|
||||
if (!autoconfig_handle)
|
||||
if (!(autoconfig_handle = (autoconfig_handle_t*)task->state))
|
||||
return false;
|
||||
|
||||
port = (unsigned*)user_data;
|
||||
return (*port == autoconfig_handle->port);
|
||||
}
|
||||
|
||||
void input_autoconfigure_connect(
|
||||
bool input_autoconfigure_connect(
|
||||
const char *name,
|
||||
const char *display_name,
|
||||
const char *driver,
|
||||
@ -597,6 +594,7 @@ void input_autoconfigure_connect(
|
||||
unsigned vid,
|
||||
unsigned pid)
|
||||
{
|
||||
task_finder_data_t find_data;
|
||||
retro_task_t *task = NULL;
|
||||
autoconfig_handle_t *autoconfig_handle = NULL;
|
||||
bool driver_valid = false;
|
||||
@ -607,10 +605,9 @@ void input_autoconfigure_connect(
|
||||
settings->paths.directory_autoconfig : NULL;
|
||||
bool notification_show_autoconfig = settings ?
|
||||
settings->bools.notification_show_autoconfig : true;
|
||||
task_finder_data_t find_data;
|
||||
|
||||
if (port >= MAX_INPUT_DEVICES)
|
||||
goto error;
|
||||
return false;
|
||||
|
||||
/* Cannot connect a device that is currently
|
||||
* being connected */
|
||||
@ -618,13 +615,12 @@ void input_autoconfigure_connect(
|
||||
find_data.userdata = (void*)&port;
|
||||
|
||||
if (task_queue_find(&find_data))
|
||||
goto error;
|
||||
return false;
|
||||
|
||||
/* Configure handle */
|
||||
autoconfig_handle = (autoconfig_handle_t*)malloc(sizeof(autoconfig_handle_t));
|
||||
|
||||
if (!autoconfig_handle)
|
||||
goto error;
|
||||
if (!(autoconfig_handle =
|
||||
(autoconfig_handle_t*)malloc(sizeof(autoconfig_handle_t))))
|
||||
return false;
|
||||
|
||||
autoconfig_handle->port = port;
|
||||
autoconfig_handle->device_info.vid = vid;
|
||||
@ -716,10 +712,12 @@ void input_autoconfigure_connect(
|
||||
}
|
||||
|
||||
/* Configure task */
|
||||
task = task_init();
|
||||
|
||||
if (!task)
|
||||
goto error;
|
||||
if (!(task = task_init()))
|
||||
{
|
||||
free_autoconfig_handle(autoconfig_handle);
|
||||
autoconfig_handle = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
task->handler = input_autoconfigure_connect_handler;
|
||||
task->state = autoconfig_handle;
|
||||
@ -730,18 +728,7 @@ void input_autoconfigure_connect(
|
||||
|
||||
task_queue_push(task);
|
||||
|
||||
return;
|
||||
|
||||
error:
|
||||
|
||||
if (task)
|
||||
{
|
||||
free(task);
|
||||
task = NULL;
|
||||
}
|
||||
|
||||
free_autoconfig_handle(autoconfig_handle);
|
||||
autoconfig_handle = NULL;
|
||||
return true;
|
||||
}
|
||||
|
||||
/****************************/
|
||||
@ -758,9 +745,7 @@ static void cb_input_autoconfigure_disconnect(
|
||||
if (!task)
|
||||
return;
|
||||
|
||||
autoconfig_handle = (autoconfig_handle_t*)task->state;
|
||||
|
||||
if (!autoconfig_handle)
|
||||
if (!(autoconfig_handle = (autoconfig_handle_t*)task->state))
|
||||
return;
|
||||
|
||||
/* Use local copy of port index for brevity... */
|
||||
@ -787,12 +772,15 @@ static void input_autoconfigure_disconnect_handler(retro_task_t *task)
|
||||
task_title[0] = '\0';
|
||||
|
||||
if (!task)
|
||||
goto task_finished;
|
||||
return;
|
||||
|
||||
autoconfig_handle = (autoconfig_handle_t*)task->state;
|
||||
|
||||
if (!autoconfig_handle)
|
||||
goto task_finished;
|
||||
{
|
||||
task_set_finished(task, true);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Set task title */
|
||||
if (!string_is_empty(autoconfig_handle->device_info.name))
|
||||
@ -809,10 +797,7 @@ static void input_autoconfigure_disconnect_handler(retro_task_t *task)
|
||||
if (!autoconfig_handle->suppress_notifcations)
|
||||
task_set_title(task, strdup(task_title));
|
||||
|
||||
task_finished:
|
||||
|
||||
if (task)
|
||||
task_set_finished(task, true);
|
||||
task_set_finished(task, true);
|
||||
}
|
||||
|
||||
static bool autoconfigure_disconnect_finder(retro_task_t *task, void *user_data)
|
||||
@ -826,8 +811,7 @@ static bool autoconfigure_disconnect_finder(retro_task_t *task, void *user_data)
|
||||
if (task->handler != input_autoconfigure_disconnect_handler)
|
||||
return false;
|
||||
|
||||
autoconfig_handle = (autoconfig_handle_t*)task->state;
|
||||
if (!autoconfig_handle)
|
||||
if (!(autoconfig_handle = (autoconfig_handle_t*)task->state))
|
||||
return false;
|
||||
|
||||
port = (unsigned*)user_data;
|
||||
@ -845,15 +829,15 @@ static bool autoconfigure_disconnect_finder(retro_task_t *task, void *user_data)
|
||||
* we ensure uniformity of OSD status messages */
|
||||
bool input_autoconfigure_disconnect(unsigned port, const char *name)
|
||||
{
|
||||
task_finder_data_t find_data;
|
||||
retro_task_t *task = NULL;
|
||||
autoconfig_handle_t *autoconfig_handle = NULL;
|
||||
task_finder_data_t find_data;
|
||||
settings_t *settings = config_get_ptr();
|
||||
bool notification_show_autoconfig = settings ?
|
||||
settings->bools.notification_show_autoconfig : true;
|
||||
|
||||
if (port >= MAX_INPUT_DEVICES)
|
||||
goto error;
|
||||
return false;
|
||||
|
||||
/* Cannot disconnect a device that is currently
|
||||
* being disconnected */
|
||||
@ -861,13 +845,12 @@ bool input_autoconfigure_disconnect(unsigned port, const char *name)
|
||||
find_data.userdata = (void*)&port;
|
||||
|
||||
if (task_queue_find(&find_data))
|
||||
goto error;
|
||||
return false;
|
||||
|
||||
/* Configure handle */
|
||||
autoconfig_handle = (autoconfig_handle_t*)calloc(1, sizeof(autoconfig_handle_t));
|
||||
|
||||
if (!autoconfig_handle)
|
||||
goto error;
|
||||
if (!(autoconfig_handle = (autoconfig_handle_t*)calloc(1,
|
||||
sizeof(autoconfig_handle_t))))
|
||||
return false;
|
||||
|
||||
autoconfig_handle->port = port;
|
||||
autoconfig_handle->suppress_notifcations = !notification_show_autoconfig;
|
||||
@ -877,10 +860,12 @@ bool input_autoconfigure_disconnect(unsigned port, const char *name)
|
||||
name, sizeof(autoconfig_handle->device_info.name));
|
||||
|
||||
/* Configure task */
|
||||
task = task_init();
|
||||
|
||||
if (!task)
|
||||
goto error;
|
||||
if (!(task = task_init()))
|
||||
{
|
||||
free_autoconfig_handle(autoconfig_handle);
|
||||
autoconfig_handle = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
task->handler = input_autoconfigure_disconnect_handler;
|
||||
task->state = autoconfig_handle;
|
||||
@ -891,17 +876,4 @@ bool input_autoconfigure_disconnect(unsigned port, const char *name)
|
||||
task_queue_push(task);
|
||||
|
||||
return true;
|
||||
|
||||
error:
|
||||
|
||||
if (task)
|
||||
{
|
||||
free(task);
|
||||
task = NULL;
|
||||
}
|
||||
|
||||
free_autoconfig_handle(autoconfig_handle);
|
||||
autoconfig_handle = NULL;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -80,8 +80,8 @@ void task_file_load_handler(retro_task_t *task)
|
||||
nbio_begin_read(handle);
|
||||
return;
|
||||
}
|
||||
else
|
||||
task_set_cancelled(task, true);
|
||||
|
||||
task_set_cancelled(task, true);
|
||||
}
|
||||
break;
|
||||
case NBIO_STATUS_TRANSFER_PARSE:
|
||||
|
@ -97,12 +97,10 @@ static int task_image_process(
|
||||
if (!image_transfer_is_valid(image->handle, image->type))
|
||||
return IMAGE_PROCESS_ERROR;
|
||||
|
||||
retval = image_transfer_process(
|
||||
if ((retval = image_transfer_process(
|
||||
image->handle,
|
||||
image->type,
|
||||
&image->ti.pixels, image->size, width, height);
|
||||
|
||||
if (retval == IMAGE_PROCESS_ERROR)
|
||||
&image->ti.pixels, image->size, width, height)) == IMAGE_PROCESS_ERROR)
|
||||
return IMAGE_PROCESS_ERROR;
|
||||
|
||||
image->ti.width = *width;
|
||||
@ -140,9 +138,7 @@ static int task_image_iterate_process_transfer(struct nbio_image_handle *image)
|
||||
|
||||
do
|
||||
{
|
||||
retval = task_image_process(image, &width, &height);
|
||||
|
||||
if (retval != IMAGE_PROCESS_NEXT)
|
||||
if ((retval = task_image_process(image, &width, &height)) != IMAGE_PROCESS_NEXT)
|
||||
break;
|
||||
}while (cpu_features_get_time_usec() - start_time
|
||||
< image->frame_duration);
|
||||
@ -162,8 +158,8 @@ static void task_image_cleanup(nbio_handle_t *nbio)
|
||||
{
|
||||
image_transfer_free(image->handle, image->type);
|
||||
|
||||
image->handle = NULL;
|
||||
image->cb = NULL;
|
||||
image->handle = NULL;
|
||||
image->cb = NULL;
|
||||
}
|
||||
if (!string_is_empty(nbio->path))
|
||||
free(nbio->path);
|
||||
@ -177,7 +173,7 @@ static void task_image_cleanup(nbio_handle_t *nbio)
|
||||
|
||||
static void task_image_load_free(retro_task_t *task)
|
||||
{
|
||||
nbio_handle_t *nbio = task ? (nbio_handle_t*)task->state : NULL;
|
||||
nbio_handle_t *nbio = task ? (nbio_handle_t*)task->state : NULL;
|
||||
|
||||
if (nbio)
|
||||
{
|
||||
@ -236,8 +232,7 @@ static bool upscale_image(
|
||||
struct texture_image *image_dst)
|
||||
{
|
||||
uint32_t x_ratio, y_ratio;
|
||||
unsigned x_src, y_src;
|
||||
unsigned x_dst, y_dst;
|
||||
unsigned y_dst;
|
||||
|
||||
/* Sanity check */
|
||||
if ((scale_factor < 1) || !image_src || !image_dst)
|
||||
@ -247,12 +242,11 @@ static bool upscale_image(
|
||||
return false;
|
||||
|
||||
/* Get output dimensions */
|
||||
image_dst->width = image_src->width * scale_factor;
|
||||
image_dst->width = image_src->width * scale_factor;
|
||||
image_dst->height = image_src->height * scale_factor;
|
||||
|
||||
/* Allocate pixel buffer */
|
||||
image_dst->pixels = (uint32_t*)calloc(image_dst->width * image_dst->height, sizeof(uint32_t));
|
||||
if (!image_dst->pixels)
|
||||
if (!(image_dst->pixels = (uint32_t*)calloc(image_dst->width * image_dst->height, sizeof(uint32_t))))
|
||||
return false;
|
||||
|
||||
/* Perform nearest neighbour resampling */
|
||||
@ -261,10 +255,11 @@ static bool upscale_image(
|
||||
|
||||
for (y_dst = 0; y_dst < image_dst->height; y_dst++)
|
||||
{
|
||||
y_src = (y_dst * y_ratio) >> 16;
|
||||
unsigned x_dst;
|
||||
unsigned y_src = (y_dst * y_ratio) >> 16;
|
||||
for (x_dst = 0; x_dst < image_dst->width; x_dst++)
|
||||
{
|
||||
x_src = (x_dst * x_ratio) >> 16;
|
||||
unsigned x_src = (x_dst * x_ratio) >> 16;
|
||||
image_dst->pixels[(y_dst * image_dst->width) + x_dst] = image_src->pixels[(y_src * image_src->width) + x_src];
|
||||
}
|
||||
}
|
||||
@ -391,9 +386,7 @@ bool task_push_image_load(const char *fullpath,
|
||||
if (!t)
|
||||
return false;
|
||||
|
||||
nbio = (nbio_handle_t*)malloc(sizeof(*nbio));
|
||||
|
||||
if (!nbio)
|
||||
if (!(nbio = (nbio_handle_t*)malloc(sizeof(*nbio))))
|
||||
{
|
||||
free(t);
|
||||
return false;
|
||||
@ -411,8 +404,7 @@ bool task_push_image_load(const char *fullpath,
|
||||
if (supports_rgba)
|
||||
BIT32_SET(nbio->status_flags, NBIO_FLAG_IMAGE_SUPPORTS_RGBA);
|
||||
|
||||
image = (struct nbio_image_handle*)malloc(sizeof(*image));
|
||||
if (!image)
|
||||
if (!(image = (struct nbio_image_handle*)malloc(sizeof(*image))))
|
||||
{
|
||||
free(nbio);
|
||||
free(t);
|
||||
|
@ -263,7 +263,7 @@ void path_init_savefile_new(void);
|
||||
extern const char* const input_builtin_autoconfs[];
|
||||
void input_autoconfigure_blissbox_override_handler(
|
||||
int vid, int pid, char *device_name, size_t len);
|
||||
void input_autoconfigure_connect(
|
||||
bool input_autoconfigure_connect(
|
||||
const char *name,
|
||||
const char *display_name,
|
||||
const char *driver,
|
||||
|
Loading…
x
Reference in New Issue
Block a user