mirror of
https://github.com/libretro/RetroArch
synced 2025-03-29 22:20:21 +00:00
commit
20c08a6137
@ -125,6 +125,7 @@ OBJ += frontend/frontend.o \
|
||||
runloop.o \
|
||||
runloop_data.o \
|
||||
runloop_msg.o \
|
||||
tasks/tasks.o \
|
||||
tasks/task_file_transfer.o \
|
||||
content.o \
|
||||
libretro-common/encodings/encoding_utf.o \
|
||||
|
@ -1338,14 +1338,14 @@ bool event_command(enum event_command cmd)
|
||||
break;
|
||||
case EVENT_CMD_OVERLAY_DEINIT:
|
||||
#ifdef HAVE_OVERLAY
|
||||
input_overlay_free_ptr();
|
||||
input_overlay_free();
|
||||
#endif
|
||||
break;
|
||||
case EVENT_CMD_OVERLAY_INIT:
|
||||
event_command(EVENT_CMD_OVERLAY_DEINIT);
|
||||
#ifdef HAVE_OVERLAY
|
||||
if (input_overlay_new_ptr() == -1)
|
||||
RARCH_ERR("%s.\n", msg_hash_to_str(MSG_FAILED_TO_LOAD_OVERLAY));
|
||||
input_overlay_init();
|
||||
//RARCH_ERR("%s.\n", msg_hash_to_str(MSG_FAILED_TO_LOAD_OVERLAY));
|
||||
#endif
|
||||
break;
|
||||
case EVENT_CMD_OVERLAY_NEXT:
|
||||
|
@ -33,102 +33,15 @@
|
||||
|
||||
#include "../configuration.h"
|
||||
#include "../verbosity.h"
|
||||
#include "../tasks/tasks.h"
|
||||
#include "input_common.h"
|
||||
|
||||
#define BOX_RADIAL 0x18df06d2U
|
||||
#define BOX_RECT 0x7c9d4d93U
|
||||
|
||||
#define KEY_ANALOG_LEFT 0x56b92e81U
|
||||
#define KEY_ANALOG_RIGHT 0x2e4dc654U
|
||||
|
||||
struct overlay
|
||||
{
|
||||
struct overlay_desc *descs;
|
||||
size_t size;
|
||||
size_t pos;
|
||||
unsigned pos_increment;
|
||||
|
||||
struct texture_image image;
|
||||
|
||||
bool block_scale;
|
||||
float mod_x, mod_y, mod_w, mod_h;
|
||||
float x, y, w, h;
|
||||
float scale;
|
||||
float center_x, center_y;
|
||||
|
||||
bool full_screen;
|
||||
|
||||
char name[64];
|
||||
|
||||
struct
|
||||
{
|
||||
struct
|
||||
{
|
||||
char key[64];
|
||||
char path[PATH_MAX_LENGTH];
|
||||
} paths;
|
||||
|
||||
struct
|
||||
{
|
||||
char key[64];
|
||||
} names;
|
||||
|
||||
struct
|
||||
{
|
||||
char array[256];
|
||||
char key[64];
|
||||
} rect;
|
||||
|
||||
struct
|
||||
{
|
||||
char key[64];
|
||||
unsigned size;
|
||||
} descs;
|
||||
|
||||
bool normalized;
|
||||
float alpha_mod;
|
||||
float range_mod;
|
||||
} config;
|
||||
|
||||
struct texture_image *load_images;
|
||||
unsigned load_images_size;
|
||||
};
|
||||
|
||||
struct overlay_desc
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
|
||||
enum overlay_hitbox hitbox;
|
||||
float range_x, range_y;
|
||||
float range_x_mod, range_y_mod;
|
||||
float mod_x, mod_y, mod_w, mod_h;
|
||||
float delta_x, delta_y;
|
||||
|
||||
enum overlay_type type;
|
||||
uint64_t key_mask;
|
||||
float analog_saturate_pct;
|
||||
|
||||
unsigned next_index;
|
||||
char next_index_name[64];
|
||||
|
||||
struct texture_image image;
|
||||
unsigned image_index;
|
||||
|
||||
float alpha_mod;
|
||||
float range_mod;
|
||||
|
||||
bool updated;
|
||||
bool movable;
|
||||
};
|
||||
|
||||
struct input_overlay
|
||||
{
|
||||
void *iface_data;
|
||||
const video_overlay_interface_t *iface;
|
||||
bool enable;
|
||||
|
||||
enum overlay_image_transfer_status loading_status;
|
||||
bool blocked;
|
||||
bool alive;
|
||||
|
||||
@ -136,28 +49,9 @@ struct input_overlay
|
||||
const struct overlay *active;
|
||||
size_t index;
|
||||
size_t size;
|
||||
unsigned pos;
|
||||
size_t resolve_pos;
|
||||
size_t pos_increment;
|
||||
|
||||
unsigned next_index;
|
||||
char *overlay_path;
|
||||
enum overlay_status state;
|
||||
|
||||
struct
|
||||
{
|
||||
struct
|
||||
{
|
||||
unsigned size;
|
||||
} overlays;
|
||||
} config;
|
||||
|
||||
struct
|
||||
{
|
||||
bool enable;
|
||||
float opacity;
|
||||
float scale_factor;
|
||||
} deferred;
|
||||
};
|
||||
|
||||
typedef struct input_overlay_state
|
||||
@ -305,10 +199,9 @@ static void input_overlay_free_overlay(struct overlay *overlay)
|
||||
texture_image_free(&overlay->image);
|
||||
}
|
||||
|
||||
static void input_overlay_free_overlays(void)
|
||||
static void input_overlay_free_overlays(input_overlay_t *ol)
|
||||
{
|
||||
size_t i;
|
||||
input_overlay_t *ol = overlay_ptr;
|
||||
|
||||
if (!ol)
|
||||
return;
|
||||
@ -321,313 +214,6 @@ static void input_overlay_free_overlays(void)
|
||||
ol->overlays = NULL;
|
||||
}
|
||||
|
||||
static bool input_overlay_load_texture_image(struct overlay *overlay,
|
||||
struct texture_image *image, const char *path)
|
||||
{
|
||||
if (!image)
|
||||
return false;
|
||||
if (!texture_image_load(image, path))
|
||||
return false;
|
||||
|
||||
overlay->load_images[overlay->load_images_size++] = *image;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool input_overlay_load_desc_image(
|
||||
struct overlay_desc *desc,
|
||||
struct overlay *input_overlay,
|
||||
unsigned ol_idx, unsigned desc_idx)
|
||||
{
|
||||
char overlay_desc_image_key[64] = {0};
|
||||
char image_path[PATH_MAX_LENGTH] = {0};
|
||||
input_overlay_t *ol = overlay_ptr;
|
||||
config_file_t *conf = ol ? config_file_new(ol->overlay_path) : NULL;
|
||||
|
||||
if (!ol || !conf)
|
||||
return false;
|
||||
|
||||
snprintf(overlay_desc_image_key, sizeof(overlay_desc_image_key),
|
||||
"overlay%u_desc%u_overlay", ol_idx, desc_idx);
|
||||
|
||||
if (config_get_path(conf, overlay_desc_image_key,
|
||||
image_path, sizeof(image_path)))
|
||||
{
|
||||
char path[PATH_MAX_LENGTH] = {0};
|
||||
fill_pathname_resolve_relative(path, ol->overlay_path,
|
||||
image_path, sizeof(path));
|
||||
|
||||
if (input_overlay_load_texture_image(input_overlay, &desc->image, path))
|
||||
desc->image_index = input_overlay->load_images_size - 1;
|
||||
}
|
||||
|
||||
input_overlay->pos ++;
|
||||
|
||||
config_file_free(conf);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool input_overlay_load_desc(
|
||||
struct overlay_desc *desc,
|
||||
struct overlay *input_overlay,
|
||||
unsigned ol_idx, unsigned desc_idx,
|
||||
unsigned width, unsigned height,
|
||||
bool normalized, float alpha_mod, float range_mod)
|
||||
{
|
||||
float width_mod, height_mod;
|
||||
uint32_t box_hash, key_hash;
|
||||
bool ret = true;
|
||||
bool by_pixel = false;
|
||||
char overlay_desc_key[64] = {0};
|
||||
char conf_key[64] = {0};
|
||||
char overlay_desc_normalized_key[64] = {0};
|
||||
char overlay[256] = {0};
|
||||
char *save = NULL;
|
||||
char *key = NULL;
|
||||
struct string_list *list = NULL;
|
||||
const char *x = NULL;
|
||||
const char *y = NULL;
|
||||
const char *box = NULL;
|
||||
input_overlay_t *ol = overlay_ptr;
|
||||
config_file_t *conf = ol ? config_file_new(ol->overlay_path) : NULL;
|
||||
|
||||
if (!ol || !conf)
|
||||
return false;
|
||||
|
||||
snprintf(overlay_desc_key, sizeof(overlay_desc_key),
|
||||
"overlay%u_desc%u", ol_idx, desc_idx);
|
||||
|
||||
snprintf(overlay_desc_normalized_key, sizeof(overlay_desc_normalized_key),
|
||||
"overlay%u_desc%u_normalized", ol_idx, desc_idx);
|
||||
config_get_bool(conf, overlay_desc_normalized_key, &normalized);
|
||||
|
||||
by_pixel = !normalized;
|
||||
|
||||
if (by_pixel && (width == 0 || height == 0))
|
||||
{
|
||||
RARCH_ERR("[Overlay]: Base overlay is not set and not using normalized coordinates.\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!config_get_array(conf, overlay_desc_key, overlay, sizeof(overlay)))
|
||||
{
|
||||
RARCH_ERR("[Overlay]: Didn't find key: %s.\n", overlay_desc_key);
|
||||
goto error;
|
||||
}
|
||||
|
||||
list = string_split(overlay, ", ");
|
||||
|
||||
if (!list)
|
||||
{
|
||||
RARCH_ERR("[Overlay]: Failed to split overlay desc.\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (list->size < 6)
|
||||
{
|
||||
RARCH_ERR("[Overlay]: Overlay desc is invalid. Requires at least 6 tokens.\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
key = list->elems[0].data;
|
||||
x = list->elems[1].data;
|
||||
y = list->elems[2].data;
|
||||
box = list->elems[3].data;
|
||||
|
||||
box_hash = djb2_calculate(box);
|
||||
key_hash = djb2_calculate(key);
|
||||
|
||||
desc->key_mask = 0;
|
||||
|
||||
switch (key_hash)
|
||||
{
|
||||
case KEY_ANALOG_LEFT:
|
||||
desc->type = OVERLAY_TYPE_ANALOG_LEFT;
|
||||
break;
|
||||
case KEY_ANALOG_RIGHT:
|
||||
desc->type = OVERLAY_TYPE_ANALOG_RIGHT;
|
||||
break;
|
||||
default:
|
||||
if (strstr(key, "retrok_") == key)
|
||||
{
|
||||
desc->type = OVERLAY_TYPE_KEYBOARD;
|
||||
desc->key_mask = input_translate_str_to_rk(key + 7);
|
||||
}
|
||||
else
|
||||
{
|
||||
const char *tmp = NULL;
|
||||
|
||||
desc->type = OVERLAY_TYPE_BUTTONS;
|
||||
for (tmp = strtok_r(key, "|", &save); tmp; tmp = strtok_r(NULL, "|", &save))
|
||||
{
|
||||
if (strcmp(tmp, "nul") != 0)
|
||||
desc->key_mask |= UINT64_C(1) << input_translate_str_to_bind_id(tmp);
|
||||
}
|
||||
|
||||
if (desc->key_mask & (UINT64_C(1) << RARCH_OVERLAY_NEXT))
|
||||
{
|
||||
char overlay_target_key[64] = {0};
|
||||
|
||||
snprintf(overlay_target_key, sizeof(overlay_target_key),
|
||||
"overlay%u_desc%u_next_target", ol_idx, desc_idx);
|
||||
config_get_array(conf, overlay_target_key,
|
||||
desc->next_index_name, sizeof(desc->next_index_name));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
width_mod = 1.0f;
|
||||
height_mod = 1.0f;
|
||||
|
||||
if (by_pixel)
|
||||
{
|
||||
width_mod /= width;
|
||||
height_mod /= height;
|
||||
}
|
||||
|
||||
desc->x = (float)strtod(x, NULL) * width_mod;
|
||||
desc->y = (float)strtod(y, NULL) * height_mod;
|
||||
|
||||
switch (box_hash)
|
||||
{
|
||||
case BOX_RADIAL:
|
||||
desc->hitbox = OVERLAY_HITBOX_RADIAL;
|
||||
break;
|
||||
case BOX_RECT:
|
||||
desc->hitbox = OVERLAY_HITBOX_RECT;
|
||||
break;
|
||||
default:
|
||||
RARCH_ERR("[Overlay]: Hitbox type (%s) is invalid. Use \"radial\" or \"rect\".\n", box);
|
||||
ret = false;
|
||||
goto end;
|
||||
}
|
||||
|
||||
switch (desc->type)
|
||||
{
|
||||
case OVERLAY_TYPE_ANALOG_LEFT:
|
||||
case OVERLAY_TYPE_ANALOG_RIGHT:
|
||||
{
|
||||
char overlay_analog_saturate_key[64] = {0};
|
||||
|
||||
if (desc->hitbox != OVERLAY_HITBOX_RADIAL)
|
||||
{
|
||||
RARCH_ERR("[Overlay]: Analog hitbox type must be \"radial\".\n");
|
||||
ret = false;
|
||||
goto end;
|
||||
}
|
||||
|
||||
snprintf(overlay_analog_saturate_key, sizeof(overlay_analog_saturate_key),
|
||||
"overlay%u_desc%u_saturate_pct", ol_idx, desc_idx);
|
||||
if (!config_get_float(conf, overlay_analog_saturate_key,
|
||||
&desc->analog_saturate_pct))
|
||||
desc->analog_saturate_pct = 1.0f;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
/* OVERLAY_TYPE_BUTTONS - unhandled */
|
||||
/* OVERLAY_TYPE_KEYBOARD - unhandled */
|
||||
break;
|
||||
}
|
||||
|
||||
desc->range_x = (float)strtod(list->elems[4].data, NULL) * width_mod;
|
||||
desc->range_y = (float)strtod(list->elems[5].data, NULL) * height_mod;
|
||||
|
||||
desc->mod_x = desc->x - desc->range_x;
|
||||
desc->mod_w = 2.0f * desc->range_x;
|
||||
desc->mod_y = desc->y - desc->range_y;
|
||||
desc->mod_h = 2.0f * desc->range_y;
|
||||
|
||||
snprintf(conf_key, sizeof(conf_key),
|
||||
"overlay%u_desc%u_alpha_mod", ol_idx, desc_idx);
|
||||
desc->alpha_mod = alpha_mod;
|
||||
config_get_float(conf, conf_key, &desc->alpha_mod);
|
||||
|
||||
snprintf(conf_key, sizeof(conf_key),
|
||||
"overlay%u_desc%u_range_mod", ol_idx, desc_idx);
|
||||
desc->range_mod = range_mod;
|
||||
config_get_float(conf, conf_key, &desc->range_mod);
|
||||
|
||||
snprintf(conf_key, sizeof(conf_key),
|
||||
"overlay%u_desc%u_movable", ol_idx, desc_idx);
|
||||
desc->movable = false;
|
||||
desc->delta_x = 0.0f;
|
||||
desc->delta_y = 0.0f;
|
||||
config_get_bool(conf, conf_key, &desc->movable);
|
||||
|
||||
desc->range_x_mod = desc->range_x;
|
||||
desc->range_y_mod = desc->range_y;
|
||||
|
||||
input_overlay->pos ++;
|
||||
|
||||
end:
|
||||
if (list)
|
||||
string_list_free(list);
|
||||
if (conf)
|
||||
config_file_free(conf);
|
||||
return ret;
|
||||
|
||||
error:
|
||||
if (list)
|
||||
string_list_free(list);
|
||||
if (conf)
|
||||
config_file_free(conf);
|
||||
return false;
|
||||
}
|
||||
|
||||
static ssize_t input_overlay_find_index(const struct overlay *ol,
|
||||
const char *name, size_t size)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (!ol)
|
||||
return -1;
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
if (!strcmp(ol[i].name, name))
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static bool input_overlay_resolve_targets(struct overlay *ol,
|
||||
size_t idx, size_t size)
|
||||
{
|
||||
size_t i;
|
||||
struct overlay *current = NULL;
|
||||
|
||||
if (!ol)
|
||||
return false;
|
||||
|
||||
current = (struct overlay*)&ol[idx];
|
||||
|
||||
for (i = 0; i < current->size; i++)
|
||||
{
|
||||
const char *next = current->descs[i].next_index_name;
|
||||
|
||||
if (*next)
|
||||
{
|
||||
ssize_t next_idx = input_overlay_find_index(ol, next, size);
|
||||
|
||||
if (next_idx < 0)
|
||||
{
|
||||
RARCH_ERR("[Overlay]: Couldn't find overlay called: \"%s\".\n",
|
||||
next);
|
||||
return false;
|
||||
}
|
||||
|
||||
current->descs[i].next_index = next_idx;
|
||||
}
|
||||
else
|
||||
current->descs[i].next_index = (idx + 1) % size;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void input_overlay_load_active(float opacity)
|
||||
{
|
||||
input_overlay_t *ol = overlay_ptr;
|
||||
@ -662,416 +248,6 @@ static void input_overlay_enable(bool enable)
|
||||
ol->iface->enable(ol->iface_data, enable);
|
||||
}
|
||||
|
||||
bool input_overlay_load_overlays_resolve_iterate(void)
|
||||
{
|
||||
input_overlay_t *ol = overlay_ptr;
|
||||
bool not_done = true;
|
||||
|
||||
if (!ol)
|
||||
return false;
|
||||
|
||||
not_done = ol->resolve_pos < ol->size;
|
||||
|
||||
if (!not_done)
|
||||
{
|
||||
ol->state = OVERLAY_STATUS_DEFERRED_DONE;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!input_overlay_resolve_targets(ol->overlays, ol->resolve_pos, ol->size))
|
||||
{
|
||||
RARCH_ERR("[Overlay]: Failed to resolve next targets.\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (ol->resolve_pos == 0)
|
||||
{
|
||||
ol->active = &ol->overlays[0];
|
||||
|
||||
input_overlay_load_active(ol->deferred.opacity);
|
||||
input_overlay_enable(ol->deferred.enable);
|
||||
}
|
||||
|
||||
ol->resolve_pos += 1;
|
||||
|
||||
return true;
|
||||
error:
|
||||
ol->state = OVERLAY_STATUS_DEFERRED_ERROR;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static bool input_overlay_load_overlay_image_done(struct overlay *overlay)
|
||||
{
|
||||
overlay->pos = 0;
|
||||
/* Divide iteration steps by half of total descs if size is even,
|
||||
* otherwise default to 8 (arbitrary value for now to speed things up). */
|
||||
overlay->pos_increment = (overlay->size / 2) ? (overlay->size / 2) : 8;
|
||||
|
||||
#if 0
|
||||
RARCH_LOG("pos increment: %u\n", overlay->pos_increment);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool input_overlay_load_overlays_iterate(void)
|
||||
{
|
||||
size_t i = 0;
|
||||
bool not_done = true;
|
||||
struct overlay *overlay = NULL;
|
||||
input_overlay_t *ol = overlay_ptr;
|
||||
|
||||
if (!ol)
|
||||
return false;
|
||||
|
||||
overlay = &ol->overlays[ol->pos];
|
||||
|
||||
not_done = ol->pos < ol->size;
|
||||
|
||||
if (!not_done)
|
||||
{
|
||||
ol->state = OVERLAY_STATUS_DEFERRED_LOADING_RESOLVE;
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (ol->loading_status)
|
||||
{
|
||||
case OVERLAY_IMAGE_TRANSFER_NONE:
|
||||
case OVERLAY_IMAGE_TRANSFER_BUSY:
|
||||
ol->loading_status = OVERLAY_IMAGE_TRANSFER_DONE;
|
||||
break;
|
||||
case OVERLAY_IMAGE_TRANSFER_DONE:
|
||||
input_overlay_load_overlay_image_done(&ol->overlays[ol->pos]);
|
||||
ol->loading_status = OVERLAY_IMAGE_TRANSFER_DESC_IMAGE_ITERATE;
|
||||
ol->overlays[ol->pos].pos = 0;
|
||||
break;
|
||||
case OVERLAY_IMAGE_TRANSFER_DESC_IMAGE_ITERATE:
|
||||
for (i = 0; i < overlay->pos_increment; i++)
|
||||
{
|
||||
if (overlay->pos < overlay->size)
|
||||
{
|
||||
input_overlay_load_desc_image(
|
||||
&overlay->descs[overlay->pos], overlay,
|
||||
ol->pos, overlay->pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
overlay->pos = 0;
|
||||
ol->loading_status = OVERLAY_IMAGE_TRANSFER_DESC_ITERATE;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case OVERLAY_IMAGE_TRANSFER_DESC_ITERATE:
|
||||
for (i = 0; i < overlay->pos_increment; i++)
|
||||
{
|
||||
if (overlay->pos < overlay->size)
|
||||
{
|
||||
if (!input_overlay_load_desc(&overlay->descs[overlay->pos], overlay,
|
||||
ol->pos, overlay->pos,
|
||||
overlay->image.width, overlay->image.height,
|
||||
overlay->config.normalized,
|
||||
overlay->config.alpha_mod, overlay->config.range_mod))
|
||||
{
|
||||
RARCH_ERR("[Overlay]: Failed to load overlay descs for overlay #%u.\n",
|
||||
(unsigned)overlay->pos);
|
||||
goto error;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
overlay->pos = 0;
|
||||
ol->loading_status = OVERLAY_IMAGE_TRANSFER_DESC_DONE;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case OVERLAY_IMAGE_TRANSFER_DESC_DONE:
|
||||
if (ol->pos == 0)
|
||||
input_overlay_load_overlays_resolve_iterate();
|
||||
ol->pos += 1;
|
||||
ol->loading_status = OVERLAY_IMAGE_TRANSFER_NONE;
|
||||
break;
|
||||
case OVERLAY_IMAGE_TRANSFER_ERROR:
|
||||
goto error;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
error:
|
||||
ol->state = OVERLAY_STATUS_DEFERRED_ERROR;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool input_overlay_load_overlays(void)
|
||||
{
|
||||
unsigned i;
|
||||
input_overlay_t *ol = overlay_ptr;
|
||||
config_file_t *conf = config_file_new(ol->overlay_path);
|
||||
|
||||
if (!ol || !conf)
|
||||
return false;
|
||||
|
||||
for (i = 0; i < ol->pos_increment; i++, ol->pos++)
|
||||
{
|
||||
char conf_key[64] = {0};
|
||||
char overlay_full_screen_key[64] = {0};
|
||||
struct overlay *overlay = NULL;
|
||||
bool to_cont = ol->pos < ol->size;
|
||||
|
||||
if (!to_cont)
|
||||
{
|
||||
ol->pos = 0;
|
||||
ol->state = OVERLAY_STATUS_DEFERRED_LOADING;
|
||||
break;
|
||||
}
|
||||
|
||||
overlay = &ol->overlays[ol->pos];
|
||||
|
||||
if (!overlay)
|
||||
continue;
|
||||
|
||||
snprintf(overlay->config.descs.key,
|
||||
sizeof(overlay->config.descs.key), "overlay%u_descs", ol->pos);
|
||||
|
||||
if (!config_get_uint(conf, overlay->config.descs.key, &overlay->config.descs.size))
|
||||
{
|
||||
RARCH_ERR("[Overlay]: Failed to read number of descs from config key: %s.\n",
|
||||
overlay->config.descs.key);
|
||||
goto error;
|
||||
}
|
||||
|
||||
overlay->descs = (struct overlay_desc*)
|
||||
calloc(overlay->config.descs.size, sizeof(*overlay->descs));
|
||||
|
||||
if (!overlay->descs)
|
||||
{
|
||||
RARCH_ERR("[Overlay]: Failed to allocate descs.\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
overlay->size = overlay->config.descs.size;
|
||||
|
||||
snprintf(overlay_full_screen_key, sizeof(overlay_full_screen_key),
|
||||
"overlay%u_full_screen", ol->pos);
|
||||
overlay->full_screen = false;
|
||||
config_get_bool(conf, overlay_full_screen_key, &overlay->full_screen);
|
||||
|
||||
overlay->config.normalized = false;
|
||||
overlay->config.alpha_mod = 1.0f;
|
||||
overlay->config.range_mod = 1.0f;
|
||||
|
||||
snprintf(conf_key, sizeof(conf_key),
|
||||
"overlay%u_normalized", ol->pos);
|
||||
config_get_bool(conf, conf_key, &overlay->config.normalized);
|
||||
|
||||
snprintf(conf_key, sizeof(conf_key), "overlay%u_alpha_mod", ol->pos);
|
||||
config_get_float(conf, conf_key, &overlay->config.alpha_mod);
|
||||
|
||||
snprintf(conf_key, sizeof(conf_key), "overlay%u_range_mod", ol->pos);
|
||||
config_get_float(conf, conf_key, &overlay->config.range_mod);
|
||||
|
||||
/* Precache load image array for simplicity. */
|
||||
overlay->load_images = (struct texture_image*)
|
||||
calloc(1 + overlay->size, sizeof(struct texture_image));
|
||||
|
||||
if (!overlay->load_images)
|
||||
{
|
||||
RARCH_ERR("[Overlay]: Failed to allocate load_images.\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
snprintf(overlay->config.paths.key, sizeof(overlay->config.paths.key),
|
||||
"overlay%u_overlay", ol->pos);
|
||||
|
||||
config_get_path(conf, overlay->config.paths.key,
|
||||
overlay->config.paths.path, sizeof(overlay->config.paths.path));
|
||||
|
||||
if (overlay->config.paths.path[0] != '\0')
|
||||
{
|
||||
char overlay_resolved_path[PATH_MAX_LENGTH] = {0};
|
||||
|
||||
fill_pathname_resolve_relative(overlay_resolved_path, ol->overlay_path,
|
||||
overlay->config.paths.path, sizeof(overlay_resolved_path));
|
||||
|
||||
if (!input_overlay_load_texture_image(overlay, &overlay->image, overlay_resolved_path))
|
||||
{
|
||||
RARCH_ERR("[Overlay]: Failed to load image: %s.\n",
|
||||
overlay_resolved_path);
|
||||
ol->loading_status = OVERLAY_IMAGE_TRANSFER_ERROR;
|
||||
goto error;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
snprintf(overlay->config.names.key, sizeof(overlay->config.names.key),
|
||||
"overlay%u_name", ol->pos);
|
||||
config_get_array(conf, overlay->config.names.key,
|
||||
overlay->name, sizeof(overlay->name));
|
||||
|
||||
/* By default, we stretch the overlay out in full. */
|
||||
overlay->x = overlay->y = 0.0f;
|
||||
overlay->w = overlay->h = 1.0f;
|
||||
|
||||
snprintf(overlay->config.rect.key, sizeof(overlay->config.rect.key),
|
||||
"overlay%u_rect", ol->pos);
|
||||
|
||||
if (config_get_array(conf, overlay->config.rect.key,
|
||||
overlay->config.rect.array, sizeof(overlay->config.rect.array)))
|
||||
{
|
||||
struct string_list *list = string_split(overlay->config.rect.array, ", ");
|
||||
|
||||
if (!list || list->size < 4)
|
||||
{
|
||||
RARCH_ERR("[Overlay]: Failed to split rect \"%s\" into at least four tokens.\n",
|
||||
overlay->config.rect.array);
|
||||
string_list_free(list);
|
||||
goto error;
|
||||
}
|
||||
|
||||
overlay->x = (float)strtod(list->elems[0].data, NULL);
|
||||
overlay->y = (float)strtod(list->elems[1].data, NULL);
|
||||
overlay->w = (float)strtod(list->elems[2].data, NULL);
|
||||
overlay->h = (float)strtod(list->elems[3].data, NULL);
|
||||
string_list_free(list);
|
||||
}
|
||||
|
||||
/* Assume for now that scaling center is in the middle.
|
||||
* TODO: Make this configurable. */
|
||||
overlay->block_scale = false;
|
||||
overlay->center_x = overlay->x + 0.5f * overlay->w;
|
||||
overlay->center_y = overlay->y + 0.5f * overlay->h;
|
||||
}
|
||||
|
||||
if (conf)
|
||||
config_file_free(conf);
|
||||
|
||||
return true;
|
||||
|
||||
error:
|
||||
ol->pos = 0;
|
||||
ol->state = OVERLAY_STATUS_DEFERRED_ERROR;
|
||||
|
||||
if (conf)
|
||||
config_file_free(conf);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool input_overlay_new_done(void)
|
||||
{
|
||||
input_overlay_t *ol = overlay_ptr;
|
||||
if (!ol)
|
||||
return false;
|
||||
|
||||
input_overlay_set_alpha_mod(ol->deferred.opacity);
|
||||
input_overlay_set_scale_factor(ol->deferred.scale_factor);
|
||||
|
||||
ol->next_index = (ol->index + 1) % ol->size;
|
||||
ol->state = OVERLAY_STATUS_NONE;
|
||||
ol->alive = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool input_overlay_load_overlays_init(input_overlay_t *ol)
|
||||
{
|
||||
config_file_t *conf = config_file_new(ol->overlay_path);
|
||||
|
||||
if (!conf)
|
||||
return false;
|
||||
|
||||
if (!config_get_uint(conf, "overlays", &ol->config.overlays.size))
|
||||
{
|
||||
RARCH_ERR("overlays variable not defined in config.\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!ol->config.overlays.size)
|
||||
goto error;
|
||||
|
||||
ol->overlays = (struct overlay*)calloc(
|
||||
ol->config.overlays.size, sizeof(*ol->overlays));
|
||||
if (!ol->overlays)
|
||||
goto error;
|
||||
|
||||
ol->size = ol->config.overlays.size;
|
||||
ol->pos = 0;
|
||||
ol->resolve_pos = 0;
|
||||
ol->pos_increment = (ol->size / 4) ? (ol->size / 4) : 4;
|
||||
|
||||
config_file_free(conf);
|
||||
|
||||
return true;
|
||||
|
||||
error:
|
||||
ol->state = OVERLAY_STATUS_DEFERRED_ERROR;
|
||||
|
||||
if (conf)
|
||||
config_file_free(conf);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* input_overlay_new:
|
||||
* @path : Path to overlay file.
|
||||
* @enable : Enable the overlay after initializing it?
|
||||
*
|
||||
* Creates and initializes an overlay handle.
|
||||
*
|
||||
* Returns: Overlay handle on success, otherwise NULL.
|
||||
**/
|
||||
input_overlay_t *input_overlay_new(const char *path, bool enable,
|
||||
float opacity, float scale_factor)
|
||||
{
|
||||
input_overlay_t *ol = (input_overlay_t*)calloc(1, sizeof(*ol));
|
||||
|
||||
if (!ol)
|
||||
goto error;
|
||||
|
||||
ol->overlay_path = strdup(path);
|
||||
if (!ol->overlay_path)
|
||||
{
|
||||
free(ol);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!video_driver_overlay_interface(&ol->iface))
|
||||
{
|
||||
RARCH_ERR("Overlay interface is not present in video driver.\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
ol->iface_data = video_driver_get_ptr(true);
|
||||
|
||||
if (!ol->iface)
|
||||
goto error;
|
||||
|
||||
ol->state = OVERLAY_STATUS_DEFERRED_LOAD;
|
||||
ol->deferred.enable = enable;
|
||||
ol->deferred.opacity = opacity;
|
||||
ol->deferred.scale_factor = scale_factor;
|
||||
ol->pos = 0;
|
||||
|
||||
input_overlay_load_overlays_init(ol);
|
||||
|
||||
return ol;
|
||||
|
||||
error:
|
||||
input_overlay_free();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* inside_hitbox:
|
||||
* @desc : Overlay descriptor handle.
|
||||
@ -1357,54 +533,76 @@ void input_overlay_free(void)
|
||||
input_overlay_t *ol = overlay_ptr;
|
||||
if (!ol)
|
||||
return;
|
||||
overlay_ptr = NULL;
|
||||
|
||||
input_overlay_free_overlays();
|
||||
input_overlay_free_overlays(ol);
|
||||
|
||||
if (ol->iface && ol->iface->enable)
|
||||
ol->iface->enable(ol->iface_data, false);
|
||||
|
||||
if (ol->overlay_path)
|
||||
free(ol->overlay_path);
|
||||
ol->overlay_path = NULL;
|
||||
free(ol);
|
||||
}
|
||||
|
||||
void input_overlay_free_ptr(void)
|
||||
/* task_data = overlay_task_data_t* */
|
||||
static void input_overlay_loaded(void *task_data, void *user_data, const char *err)
|
||||
{
|
||||
input_overlay_free();
|
||||
overlay_ptr = NULL;
|
||||
overlay_task_data_t *data = (overlay_task_data_t*)task_data;
|
||||
settings_t *settings = config_get_ptr();
|
||||
input_overlay_t *ol;
|
||||
driver_t *driver = driver_get_ptr();
|
||||
|
||||
memset(&overlay_st_ptr, 0, sizeof(overlay_st_ptr));
|
||||
/* We can't display when the menu is up */
|
||||
if (settings->input.overlay_hide_in_menu && menu_driver_alive())
|
||||
{
|
||||
if (!driver->osk_enable && settings->input.overlay_enable)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < data->size; i++)
|
||||
input_overlay_free_overlay(&data->overlays[i]);
|
||||
|
||||
free(data->overlays);
|
||||
free(data);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ol = (input_overlay_t*)calloc(1, sizeof(*ol));
|
||||
ol->overlays = data->overlays;
|
||||
ol->size = data->size;
|
||||
ol->active = data->active;
|
||||
|
||||
if (!video_driver_overlay_interface(&ol->iface))
|
||||
{
|
||||
RARCH_ERR("Overlay interface is not present in video driver.\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
ol->iface_data = video_driver_get_ptr(true);
|
||||
|
||||
if (!ol->iface)
|
||||
goto error;
|
||||
|
||||
overlay_ptr = ol;
|
||||
|
||||
input_overlay_load_active(settings->input.overlay_opacity);
|
||||
input_overlay_enable(driver->osk_enable ? settings->osk.enable : settings->input.overlay_enable);
|
||||
input_overlay_set_scale_factor(settings->input.overlay_scale);
|
||||
|
||||
ol->next_index = (ol->index + 1) % ol->size;
|
||||
ol->state = OVERLAY_STATUS_NONE;
|
||||
ol->alive = true;
|
||||
|
||||
free(data);
|
||||
return;
|
||||
error:
|
||||
input_overlay_free();
|
||||
free(data);
|
||||
}
|
||||
|
||||
int input_overlay_new_ptr(void)
|
||||
void input_overlay_init(void)
|
||||
{
|
||||
driver_t *driver = driver_get_ptr();
|
||||
settings_t *settings = config_get_ptr();
|
||||
|
||||
if (driver->osk_enable)
|
||||
{
|
||||
if (!*settings->osk.overlay)
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!*settings->input.overlay)
|
||||
return 1;
|
||||
}
|
||||
|
||||
overlay_ptr = input_overlay_new(
|
||||
driver->osk_enable ?
|
||||
settings->osk.overlay : settings->input.overlay,
|
||||
driver->osk_enable ?
|
||||
settings->osk.enable : settings->input.overlay_enable,
|
||||
settings->input.overlay_opacity,
|
||||
settings->input.overlay_scale);
|
||||
|
||||
if (!overlay_ptr)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
input_overlay_free();
|
||||
rarch_task_push_overlay_load_default(input_overlay_loaded, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -21,12 +21,19 @@
|
||||
#include <boolean.h>
|
||||
|
||||
#include <retro_miscellaneous.h>
|
||||
#include <formats/image.h>
|
||||
#include "../libretro.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define BOX_RADIAL 0x18df06d2U
|
||||
#define BOX_RECT 0x7c9d4d93U
|
||||
|
||||
#define KEY_ANALOG_LEFT 0x56b92e81U
|
||||
#define KEY_ANALOG_RIGHT 0x2e4dc654U
|
||||
|
||||
#define OVERLAY_GET_KEY(state, key) (((state)->keys[(key) / 32] >> ((key) % 32)) & 1)
|
||||
#define OVERLAY_SET_KEY(state, key) (state)->keys[(key) / 32] |= 1 << ((key) % 32)
|
||||
#define OVERLAY_CLEAR_KEY(state, key) (state)->keys[(key) / 32] &= ~(1 << ((key) % 32))
|
||||
@ -91,29 +98,98 @@ enum overlay_image_transfer_status
|
||||
OVERLAY_IMAGE_TRANSFER_ERROR
|
||||
};
|
||||
|
||||
|
||||
struct overlay
|
||||
{
|
||||
struct overlay_desc *descs;
|
||||
size_t size;
|
||||
size_t pos;
|
||||
unsigned pos_increment;
|
||||
|
||||
struct texture_image image;
|
||||
|
||||
bool block_scale;
|
||||
float mod_x, mod_y, mod_w, mod_h;
|
||||
float x, y, w, h;
|
||||
float scale;
|
||||
float center_x, center_y;
|
||||
|
||||
bool full_screen;
|
||||
|
||||
char name[64];
|
||||
|
||||
struct
|
||||
{
|
||||
struct
|
||||
{
|
||||
char key[64];
|
||||
char path[PATH_MAX_LENGTH];
|
||||
} paths;
|
||||
|
||||
struct
|
||||
{
|
||||
char key[64];
|
||||
} names;
|
||||
|
||||
struct
|
||||
{
|
||||
char array[256];
|
||||
char key[64];
|
||||
} rect;
|
||||
|
||||
struct
|
||||
{
|
||||
char key[64];
|
||||
unsigned size;
|
||||
} descs;
|
||||
|
||||
bool normalized;
|
||||
float alpha_mod;
|
||||
float range_mod;
|
||||
} config;
|
||||
|
||||
struct texture_image *load_images;
|
||||
unsigned load_images_size;
|
||||
};
|
||||
|
||||
struct overlay_desc
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
|
||||
enum overlay_hitbox hitbox;
|
||||
float range_x, range_y;
|
||||
float range_x_mod, range_y_mod;
|
||||
float mod_x, mod_y, mod_w, mod_h;
|
||||
float delta_x, delta_y;
|
||||
|
||||
enum overlay_type type;
|
||||
uint64_t key_mask;
|
||||
float analog_saturate_pct;
|
||||
|
||||
unsigned next_index;
|
||||
char next_index_name[64];
|
||||
|
||||
struct texture_image image;
|
||||
unsigned image_index;
|
||||
|
||||
float alpha_mod;
|
||||
float range_mod;
|
||||
|
||||
bool updated;
|
||||
bool movable;
|
||||
};
|
||||
|
||||
typedef struct overlay_desc overlay_desc_t;
|
||||
|
||||
typedef struct input_overlay input_overlay_t;
|
||||
|
||||
/**
|
||||
* input_overlay_new:
|
||||
* @path : Path to overlay file.
|
||||
* @enable : Enable the overlay after initializing it?
|
||||
*
|
||||
* Creates and initializes an overlay handle.
|
||||
*
|
||||
* Returns: Overlay handle on success, otherwise NULL.
|
||||
**/
|
||||
input_overlay_t *input_overlay_new(const char *path, bool enable,
|
||||
float alpha_mod, float scale_factor);
|
||||
|
||||
bool input_overlay_load_overlays(void);
|
||||
|
||||
bool input_overlay_load_overlays_iterate(void);
|
||||
|
||||
bool input_overlay_load_overlays_resolve_iterate(void);
|
||||
|
||||
bool input_overlay_new_done(void);
|
||||
typedef struct
|
||||
{
|
||||
struct overlay *overlays;
|
||||
struct overlay *active;
|
||||
size_t size;
|
||||
} overlay_task_data_t;
|
||||
|
||||
/**
|
||||
* input_overlay_free:
|
||||
@ -122,6 +198,13 @@ bool input_overlay_new_done(void);
|
||||
**/
|
||||
void input_overlay_free(void);
|
||||
|
||||
|
||||
/**
|
||||
* input_overlay_init
|
||||
*
|
||||
* Initializes the overlay system.
|
||||
*/
|
||||
void input_overlay_init(void);
|
||||
/**
|
||||
* input_overlay_set_alpha_mod:
|
||||
* @mod : New modulating factor to apply.
|
||||
@ -147,12 +230,6 @@ void input_overlay_set_scale_factor(float scale);
|
||||
**/
|
||||
void input_overlay_next(float opacity);
|
||||
|
||||
bool input_overlay_data_is_active(void);
|
||||
|
||||
void input_overlay_free_ptr(void);
|
||||
|
||||
int input_overlay_new_ptr(void);
|
||||
|
||||
enum overlay_status input_overlay_status(void);
|
||||
|
||||
/*
|
||||
|
@ -559,7 +559,7 @@ void net_http_delete(struct http_t *state)
|
||||
|
||||
if (state->fd != -1)
|
||||
socket_close(state->fd);
|
||||
if (state->data)
|
||||
free(state->data);
|
||||
// if (state->data)
|
||||
// free(state->data);
|
||||
free(state);
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "../menu.h"
|
||||
#include "../menu_cbs.h"
|
||||
#include "../../msg_hash.h"
|
||||
|
||||
#ifdef HAVE_LIBRETRODB
|
||||
#include "../../database_info.h"
|
||||
@ -25,6 +26,21 @@
|
||||
#include "../../cores/internal_cores.h"
|
||||
|
||||
#include "../../general.h"
|
||||
#include "../../verbosity.h"
|
||||
#include "../../tasks/tasks.h"
|
||||
|
||||
#define CB_CORE_UPDATER_DOWNLOAD 0x7412da7dU
|
||||
#define CB_CORE_UPDATER_LIST 0x32fd4f01U
|
||||
#define CB_UPDATE_ASSETS 0xbf85795eU
|
||||
#define CB_UPDATE_CORE_INFO_FILES 0xe6084091U
|
||||
#define CB_UPDATE_AUTOCONFIG_PROFILES 0x28ada67dU
|
||||
#define CB_UPDATE_CHEATS 0xc360fec3U
|
||||
#define CB_UPDATE_OVERLAYS 0x699009a0U
|
||||
#define CB_UPDATE_DATABASES 0x931eb8d3U
|
||||
#define CB_UPDATE_SHADERS_GLSL 0x0121a186U
|
||||
#define CB_UPDATE_SHADERS_CG 0xc93a53feU
|
||||
#define CB_CORE_CONTENT_LIST 0xebc51227U
|
||||
#define CB_CORE_CONTENT_DOWNLOAD 0x03b3c0a3U
|
||||
|
||||
#ifndef BIND_ACTION_DEFERRED_PUSH
|
||||
#define BIND_ACTION_DEFERRED_PUSH(cbs, name) \
|
||||
@ -32,10 +48,6 @@
|
||||
cbs->action_deferred_push_ident = #name;
|
||||
#endif
|
||||
|
||||
/* foward declarations */
|
||||
int cb_core_updater_list(void *data_, size_t len);
|
||||
int cb_core_content_list(void *data_, size_t len);
|
||||
|
||||
static int deferred_push_dlist(menu_displaylist_info_t *info, unsigned val)
|
||||
{
|
||||
if (menu_displaylist_push_list(info, val) != 0)
|
||||
@ -282,41 +294,176 @@ static int deferred_push_disk_options(menu_displaylist_info_t *info)
|
||||
char *core_buf;
|
||||
size_t core_len;
|
||||
|
||||
static int cb_net_generic(void *data_, size_t len)
|
||||
void cb_net_generic(void *task_data, void *user_data, const char *err)
|
||||
{
|
||||
int ret = -1;
|
||||
char *data = (char*)data_;
|
||||
menu_handle_t *menu = menu_driver_get_ptr();
|
||||
if (!menu || !data)
|
||||
goto end;
|
||||
http_transfer_data_t *data = (http_transfer_data_t*)task_data;
|
||||
|
||||
if (!menu || !data || err)
|
||||
goto finish;
|
||||
|
||||
if (core_buf)
|
||||
free(core_buf);
|
||||
|
||||
core_buf = (char*)malloc((len+1) * sizeof(char));
|
||||
core_buf = (char*)malloc((data->len+1) * sizeof(char));
|
||||
|
||||
if (!core_buf)
|
||||
goto end;
|
||||
goto finish;
|
||||
|
||||
memcpy(core_buf, data, len * sizeof(char));
|
||||
core_buf[len] = '\0';
|
||||
core_len = len;
|
||||
memcpy(core_buf, data->data, data->len * sizeof(char));
|
||||
core_buf[data->len] = '\0';
|
||||
core_len = data->len;
|
||||
ret = 0;
|
||||
|
||||
menu_entries_unset_refresh(true);
|
||||
|
||||
end:
|
||||
return ret;
|
||||
finish:
|
||||
if (data)
|
||||
{
|
||||
if (data->data)
|
||||
free(data->data);
|
||||
free(data);
|
||||
}
|
||||
}
|
||||
|
||||
int cb_core_updater_list(void *data_, size_t len)
|
||||
static int zlib_extract_core_callback(const char *name, const char *valid_exts,
|
||||
const uint8_t *cdata, unsigned cmode, uint32_t csize, uint32_t size,
|
||||
uint32_t crc32, void *userdata)
|
||||
{
|
||||
return cb_net_generic(data_, len);
|
||||
char path[PATH_MAX_LENGTH];
|
||||
|
||||
/* Make directory */
|
||||
fill_pathname_join(path, (const char*)userdata, name, sizeof(path));
|
||||
path_basedir(path);
|
||||
|
||||
if (!path_mkdir(path))
|
||||
goto error;
|
||||
|
||||
/* Ignore directories. */
|
||||
if (name[strlen(name) - 1] == '/' || name[strlen(name) - 1] == '\\')
|
||||
return 1;
|
||||
|
||||
fill_pathname_join(path, (const char*)userdata, name, sizeof(path));
|
||||
|
||||
RARCH_LOG("path is: %s, CRC32: 0x%x\n", path, crc32);
|
||||
|
||||
if (!zlib_perform_mode(path, valid_exts,
|
||||
cdata, cmode, csize, size, crc32, userdata))
|
||||
goto error;
|
||||
|
||||
return 1;
|
||||
|
||||
error:
|
||||
RARCH_ERR("Failed to deflate to: %s.\n", path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cb_core_content_list(void *data_, size_t len)
|
||||
/* expects http_transfer_t*, menu_file_transfer_t* */
|
||||
void cb_generic_download(void *task_data, void *user_data, const char *err)
|
||||
//(void *data, size_t len, const char *dir_path)
|
||||
{
|
||||
return cb_net_generic(data_, len);
|
||||
char msg[PATH_MAX_LENGTH];
|
||||
char output_path[PATH_MAX_LENGTH];
|
||||
char shaderdir[PATH_MAX_LENGTH];
|
||||
const char *file_ext = NULL;
|
||||
const char *dir_path = NULL;
|
||||
menu_file_transfer_t *transf = (menu_file_transfer_t*)user_data;
|
||||
settings_t *settings = config_get_ptr();
|
||||
http_transfer_data_t *data = (http_transfer_data_t*)task_data;
|
||||
|
||||
if (!data || !data->data | !transf)
|
||||
goto finish;
|
||||
|
||||
/* we have to determine dir_path at the time of writting or else
|
||||
* we'd run into races when the user changes the setting during an
|
||||
* http transfer. */
|
||||
switch (transf->type_hash)
|
||||
{
|
||||
case CB_CORE_UPDATER_DOWNLOAD:
|
||||
dir_path = settings->libretro_directory;
|
||||
break;
|
||||
case CB_CORE_CONTENT_DOWNLOAD:
|
||||
dir_path = settings->core_assets_directory;
|
||||
break;
|
||||
case CB_UPDATE_CORE_INFO_FILES:
|
||||
dir_path = settings->libretro_info_path;
|
||||
break;
|
||||
case CB_UPDATE_ASSETS:
|
||||
dir_path = settings->assets_directory;
|
||||
break;
|
||||
case CB_UPDATE_AUTOCONFIG_PROFILES:
|
||||
dir_path = settings->input.autoconfig_dir;
|
||||
break;
|
||||
case CB_UPDATE_DATABASES:
|
||||
dir_path = settings->content_database;
|
||||
break;
|
||||
case CB_UPDATE_OVERLAYS:
|
||||
dir_path = settings->overlay_directory;
|
||||
break;
|
||||
case CB_UPDATE_CHEATS:
|
||||
dir_path = settings->cheat_database;
|
||||
break;
|
||||
case CB_UPDATE_SHADERS_CG:
|
||||
case CB_UPDATE_SHADERS_GLSL:
|
||||
{
|
||||
const char *dirname = transf->type_hash == CB_UPDATE_SHADERS_CG ?
|
||||
"shaders_cg" : "shaders_glsl";
|
||||
|
||||
fill_pathname_join(shaderdir, settings->video.shader_dir, dirname,
|
||||
sizeof(shaderdir));
|
||||
if (!path_file_exists(shaderdir))
|
||||
if (!path_mkdir(shaderdir))
|
||||
goto finish;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
RARCH_WARN("Unknown transfer type '%u' bailing out.\n", transf->type_hash);
|
||||
break;
|
||||
}
|
||||
|
||||
fill_pathname_join(output_path, dir_path,
|
||||
transf->path, sizeof(output_path));
|
||||
|
||||
if (!retro_write_file(output_path, data->data, data->len))
|
||||
goto finish;
|
||||
|
||||
snprintf(msg, sizeof(msg), "%s: %s.",
|
||||
msg_hash_to_str(MSG_DOWNLOAD_COMPLETE),
|
||||
transf->path);
|
||||
|
||||
rarch_main_msg_queue_push(msg, 1, 90, true);
|
||||
|
||||
#ifdef HAVE_ZLIB
|
||||
/* TODO: this should generate a new task instead of blocking */
|
||||
file_ext = path_get_extension(output_path);
|
||||
|
||||
if (!settings->network.buildbot_auto_extract_archive)
|
||||
goto finish;
|
||||
|
||||
if (!strcasecmp(file_ext, "zip"))
|
||||
{
|
||||
if (!zlib_parse_file(output_path, NULL, zlib_extract_core_callback,
|
||||
(void*)dir_path))
|
||||
RARCH_LOG("%s\n", msg_hash_to_str(MSG_COULD_NOT_PROCESS_ZIP_FILE));
|
||||
|
||||
if (path_file_exists(output_path))
|
||||
remove(output_path);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (transf->type_hash == CB_CORE_UPDATER_DOWNLOAD)
|
||||
event_command(EVENT_CMD_CORE_INFO_INIT);
|
||||
|
||||
finish:
|
||||
if (data)
|
||||
{
|
||||
if (data->data)
|
||||
free(data->data);
|
||||
free(data);
|
||||
}
|
||||
|
||||
free(transf);
|
||||
}
|
||||
|
||||
static int deferred_push_core_updater_list(menu_displaylist_info_t *info)
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
#include "../../general.h"
|
||||
#include "../../runloop_data.h"
|
||||
#include "../../tasks/tasks.h"
|
||||
#include "../../input/input_remapping.h"
|
||||
#include "../../system.h"
|
||||
|
||||
@ -38,9 +39,9 @@
|
||||
char detect_content_path[PATH_MAX_LENGTH];
|
||||
unsigned rdb_entry_start_game_selection_ptr, rpl_entry_selection_ptr;
|
||||
size_t hack_shader_pass = 0;
|
||||
#ifdef HAVE_NETWORKING
|
||||
char core_updater_path[PATH_MAX_LENGTH];
|
||||
#endif
|
||||
|
||||
/* defined in menu_cbs_deferred_push */
|
||||
void cb_net_generic(void *task_data, void *user_data, const char *err);
|
||||
|
||||
int generic_action_ok_displaylist_push(const char *path,
|
||||
const char *label, unsigned type, size_t idx, size_t entry_idx,
|
||||
@ -628,9 +629,8 @@ static int generic_action_ok(const char *path,
|
||||
if (path_file_exists(action_path))
|
||||
{
|
||||
strlcpy(settings->menu.wallpaper, action_path, sizeof(settings->menu.wallpaper));
|
||||
|
||||
rarch_main_data_msg_queue_push(DATA_TYPE_IMAGE, action_path, "cb_menu_wallpaper", 0, 1,
|
||||
true);
|
||||
rarch_task_push_image_load(action_path,
|
||||
"cb_menu_wallpaper", menu_display_handle_wallpaper_upload);
|
||||
}
|
||||
break;
|
||||
case ACTION_OK_LOAD_CORE:
|
||||
@ -1114,6 +1114,7 @@ static int action_ok_download_generic(const char *path,
|
||||
char s2[PATH_MAX_LENGTH];
|
||||
char s3[PATH_MAX_LENGTH];
|
||||
settings_t *settings = config_get_ptr();
|
||||
menu_file_transfer_t *transf;
|
||||
|
||||
fill_pathname_join(s, settings->network.buildbot_assets_url,
|
||||
"frontend", sizeof(s));
|
||||
@ -1148,7 +1149,9 @@ static int action_ok_download_generic(const char *path,
|
||||
|
||||
fill_pathname_join(s3, s, path, sizeof(s3));
|
||||
|
||||
strlcpy(core_updater_path, path, sizeof(core_updater_path));
|
||||
transf = (menu_file_transfer_t*)calloc(1, sizeof(*transf));
|
||||
transf->type_hash = menu_hash_calculate(type_msg);
|
||||
strlcpy(transf->path, path, sizeof(transf->path));
|
||||
|
||||
snprintf(s2, sizeof(s2),
|
||||
"%s %s.",
|
||||
@ -1157,8 +1160,7 @@ static int action_ok_download_generic(const char *path,
|
||||
|
||||
menu_display_msg_queue_push(s2, 1, 90, true);
|
||||
|
||||
rarch_main_data_msg_queue_push(DATA_TYPE_HTTP, s3,
|
||||
type_msg, 0, 1, true);
|
||||
rarch_task_push_http_transfer(s3, type_msg, cb_generic_download, transf);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
@ -1383,6 +1385,7 @@ static int generic_action_ok_network(const char *path,
|
||||
settings_t *settings = config_get_ptr();
|
||||
unsigned type_id2 = 0;
|
||||
const char *url_label = NULL;
|
||||
rarch_task_callback_t callback = NULL;
|
||||
|
||||
menu_entries_set_refresh(true);
|
||||
|
||||
@ -1398,17 +1401,22 @@ static int generic_action_ok_network(const char *path,
|
||||
"cores/gw/.index", sizeof(url_path));
|
||||
url_label = "cb_core_content_list";
|
||||
type_id2 = ACTION_OK_DL_CORE_CONTENT_LIST;
|
||||
callback = cb_net_generic;
|
||||
break;
|
||||
case ACTION_OK_NETWORK_CORE_UPDATER_LIST:
|
||||
fill_pathname_join(url_path, settings->network.buildbot_url,
|
||||
".index", sizeof(url_path));
|
||||
url_label = "cb_core_updater_list";
|
||||
type_id2 = ACTION_OK_DL_CORE_UPDATER_LIST;
|
||||
callback = cb_net_generic;
|
||||
break;
|
||||
}
|
||||
|
||||
rarch_main_data_msg_queue_push(DATA_TYPE_HTTP, url_path, url_label, 0, 1,
|
||||
true);
|
||||
// rarch_main_data_msg_queue_push(DATA_TYPE_HTTP, url_path, url_label, 0, 1,
|
||||
// true);
|
||||
|
||||
rarch_task_push_http_transfer(url_path, url_label, callback, NULL);
|
||||
|
||||
return generic_action_ok_displaylist_push(path,
|
||||
label, type, idx, entry_idx, type_id2);
|
||||
}
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "../menu_setting.h"
|
||||
|
||||
#include "../../runloop_data.h"
|
||||
#include "../../tasks/tasks.h"
|
||||
|
||||
#ifndef BIND_ACTION_SCAN
|
||||
#define BIND_ACTION_SCAN(cbs, name) \
|
||||
@ -29,6 +30,11 @@
|
||||
cbs->action_scan_ident = #name;
|
||||
#endif
|
||||
|
||||
static void handle_dbscan_finished(void *task_data, void *user_data, const char *err)
|
||||
{
|
||||
menu_environment_cb(MENU_ENVIRON_RESET_HORIZONTAL_LIST, NULL);
|
||||
}
|
||||
|
||||
int action_scan_file(const char *path,
|
||||
const char *label, unsigned type, size_t idx)
|
||||
{
|
||||
@ -43,8 +49,8 @@ int action_scan_file(const char *path,
|
||||
|
||||
fill_pathname_join(fullpath, menu_path, path, sizeof(fullpath));
|
||||
|
||||
rarch_main_data_msg_queue_push(DATA_TYPE_DB, fullpath,
|
||||
"cb_db_scan_file", 0, 1, true);
|
||||
rarch_task_push_dbscan(fullpath, false, handle_dbscan_finished);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -65,8 +71,8 @@ int action_scan_directory(const char *path,
|
||||
if (path)
|
||||
fill_pathname_join(fullpath, fullpath, path, sizeof(fullpath));
|
||||
|
||||
rarch_main_data_msg_queue_push(DATA_TYPE_DB, fullpath,
|
||||
"cb_db_scan_folder", 0, 1, true);
|
||||
rarch_task_push_dbscan(fullpath, true, handle_dbscan_finished);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,7 @@
|
||||
#include "../../runloop.h"
|
||||
#include "../../runloop_data.h"
|
||||
#include "../../verbosity.h"
|
||||
#include "../../tasks/tasks.h"
|
||||
|
||||
enum
|
||||
{
|
||||
@ -1163,8 +1164,8 @@ static void mui_context_reset(void)
|
||||
mui_allocate_white_texture(mui);
|
||||
mui_context_reset_textures(mui, iconpath);
|
||||
|
||||
rarch_main_data_msg_queue_push(DATA_TYPE_IMAGE,
|
||||
settings->menu.wallpaper, "cb_menu_wallpaper", 0, 1, true);
|
||||
rarch_task_push_image_load(settings->menu.wallpaper, "cb_menu_wallpaper",
|
||||
menu_display_handle_wallpaper_upload);
|
||||
}
|
||||
|
||||
static int mui_environ(menu_environ_cb_t type, void *data)
|
||||
|
@ -46,6 +46,7 @@
|
||||
|
||||
#include "../../runloop.h"
|
||||
#include "../../runloop_data.h"
|
||||
#include "../../tasks/tasks.h"
|
||||
|
||||
#ifndef XMB_THEME
|
||||
#define XMB_THEME "monochrome"
|
||||
@ -540,8 +541,8 @@ static void xmb_update_boxart_path(xmb_handle_t *xmb, unsigned i)
|
||||
static void xmb_update_boxart_image(xmb_handle_t *xmb)
|
||||
{
|
||||
if (path_file_exists(xmb->boxart_file_path))
|
||||
rarch_main_data_msg_queue_push(DATA_TYPE_IMAGE, xmb->boxart_file_path,
|
||||
"cb_menu_boxart", 0, 1, true);
|
||||
rarch_task_push_image_load(xmb->boxart_file_path, "cb_menu_boxart",
|
||||
menu_display_handle_boxart_upload);
|
||||
else if (xmb->depth == 1)
|
||||
xmb->boxart = 0;
|
||||
}
|
||||
@ -814,9 +815,8 @@ static void xmb_list_switch_new(xmb_handle_t *xmb,
|
||||
|
||||
if(strcmp(path, xmb->background_file_path) != 0) {
|
||||
if(path_file_exists(path)) {
|
||||
rarch_main_data_msg_queue_push(DATA_TYPE_IMAGE, path,
|
||||
"cb_menu_wallpaper", 0, 1, true);
|
||||
strlcpy(xmb->background_file_path, path, sizeof(xmb->background_file_path));
|
||||
rarch_task_push_image_load(path, "cb_menu_wallpaper", menu_display_handle_wallpaper_upload);
|
||||
strlcpy(xmb->background_file_path, path, sizeof(xmb->background_file_path));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2248,8 +2248,7 @@ static void xmb_context_reset_background(const char *iconpath)
|
||||
strlcpy(path, settings->menu.wallpaper, sizeof(path));
|
||||
|
||||
if (path_file_exists(path))
|
||||
rarch_main_data_msg_queue_push(DATA_TYPE_IMAGE, path,
|
||||
"cb_menu_wallpaper", 0, 1, true);
|
||||
rarch_task_push_image_load(path, "cb_menu_wallpaper", menu_display_handle_wallpaper_upload);
|
||||
}
|
||||
|
||||
static void xmb_context_reset(void)
|
||||
|
@ -47,6 +47,7 @@
|
||||
#include "../../configuration.h"
|
||||
#include "../../runloop.h"
|
||||
#include "../../verbosity.h"
|
||||
#include "../../tasks/tasks.h"
|
||||
|
||||
#if 0
|
||||
#define ZARCH_DEBUG
|
||||
@ -1109,8 +1110,8 @@ static void *zarch_init(void)
|
||||
zui->font_size = 28;
|
||||
|
||||
if (settings->menu.wallpaper[0] != '\0')
|
||||
rarch_main_data_msg_queue_push(DATA_TYPE_IMAGE,
|
||||
settings->menu.wallpaper, "cb_menu_wallpaper", 0, 1, true);
|
||||
rarch_task_push_image_load(settings->menu.wallpaper,
|
||||
"cb_menu_wallpaper", menu_display_handle_wallpaper_upload);
|
||||
|
||||
zui->ca.allocated = 0;
|
||||
|
||||
@ -1228,8 +1229,8 @@ static void zarch_context_reset(void)
|
||||
|
||||
zarch_context_bg_destroy(zui);
|
||||
|
||||
rarch_main_data_msg_queue_push(DATA_TYPE_IMAGE,
|
||||
settings->menu.wallpaper, "cb_menu_wallpaper", 0, 1, true);
|
||||
rarch_task_push_image_load(settings->menu.wallpaper,
|
||||
"cb_menu_wallpaper", menu_display_handle_wallpaper_upload);
|
||||
|
||||
zarch_allocate_white_texture(zui);
|
||||
|
||||
|
@ -67,9 +67,6 @@ enum
|
||||
|
||||
/* FIXME - Externs, refactor */
|
||||
extern size_t hack_shader_pass;
|
||||
#ifdef HAVE_NETWORKING
|
||||
extern char core_updater_path[PATH_MAX_LENGTH];
|
||||
#endif
|
||||
|
||||
/* Function callbacks */
|
||||
|
||||
@ -200,4 +197,15 @@ void menu_cbs_init(void *data,
|
||||
|
||||
bool menu_playlist_find_associated_core(const char *path, char *s, size_t len);
|
||||
|
||||
|
||||
#ifdef HAVE_NETWORKING
|
||||
void cb_net_generic(void *task_data, void *user_data, const char *err);
|
||||
|
||||
typedef struct {
|
||||
uint32_t type_hash;
|
||||
char path[PATH_MAX_LENGTH];
|
||||
} menu_file_transfer_t;
|
||||
void cb_generic_download(void *task_data, void *user_data, const char *err);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -662,3 +662,19 @@ const float *menu_display_get_tex_coords(void)
|
||||
|
||||
return menu_disp->get_tex_coords();
|
||||
}
|
||||
|
||||
void menu_display_handle_wallpaper_upload(void *task_data, void *user_data, const char *err)
|
||||
{
|
||||
struct texture_image *img = (struct texture_image*)task_data;
|
||||
menu_driver_load_image(img, MENU_IMAGE_WALLPAPER);
|
||||
texture_image_free(img);
|
||||
free(img);
|
||||
}
|
||||
|
||||
void menu_display_handle_boxart_upload(void *task_data, void *user_data, const char *err)
|
||||
{
|
||||
struct texture_image *img = (struct texture_image*)task_data;
|
||||
menu_driver_load_image(img, MENU_IMAGE_BOXART);
|
||||
texture_image_free(img);
|
||||
free(img);
|
||||
}
|
||||
|
@ -178,6 +178,10 @@ void menu_display_clear_color(float r, float g, float b, float a);
|
||||
|
||||
void menu_display_texture_unload(uintptr_t *id);
|
||||
|
||||
void menu_display_handle_wallpaper_upload(void *task_data, void *user_data, const char *err);
|
||||
|
||||
void menu_display_handle_boxart_upload(void *task_data, void *user_data, const char *err);
|
||||
|
||||
const float *menu_display_get_tex_coords(void);
|
||||
|
||||
extern menu_display_ctx_driver_t menu_display_ctx_gl;
|
||||
|
225
runloop_data.c
225
runloop_data.c
@ -23,225 +23,47 @@
|
||||
#include "verbosity.h"
|
||||
|
||||
#include "tasks/tasks.h"
|
||||
#include "input/input_overlay.h"
|
||||
|
||||
#ifdef HAVE_MENU
|
||||
#include "menu/menu.h"
|
||||
#endif
|
||||
|
||||
#undef HAVE_THREADS
|
||||
typedef struct data_runloop
|
||||
{
|
||||
bool inited;
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
bool thread_sleeping;
|
||||
bool thread_inited;
|
||||
bool alive;
|
||||
|
||||
slock_t *lock;
|
||||
slock_t *cond_lock;
|
||||
scond_t *cond;
|
||||
sthread_t *thread;
|
||||
#endif
|
||||
} data_runloop_t;
|
||||
|
||||
static char data_runloop_msg[PATH_MAX_LENGTH];
|
||||
|
||||
static data_runloop_t g_data_runloop;
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
static void data_runloop_thread_deinit(void)
|
||||
{
|
||||
if (!g_data_runloop.thread_inited)
|
||||
{
|
||||
slock_lock(g_data_runloop.cond_lock);
|
||||
g_data_runloop.alive = false;
|
||||
scond_signal(g_data_runloop.cond);
|
||||
slock_unlock(g_data_runloop.cond_lock);
|
||||
sthread_join(g_data_runloop.thread);
|
||||
|
||||
slock_free(g_data_runloop.lock);
|
||||
slock_free(g_data_runloop.cond_lock);
|
||||
scond_free(g_data_runloop.cond);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void rarch_main_data_deinit(void)
|
||||
{
|
||||
#ifdef HAVE_THREADS
|
||||
if (g_data_runloop.thread_inited)
|
||||
{
|
||||
data_runloop_thread_deinit();
|
||||
|
||||
g_data_runloop.thread_inited = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
g_data_runloop.inited = false;
|
||||
|
||||
rarch_task_deinit();
|
||||
}
|
||||
|
||||
void rarch_main_data_free(void)
|
||||
{
|
||||
rarch_main_data_nbio_uninit();
|
||||
#ifdef HAVE_NETWORKING
|
||||
rarch_main_data_http_uninit();
|
||||
#endif
|
||||
#ifdef HAVE_LIBRETRODB
|
||||
rarch_main_data_db_uninit();
|
||||
#endif
|
||||
|
||||
memset(&g_data_runloop, 0, sizeof(g_data_runloop));
|
||||
}
|
||||
|
||||
static void data_runloop_iterate(bool is_thread)
|
||||
{
|
||||
rarch_main_data_nbio_iterate (is_thread);
|
||||
#ifdef HAVE_MENU
|
||||
#ifdef HAVE_RPNG
|
||||
rarch_main_data_nbio_image_iterate (is_thread);
|
||||
#endif
|
||||
#endif
|
||||
#ifdef HAVE_NETWORKING
|
||||
rarch_main_data_http_iterate (is_thread);
|
||||
#endif
|
||||
#ifdef HAVE_LIBRETRODB
|
||||
rarch_main_data_db_iterate (is_thread);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
bool rarch_main_data_active(void)
|
||||
{
|
||||
#ifdef HAVE_LIBRETRODB
|
||||
if (rarch_main_data_db_is_active())
|
||||
return true;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_OVERLAY
|
||||
if (input_overlay_data_is_active())
|
||||
return true;
|
||||
#endif
|
||||
if (rarch_main_data_nbio_image_get_handle())
|
||||
return true;
|
||||
if (rarch_main_data_nbio_get_handle())
|
||||
return true;
|
||||
#ifdef HAVE_NETWORKING
|
||||
if (rarch_main_data_http_get_handle())
|
||||
return true;
|
||||
if (rarch_main_data_http_conn_get_handle())
|
||||
return true;
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
static void data_thread_loop(void *data)
|
||||
{
|
||||
data_runloop_t *runloop = (data_runloop_t*)data;
|
||||
|
||||
RARCH_LOG("[Data Thread]: Initializing data thread.\n");
|
||||
|
||||
slock_lock(runloop->lock);
|
||||
while (!runloop->thread_inited)
|
||||
scond_wait(runloop->cond, runloop->lock);
|
||||
slock_unlock(runloop->lock);
|
||||
|
||||
RARCH_LOG("[Data Thread]: Starting data thread.\n");
|
||||
|
||||
while (runloop->alive)
|
||||
{
|
||||
slock_lock(runloop->lock);
|
||||
|
||||
if (!runloop->alive)
|
||||
break;
|
||||
|
||||
data_runloop_iterate(true);
|
||||
|
||||
if (!rarch_main_data_active())
|
||||
{
|
||||
runloop->thread_sleeping = true;
|
||||
while(runloop->thread_sleeping)
|
||||
scond_wait(runloop->cond, runloop->lock);
|
||||
}
|
||||
|
||||
slock_unlock(runloop->lock);
|
||||
|
||||
}
|
||||
|
||||
RARCH_LOG("[Data Thread]: Stopping data thread.\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
static void rarch_main_data_thread_init(void)
|
||||
{
|
||||
if (g_data_runloop.thread_inited)
|
||||
return;
|
||||
|
||||
g_data_runloop.lock = slock_new();
|
||||
g_data_runloop.cond_lock = slock_new();
|
||||
g_data_runloop.cond = scond_new();
|
||||
|
||||
g_data_runloop.thread = sthread_create(data_thread_loop, &g_data_runloop);
|
||||
|
||||
if (!g_data_runloop.thread)
|
||||
goto error;
|
||||
|
||||
slock_lock(g_data_runloop.lock);
|
||||
g_data_runloop.thread_inited = true;
|
||||
g_data_runloop.alive = true;
|
||||
slock_unlock(g_data_runloop.lock);
|
||||
|
||||
return;
|
||||
|
||||
error:
|
||||
data_runloop_thread_deinit();
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_MENU
|
||||
static void rarch_main_data_menu_iterate(void)
|
||||
{
|
||||
#ifdef HAVE_LIBRETRODB
|
||||
if (rarch_main_data_db_pending_scan_finished())
|
||||
menu_environment_cb(MENU_ENVIRON_RESET_HORIZONTAL_LIST, NULL);
|
||||
#endif
|
||||
|
||||
menu_iterate_render();
|
||||
}
|
||||
#endif
|
||||
|
||||
void rarch_main_data_iterate(void)
|
||||
{
|
||||
settings_t *settings = config_get_ptr();
|
||||
|
||||
(void)settings;
|
||||
#ifdef HAVE_THREADS
|
||||
if (settings->threaded_data_runloop_enable)
|
||||
{
|
||||
if (!g_data_runloop.thread_inited)
|
||||
rarch_main_data_thread_init();
|
||||
else if (g_data_runloop.thread_sleeping)
|
||||
{
|
||||
slock_lock(g_data_runloop.cond_lock);
|
||||
g_data_runloop.thread_sleeping = false;
|
||||
scond_signal(g_data_runloop.cond);
|
||||
slock_unlock(g_data_runloop.cond_lock);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_RPNG
|
||||
#ifdef HAVE_MENU
|
||||
rarch_main_data_nbio_image_upload_iterate();
|
||||
#endif
|
||||
#endif
|
||||
#ifdef HAVE_OVERLAY
|
||||
rarch_main_data_overlay_iterate();
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_MENU
|
||||
rarch_main_data_menu_iterate();
|
||||
#endif
|
||||
@ -252,22 +74,14 @@ void rarch_main_data_iterate(void)
|
||||
data_runloop_msg[0] = '\0';
|
||||
}
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
if (settings->threaded_data_runloop_enable && g_data_runloop.alive)
|
||||
return;
|
||||
#endif
|
||||
|
||||
data_runloop_iterate(false);
|
||||
rarch_task_check();
|
||||
}
|
||||
|
||||
static void rarch_main_data_init(void)
|
||||
{
|
||||
#ifdef HAVE_THREADS
|
||||
g_data_runloop.thread_inited = false;
|
||||
g_data_runloop.alive = false;
|
||||
#endif
|
||||
|
||||
g_data_runloop.inited = true;
|
||||
|
||||
rarch_task_init();
|
||||
}
|
||||
|
||||
void rarch_main_data_clear_state(void)
|
||||
@ -275,26 +89,11 @@ void rarch_main_data_clear_state(void)
|
||||
rarch_main_data_deinit();
|
||||
rarch_main_data_free();
|
||||
rarch_main_data_init();
|
||||
|
||||
rarch_main_data_nbio_init();
|
||||
#ifdef HAVE_NETWORKING
|
||||
rarch_main_data_http_init();
|
||||
#endif
|
||||
#ifdef HAVE_LIBRETRODB
|
||||
rarch_main_data_db_init();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void rarch_main_data_init_queues(void)
|
||||
{
|
||||
#ifdef HAVE_NETWORKING
|
||||
rarch_main_data_http_init_msg_queue();
|
||||
#endif
|
||||
rarch_main_data_nbio_init_msg_queue();
|
||||
#ifdef HAVE_LIBRETRODB
|
||||
rarch_main_data_db_init_msg_queue();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -313,30 +112,20 @@ void rarch_main_data_msg_queue_push(unsigned type,
|
||||
case DATA_TYPE_NONE:
|
||||
break;
|
||||
case DATA_TYPE_FILE:
|
||||
queue = rarch_main_data_nbio_get_msg_queue_ptr();
|
||||
fill_pathname_join_delim(new_msg, msg, msg2, '|', sizeof(new_msg));
|
||||
break;
|
||||
case DATA_TYPE_IMAGE:
|
||||
queue = rarch_main_data_nbio_image_get_msg_queue_ptr();
|
||||
fill_pathname_join_delim(new_msg, msg, msg2, '|', sizeof(new_msg));
|
||||
break;
|
||||
#ifdef HAVE_NETWORKING
|
||||
case DATA_TYPE_HTTP:
|
||||
queue = rarch_main_data_http_get_msg_queue_ptr();
|
||||
fill_pathname_join_delim(new_msg, msg, msg2, '|', sizeof(new_msg));
|
||||
break;
|
||||
#endif
|
||||
#ifdef HAVE_OVERLAY
|
||||
case DATA_TYPE_OVERLAY:
|
||||
fill_pathname_join_delim(new_msg, msg, msg2, '|', sizeof(new_msg));
|
||||
break;
|
||||
#endif
|
||||
#ifdef HAVE_LIBRETRODB
|
||||
case DATA_TYPE_DB:
|
||||
queue = rarch_main_data_db_get_msg_queue_ptr();
|
||||
fill_pathname_join_delim(new_msg, msg, msg2, '|', sizeof(new_msg));
|
||||
default:
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (!queue)
|
||||
|
@ -62,19 +62,6 @@ typedef struct db_handle
|
||||
unsigned status;
|
||||
} db_handle_t;
|
||||
|
||||
static db_handle_t *db_ptr;
|
||||
|
||||
static bool pending_scan_finished;
|
||||
|
||||
bool rarch_main_data_db_pending_scan_finished(void)
|
||||
{
|
||||
if (!pending_scan_finished)
|
||||
return false;
|
||||
|
||||
pending_scan_finished = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef HAVE_LIBRETRODB
|
||||
|
||||
#ifdef HAVE_ZLIB
|
||||
@ -489,48 +476,6 @@ static int database_info_iterate(database_state_handle_t *db_state, database_inf
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int database_info_poll(db_handle_t *db)
|
||||
{
|
||||
char elem0[PATH_MAX_LENGTH];
|
||||
uint32_t cb_type_hash = 0;
|
||||
struct string_list *str_list = NULL;
|
||||
const char *path = msg_queue_pull(db->msg_queue);
|
||||
|
||||
if (!path)
|
||||
return -1;
|
||||
|
||||
str_list = string_split(path, "|");
|
||||
|
||||
if (!str_list)
|
||||
goto error;
|
||||
if (str_list->size < 1)
|
||||
goto error;
|
||||
|
||||
strlcpy(elem0, str_list->elems[0].data, sizeof(elem0));
|
||||
if (str_list->size > 1)
|
||||
cb_type_hash = msg_hash_calculate(str_list->elems[1].data);
|
||||
|
||||
switch (cb_type_hash)
|
||||
{
|
||||
case CB_DB_SCAN_FILE:
|
||||
db->handle = database_info_file_init(elem0, DATABASE_TYPE_ITERATE);
|
||||
break;
|
||||
case CB_DB_SCAN_FOLDER:
|
||||
db->handle = database_info_dir_init(elem0, DATABASE_TYPE_ITERATE);
|
||||
break;
|
||||
}
|
||||
|
||||
string_list_free(str_list);
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
if (str_list)
|
||||
string_list_free(str_list);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void rarch_main_data_db_cleanup_state(database_state_handle_t *db_state)
|
||||
{
|
||||
if (!db_state)
|
||||
@ -541,115 +486,92 @@ static void rarch_main_data_db_cleanup_state(database_state_handle_t *db_state)
|
||||
db_state->buf = NULL;
|
||||
}
|
||||
|
||||
void rarch_main_data_db_iterate(bool is_thread)
|
||||
static void rarch_dbscan_task_handler(rarch_task_t *task)
|
||||
{
|
||||
database_info_handle_t *db = (db_ptr) ? db_ptr->handle : NULL;
|
||||
database_state_handle_t *db_state = (db_ptr) ? &db_ptr->state : NULL;
|
||||
const char *name = db ? db->list->elems[db->list_ptr].data : NULL;
|
||||
db_handle_t *db = (db_handle_t*)task->state;
|
||||
database_info_handle_t *dbinfo = db->handle;
|
||||
database_state_handle_t *dbstate = &db->state;
|
||||
const char *name = dbinfo ? dbinfo->list->elems[dbinfo->list_ptr].data : NULL;
|
||||
|
||||
if (!db)
|
||||
goto do_poll;
|
||||
if (!dbinfo)
|
||||
goto task_finished;
|
||||
|
||||
switch (db->status)
|
||||
switch (dbinfo->status)
|
||||
{
|
||||
case DATABASE_STATUS_ITERATE_BEGIN:
|
||||
if (db_state && !db_state->list)
|
||||
db_state->list = dir_list_new_special(NULL, DIR_LIST_DATABASES, NULL);
|
||||
db->status = DATABASE_STATUS_ITERATE_START;
|
||||
if (dbstate && !dbstate->list)
|
||||
dbstate->list = dir_list_new_special(NULL, DIR_LIST_DATABASES, NULL);
|
||||
dbinfo->status = DATABASE_STATUS_ITERATE_START;
|
||||
break;
|
||||
case DATABASE_STATUS_ITERATE_START:
|
||||
rarch_main_data_db_cleanup_state(db_state);
|
||||
db_state->list_index = 0;
|
||||
db_state->entry_index = 0;
|
||||
database_info_iterate_start(db, name);
|
||||
rarch_main_data_db_cleanup_state(dbstate);
|
||||
dbstate->list_index = 0;
|
||||
dbstate->entry_index = 0;
|
||||
database_info_iterate_start(dbinfo, name);
|
||||
break;
|
||||
case DATABASE_STATUS_ITERATE:
|
||||
if (database_info_iterate(&db_ptr->state, db) == 0)
|
||||
if (database_info_iterate(&db->state, dbinfo) == 0)
|
||||
{
|
||||
db->status = DATABASE_STATUS_ITERATE_NEXT;
|
||||
db->type = DATABASE_TYPE_ITERATE;
|
||||
dbinfo->status = DATABASE_STATUS_ITERATE_NEXT;
|
||||
dbinfo->type = DATABASE_TYPE_ITERATE;
|
||||
}
|
||||
break;
|
||||
case DATABASE_STATUS_ITERATE_NEXT:
|
||||
if (database_info_iterate_next(db) == 0)
|
||||
if (database_info_iterate_next(dbinfo) == 0)
|
||||
{
|
||||
db->status = DATABASE_STATUS_ITERATE_START;
|
||||
db->type = DATABASE_TYPE_ITERATE;
|
||||
dbinfo->status = DATABASE_STATUS_ITERATE_START;
|
||||
dbinfo->type = DATABASE_TYPE_ITERATE;
|
||||
}
|
||||
else
|
||||
{
|
||||
rarch_main_msg_queue_push_new(MSG_SCANNING_OF_DIRECTORY_FINISHED, 0, 180, true);
|
||||
pending_scan_finished = true;
|
||||
db->status = DATABASE_STATUS_FREE;
|
||||
goto task_finished;
|
||||
}
|
||||
break;
|
||||
case DATABASE_STATUS_FREE:
|
||||
if (db_state->list)
|
||||
dir_list_free(db_state->list);
|
||||
db_state->list = NULL;
|
||||
rarch_main_data_db_cleanup_state(db_state);
|
||||
database_info_free(db);
|
||||
if (db_ptr->handle)
|
||||
free(db_ptr->handle);
|
||||
db_ptr->handle = NULL;
|
||||
break;
|
||||
default:
|
||||
case DATABASE_STATUS_FREE:
|
||||
case DATABASE_STATUS_NONE:
|
||||
goto do_poll;
|
||||
goto task_finished;
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
task_finished:
|
||||
task->finished = true;
|
||||
|
||||
do_poll:
|
||||
if (database_info_poll(db_ptr) != -1)
|
||||
{
|
||||
if (db_ptr->handle)
|
||||
db_ptr->handle->status = DATABASE_STATUS_ITERATE_BEGIN;
|
||||
}
|
||||
if (db->state.list)
|
||||
dir_list_free(db->state.list);
|
||||
|
||||
if (db->state.buf)
|
||||
free(db->state.buf);
|
||||
|
||||
if (db->handle)
|
||||
database_info_free(db->handle);
|
||||
|
||||
free(dbinfo);
|
||||
free(db);
|
||||
}
|
||||
|
||||
|
||||
void rarch_main_data_db_init_msg_queue(void)
|
||||
bool rarch_task_push_dbscan(const char *fullpath, bool directory, rarch_task_callback_t cb)
|
||||
{
|
||||
db_handle_t *db = (db_handle_t*)db_ptr;
|
||||
rarch_task_t *t = (rarch_task_t*)calloc(1, sizeof(*t));
|
||||
db_handle_t *db = (db_handle_t*)calloc(1, sizeof(db_handle_t));
|
||||
t->handler = rarch_dbscan_task_handler;
|
||||
t->state = db;
|
||||
t->callback = cb;
|
||||
|
||||
if (!db)
|
||||
return;
|
||||
|
||||
if (!db->msg_queue)
|
||||
retro_assert(db->msg_queue = msg_queue_new(8));
|
||||
if (directory)
|
||||
db->handle = database_info_dir_init(fullpath, DATABASE_TYPE_ITERATE);
|
||||
else
|
||||
db->handle = database_info_file_init(fullpath, DATABASE_TYPE_ITERATE);
|
||||
|
||||
if (db->handle)
|
||||
db->handle->status = DATABASE_STATUS_ITERATE_BEGIN;
|
||||
|
||||
rarch_task_push(t);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
msg_queue_t *rarch_main_data_db_get_msg_queue_ptr(void)
|
||||
{
|
||||
db_handle_t *db = (db_handle_t*)db_ptr;
|
||||
if (!db)
|
||||
return NULL;
|
||||
return db->msg_queue;
|
||||
}
|
||||
|
||||
void rarch_main_data_db_uninit(void)
|
||||
{
|
||||
if (db_ptr)
|
||||
free(db_ptr);
|
||||
db_ptr = NULL;
|
||||
pending_scan_finished = false;
|
||||
}
|
||||
|
||||
void rarch_main_data_db_init(void)
|
||||
{
|
||||
db_ptr = (db_handle_t*)calloc(1, sizeof(*db_ptr));
|
||||
pending_scan_finished = false;
|
||||
}
|
||||
|
||||
bool rarch_main_data_db_is_active(void)
|
||||
{
|
||||
db_handle_t *db = (db_handle_t*)db_ptr;
|
||||
database_info_handle_t *dbi = db ? db->handle : NULL;
|
||||
if (dbi && dbi->status != DATABASE_STATUS_NONE)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -63,7 +63,6 @@ typedef struct nbio_image_handle
|
||||
unsigned pos_increment;
|
||||
uint64_t frame_count;
|
||||
int processing_final_state;
|
||||
msg_queue_t *msg_queue;
|
||||
unsigned status;
|
||||
} nbio_image_handle_t;
|
||||
|
||||
@ -79,54 +78,15 @@ typedef struct nbio_handle
|
||||
unsigned status;
|
||||
} nbio_handle_t;
|
||||
|
||||
static nbio_handle_t *nbio_ptr;
|
||||
|
||||
msg_queue_t *rarch_main_data_nbio_get_msg_queue_ptr(void)
|
||||
{
|
||||
nbio_handle_t *nbio = (nbio_handle_t*)nbio_ptr;
|
||||
if (!nbio)
|
||||
return NULL;
|
||||
return nbio->msg_queue;
|
||||
}
|
||||
|
||||
void *rarch_main_data_nbio_get_handle(void)
|
||||
{
|
||||
nbio_handle_t *nbio = (nbio_handle_t*)nbio_ptr;
|
||||
if (!nbio)
|
||||
return NULL;
|
||||
return nbio->handle;
|
||||
}
|
||||
|
||||
msg_queue_t *rarch_main_data_nbio_image_get_msg_queue_ptr(void)
|
||||
{
|
||||
nbio_handle_t *nbio = (nbio_handle_t*)nbio_ptr;
|
||||
if (!nbio)
|
||||
return NULL;
|
||||
#ifdef HAVE_RPNG
|
||||
return nbio->image.msg_queue;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
void *rarch_main_data_nbio_image_get_handle(void)
|
||||
{
|
||||
nbio_handle_t *nbio = (nbio_handle_t*)nbio_ptr;
|
||||
if (!nbio)
|
||||
return NULL;
|
||||
#ifdef HAVE_RPNG
|
||||
return nbio->image.handle;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
static void rarch_task_file_load_handler(rarch_task_t *task);
|
||||
|
||||
#ifdef HAVE_MENU
|
||||
#include "../menu/menu_driver.h"
|
||||
|
||||
#ifdef HAVE_RPNG
|
||||
static int cb_image_menu_upload_generic(nbio_handle_t *nbio)
|
||||
static int cb_image_menu_upload_generic(void *data, size_t len)
|
||||
{
|
||||
nbio_handle_t *nbio = (nbio_handle_t*)data;
|
||||
unsigned r_shift, g_shift, b_shift, a_shift;
|
||||
|
||||
if (!nbio)
|
||||
@ -150,34 +110,6 @@ static int cb_image_menu_upload_generic(nbio_handle_t *nbio)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cb_image_menu_wallpaper_upload(void *data, size_t len)
|
||||
{
|
||||
nbio_handle_t *nbio = (nbio_handle_t*)data;
|
||||
|
||||
if (cb_image_menu_upload_generic(nbio) != 0)
|
||||
return -1;
|
||||
|
||||
menu_driver_load_image(&nbio->image.ti, MENU_IMAGE_WALLPAPER);
|
||||
|
||||
texture_image_free(&nbio->image.ti);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cb_image_menu_boxart_upload(void *data, size_t len)
|
||||
{
|
||||
nbio_handle_t *nbio = (nbio_handle_t*)data;
|
||||
|
||||
if (cb_image_menu_upload_generic(nbio) != 0)
|
||||
return -1;
|
||||
|
||||
menu_driver_load_image(&nbio->image.ti, MENU_IMAGE_BOXART);
|
||||
|
||||
texture_image_free(&nbio->image.ti);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cb_image_menu_generic(nbio_handle_t *nbio)
|
||||
{
|
||||
unsigned width = 0, height = 0;
|
||||
@ -210,7 +142,7 @@ static int cb_image_menu_wallpaper(void *data, size_t len)
|
||||
if (cb_image_menu_generic(nbio) != 0)
|
||||
return -1;
|
||||
|
||||
nbio->image.cb = &cb_image_menu_wallpaper_upload;
|
||||
nbio->image.cb = &cb_image_menu_upload_generic;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -222,31 +154,7 @@ static int cb_image_menu_boxart(void *data, size_t len)
|
||||
if (cb_image_menu_generic(nbio) != 0)
|
||||
return -1;
|
||||
|
||||
nbio->image.cb = &cb_image_menu_boxart_upload;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int rarch_main_data_image_iterate_poll(nbio_handle_t *nbio)
|
||||
{
|
||||
const char *path = NULL;
|
||||
|
||||
if (!nbio)
|
||||
return -1;
|
||||
|
||||
path = msg_queue_pull(nbio->image.msg_queue);
|
||||
|
||||
if (!path)
|
||||
return -1;
|
||||
|
||||
/* Can only deal with one image transfer at a time for now */
|
||||
if (nbio->image.handle)
|
||||
return -1;
|
||||
|
||||
/* We need to load the image file first. */
|
||||
msg_queue_clear(nbio->msg_queue);
|
||||
msg_queue_push(nbio->msg_queue, path, 0, 1);
|
||||
nbio->image.cb = &cb_image_menu_upload_generic;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -301,83 +209,26 @@ static int rarch_main_data_image_iterate_process_transfer(nbio_handle_t *nbio)
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int rarch_main_data_image_iterate_parse_free(nbio_handle_t *nbio)
|
||||
static int rarch_main_data_image_iterate_process_transfer_parse(nbio_handle_t *nbio)
|
||||
{
|
||||
if (!nbio)
|
||||
return -1;
|
||||
|
||||
rpng_nbio_load_image_free(nbio->image.handle);
|
||||
|
||||
nbio->image.handle = NULL;
|
||||
nbio->image.frame_count = 0;
|
||||
|
||||
msg_queue_clear(nbio->image.msg_queue);
|
||||
if (nbio->image.handle && nbio->image.cb)
|
||||
{
|
||||
size_t len = 0;
|
||||
nbio->image.cb(nbio, len);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void rarch_main_data_nbio_image_iterate(bool is_thread)
|
||||
static int rarch_main_data_image_iterate_transfer_parse(nbio_handle_t *nbio)
|
||||
{
|
||||
nbio_handle_t *nbio = (nbio_handle_t*)nbio_ptr;
|
||||
nbio_image_handle_t *image = nbio ? &nbio->image : NULL;
|
||||
|
||||
if (!image || !nbio)
|
||||
return;
|
||||
|
||||
(void)is_thread;
|
||||
|
||||
switch (image->status)
|
||||
if (nbio->image.handle && nbio->image.cb)
|
||||
{
|
||||
case NBIO_IMAGE_STATUS_PROCESS_TRANSFER:
|
||||
if (rarch_main_data_image_iterate_process_transfer(nbio) == -1)
|
||||
image->status = NBIO_IMAGE_STATUS_PROCESS_TRANSFER_PARSE;
|
||||
break;
|
||||
case NBIO_IMAGE_STATUS_TRANSFER_PARSE:
|
||||
if (nbio->image.handle && nbio->image.cb)
|
||||
{
|
||||
size_t len = 0;
|
||||
nbio->image.cb(nbio, len);
|
||||
}
|
||||
if (image->is_blocking_on_processing)
|
||||
image->status = NBIO_IMAGE_STATUS_PROCESS_TRANSFER;
|
||||
break;
|
||||
case NBIO_IMAGE_STATUS_TRANSFER:
|
||||
if (!image->is_blocking)
|
||||
if (rarch_main_data_image_iterate_transfer(nbio) == -1)
|
||||
image->status = NBIO_IMAGE_STATUS_TRANSFER_PARSE;
|
||||
break;
|
||||
default:
|
||||
case NBIO_IMAGE_STATUS_POLL:
|
||||
if (rarch_main_data_image_iterate_poll(nbio) == 0)
|
||||
image->status = NBIO_IMAGE_STATUS_TRANSFER;
|
||||
break;
|
||||
size_t len = 0;
|
||||
nbio->image.cb(nbio, len);
|
||||
}
|
||||
}
|
||||
|
||||
void rarch_main_data_nbio_image_upload_iterate(void)
|
||||
{
|
||||
nbio_handle_t *nbio = (nbio_handle_t*)nbio_ptr;
|
||||
nbio_image_handle_t *image = nbio ? &nbio->image : NULL;
|
||||
|
||||
if (!image || !nbio)
|
||||
return;
|
||||
|
||||
switch (image->status)
|
||||
{
|
||||
case NBIO_IMAGE_STATUS_PROCESS_TRANSFER_PARSE:
|
||||
if (nbio->image.handle && nbio->image.cb)
|
||||
{
|
||||
size_t len = 0;
|
||||
nbio->image.cb(nbio, len);
|
||||
}
|
||||
if (image->is_finished)
|
||||
image->status = NBIO_IMAGE_STATUS_TRANSFER_PARSE_FREE;
|
||||
break;
|
||||
case NBIO_IMAGE_STATUS_TRANSFER_PARSE_FREE:
|
||||
rarch_main_data_image_iterate_parse_free(nbio);
|
||||
image->status = NBIO_IMAGE_STATUS_POLL;
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -462,92 +313,50 @@ static int cb_nbio_image_menu_boxart(void *data, size_t len)
|
||||
|
||||
return cb_nbio_generic(nbio, &len);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static int rarch_main_data_nbio_iterate_poll(nbio_handle_t *nbio)
|
||||
bool rarch_task_push_image_load(const char *fullpath, const char *type, rarch_task_callback_t cb)
|
||||
{
|
||||
char elem0[PATH_MAX_LENGTH];
|
||||
unsigned elem0_hash = 0;
|
||||
rarch_task_t *t;
|
||||
nbio_handle_t *nbio;
|
||||
uint32_t cb_type_hash = 0;
|
||||
struct nbio_t* handle = NULL;
|
||||
struct string_list *str_list = NULL;
|
||||
const char *path = NULL;
|
||||
|
||||
if (!nbio)
|
||||
return -1;
|
||||
|
||||
path = msg_queue_pull(nbio->msg_queue);
|
||||
cb_type_hash = djb2_calculate(type);
|
||||
|
||||
if (!path)
|
||||
return -1;
|
||||
|
||||
/* Can only deal with one NBIO transfer at a time for now */
|
||||
if (nbio->handle)
|
||||
return -1;
|
||||
|
||||
str_list = string_split(path, "|");
|
||||
|
||||
if (!str_list || (str_list->size < 1))
|
||||
goto error;
|
||||
|
||||
strlcpy(elem0, str_list->elems[0].data, sizeof(elem0));
|
||||
elem0_hash = djb2_calculate(elem0);
|
||||
|
||||
/* TODO/FIXME - should be able to deal with this
|
||||
* in a better way. */
|
||||
switch(elem0_hash)
|
||||
{
|
||||
case CB_MENU_WALLPAPER:
|
||||
case CB_MENU_BOXART:
|
||||
goto error;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (str_list->size > 1)
|
||||
cb_type_hash = djb2_calculate(str_list->elems[1].data);
|
||||
|
||||
handle = nbio_open(elem0, NBIO_READ);
|
||||
handle = nbio_open(fullpath, NBIO_READ);
|
||||
|
||||
if (!handle)
|
||||
{
|
||||
RARCH_ERR("Could not create new file loading handle.\n");
|
||||
goto error;
|
||||
return false;
|
||||
}
|
||||
|
||||
nbio->handle = handle;
|
||||
nbio->is_finished = false;
|
||||
nbio->cb = &cb_nbio_default;
|
||||
nbio = (nbio_handle_t*)calloc(1, sizeof(*nbio));
|
||||
nbio->handle = handle;
|
||||
nbio->is_finished = false;
|
||||
nbio->cb = &cb_nbio_default;
|
||||
nbio->status = NBIO_STATUS_TRANSFER;
|
||||
nbio->image.status = NBIO_IMAGE_STATUS_TRANSFER;
|
||||
|
||||
switch (cb_type_hash)
|
||||
{
|
||||
#if defined(HAVE_MENU) && defined(HAVE_RPNG)
|
||||
case CB_MENU_WALLPAPER:
|
||||
nbio->cb = &cb_nbio_image_menu_wallpaper;
|
||||
break;
|
||||
case CB_MENU_BOXART:
|
||||
nbio->cb = &cb_nbio_image_menu_boxart;
|
||||
break;
|
||||
#endif
|
||||
case 0:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (cb_type_hash == CB_MENU_WALLPAPER)
|
||||
nbio->cb = &cb_nbio_image_menu_wallpaper;
|
||||
else if (cb_type_hash == CB_MENU_BOXART)
|
||||
nbio->cb = &cb_nbio_image_menu_boxart;
|
||||
|
||||
nbio_begin_read(handle);
|
||||
|
||||
string_list_free(str_list);
|
||||
t = (rarch_task_t*)calloc(1, sizeof(*t));
|
||||
t->state = nbio;
|
||||
t->handler = rarch_task_file_load_handler;
|
||||
t->callback = cb;
|
||||
|
||||
rarch_task_push(t);
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
if (str_list)
|
||||
string_list_free(str_list);
|
||||
|
||||
return -1;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static int rarch_main_data_nbio_iterate_transfer(nbio_handle_t *nbio)
|
||||
{
|
||||
@ -571,21 +380,6 @@ static int rarch_main_data_nbio_iterate_transfer(nbio_handle_t *nbio)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rarch_main_data_nbio_iterate_parse_free(nbio_handle_t *nbio)
|
||||
{
|
||||
if (!nbio || !nbio->is_finished)
|
||||
return -1;
|
||||
|
||||
nbio_free(nbio->handle);
|
||||
nbio->handle = NULL;
|
||||
nbio->is_finished = false;
|
||||
nbio->frame_count = 0;
|
||||
|
||||
msg_queue_clear(nbio->msg_queue);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rarch_main_data_nbio_iterate_parse(nbio_handle_t *nbio)
|
||||
{
|
||||
if (!nbio)
|
||||
@ -600,11 +394,10 @@ static int rarch_main_data_nbio_iterate_parse(nbio_handle_t *nbio)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void rarch_main_data_nbio_iterate(bool is_thread)
|
||||
static void rarch_task_file_load_handler(rarch_task_t *task)
|
||||
{
|
||||
nbio_handle_t *nbio = (nbio_handle_t*)nbio_ptr;
|
||||
if (!nbio)
|
||||
return;
|
||||
nbio_handle_t *nbio = (nbio_handle_t*)task->state;
|
||||
nbio_image_handle_t *image = nbio ? &nbio->image : NULL;
|
||||
|
||||
switch (nbio->status)
|
||||
{
|
||||
@ -617,37 +410,65 @@ void rarch_main_data_nbio_iterate(bool is_thread)
|
||||
nbio->status = NBIO_STATUS_TRANSFER_PARSE;
|
||||
break;
|
||||
case NBIO_STATUS_TRANSFER_PARSE_FREE:
|
||||
rarch_main_data_nbio_iterate_parse_free(nbio);
|
||||
nbio->status = NBIO_STATUS_POLL;
|
||||
break;
|
||||
case NBIO_STATUS_POLL:
|
||||
default:
|
||||
if (rarch_main_data_nbio_iterate_poll(nbio) == 0)
|
||||
nbio->status = NBIO_STATUS_TRANSFER;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void rarch_main_data_nbio_init_msg_queue(void)
|
||||
{
|
||||
nbio_handle_t *nbio = (nbio_handle_t*)nbio_ptr;
|
||||
if (!nbio)
|
||||
return;
|
||||
if (nbio->image.handle)
|
||||
{
|
||||
switch (image->status)
|
||||
{
|
||||
case NBIO_IMAGE_STATUS_PROCESS_TRANSFER:
|
||||
if (rarch_main_data_image_iterate_process_transfer(nbio) == -1)
|
||||
image->status = NBIO_IMAGE_STATUS_PROCESS_TRANSFER_PARSE;
|
||||
break;
|
||||
case NBIO_IMAGE_STATUS_TRANSFER_PARSE:
|
||||
rarch_main_data_image_iterate_transfer_parse(nbio);
|
||||
if (image->is_blocking_on_processing)
|
||||
image->status = NBIO_IMAGE_STATUS_PROCESS_TRANSFER;
|
||||
break;
|
||||
case NBIO_IMAGE_STATUS_TRANSFER:
|
||||
if (!image->is_blocking)
|
||||
if (rarch_main_data_image_iterate_transfer(nbio) == -1)
|
||||
image->status = NBIO_IMAGE_STATUS_TRANSFER_PARSE;
|
||||
break;
|
||||
case NBIO_IMAGE_STATUS_PROCESS_TRANSFER_PARSE:
|
||||
rarch_main_data_image_iterate_process_transfer_parse(nbio);
|
||||
if (!image->is_finished)
|
||||
break;
|
||||
case NBIO_IMAGE_STATUS_TRANSFER_PARSE_FREE:
|
||||
case NBIO_IMAGE_STATUS_POLL:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (!nbio->msg_queue)
|
||||
retro_assert(nbio->msg_queue = msg_queue_new(8));
|
||||
if (!nbio->image.msg_queue)
|
||||
retro_assert(nbio->image.msg_queue = msg_queue_new(8));
|
||||
}
|
||||
if (nbio->is_finished && nbio->image.is_finished)
|
||||
{
|
||||
task->task_data = malloc(sizeof(nbio->image.ti));
|
||||
memcpy(task->task_data, &nbio->image.ti, sizeof(nbio->image.ti));
|
||||
goto task_finished;
|
||||
}
|
||||
|
||||
void rarch_main_data_nbio_uninit(void)
|
||||
{
|
||||
if (nbio_ptr)
|
||||
free(nbio_ptr);
|
||||
nbio_ptr = NULL;
|
||||
}
|
||||
} else if (nbio->is_finished)
|
||||
goto task_finished;
|
||||
|
||||
void rarch_main_data_nbio_init(void)
|
||||
{
|
||||
nbio_ptr = (nbio_handle_t*)calloc(1, sizeof(*nbio_ptr));
|
||||
return;
|
||||
|
||||
task_finished:
|
||||
task->finished = true;
|
||||
|
||||
if (image->handle)
|
||||
{
|
||||
rpng_nbio_load_image_free(image->handle);
|
||||
|
||||
image->handle = NULL;
|
||||
image->frame_count = 0;
|
||||
}
|
||||
|
||||
nbio_free(nbio->handle);
|
||||
nbio->handle = NULL;
|
||||
nbio->is_finished = false;
|
||||
nbio->frame_count = 0;
|
||||
free(nbio);
|
||||
}
|
||||
|
@ -30,19 +30,6 @@
|
||||
#include "../verbosity.h"
|
||||
#include "tasks.h"
|
||||
|
||||
#define CB_CORE_UPDATER_DOWNLOAD 0x7412da7dU
|
||||
#define CB_CORE_UPDATER_LIST 0x32fd4f01U
|
||||
#define CB_UPDATE_ASSETS 0xbf85795eU
|
||||
#define CB_UPDATE_CORE_INFO_FILES 0xe6084091U
|
||||
#define CB_UPDATE_AUTOCONFIG_PROFILES 0x28ada67dU
|
||||
#define CB_UPDATE_CHEATS 0xc360fec3U
|
||||
#define CB_UPDATE_OVERLAYS 0x699009a0U
|
||||
#define CB_UPDATE_DATABASES 0x931eb8d3U
|
||||
#define CB_UPDATE_SHADERS_GLSL 0x0121a186U
|
||||
#define CB_UPDATE_SHADERS_CG 0xc93a53feU
|
||||
#define CB_CORE_CONTENT_LIST 0xebc51227U
|
||||
#define CB_CORE_CONTENT_DOWNLOAD 0x03b3c0a3U
|
||||
|
||||
extern char core_updater_path[PATH_MAX_LENGTH];
|
||||
|
||||
enum http_status_enum
|
||||
@ -63,175 +50,11 @@ typedef struct http_handle
|
||||
transfer_cb_t cb;
|
||||
char elem1[PATH_MAX_LENGTH];
|
||||
} connection;
|
||||
msg_queue_t *msg_queue;
|
||||
struct http_t *handle;
|
||||
transfer_cb_t cb;
|
||||
unsigned status;
|
||||
} http_handle_t;
|
||||
|
||||
int cb_core_updater_list(void *data_, size_t len);
|
||||
int cb_core_content_list(void *data_, size_t len);
|
||||
|
||||
static http_handle_t *http_ptr;
|
||||
|
||||
#ifdef HAVE_ZLIB
|
||||
#ifdef HAVE_MENU
|
||||
static int zlib_extract_core_callback(const char *name, const char *valid_exts,
|
||||
const uint8_t *cdata, unsigned cmode, uint32_t csize, uint32_t size,
|
||||
uint32_t crc32, void *userdata)
|
||||
{
|
||||
char path[PATH_MAX_LENGTH];
|
||||
|
||||
/* Make directory */
|
||||
fill_pathname_join(path, (const char*)userdata, name, sizeof(path));
|
||||
path_basedir(path);
|
||||
|
||||
if (!path_mkdir(path))
|
||||
goto error;
|
||||
|
||||
/* Ignore directories. */
|
||||
if (name[strlen(name) - 1] == '/' || name[strlen(name) - 1] == '\\')
|
||||
return 1;
|
||||
|
||||
fill_pathname_join(path, (const char*)userdata, name, sizeof(path));
|
||||
|
||||
RARCH_LOG("path is: %s, CRC32: 0x%x\n", path, crc32);
|
||||
|
||||
if (!zlib_perform_mode(path, valid_exts,
|
||||
cdata, cmode, csize, size, crc32, userdata))
|
||||
goto error;
|
||||
|
||||
return 1;
|
||||
|
||||
error:
|
||||
RARCH_ERR("Failed to deflate to: %s.\n", path);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_MENU
|
||||
static int cb_generic_download(void *data, size_t len,
|
||||
const char *dir_path)
|
||||
{
|
||||
char msg[PATH_MAX_LENGTH];
|
||||
char output_path[PATH_MAX_LENGTH];
|
||||
const char *file_ext = NULL;
|
||||
settings_t *settings = config_get_ptr();
|
||||
|
||||
if (!data)
|
||||
return -1;
|
||||
|
||||
fill_pathname_join(output_path, dir_path,
|
||||
core_updater_path, sizeof(output_path));
|
||||
|
||||
if (!retro_write_file(output_path, data, len))
|
||||
return -1;
|
||||
|
||||
snprintf(msg, sizeof(msg), "%s: %s.",
|
||||
msg_hash_to_str(MSG_DOWNLOAD_COMPLETE),
|
||||
core_updater_path);
|
||||
|
||||
rarch_main_msg_queue_push(msg, 1, 90, true);
|
||||
|
||||
#ifdef HAVE_ZLIB
|
||||
file_ext = path_get_extension(output_path);
|
||||
|
||||
if (!settings->network.buildbot_auto_extract_archive)
|
||||
return 0;
|
||||
|
||||
if (!strcasecmp(file_ext,"zip"))
|
||||
{
|
||||
if (!zlib_parse_file(output_path, NULL, zlib_extract_core_callback,
|
||||
(void*)dir_path))
|
||||
RARCH_LOG("%s\n", msg_hash_to_str(MSG_COULD_NOT_PROCESS_ZIP_FILE));
|
||||
|
||||
if (path_file_exists(output_path))
|
||||
remove(output_path);
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cb_core_updater_download(void *data, size_t len)
|
||||
{
|
||||
settings_t *settings = config_get_ptr();
|
||||
int ret = cb_generic_download(data, len, settings->libretro_directory);
|
||||
if (ret == 0)
|
||||
event_command(EVENT_CMD_CORE_INFO_INIT);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int cb_core_content_download(void *data, size_t len)
|
||||
{
|
||||
settings_t *settings = config_get_ptr();
|
||||
return cb_generic_download(data, len, settings->core_assets_directory);
|
||||
}
|
||||
|
||||
static int cb_update_core_info_files(void *data, size_t len)
|
||||
{
|
||||
settings_t *settings = config_get_ptr();
|
||||
return cb_generic_download(data, len, settings->libretro_info_path);
|
||||
}
|
||||
|
||||
static int cb_update_assets(void *data, size_t len)
|
||||
{
|
||||
settings_t *settings = config_get_ptr();
|
||||
return cb_generic_download(data, len, settings->assets_directory);
|
||||
}
|
||||
|
||||
static int cb_update_autoconfig_profiles(void *data, size_t len)
|
||||
{
|
||||
settings_t *settings = config_get_ptr();
|
||||
return cb_generic_download(data, len, settings->input.autoconfig_dir);
|
||||
}
|
||||
|
||||
static int cb_update_shaders_cg(void *data, size_t len)
|
||||
{
|
||||
char shaderdir[PATH_MAX_LENGTH];
|
||||
settings_t *settings = config_get_ptr();
|
||||
fill_pathname_join(shaderdir, settings->video.shader_dir, "shaders_cg",
|
||||
sizeof(shaderdir));
|
||||
if (!path_file_exists(shaderdir))
|
||||
if (!path_mkdir(shaderdir))
|
||||
return -1;
|
||||
|
||||
return cb_generic_download(data, len, shaderdir);
|
||||
}
|
||||
|
||||
static int cb_update_shaders_glsl(void *data, size_t len)
|
||||
{
|
||||
char shaderdir[PATH_MAX_LENGTH];
|
||||
settings_t *settings = config_get_ptr();
|
||||
fill_pathname_join(shaderdir, settings->video.shader_dir, "shaders_glsl",
|
||||
sizeof(shaderdir));
|
||||
if (!path_file_exists(shaderdir))
|
||||
if (!path_mkdir(shaderdir))
|
||||
return -1;
|
||||
|
||||
return cb_generic_download(data, len, shaderdir);
|
||||
}
|
||||
|
||||
static int cb_update_databases(void *data, size_t len)
|
||||
{
|
||||
settings_t *settings = config_get_ptr();
|
||||
return cb_generic_download(data, len, settings->content_database);
|
||||
}
|
||||
|
||||
static int cb_update_overlays(void *data, size_t len)
|
||||
{
|
||||
settings_t *settings = config_get_ptr();
|
||||
return cb_generic_download(data, len, settings->overlay_directory);
|
||||
}
|
||||
|
||||
static int cb_update_cheats(void *data, size_t len)
|
||||
{
|
||||
settings_t *settings = config_get_ptr();
|
||||
return cb_generic_download(data, len, settings->cheat_database);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int rarch_main_data_http_con_iterate_transfer(http_handle_t *http)
|
||||
{
|
||||
if (!net_http_connection_iterate(http->connection.handle))
|
||||
@ -254,23 +77,6 @@ static int rarch_main_data_http_conn_iterate_transfer_parse(http_handle_t *http)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rarch_main_data_http_iterate_transfer_parse(http_handle_t *http)
|
||||
{
|
||||
size_t len = 0;
|
||||
char *data = (char*)net_http_data(http->handle, &len, false);
|
||||
|
||||
if (data && http->cb)
|
||||
http->cb(data, len);
|
||||
|
||||
net_http_delete(http->handle);
|
||||
|
||||
http->handle = NULL;
|
||||
msg_queue_clear(http->msg_queue);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int cb_http_conn_default(void *data_, size_t len)
|
||||
{
|
||||
http_handle_t *http = (http_handle_t*)data_;
|
||||
@ -291,116 +97,9 @@ static int cb_http_conn_default(void *data_, size_t len)
|
||||
|
||||
http->cb = NULL;
|
||||
|
||||
if (http->connection.elem1[0] != '\0')
|
||||
{
|
||||
uint32_t label_hash = msg_hash_calculate(http->connection.elem1);
|
||||
|
||||
switch (label_hash)
|
||||
{
|
||||
#ifdef HAVE_MENU
|
||||
case CB_CORE_UPDATER_DOWNLOAD:
|
||||
http->cb = &cb_core_updater_download;
|
||||
break;
|
||||
case CB_CORE_CONTENT_DOWNLOAD:
|
||||
http->cb = &cb_core_content_download;
|
||||
break;
|
||||
case CB_CORE_UPDATER_LIST:
|
||||
http->cb = &cb_core_updater_list;
|
||||
break;
|
||||
case CB_CORE_CONTENT_LIST:
|
||||
http->cb = &cb_core_content_list;
|
||||
break;
|
||||
case CB_UPDATE_ASSETS:
|
||||
http->cb = &cb_update_assets;
|
||||
break;
|
||||
case CB_UPDATE_CORE_INFO_FILES:
|
||||
http->cb = &cb_update_core_info_files;
|
||||
break;
|
||||
case CB_UPDATE_AUTOCONFIG_PROFILES:
|
||||
http->cb = &cb_update_autoconfig_profiles;
|
||||
break;
|
||||
case CB_UPDATE_CHEATS:
|
||||
http->cb = &cb_update_cheats;
|
||||
break;
|
||||
case CB_UPDATE_DATABASES:
|
||||
http->cb = &cb_update_databases;
|
||||
break;
|
||||
case CB_UPDATE_SHADERS_CG:
|
||||
http->cb = &cb_update_shaders_cg;
|
||||
break;
|
||||
case CB_UPDATE_SHADERS_GLSL:
|
||||
http->cb = &cb_update_shaders_glsl;
|
||||
break;
|
||||
case CB_UPDATE_OVERLAYS:
|
||||
http->cb = &cb_update_overlays;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* rarch_main_data_http_iterate_poll:
|
||||
*
|
||||
* Polls HTTP message queue to see if any new URLs
|
||||
* are pending.
|
||||
*
|
||||
* If handle is freed, will set up a new http handle.
|
||||
* The transfer will be started on the next frame.
|
||||
*
|
||||
* Returns: 0 when an URL has been pulled and we will
|
||||
* begin transferring on the next frame. Returns -1 if
|
||||
* no HTTP URL has been pulled. Do nothing in that case.
|
||||
**/
|
||||
static int rarch_main_data_http_iterate_poll(http_handle_t *http)
|
||||
{
|
||||
char elem0[PATH_MAX_LENGTH];
|
||||
struct string_list *str_list = NULL;
|
||||
const char *url = msg_queue_pull(http->msg_queue);
|
||||
|
||||
if (!url)
|
||||
return -1;
|
||||
|
||||
/* Can only deal with one HTTP transfer at a time for now */
|
||||
if (http->handle)
|
||||
return -1;
|
||||
|
||||
str_list = string_split(url, "|");
|
||||
|
||||
if (!str_list || (str_list->size < 1))
|
||||
goto error;
|
||||
|
||||
strlcpy(elem0, str_list->elems[0].data, sizeof(elem0));
|
||||
|
||||
http->connection.handle = net_http_connection_new(elem0);
|
||||
|
||||
if (!http->connection.handle)
|
||||
return -1;
|
||||
|
||||
http->connection.cb = &cb_http_conn_default;
|
||||
|
||||
|
||||
if (str_list->size > 1)
|
||||
{
|
||||
strlcpy(http->connection.elem1,
|
||||
str_list->elems[1].data,
|
||||
sizeof(http->connection.elem1));
|
||||
}
|
||||
|
||||
string_list_free(str_list);
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
if (str_list)
|
||||
string_list_free(str_list);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* rarch_main_data_http_iterate_transfer:
|
||||
*
|
||||
@ -437,11 +136,10 @@ static int rarch_main_data_http_iterate_transfer(void *data)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void rarch_main_data_http_iterate(bool is_thread)
|
||||
static void rarch_task_http_transfer_handler(rarch_task_t *task)
|
||||
{
|
||||
http_handle_t *http = (http_handle_t*)http_ptr;
|
||||
if (!http)
|
||||
return;
|
||||
http_handle_t *http = (http_handle_t*)task->state;
|
||||
http_transfer_data_t *data;
|
||||
|
||||
switch (http->status)
|
||||
{
|
||||
@ -454,69 +152,69 @@ void rarch_main_data_http_iterate(bool is_thread)
|
||||
http->status = HTTP_STATUS_CONNECTION_TRANSFER_PARSE;
|
||||
break;
|
||||
case HTTP_STATUS_TRANSFER_PARSE:
|
||||
rarch_main_data_http_iterate_transfer_parse(http);
|
||||
http->status = HTTP_STATUS_POLL;
|
||||
goto task_finished;
|
||||
break;
|
||||
case HTTP_STATUS_TRANSFER:
|
||||
if (!rarch_main_data_http_iterate_transfer(http))
|
||||
http->status = HTTP_STATUS_TRANSFER_PARSE;
|
||||
break;
|
||||
case HTTP_STATUS_POLL:
|
||||
goto task_finished;
|
||||
default:
|
||||
if (rarch_main_data_http_iterate_poll(http) == 0)
|
||||
http->status = HTTP_STATUS_CONNECTION_TRANSFER;
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
task_finished:
|
||||
task->finished = true;
|
||||
|
||||
data = (http_transfer_data_t*)calloc(1, sizeof(*data));
|
||||
task->task_data = data;
|
||||
|
||||
if (http->handle)
|
||||
{
|
||||
data->data = (char*)net_http_data(http->handle, &data->len, false);
|
||||
|
||||
if (data->data && http->cb)
|
||||
http->cb(data->data, data->len);
|
||||
|
||||
/* we can't let net_http_delete free our data */
|
||||
net_http_delete(http->handle);
|
||||
}
|
||||
|
||||
free(http);
|
||||
}
|
||||
|
||||
|
||||
void rarch_main_data_http_init_msg_queue(void)
|
||||
bool rarch_task_push_http_transfer(const char *url, const char *type, rarch_task_callback_t cb, void *user_data)
|
||||
{
|
||||
http_handle_t *http = (http_handle_t*)http_ptr;
|
||||
if (!http)
|
||||
return;
|
||||
rarch_task_t *t;
|
||||
http_handle_t *http;
|
||||
struct http_connection_t *conn;
|
||||
|
||||
if (!http->msg_queue)
|
||||
retro_assert(http->msg_queue = msg_queue_new(8));
|
||||
}
|
||||
|
||||
|
||||
msg_queue_t *rarch_main_data_http_get_msg_queue_ptr(void)
|
||||
{
|
||||
http_handle_t *http = (http_handle_t*)http_ptr;
|
||||
if (!http)
|
||||
return NULL;
|
||||
return http->msg_queue;
|
||||
}
|
||||
|
||||
void *rarch_main_data_http_get_handle(void)
|
||||
{
|
||||
http_handle_t *http = (http_handle_t*)http_ptr;
|
||||
if (!http)
|
||||
return NULL;
|
||||
if (http->handle == NULL)
|
||||
return NULL;
|
||||
return http->handle;
|
||||
}
|
||||
|
||||
void *rarch_main_data_http_conn_get_handle(void)
|
||||
{
|
||||
http_handle_t *http = (http_handle_t*)http_ptr;
|
||||
if (!http)
|
||||
return NULL;
|
||||
if (http->connection.handle == NULL)
|
||||
return NULL;
|
||||
return http->connection.handle;
|
||||
}
|
||||
|
||||
void rarch_main_data_http_uninit(void)
|
||||
{
|
||||
if (http_ptr)
|
||||
free(http_ptr);
|
||||
http_ptr = NULL;
|
||||
}
|
||||
|
||||
void rarch_main_data_http_init(void)
|
||||
{
|
||||
http_ptr = (http_handle_t*)calloc(1, sizeof(*http_ptr));
|
||||
if (!url || !*url)
|
||||
return false;
|
||||
|
||||
conn = net_http_connection_new(url);
|
||||
|
||||
if (!conn)
|
||||
return false;
|
||||
|
||||
http = (http_handle_t*)calloc(1, sizeof(*http));
|
||||
http->connection.handle = conn;
|
||||
http->connection.cb = &cb_http_conn_default;
|
||||
|
||||
if (type)
|
||||
strlcpy(http->connection.elem1, type, sizeof(http->connection.elem1));
|
||||
|
||||
http->status = HTTP_STATUS_CONNECTION_TRANSFER;
|
||||
|
||||
t = (rarch_task_t*)calloc(1, sizeof(*t));
|
||||
t->handler = rarch_task_http_transfer_handler;
|
||||
t->state = http;
|
||||
t->callback = cb;
|
||||
t->user_data = user_data;
|
||||
|
||||
rarch_task_push(t);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -13,35 +13,716 @@
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <retro_miscellaneous.h>
|
||||
|
||||
#include <file/file_path.h>
|
||||
#include <file/config_file.h>
|
||||
#include <string/string_list.h>
|
||||
#include <rhash.h>
|
||||
#include "tasks.h"
|
||||
#include "../input/input_overlay.h"
|
||||
|
||||
void rarch_main_data_overlay_iterate(void)
|
||||
#include "../input/input_common.h"
|
||||
#include "../input/input_overlay.h"
|
||||
#include "../configuration.h"
|
||||
#include "../verbosity.h"
|
||||
|
||||
typedef struct {
|
||||
enum overlay_status state;
|
||||
enum overlay_image_transfer_status loading_status;
|
||||
config_file_t *conf;
|
||||
char *overlay_path;
|
||||
unsigned size;
|
||||
unsigned pos;
|
||||
unsigned pos_increment;
|
||||
struct overlay *overlays;
|
||||
struct overlay *active;
|
||||
size_t resolve_pos;
|
||||
|
||||
} overlay_loader_t;
|
||||
|
||||
static void rarch_task_overlay_resolve_iterate(overlay_loader_t *loader);
|
||||
|
||||
static void rarch_task_overlay_image_done(struct overlay *overlay)
|
||||
{
|
||||
while (input_overlay_status() != OVERLAY_STATUS_NONE)
|
||||
{
|
||||
switch (input_overlay_status())
|
||||
{
|
||||
case OVERLAY_STATUS_DEFERRED_LOADING:
|
||||
input_overlay_load_overlays_iterate();
|
||||
break;
|
||||
case OVERLAY_STATUS_DEFERRED_LOAD:
|
||||
input_overlay_load_overlays();
|
||||
break;
|
||||
case OVERLAY_STATUS_DEFERRED_LOADING_RESOLVE:
|
||||
input_overlay_load_overlays_resolve_iterate();
|
||||
break;
|
||||
case OVERLAY_STATUS_DEFERRED_DONE:
|
||||
input_overlay_new_done();
|
||||
break;
|
||||
case OVERLAY_STATUS_DEFERRED_ERROR:
|
||||
input_overlay_free();
|
||||
break;
|
||||
default:
|
||||
case OVERLAY_STATUS_NONE:
|
||||
break;
|
||||
}
|
||||
}
|
||||
overlay->pos = 0;
|
||||
/* Divide iteration steps by half of total descs if size is even,
|
||||
* otherwise default to 8 (arbitrary value for now to speed things up). */
|
||||
overlay->pos_increment = (overlay->size / 2) ? (overlay->size / 2) : 8;
|
||||
}
|
||||
|
||||
static bool rarch_task_overlay_load_texture_image(struct overlay *overlay,
|
||||
struct texture_image *image, const char *path)
|
||||
{
|
||||
if (!image)
|
||||
return false;
|
||||
if (!texture_image_load(image, path)) /* possibly unsafe on XBOX */
|
||||
return false;
|
||||
|
||||
overlay->load_images[overlay->load_images_size++] = *image;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static void rarch_task_overlay_load_desc_image(
|
||||
overlay_loader_t *loader,
|
||||
struct overlay_desc *desc,
|
||||
struct overlay *input_overlay,
|
||||
unsigned ol_idx, unsigned desc_idx)
|
||||
{
|
||||
char overlay_desc_image_key[64] = {0};
|
||||
char image_path[PATH_MAX_LENGTH] = {0};
|
||||
config_file_t *conf = loader->conf;
|
||||
|
||||
snprintf(overlay_desc_image_key, sizeof(overlay_desc_image_key),
|
||||
"overlay%u_desc%u_overlay", ol_idx, desc_idx);
|
||||
|
||||
if (config_get_path(conf, overlay_desc_image_key,
|
||||
image_path, sizeof(image_path)))
|
||||
{
|
||||
char path[PATH_MAX_LENGTH] = {0};
|
||||
fill_pathname_resolve_relative(path, loader->overlay_path,
|
||||
image_path, sizeof(path));
|
||||
|
||||
if (rarch_task_overlay_load_texture_image(input_overlay, &desc->image, path))
|
||||
desc->image_index = input_overlay->load_images_size - 1;
|
||||
}
|
||||
|
||||
input_overlay->pos ++;
|
||||
}
|
||||
|
||||
static bool rarch_task_overlay_load_desc(
|
||||
overlay_loader_t *loader,
|
||||
struct overlay_desc *desc,
|
||||
struct overlay *input_overlay,
|
||||
unsigned ol_idx, unsigned desc_idx,
|
||||
unsigned width, unsigned height,
|
||||
bool normalized, float alpha_mod, float range_mod)
|
||||
{
|
||||
float width_mod, height_mod;
|
||||
uint32_t box_hash, key_hash;
|
||||
bool ret = true;
|
||||
bool by_pixel = false;
|
||||
char overlay_desc_key[64] = {0};
|
||||
char conf_key[64] = {0};
|
||||
char overlay_desc_normalized_key[64] = {0};
|
||||
char overlay[256] = {0};
|
||||
char *save = NULL;
|
||||
char *key = NULL;
|
||||
struct string_list *list = NULL;
|
||||
const char *x = NULL;
|
||||
const char *y = NULL;
|
||||
const char *box = NULL;
|
||||
config_file_t *conf = loader->conf;
|
||||
|
||||
snprintf(overlay_desc_key, sizeof(overlay_desc_key),
|
||||
"overlay%u_desc%u", ol_idx, desc_idx);
|
||||
|
||||
snprintf(overlay_desc_normalized_key, sizeof(overlay_desc_normalized_key),
|
||||
"overlay%u_desc%u_normalized", ol_idx, desc_idx);
|
||||
config_get_bool(conf, overlay_desc_normalized_key, &normalized);
|
||||
|
||||
by_pixel = !normalized;
|
||||
|
||||
if (by_pixel && (width == 0 || height == 0))
|
||||
{
|
||||
RARCH_ERR("[Overlay]: Base overlay is not set and not using normalized coordinates.\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!config_get_array(conf, overlay_desc_key, overlay, sizeof(overlay)))
|
||||
{
|
||||
RARCH_ERR("[Overlay]: Didn't find key: %s.\n", overlay_desc_key);
|
||||
goto error;
|
||||
}
|
||||
|
||||
list = string_split(overlay, ", ");
|
||||
|
||||
if (!list)
|
||||
{
|
||||
RARCH_ERR("[Overlay]: Failed to split overlay desc.\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (list->size < 6)
|
||||
{
|
||||
RARCH_ERR("[Overlay]: Overlay desc is invalid. Requires at least 6 tokens.\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
key = list->elems[0].data;
|
||||
x = list->elems[1].data;
|
||||
y = list->elems[2].data;
|
||||
box = list->elems[3].data;
|
||||
|
||||
box_hash = djb2_calculate(box);
|
||||
key_hash = djb2_calculate(key);
|
||||
|
||||
desc->key_mask = 0;
|
||||
|
||||
switch (key_hash)
|
||||
{
|
||||
case KEY_ANALOG_LEFT:
|
||||
desc->type = OVERLAY_TYPE_ANALOG_LEFT;
|
||||
break;
|
||||
case KEY_ANALOG_RIGHT:
|
||||
desc->type = OVERLAY_TYPE_ANALOG_RIGHT;
|
||||
break;
|
||||
default:
|
||||
if (strstr(key, "retrok_") == key)
|
||||
{
|
||||
desc->type = OVERLAY_TYPE_KEYBOARD;
|
||||
desc->key_mask = input_translate_str_to_rk(key + 7);
|
||||
}
|
||||
else
|
||||
{
|
||||
const char *tmp = NULL;
|
||||
|
||||
desc->type = OVERLAY_TYPE_BUTTONS;
|
||||
for (tmp = strtok_r(key, "|", &save); tmp; tmp = strtok_r(NULL, "|", &save))
|
||||
{
|
||||
if (strcmp(tmp, "nul") != 0)
|
||||
desc->key_mask |= UINT64_C(1) << input_translate_str_to_bind_id(tmp);
|
||||
}
|
||||
|
||||
if (desc->key_mask & (UINT64_C(1) << RARCH_OVERLAY_NEXT))
|
||||
{
|
||||
char overlay_target_key[64] = {0};
|
||||
|
||||
snprintf(overlay_target_key, sizeof(overlay_target_key),
|
||||
"overlay%u_desc%u_next_target", ol_idx, desc_idx);
|
||||
config_get_array(conf, overlay_target_key,
|
||||
desc->next_index_name, sizeof(desc->next_index_name));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
width_mod = 1.0f;
|
||||
height_mod = 1.0f;
|
||||
|
||||
if (by_pixel)
|
||||
{
|
||||
width_mod /= width;
|
||||
height_mod /= height;
|
||||
}
|
||||
|
||||
desc->x = (float)strtod(x, NULL) * width_mod;
|
||||
desc->y = (float)strtod(y, NULL) * height_mod;
|
||||
|
||||
switch (box_hash)
|
||||
{
|
||||
case BOX_RADIAL:
|
||||
desc->hitbox = OVERLAY_HITBOX_RADIAL;
|
||||
break;
|
||||
case BOX_RECT:
|
||||
desc->hitbox = OVERLAY_HITBOX_RECT;
|
||||
break;
|
||||
default:
|
||||
RARCH_ERR("[Overlay]: Hitbox type (%s) is invalid. Use \"radial\" or \"rect\".\n", box);
|
||||
ret = false;
|
||||
goto end;
|
||||
}
|
||||
|
||||
switch (desc->type)
|
||||
{
|
||||
case OVERLAY_TYPE_ANALOG_LEFT:
|
||||
case OVERLAY_TYPE_ANALOG_RIGHT:
|
||||
{
|
||||
char overlay_analog_saturate_key[64] = {0};
|
||||
|
||||
if (desc->hitbox != OVERLAY_HITBOX_RADIAL)
|
||||
{
|
||||
RARCH_ERR("[Overlay]: Analog hitbox type must be \"radial\".\n");
|
||||
ret = false;
|
||||
goto end;
|
||||
}
|
||||
|
||||
snprintf(overlay_analog_saturate_key, sizeof(overlay_analog_saturate_key),
|
||||
"overlay%u_desc%u_saturate_pct", ol_idx, desc_idx);
|
||||
if (!config_get_float(conf, overlay_analog_saturate_key,
|
||||
&desc->analog_saturate_pct))
|
||||
desc->analog_saturate_pct = 1.0f;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
/* OVERLAY_TYPE_BUTTONS - unhandled */
|
||||
/* OVERLAY_TYPE_KEYBOARD - unhandled */
|
||||
break;
|
||||
}
|
||||
|
||||
desc->range_x = (float)strtod(list->elems[4].data, NULL) * width_mod;
|
||||
desc->range_y = (float)strtod(list->elems[5].data, NULL) * height_mod;
|
||||
|
||||
desc->mod_x = desc->x - desc->range_x;
|
||||
desc->mod_w = 2.0f * desc->range_x;
|
||||
desc->mod_y = desc->y - desc->range_y;
|
||||
desc->mod_h = 2.0f * desc->range_y;
|
||||
|
||||
snprintf(conf_key, sizeof(conf_key),
|
||||
"overlay%u_desc%u_alpha_mod", ol_idx, desc_idx);
|
||||
desc->alpha_mod = alpha_mod;
|
||||
config_get_float(conf, conf_key, &desc->alpha_mod);
|
||||
|
||||
snprintf(conf_key, sizeof(conf_key),
|
||||
"overlay%u_desc%u_range_mod", ol_idx, desc_idx);
|
||||
desc->range_mod = range_mod;
|
||||
config_get_float(conf, conf_key, &desc->range_mod);
|
||||
|
||||
snprintf(conf_key, sizeof(conf_key),
|
||||
"overlay%u_desc%u_movable", ol_idx, desc_idx);
|
||||
desc->movable = false;
|
||||
desc->delta_x = 0.0f;
|
||||
desc->delta_y = 0.0f;
|
||||
config_get_bool(conf, conf_key, &desc->movable);
|
||||
|
||||
desc->range_x_mod = desc->range_x;
|
||||
desc->range_y_mod = desc->range_y;
|
||||
|
||||
input_overlay->pos ++;
|
||||
|
||||
end:
|
||||
if (list)
|
||||
string_list_free(list);
|
||||
return ret;
|
||||
|
||||
error:
|
||||
if (list)
|
||||
string_list_free(list);
|
||||
return false;
|
||||
}
|
||||
|
||||
static void rarch_task_overlay_deferred_loading(overlay_loader_t *loader)
|
||||
{
|
||||
size_t i = 0;
|
||||
bool not_done = true;
|
||||
struct overlay *overlay = NULL;
|
||||
|
||||
overlay = &loader->overlays[loader->pos];
|
||||
not_done = loader->pos < loader->size;
|
||||
|
||||
if (!not_done)
|
||||
{
|
||||
loader->state = OVERLAY_STATUS_DEFERRED_LOADING_RESOLVE;
|
||||
return;
|
||||
}
|
||||
|
||||
switch (loader->loading_status)
|
||||
{
|
||||
case OVERLAY_IMAGE_TRANSFER_NONE:
|
||||
case OVERLAY_IMAGE_TRANSFER_BUSY:
|
||||
loader->loading_status = OVERLAY_IMAGE_TRANSFER_DONE;
|
||||
//break;
|
||||
case OVERLAY_IMAGE_TRANSFER_DONE:
|
||||
rarch_task_overlay_image_done(&loader->overlays[loader->pos]);
|
||||
loader->loading_status = OVERLAY_IMAGE_TRANSFER_DESC_IMAGE_ITERATE;
|
||||
loader->overlays[loader->pos].pos = 0;
|
||||
break;
|
||||
case OVERLAY_IMAGE_TRANSFER_DESC_IMAGE_ITERATE:
|
||||
for (i = 0; i < overlay->pos_increment; i++)
|
||||
{
|
||||
if (overlay->pos < overlay->size)
|
||||
{
|
||||
rarch_task_overlay_load_desc_image(loader,
|
||||
&overlay->descs[overlay->pos], overlay,
|
||||
loader->pos, overlay->pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
overlay->pos = 0;
|
||||
loader->loading_status = OVERLAY_IMAGE_TRANSFER_DESC_ITERATE;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case OVERLAY_IMAGE_TRANSFER_DESC_ITERATE:
|
||||
for (i = 0; i < overlay->pos_increment; i++)
|
||||
{
|
||||
if (overlay->pos < overlay->size)
|
||||
{
|
||||
if (!rarch_task_overlay_load_desc(loader,
|
||||
&overlay->descs[overlay->pos], overlay,
|
||||
loader->pos, overlay->pos,
|
||||
overlay->image.width, overlay->image.height,
|
||||
overlay->config.normalized,
|
||||
overlay->config.alpha_mod, overlay->config.range_mod))
|
||||
{
|
||||
RARCH_ERR("[Overlay]: Failed to load overlay descs for overlay #%u.\n",
|
||||
(unsigned)overlay->pos);
|
||||
goto error;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
overlay->pos = 0;
|
||||
loader->loading_status = OVERLAY_IMAGE_TRANSFER_DESC_DONE;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case OVERLAY_IMAGE_TRANSFER_DESC_DONE:
|
||||
if (loader->pos == 0)
|
||||
rarch_task_overlay_resolve_iterate(loader);
|
||||
|
||||
loader->pos += 1;
|
||||
loader->loading_status = OVERLAY_IMAGE_TRANSFER_NONE;
|
||||
break;
|
||||
case OVERLAY_IMAGE_TRANSFER_ERROR:
|
||||
goto error;
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
error:
|
||||
loader->state = OVERLAY_STATUS_DEFERRED_ERROR;
|
||||
}
|
||||
|
||||
static void rarch_task_overlay_deferred_load(overlay_loader_t *loader)
|
||||
{
|
||||
unsigned i;
|
||||
config_file_t *conf = loader->conf;
|
||||
|
||||
for (i = 0; i < loader->pos_increment; i++, loader->pos++)
|
||||
{
|
||||
char conf_key[64] = {0};
|
||||
char overlay_full_screen_key[64] = {0};
|
||||
struct overlay *overlay = NULL;
|
||||
bool to_cont = loader->pos < loader->size;
|
||||
|
||||
if (!to_cont)
|
||||
{
|
||||
loader->pos = 0;
|
||||
loader->state = OVERLAY_STATUS_DEFERRED_LOADING;
|
||||
break;
|
||||
}
|
||||
|
||||
overlay = &loader->overlays[loader->pos];
|
||||
|
||||
if (!overlay)
|
||||
continue;
|
||||
|
||||
snprintf(overlay->config.descs.key,
|
||||
sizeof(overlay->config.descs.key), "overlay%u_descs", loader->pos);
|
||||
|
||||
if (!config_get_uint(conf, overlay->config.descs.key, &overlay->config.descs.size))
|
||||
{
|
||||
RARCH_ERR("[Overlay]: Failed to read number of descs from config key: %s.\n",
|
||||
overlay->config.descs.key);
|
||||
goto error;
|
||||
}
|
||||
|
||||
overlay->descs = (struct overlay_desc*)
|
||||
calloc(overlay->config.descs.size, sizeof(*overlay->descs));
|
||||
|
||||
if (!overlay->descs)
|
||||
{
|
||||
RARCH_ERR("[Overlay]: Failed to allocate descs.\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
overlay->size = overlay->config.descs.size;
|
||||
|
||||
snprintf(overlay_full_screen_key, sizeof(overlay_full_screen_key),
|
||||
"overlay%u_full_screen", loader->pos);
|
||||
overlay->full_screen = false;
|
||||
config_get_bool(conf, overlay_full_screen_key, &overlay->full_screen);
|
||||
|
||||
overlay->config.normalized = false;
|
||||
overlay->config.alpha_mod = 1.0f;
|
||||
overlay->config.range_mod = 1.0f;
|
||||
|
||||
snprintf(conf_key, sizeof(conf_key),
|
||||
"overlay%u_normalized", loader->pos);
|
||||
config_get_bool(conf, conf_key, &overlay->config.normalized);
|
||||
|
||||
snprintf(conf_key, sizeof(conf_key), "overlay%u_alpha_mod", loader->pos);
|
||||
config_get_float(conf, conf_key, &overlay->config.alpha_mod);
|
||||
|
||||
snprintf(conf_key, sizeof(conf_key), "overlay%u_range_mod", loader->pos);
|
||||
config_get_float(conf, conf_key, &overlay->config.range_mod);
|
||||
|
||||
/* Precache load image array for simplicity. */
|
||||
overlay->load_images = (struct texture_image*)
|
||||
calloc(1 + overlay->size, sizeof(struct texture_image));
|
||||
|
||||
if (!overlay->load_images)
|
||||
{
|
||||
RARCH_ERR("[Overlay]: Failed to allocate load_images.\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
snprintf(overlay->config.paths.key, sizeof(overlay->config.paths.key),
|
||||
"overlay%u_overlay", loader->pos);
|
||||
|
||||
config_get_path(conf, overlay->config.paths.key,
|
||||
overlay->config.paths.path, sizeof(overlay->config.paths.path));
|
||||
|
||||
if (overlay->config.paths.path[0] != '\0')
|
||||
{
|
||||
char overlay_resolved_path[PATH_MAX_LENGTH] = {0};
|
||||
|
||||
fill_pathname_resolve_relative(overlay_resolved_path, loader->overlay_path,
|
||||
overlay->config.paths.path, sizeof(overlay_resolved_path));
|
||||
|
||||
if (!rarch_task_overlay_load_texture_image(overlay, &overlay->image, overlay_resolved_path))
|
||||
{
|
||||
RARCH_ERR("[Overlay]: Failed to load image: %s.\n",
|
||||
overlay_resolved_path);
|
||||
loader->loading_status = OVERLAY_IMAGE_TRANSFER_ERROR;
|
||||
goto error;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
snprintf(overlay->config.names.key, sizeof(overlay->config.names.key),
|
||||
"overlay%u_name", loader->pos);
|
||||
config_get_array(conf, overlay->config.names.key,
|
||||
overlay->name, sizeof(overlay->name));
|
||||
|
||||
/* By default, we stretch the overlay out in full. */
|
||||
overlay->x = overlay->y = 0.0f;
|
||||
overlay->w = overlay->h = 1.0f;
|
||||
|
||||
snprintf(overlay->config.rect.key, sizeof(overlay->config.rect.key),
|
||||
"overlay%u_rect", loader->pos);
|
||||
|
||||
if (config_get_array(conf, overlay->config.rect.key,
|
||||
overlay->config.rect.array, sizeof(overlay->config.rect.array)))
|
||||
{
|
||||
struct string_list *list = string_split(overlay->config.rect.array, ", ");
|
||||
|
||||
if (!list || list->size < 4)
|
||||
{
|
||||
RARCH_ERR("[Overlay]: Failed to split rect \"%s\" into at least four tokens.\n",
|
||||
overlay->config.rect.array);
|
||||
string_list_free(list);
|
||||
goto error;
|
||||
}
|
||||
|
||||
overlay->x = (float)strtod(list->elems[0].data, NULL);
|
||||
overlay->y = (float)strtod(list->elems[1].data, NULL);
|
||||
overlay->w = (float)strtod(list->elems[2].data, NULL);
|
||||
overlay->h = (float)strtod(list->elems[3].data, NULL);
|
||||
string_list_free(list);
|
||||
}
|
||||
|
||||
/* Assume for now that scaling center is in the middle.
|
||||
* TODO: Make this configurable. */
|
||||
overlay->block_scale = false;
|
||||
overlay->center_x = overlay->x + 0.5f * overlay->w;
|
||||
overlay->center_y = overlay->y + 0.5f * overlay->h;
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
error:
|
||||
loader->pos = 0;
|
||||
loader->state = OVERLAY_STATUS_DEFERRED_ERROR;
|
||||
}
|
||||
|
||||
static ssize_t rarch_task_overlay_find_index(const struct overlay *ol,
|
||||
const char *name, size_t size)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (!ol)
|
||||
return -1;
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
if (!strcmp(ol[i].name, name))
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static bool rarch_task_overlay_resolve_targets(struct overlay *ol,
|
||||
size_t idx, size_t size)
|
||||
{
|
||||
size_t i;
|
||||
struct overlay *current = NULL;
|
||||
|
||||
current = (struct overlay*)&ol[idx];
|
||||
|
||||
for (i = 0; i < current->size; i++)
|
||||
{
|
||||
const char *next = current->descs[i].next_index_name;
|
||||
|
||||
if (*next)
|
||||
{
|
||||
ssize_t next_idx = rarch_task_overlay_find_index(ol, next, size);
|
||||
|
||||
if (next_idx < 0)
|
||||
{
|
||||
RARCH_ERR("[Overlay]: Couldn't find overlay called: \"%s\".\n",
|
||||
next);
|
||||
return false;
|
||||
}
|
||||
|
||||
current->descs[i].next_index = next_idx;
|
||||
}
|
||||
else
|
||||
current->descs[i].next_index = (idx + 1) % size;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void rarch_task_overlay_resolve_iterate(overlay_loader_t *loader)
|
||||
{
|
||||
bool not_done = true;
|
||||
|
||||
not_done = loader->resolve_pos < loader->size;
|
||||
|
||||
if (!not_done)
|
||||
{
|
||||
loader->state = OVERLAY_STATUS_DEFERRED_DONE;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!rarch_task_overlay_resolve_targets(loader->overlays, loader->resolve_pos, loader->size))
|
||||
{
|
||||
RARCH_ERR("[Overlay]: Failed to resolve next targets.\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (loader->resolve_pos == 0)
|
||||
{
|
||||
loader->active = &loader->overlays[0];
|
||||
|
||||
/* TODO: MOVE TO MAIN THREAD / CALLBACK */
|
||||
// input_overlay_load_active(loader->deferred.opacity);
|
||||
// input_overlay_enable(loader->deferred.enable);
|
||||
}
|
||||
|
||||
loader->resolve_pos += 1;
|
||||
|
||||
return;
|
||||
error:
|
||||
loader->state = OVERLAY_STATUS_DEFERRED_ERROR;
|
||||
}
|
||||
|
||||
static void rarch_task_overlay_handler(rarch_task_t *task)
|
||||
{
|
||||
overlay_loader_t *loader = (overlay_loader_t*)task->state;
|
||||
overlay_task_data_t *data;
|
||||
|
||||
switch (loader->state)
|
||||
{
|
||||
case OVERLAY_STATUS_DEFERRED_LOADING:
|
||||
rarch_task_overlay_deferred_loading(loader);
|
||||
break;
|
||||
case OVERLAY_STATUS_DEFERRED_LOAD:
|
||||
rarch_task_overlay_deferred_load(loader);
|
||||
break;
|
||||
case OVERLAY_STATUS_DEFERRED_LOADING_RESOLVE:
|
||||
rarch_task_overlay_resolve_iterate(loader);
|
||||
break;
|
||||
case OVERLAY_STATUS_DEFERRED_DONE:
|
||||
// input_overlay_new_done();
|
||||
// break;
|
||||
case OVERLAY_STATUS_DEFERRED_ERROR:
|
||||
// input_overlay_free();
|
||||
// break;
|
||||
|
||||
default:
|
||||
case OVERLAY_STATUS_NONE:
|
||||
goto task_finished;
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
task_finished:
|
||||
task->finished = true;
|
||||
|
||||
data = (overlay_task_data_t*)calloc(1, sizeof(*data));
|
||||
|
||||
data->overlays = loader->overlays;
|
||||
data->size = loader->size;
|
||||
data->active = loader->active;
|
||||
|
||||
task->task_data = data;
|
||||
|
||||
if (loader->overlay_path)
|
||||
free(loader->overlay_path);
|
||||
|
||||
if (loader->conf)
|
||||
config_file_free(loader->conf);
|
||||
|
||||
free(loader);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static bool rarch_task_push_overlay_load(const char *overlay_path,
|
||||
rarch_task_callback_t cb, void *user_data)
|
||||
{
|
||||
rarch_task_t *t;
|
||||
overlay_loader_t *loader = (overlay_loader_t*)calloc(1, sizeof(*loader));
|
||||
config_file_t *conf = config_file_new(overlay_path);
|
||||
|
||||
if (!conf || !loader)
|
||||
goto error;
|
||||
|
||||
if (!config_get_uint(conf, "overlays", &loader->size))
|
||||
{
|
||||
RARCH_ERR("overlays variable not defined in config.\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
loader->overlays = (struct overlay*)calloc(loader->size, sizeof(*loader->overlays));
|
||||
if (!loader->overlays)
|
||||
goto error;
|
||||
|
||||
loader->overlay_path = strdup(overlay_path);
|
||||
loader->conf = conf;
|
||||
loader->state = OVERLAY_STATUS_DEFERRED_LOAD;
|
||||
loader->pos_increment = (loader->size / 4) ? (loader->size / 4) : 4;
|
||||
|
||||
t = (rarch_task_t*)calloc(1, sizeof(*t));
|
||||
t->handler = rarch_task_overlay_handler;
|
||||
t->state = loader;
|
||||
t->callback = cb;
|
||||
t->user_data = user_data;
|
||||
|
||||
rarch_task_push(t);
|
||||
|
||||
return true;
|
||||
error:
|
||||
if (conf)
|
||||
config_file_free(conf);
|
||||
|
||||
if (loader)
|
||||
{
|
||||
if (loader->overlays)
|
||||
free(loader->overlays);
|
||||
free(loader);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool rarch_task_push_overlay_load_default(
|
||||
rarch_task_callback_t cb, void *user_data)
|
||||
{
|
||||
driver_t *driver = driver_get_ptr();
|
||||
settings_t *settings = config_get_ptr();
|
||||
|
||||
if (driver->osk_enable)
|
||||
{
|
||||
if (!*settings->osk.overlay)
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!*settings->input.overlay)
|
||||
return false;
|
||||
}
|
||||
|
||||
return rarch_task_push_overlay_load(
|
||||
driver->osk_enable ? settings->osk.overlay : settings->input.overlay,
|
||||
cb, user_data);
|
||||
}
|
||||
|
288
tasks/tasks.c
Normal file
288
tasks/tasks.c
Normal file
@ -0,0 +1,288 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../general.h"
|
||||
#include "../verbosity.h"
|
||||
#include "tasks.h"
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
#include "rthreads/rthreads.h"
|
||||
#endif
|
||||
|
||||
static rarch_task_t *running_queue = NULL;
|
||||
static rarch_task_t *finished_queue = NULL;
|
||||
static bool thread_enabled = false;
|
||||
|
||||
struct rarch_task_impl {
|
||||
void (*push_running)(rarch_task_t *);
|
||||
void (*push_finished)(rarch_task_t *);
|
||||
void (*gather)(void);
|
||||
void (*init)(void);
|
||||
void (*deinit)(void);
|
||||
};
|
||||
|
||||
static struct rarch_task_impl *impl_current = NULL;
|
||||
|
||||
static void _push_task(rarch_task_t **q, rarch_task_t *task)
|
||||
{
|
||||
if (*q == NULL)
|
||||
*q = task;
|
||||
else
|
||||
{
|
||||
rarch_task_t *last = *q;
|
||||
while (last->next)
|
||||
last = last->next;
|
||||
|
||||
last->next = task;
|
||||
}
|
||||
|
||||
task->next = NULL;
|
||||
}
|
||||
|
||||
static rarch_task_t *_pop_task(rarch_task_t **q)
|
||||
{
|
||||
rarch_task_t *task = *q;
|
||||
|
||||
if (*q == NULL)
|
||||
return NULL;
|
||||
|
||||
*q = task->next;
|
||||
task->next = NULL;
|
||||
|
||||
return task;
|
||||
}
|
||||
|
||||
static void rarch_task_internal_gather(void)
|
||||
{
|
||||
rarch_task_t *next = NULL;
|
||||
while ((next = _pop_task(&finished_queue)) != NULL)
|
||||
{
|
||||
rarch_task_t *task = next;
|
||||
next = next->next;
|
||||
|
||||
if (task->callback)
|
||||
task->callback(task->task_data, task->user_data, task->error);
|
||||
|
||||
if (task->error)
|
||||
free(task->error);
|
||||
|
||||
free(task);
|
||||
}
|
||||
}
|
||||
|
||||
static void regular_push_finished(rarch_task_t *task)
|
||||
{
|
||||
_push_task(&finished_queue, task);
|
||||
}
|
||||
|
||||
static void regular_push_running(rarch_task_t *task)
|
||||
{
|
||||
_push_task(&running_queue, task);
|
||||
}
|
||||
|
||||
static void regular_gather(void)
|
||||
{
|
||||
rarch_task_t *task = NULL;
|
||||
rarch_task_t *queue = NULL;
|
||||
rarch_task_t *next = NULL;
|
||||
|
||||
/* mimics threaded_gather() for compatibility, a faster implementation
|
||||
* can be written for systems without HAVE_THREADS if necessary. */
|
||||
while ((task = _pop_task(&running_queue)) != NULL)
|
||||
{
|
||||
task->next = queue;
|
||||
queue = task;
|
||||
}
|
||||
|
||||
for (task = queue; task; task = next)
|
||||
{
|
||||
next = task->next;
|
||||
task->handler(task);
|
||||
|
||||
if (task->finished)
|
||||
regular_push_finished(task);
|
||||
else
|
||||
regular_push_running(task);
|
||||
}
|
||||
|
||||
rarch_task_internal_gather();
|
||||
}
|
||||
|
||||
static void regular_init(void)
|
||||
{
|
||||
}
|
||||
|
||||
static void regular_deinit(void)
|
||||
{
|
||||
}
|
||||
|
||||
static struct rarch_task_impl impl_regular = {
|
||||
regular_push_running,
|
||||
regular_push_finished,
|
||||
regular_gather,
|
||||
regular_init,
|
||||
regular_deinit
|
||||
};
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
static slock_t *running_lock = NULL;
|
||||
static slock_t *finished_lock = NULL;
|
||||
static scond_t *worker_cond = NULL;
|
||||
static sthread_t *worker_thread = NULL;
|
||||
static bool worker_continue = true; /* use running_lock when touching it */
|
||||
|
||||
static void threaded_push_finished(rarch_task_t *task)
|
||||
{
|
||||
slock_lock(finished_lock);
|
||||
_push_task(&finished_queue, task);
|
||||
slock_unlock(finished_lock);
|
||||
}
|
||||
|
||||
static void threaded_push_running(rarch_task_t *task)
|
||||
{
|
||||
slock_lock(running_lock);
|
||||
_push_task(&running_queue, task);
|
||||
scond_signal(worker_cond);
|
||||
slock_unlock(running_lock);
|
||||
}
|
||||
|
||||
static void threaded_gather(void)
|
||||
{
|
||||
slock_lock(finished_lock);
|
||||
rarch_task_internal_gather();
|
||||
slock_unlock(finished_lock);
|
||||
}
|
||||
|
||||
static void threaded_worker(void *userdata)
|
||||
{
|
||||
(void)userdata;
|
||||
|
||||
RARCH_LOG("Threaded rarch_task started\n");
|
||||
|
||||
for (;;)
|
||||
{
|
||||
rarch_task_t *queue = NULL;
|
||||
rarch_task_t *task = NULL;
|
||||
rarch_task_t *next = NULL;
|
||||
|
||||
/* pop all into a local queue to avoid trouble with rarch_task_push(),
|
||||
* tasks are in the reverse order here. */
|
||||
slock_lock(running_lock);
|
||||
|
||||
if (!worker_continue)
|
||||
break; /* should we keep running until all tasks finished? */
|
||||
|
||||
while ((task = _pop_task(&running_queue)) != NULL)
|
||||
{
|
||||
task->next = queue;
|
||||
queue = task;
|
||||
}
|
||||
|
||||
if (queue == NULL) /* no tasks running, lets wait a bit */
|
||||
{
|
||||
scond_wait(worker_cond, running_lock);
|
||||
slock_unlock(running_lock);
|
||||
continue;
|
||||
}
|
||||
|
||||
slock_unlock(running_lock);
|
||||
|
||||
for (task = queue; task; task = next)
|
||||
{
|
||||
next = task->next;
|
||||
task->handler(task);
|
||||
|
||||
if (task->finished)
|
||||
threaded_push_finished(task);
|
||||
else
|
||||
threaded_push_running(task);
|
||||
}
|
||||
}
|
||||
|
||||
slock_unlock(running_lock);
|
||||
}
|
||||
|
||||
static void threaded_init(void)
|
||||
{
|
||||
running_lock = slock_new();
|
||||
finished_lock = slock_new();
|
||||
worker_cond = scond_new();
|
||||
|
||||
slock_lock(running_lock);
|
||||
worker_continue = true;
|
||||
slock_unlock(running_lock);
|
||||
|
||||
worker_thread = sthread_create(threaded_worker, NULL);
|
||||
}
|
||||
|
||||
static void threaded_deinit(void)
|
||||
{
|
||||
slock_lock(running_lock);
|
||||
worker_continue = false;
|
||||
scond_signal(worker_cond);
|
||||
slock_unlock(running_lock);
|
||||
|
||||
sthread_join(worker_thread);
|
||||
|
||||
scond_free(worker_cond);
|
||||
slock_free(running_lock);
|
||||
slock_free(finished_lock);
|
||||
|
||||
worker_thread = NULL;
|
||||
worker_cond = NULL;
|
||||
running_lock = NULL;
|
||||
finished_lock = NULL;
|
||||
}
|
||||
|
||||
static struct rarch_task_impl impl_threaded = {
|
||||
threaded_push_running,
|
||||
threaded_push_finished,
|
||||
threaded_gather,
|
||||
threaded_init,
|
||||
threaded_deinit
|
||||
};
|
||||
#endif
|
||||
|
||||
void rarch_task_init(void)
|
||||
{
|
||||
#ifdef HAVE_THREADS
|
||||
if (config_get_ptr()->threaded_data_runloop_enable)
|
||||
impl_current = &impl_threaded;
|
||||
else
|
||||
#endif
|
||||
impl_current = &impl_regular;
|
||||
|
||||
impl_current->init();
|
||||
}
|
||||
|
||||
void rarch_task_deinit(void)
|
||||
{
|
||||
if (!impl_current)
|
||||
return;
|
||||
|
||||
impl_current->deinit();
|
||||
impl_current = NULL;
|
||||
}
|
||||
|
||||
void rarch_task_check(void)
|
||||
{
|
||||
#ifdef HAVE_THREADS
|
||||
bool current_threaded = impl_current == &impl_threaded;
|
||||
bool want_threaded = config_get_ptr()->threaded_data_runloop_enable;
|
||||
|
||||
if (want_threaded != current_threaded) {
|
||||
RARCH_LOG("Switching rarch_task implementation.\n");
|
||||
rarch_task_deinit();
|
||||
}
|
||||
|
||||
if (impl_current == NULL)
|
||||
rarch_task_init();
|
||||
#endif
|
||||
|
||||
impl_current->gather();
|
||||
}
|
||||
|
||||
void rarch_task_push(rarch_task_t *task)
|
||||
{
|
||||
impl_current->push_running(task);
|
||||
}
|
@ -29,71 +29,62 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void rarch_main_data_nbio_uninit(void);
|
||||
typedef struct rarch_task rarch_task_t;
|
||||
typedef void (*rarch_task_callback_t)(void *task_data, void *user_data, const char *error);
|
||||
typedef void (*rarch_task_handler_t)(rarch_task_t *task);
|
||||
|
||||
void rarch_main_data_nbio_init(void);
|
||||
struct rarch_task {
|
||||
rarch_task_handler_t handler;
|
||||
rarch_task_callback_t callback; /* always called from the main loop */
|
||||
|
||||
void rarch_main_data_nbio_init_msg_queue(void);
|
||||
/* set by the handler */
|
||||
bool finished;
|
||||
|
||||
msg_queue_t *rarch_main_data_nbio_get_msg_queue_ptr(void);
|
||||
/* created by the handler, destroyed by the user */
|
||||
void *task_data;
|
||||
|
||||
msg_queue_t *rarch_main_data_nbio_image_get_msg_queue_ptr(void);
|
||||
/* owned by the user */
|
||||
void *user_data;
|
||||
|
||||
void *rarch_main_data_nbio_get_handle(void);
|
||||
/* created and destroyed by the code related to the handler */
|
||||
void *state;
|
||||
|
||||
void *rarch_main_data_nbio_image_get_handle(void);
|
||||
/* created by task handler; destroyed by main loop (after calling the callback) */
|
||||
char *error;
|
||||
|
||||
/* don't touch this. */
|
||||
rarch_task_t *next;
|
||||
};
|
||||
|
||||
/* MAIN THREAD ONLY */
|
||||
void rarch_task_init(void);
|
||||
void rarch_task_deinit(void);
|
||||
void rarch_task_check(void);
|
||||
|
||||
/* MAIN AND TASK THREADS */
|
||||
void rarch_task_push(rarch_task_t *task);
|
||||
|
||||
#ifdef HAVE_NETWORKING
|
||||
/**
|
||||
* rarch_main_data_http_iterate_transfer:
|
||||
*
|
||||
* Resumes HTTP transfer update.
|
||||
*
|
||||
* Returns: 0 when finished, -1 when we should continue
|
||||
* with the transfer on the next frame.
|
||||
**/
|
||||
void rarch_main_data_http_iterate(bool is_thread);
|
||||
typedef struct {
|
||||
char *data;
|
||||
size_t len;
|
||||
} http_transfer_data_t;
|
||||
|
||||
msg_queue_t *rarch_main_data_http_get_msg_queue_ptr(void);
|
||||
|
||||
void rarch_main_data_http_init_msg_queue(void);
|
||||
|
||||
void *rarch_main_data_http_get_handle(void);
|
||||
|
||||
void *rarch_main_data_http_conn_get_handle(void);
|
||||
|
||||
void rarch_main_data_http_uninit(void);
|
||||
|
||||
void rarch_main_data_http_init(void);
|
||||
bool rarch_task_push_http_transfer(const char *url, const char *type, rarch_task_callback_t cb, void *user_data);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_RPNG
|
||||
void rarch_main_data_nbio_image_iterate(bool is_thread);
|
||||
void rarch_main_data_nbio_image_upload_iterate(void);
|
||||
bool rarch_task_push_image_load(const char *fullpath, const char *type, rarch_task_callback_t cb);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LIBRETRODB
|
||||
void rarch_main_data_db_iterate(bool is_thread);
|
||||
#ifdef HAVE_MENU
|
||||
bool rarch_main_data_db_pending_scan_finished(void);
|
||||
#endif
|
||||
|
||||
void rarch_main_data_db_init_msg_queue(void);
|
||||
|
||||
msg_queue_t *rarch_main_data_db_get_msg_queue_ptr(void);
|
||||
|
||||
void rarch_main_data_db_uninit(void);
|
||||
|
||||
void rarch_main_data_db_init(void);
|
||||
|
||||
bool rarch_main_data_db_is_active(void);
|
||||
bool rarch_task_push_dbscan(const char *fullpath, bool directory, rarch_task_callback_t cb);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_OVERLAY
|
||||
void rarch_main_data_overlay_iterate(void);
|
||||
bool rarch_task_push_overlay_load_default(
|
||||
rarch_task_callback_t cb, void *user_data);
|
||||
#endif
|
||||
|
||||
void rarch_main_data_nbio_iterate(bool is_thread);
|
||||
|
||||
void data_runloop_osd_msg(const char *s, size_t len);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user