(Overlay Keyboard) Use 1 bit per key to store state.

This commit is contained in:
meancoot 2014-01-02 23:20:06 -05:00
parent 1ff9630d74
commit f55bac7f7e
3 changed files with 9 additions and 5 deletions

View File

@ -925,7 +925,7 @@ void input_overlay_poll(input_overlay_t *ol, input_overlay_state_t *out, int16_t
else if (desc->type == OVERLAY_TYPE_KEYBOARD)
{
if (desc->key_mask < RETROK_LAST)
out->keys[desc->key_mask] = 1;
OVERLAY_SET_KEY(out, desc->key_mask);
}
else
{

View File

@ -34,9 +34,13 @@ 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
bool keys[RETROK_LAST];
uint32_t keys[RETROK_LAST / 32 + 1];
} input_overlay_state_t;
#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))
input_overlay_t *input_overlay_new(const char *overlay);
void input_overlay_free(input_overlay_t *ol);

View File

@ -513,7 +513,7 @@ static inline void input_poll_overlay(void)
driver.overlay_state.buttons |= polled_data.buttons;
for (j = 0; j < RETROK_LAST; j ++)
for (j = 0; j < ARRAY_SIZE(driver.overlay_state.keys); j ++)
driver.overlay_state.keys[j] |= polled_data.keys[j];
// Fingers pressed later take prio and matched up with overlay poll priorities.
@ -592,8 +592,8 @@ 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.buttons & (UINT64_C(1) << id) ? 1 : 0;
else if (device == RETRO_DEVICE_KEYBOARD && port == 0)
res |= driver.overlay_state.keys[(id < RETROK_LAST) ? id : 0];
else if (device == RETRO_DEVICE_KEYBOARD && port == 0 && id < RETROK_LAST)
res |= OVERLAY_GET_KEY(&driver.overlay_state, id) ? 1 : 0;
else if (device == RETRO_DEVICE_ANALOG && port == 0)
{
unsigned base = (index == RETRO_DEVICE_INDEX_ANALOG_RIGHT) ? 2 : 0;