Cleanup input_overlay.c

This commit is contained in:
twinaphex 2015-07-11 08:07:14 +02:00
parent 70b423cc3e
commit 1b163e6a5a
4 changed files with 159 additions and 137 deletions

View File

@ -37,6 +37,124 @@
#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;
struct overlay *overlays;
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;
};
static input_overlay_t *overlay_ptr;
static input_overlay_state_t *overlay_state_ptr;
static config_file_t *overlay_conf;
@ -1252,3 +1370,17 @@ void input_overlay_set_alpha_mod(input_overlay_t *ol, float mod)
for (i = 0; i < ol->active->load_images_size; i++)
ol->iface->set_alpha(ol->iface_data, i, mod);
}
bool input_overlay_is_alive(input_overlay_t *ol)
{
if (!ol)
return false;
return ol->state == OVERLAY_STATUS_ALIVE;
}
enum overlay_status input_overlay_status(input_overlay_t *ol)
{
if (!ol)
return OVERLAY_STATUS_NONE;
return ol->state;
}

View File

@ -19,9 +19,11 @@
#include <stdint.h>
#include <boolean.h>
#include "../libretro.h"
#include <formats/image.h>
#include <retro_miscellaneous.h>
#include <formats/image.h>
#include "../libretro.h"
#ifdef __cplusplus
extern "C" {
@ -92,123 +94,7 @@ enum overlay_image_transfer_status
OVERLAY_IMAGE_TRANSFER_ERROR
};
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 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 input_overlay
{
void *iface_data;
const video_overlay_interface_t *iface;
bool enable;
enum overlay_image_transfer_status loading_status;
bool blocked;
struct overlay *overlays;
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 overlay_desc overlay_desc_t;
typedef struct input_overlay input_overlay_t;
@ -345,6 +231,10 @@ void input_overlay_free_ptr(void);
int input_overlay_new_ptr(void);
bool input_overlay_is_alive(input_overlay_t *ol);
enum overlay_status input_overlay_status(input_overlay_t *ol);
#ifdef __cplusplus
}
#endif

View File

@ -239,12 +239,12 @@ static int16_t input_state(unsigned port, unsigned device,
#ifdef HAVE_OVERLAY
/*
* input_poll_overlay:
* @overlay_device : pointer to overlay
* @ol : pointer to overlay
*
* Poll pressed buttons/keys on currently active overlay.
**/
static INLINE void input_poll_overlay(
input_overlay_t *overlay_device, float opacity)
input_overlay_t *ol, float opacity)
{
input_overlay_state_t old_key_state;
unsigned i, j, device;
@ -253,14 +253,14 @@ static INLINE void input_poll_overlay(
settings_t *settings = config_get_ptr();
input_overlay_state_t *ol_state = input_overlay_get_state_ptr();
if (overlay_device->state != OVERLAY_STATUS_ALIVE || !ol_state)
if (!input_overlay_is_alive(ol) || !ol_state)
return;
memcpy(old_key_state.keys, ol_state->keys,
sizeof(ol_state->keys));
memset(ol_state, 0, sizeof(*ol_state));
device = input_overlay_full_screen(overlay_device) ?
device = input_overlay_full_screen(ol) ?
RARCH_DEVICE_POINTER_SCREEN : RETRO_DEVICE_POINTER;
for (i = 0;
@ -274,7 +274,7 @@ static INLINE void input_poll_overlay(
int16_t y = input_driver_state(NULL, 0,
device, i, RETRO_DEVICE_ID_POINTER_Y);
input_overlay_poll(overlay_device, &polled_data, x, y);
input_overlay_poll(ol, &polled_data, x, y);
ol_state->buttons |= polled_data.buttons;
@ -368,9 +368,9 @@ static INLINE void input_poll_overlay(
}
if (polled)
input_overlay_post_poll(overlay_device, opacity);
input_overlay_post_poll(ol, opacity);
else
input_overlay_poll_clear(overlay_device, opacity);
input_overlay_poll_clear(ol, opacity);
}
#endif

View File

@ -27,8 +27,8 @@ static slock_t *overlay_lock;
void rarch_main_data_overlay_image_upload_iterate(bool is_thread)
{
input_overlay_t *overlay = input_overlay_get_ptr();
if (!overlay)
input_overlay_t *ol = input_overlay_get_ptr();
if (!ol)
return;
#ifdef HAVE_THREADS
@ -36,10 +36,10 @@ void rarch_main_data_overlay_image_upload_iterate(bool is_thread)
slock_lock(overlay_lock);
#endif
switch (overlay->state)
switch (input_overlay_status(ol))
{
case OVERLAY_STATUS_DEFERRED_LOADING:
input_overlay_load_overlays_iterate(overlay);
input_overlay_load_overlays_iterate(ol);
break;
default:
break;
@ -53,32 +53,32 @@ void rarch_main_data_overlay_image_upload_iterate(bool is_thread)
void rarch_main_data_overlay_iterate(bool is_thread)
{
input_overlay_t *overlay = input_overlay_get_ptr();
input_overlay_t *ol = input_overlay_get_ptr();
#ifdef HAVE_THREADS
if (is_thread)
slock_lock(overlay_lock);
#endif
if (!overlay)
if (!ol)
goto end;
switch (overlay->state)
switch (input_overlay_status(ol))
{
case OVERLAY_STATUS_DEFERRED_LOAD:
input_overlay_load_overlays(overlay);
input_overlay_load_overlays(ol);
break;
case OVERLAY_STATUS_NONE:
case OVERLAY_STATUS_ALIVE:
break;
case OVERLAY_STATUS_DEFERRED_LOADING_RESOLVE:
input_overlay_load_overlays_resolve_iterate(overlay);
input_overlay_load_overlays_resolve_iterate(ol);
break;
case OVERLAY_STATUS_DEFERRED_DONE:
input_overlay_new_done(overlay);
input_overlay_new_done(ol);
break;
case OVERLAY_STATUS_DEFERRED_ERROR:
input_overlay_free(overlay);
input_overlay_free(ol);
break;
default:
break;