(Overlay) Add basic analog support

This commit is contained in:
meancoot 2013-09-05 11:38:00 -04:00
parent cb55a1d45a
commit 21388592ea
3 changed files with 50 additions and 7 deletions

View File

@ -463,6 +463,7 @@ typedef struct driver
#ifdef HAVE_OVERLAY
input_overlay_t *overlay;
uint64_t overlay_state;
int16_t overlay_analog_state[4];
#endif
// Interface for "poking".

View File

@ -31,6 +31,13 @@ enum overlay_hitbox
OVERLAY_HITBOX_RECT
};
enum overlay_type
{
OVERLAY_TYPE_BUTTONS = 0,
OVERLAY_TYPE_ANALOG_LEFT,
OVERLAY_TYPE_ANALOG_RIGHT
};
struct overlay_desc
{
float x;
@ -39,6 +46,7 @@ struct overlay_desc
enum overlay_hitbox hitbox;
float range_x, range_y;
enum overlay_type type;
uint64_t key_mask;
unsigned next_index;
@ -234,14 +242,23 @@ static bool input_overlay_load_desc(config_file_t *conf, struct overlay_desc *de
char *key = list->elems[0].data;
char *save;
desc->key_mask = 0;
for (const char *tmp = strtok_r(key, "|", &save); tmp; tmp = strtok_r(NULL, "|", &save))
desc->key_mask |= UINT64_C(1) << input_str_to_bind(tmp);
if (desc->key_mask & (UINT64_C(1) << RARCH_OVERLAY_NEXT))
if (strcmp(key, "analog_left") == 0)
desc->type = OVERLAY_TYPE_ANALOG_LEFT;
else if (strcmp(key, "analog_right") == 0)
desc->type = OVERLAY_TYPE_ANALOG_RIGHT;
else
{
char overlay_target_key[64];
snprintf(overlay_target_key, sizeof(overlay_target_key), "overlay%u_desc%u_next_target", ol_index, desc_index);
config_get_array(conf, overlay_target_key, desc->next_index_name, sizeof(desc->next_index_name));
desc->type = OVERLAY_TYPE_BUTTONS;
for (const char *tmp = strtok_r(key, "|", &save); tmp; tmp = strtok_r(NULL, "|", &save))
desc->key_mask |= UINT64_C(1) << input_str_to_bind(tmp);
if (desc->key_mask & (UINT64_C(1) << RARCH_OVERLAY_NEXT))
{
char overlay_target_key[64];
snprintf(overlay_target_key, sizeof(overlay_target_key), "overlay%u_desc%u_next_target", ol_index, desc_index);
config_get_array(conf, overlay_target_key, desc->next_index_name, sizeof(desc->next_index_name));
}
}
desc->x = strtod(x, NULL) / width;
@ -258,6 +275,13 @@ static bool input_overlay_load_desc(config_file_t *conf, struct overlay_desc *de
goto end;
}
if (desc->hitbox != OVERLAY_HITBOX_RADIAL && desc->type != OVERLAY_TYPE_BUTTONS)
{
RARCH_ERR("[Overlay]: Analog hitbox type must be \"radial\".\n");
ret = false;
goto end;
}
desc->range_x = strtod(list->elems[4].data, NULL) / width;
desc->range_y = strtod(list->elems[5].data, NULL) / height;
@ -550,7 +574,10 @@ uint64_t input_overlay_poll(input_overlay_t *ol, int16_t norm_x, int16_t norm_y)
uint64_t state = 0;
for (size_t i = 0; i < ol->active->size; i++)
{
if (inside_hitbox(&ol->active->descs[i], x, y))
if (!inside_hitbox(&ol->active->descs[i], x, y))
continue;
if (ol->active->descs[i].type == OVERLAY_TYPE_BUTTONS)
{
uint64_t mask = ol->active->descs[i].key_mask;
state |= mask;
@ -558,6 +585,14 @@ uint64_t input_overlay_poll(input_overlay_t *ol, int16_t norm_x, int16_t norm_y)
if (mask & (UINT64_C(1) << RARCH_OVERLAY_NEXT))
ol->next_index = ol->active->descs[i].next_index;
}
else
{
float tgt_x = (x - ol->active->descs[i].x) / ol->active->descs[i].range_x;
float tgt_y = (y - ol->active->descs[i].y) / ol->active->descs[i].range_y;
unsigned base = (ol->active->descs[i].type == OVERLAY_TYPE_ANALOG_RIGHT) ? 2 : 0;
driver.overlay_analog_state[base + 0] = tgt_x * 32767.0f;
driver.overlay_analog_state[base + 1] = tgt_y * 32767.0f;
}
}
if (!state)

View File

@ -462,6 +462,7 @@ size_t audio_sample_batch(const int16_t *data, size_t frames)
static inline void input_poll_overlay(void)
{
driver.overlay_state = 0;
memset(driver.overlay_analog_state, 0, sizeof(driver.overlay_analog_state));
unsigned device = input_overlay_full_screen(driver.overlay) ?
RARCH_DEVICE_POINTER_SCREEN : RETRO_DEVICE_POINTER;
@ -544,6 +545,12 @@ static int16_t input_state(unsigned port, unsigned device, unsigned index, unsig
#ifdef HAVE_OVERLAY
if (device == RETRO_DEVICE_JOYPAD && port == 0)
res |= driver.overlay_state & (UINT64_C(1) << id) ? 1 : 0;
else if (device == RETRO_DEVICE_ANALOG && port == 0)
{
unsigned base = (index == RETRO_DEVICE_INDEX_ANALOG_RIGHT) ? 2 : 0;
base += (id == RETRO_DEVICE_ID_ANALOG_Y) ? 1 : 0;
res += driver.overlay_analog_state[base];
}
#endif
// Don't allow turbo for D-pad.