(Overlay Analog) Coding style fixes

This commit is contained in:
meancoot 2013-09-05 18:19:07 -04:00
parent 21388592ea
commit 149a0f37d0
7 changed files with 36 additions and 25 deletions

View File

@ -1058,7 +1058,7 @@ void uninit_video_input(void)
{
input_overlay_free(driver.overlay);
driver.overlay = NULL;
driver.overlay_state = 0;
memset(&driver.overlay_state, 0, sizeof(driver.overlay_state));
}
#endif

View File

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

View File

@ -56,7 +56,7 @@ static inline bool input_key_pressed_func(int key)
bool ret = driver.input->key_pressed(driver.input_data, key);
#ifdef HAVE_OVERLAY
ret |= driver.overlay_state & (UINT64_C(1) << key);
ret |= driver.overlay_state.buttons & (UINT64_C(1) << key);
#endif
#ifdef HAVE_COMMAND

View File

@ -725,7 +725,7 @@ static uint64_t rgui_input(void)
input_state |= input_input_state_func(binds,
0, RETRO_DEVICE_JOYPAD, 0, maps[i + 0]) ? (1ULL << maps[i + 1]) : 0;
#ifdef HAVE_OVERLAY
input_state |= (driver.overlay_state & (UINT64_C(1) << maps[i + 0])) ? (1ULL << maps[i + 1]) : 0;
input_state |= (driver.overlay_state.buttons & (UINT64_C(1) << maps[i + 0])) ? (1ULL << maps[i + 1]) : 0;
#endif
}

View File

@ -554,12 +554,14 @@ static bool inside_hitbox(const struct overlay_desc *desc, float x, float y)
}
}
uint64_t input_overlay_poll(input_overlay_t *ol, int16_t norm_x, int16_t norm_y)
void input_overlay_poll(input_overlay_t *ol, input_overlay_state_t *out, int16_t norm_x, int16_t norm_y)
{
memset(out, 0, sizeof(*out));
if (!ol->enable)
{
ol->blocked = false;
return 0;
return;
}
// norm_x and norm_y is in [-0x7fff, 0x7fff] range, like RETRO_DEVICE_POINTER.
@ -571,7 +573,6 @@ uint64_t input_overlay_poll(input_overlay_t *ol, int16_t norm_x, int16_t norm_y)
x /= ol->active->mod_w;
y /= ol->active->mod_h;
uint64_t state = 0;
for (size_t i = 0; i < ol->active->size; i++)
{
if (!inside_hitbox(&ol->active->descs[i], x, y))
@ -580,27 +581,26 @@ uint64_t input_overlay_poll(input_overlay_t *ol, int16_t norm_x, int16_t norm_y)
if (ol->active->descs[i].type == OVERLAY_TYPE_BUTTONS)
{
uint64_t mask = ol->active->descs[i].key_mask;
state |= mask;
out->buttons |= mask;
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;
float x_val = (x - ol->active->descs[i].x) / ol->active->descs[i].range_x * 32767.0f;
float y_val = (y - ol->active->descs[i].y) / ol->active->descs[i].range_y * 32767.0f;
unsigned int base = (ol->active->descs[i].type == OVERLAY_TYPE_ANALOG_RIGHT) ? 2 : 0;
out->analog[base + 0] = x_val;
out->analog[base + 1] = y_val;
}
}
if (!state)
if (!out->buttons)
ol->blocked = false;
else if (ol->blocked)
state = 0;
return state;
memset(out, 0, sizeof(*out));
}
void input_overlay_poll_clear(input_overlay_t *ol)

View File

@ -30,6 +30,12 @@ extern "C" {
// This interface requires that the video driver has support for the overlay interface.
typedef struct input_overlay input_overlay_t;
typedef struct input_overlay_state
{
uint64_t buttons; // This is a bitmask of (1 << key_bind_id).
int16_t analog[4]; // Left X, Left Y, Right X, Right Y
} input_overlay_state_t;
input_overlay_t *input_overlay_new(const char *overlay);
void input_overlay_free(input_overlay_t *ol);
@ -38,8 +44,7 @@ void input_overlay_enable(input_overlay_t *ol, bool enable);
bool input_overlay_full_screen(input_overlay_t *ol);
// norm_x and norm_y are the result of input_translate_coord_viewport().
// Resulting state is a bitmask of (1 << key_bind_id).
uint64_t input_overlay_poll(input_overlay_t *ol, int16_t norm_x, int16_t norm_y);
void input_overlay_poll(input_overlay_t *ol, input_overlay_state_t *out, int16_t norm_x, int16_t norm_y);
// Call when there is nothing to poll. Allows overlay to clear certain state.
void input_overlay_poll_clear(input_overlay_t *ol);

View File

@ -461,8 +461,7 @@ size_t audio_sample_batch(const int16_t *data, size_t frames)
#ifdef HAVE_OVERLAY
static inline void input_poll_overlay(void)
{
driver.overlay_state = 0;
memset(driver.overlay_analog_state, 0, sizeof(driver.overlay_analog_state));
memset(&driver.overlay_state, 0, sizeof(driver.overlay_state));
unsigned device = input_overlay_full_screen(driver.overlay) ?
RARCH_DEVICE_POINTER_SCREEN : RETRO_DEVICE_POINTER;
@ -477,7 +476,15 @@ static inline void input_poll_overlay(void)
int16_t y = input_input_state_func(NULL, 0,
device, i, RETRO_DEVICE_ID_POINTER_Y);
driver.overlay_state |= input_overlay_poll(driver.overlay, x, y);
input_overlay_state_t polled_data;
input_overlay_poll(driver.overlay, &polled_data, x, y);
driver.overlay_state.buttons |= polled_data.buttons;
for (unsigned j = 0; j < 4; j ++)
if (driver.overlay_state.analog[j] == 0)
driver.overlay_state.analog[j] = polled_data.analog[j];
polled = true;
}
@ -544,12 +551,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;
res |= driver.overlay_state.buttons & (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];
res += driver.overlay_state.analog[base];
}
#endif