Rewrite input_mapper code - no longer have an internal pointer

inside input_mapper
This commit is contained in:
twinaphex 2017-11-24 02:37:53 +01:00
parent 2d3aa5b917
commit 7ac5eda1e1
3 changed files with 40 additions and 31 deletions

View File

@ -669,7 +669,8 @@ int16_t input_state(unsigned port, unsigned device,
#ifdef HAVE_KEYMAPPER
if (input_driver_mapper)
input_mapper_state(&res, port, device, idx, id);
input_mapper_state(input_driver_mapper,
&res, port, device, idx, id);
#endif
/* Don't allow turbo for D-pad. */

View File

@ -56,82 +56,89 @@ struct input_mapper
uint64_t buttons;
};
static input_mapper_t *mapper_ptr;
input_mapper_t *input_mapper_new(uint16_t port)
{
settings_t *settings = config_get_ptr();
input_mapper_t* handle = (input_mapper_t*)
calloc(1, sizeof(*handle));
if (!handle)
return NULL;
handle->port = port;
mapper_ptr = handle;
return handle;
}
void input_mapper_free(input_mapper_t *handle)
{
if (!handle)
return;
free (handle);
}
void input_mapper_poll(input_mapper_t *handle)
{
int i;
settings_t *settings = config_get_ptr();
unsigned device = settings->uints.input_libretro_device[handle->port];
device &= RETRO_DEVICE_MASK;
unsigned device = settings->uints.input_libretro_device[handle->port];
device &= RETRO_DEVICE_MASK;
/* for now we only handle keyboard inputs */
if (device == RETRO_DEVICE_KEYBOARD)
{
int i;
memset(handle->keys, 0, sizeof(handle->keys));
if (device != RETRO_DEVICE_KEYBOARD)
return;
for (i = 0; i < RARCH_CUSTOM_BIND_LIST_END; i++)
memset(handle->keys, 0, sizeof(handle->keys));
for (i = 0; i < RARCH_CUSTOM_BIND_LIST_END; i++)
{
if (i < RETROK_LAST)
{
if (i < RETROK_LAST)
if (input_state(handle->port, RETRO_DEVICE_JOYPAD, 0, i))
{
if (input_state(handle->port, RETRO_DEVICE_JOYPAD, 0, i))
{
MAPPER_SET_KEY (handle, settings->uints.input_keymapper_ids[i]);
input_keyboard_event(true, settings->uints.input_keymapper_ids[i], 0, 0, RETRO_DEVICE_KEYBOARD);
}
else
input_keyboard_event(false, settings->uints.input_keymapper_ids[i], 0, 0, RETRO_DEVICE_KEYBOARD);
MAPPER_SET_KEY (handle,
settings->uints.input_keymapper_ids[i]);
input_keyboard_event(true,
settings->uints.input_keymapper_ids[i],
0, 0, RETRO_DEVICE_KEYBOARD);
}
else
input_keyboard_event(false,
settings->uints.input_keymapper_ids[i],
0, 0, RETRO_DEVICE_KEYBOARD);
}
}
return;
}
void input_mapper_state(
input_mapper_t *handle,
int16_t *ret,
unsigned port,
unsigned device,
unsigned idx,
unsigned id)
{
if (!handle)
return;
settings_t *settings = config_get_ptr();
switch (device)
{
case RETRO_DEVICE_KEYBOARD:
if (id < RETROK_LAST)
{
/*
RARCH_LOG("State: UDLR %u %u %u %u\n",
MAPPER_GET_KEY(mapper_ptr, RETROK_UP),
MAPPER_GET_KEY(mapper_ptr, RETROK_DOWN),
MAPPER_GET_KEY(mapper_ptr, RETROK_LEFT),
MAPPER_GET_KEY(mapper_ptr, RETROK_RIGHT)
);*/
RARCH_LOG("State: UDLR %u %u %u %u\n",
MAPPER_GET_KEY(handle, RETROK_UP),
MAPPER_GET_KEY(handle, RETROK_DOWN),
MAPPER_GET_KEY(handle, RETROK_LEFT),
MAPPER_GET_KEY(handle, RETROK_RIGHT)
);*/
if (MAPPER_GET_KEY(mapper_ptr, id))
if (MAPPER_GET_KEY(handle, id))
*ret |= 1;
}
break;
default:
break;
}
return;
}

View File

@ -40,6 +40,7 @@ void input_mapper_poll(input_mapper_t *handle);
bool input_mapper_key_pressed(int key);
void input_mapper_state(
input_mapper_t *handle,
int16_t *ret,
unsigned port,
unsigned device,