Skip to content

Commit

Permalink
Rewrite input_mapper code - no longer have an internal pointer
Browse files Browse the repository at this point in the history
inside input_mapper
  • Loading branch information
inactive123 committed Nov 24, 2017
1 parent 2d3aa5b commit 7ac5eda
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 32 deletions.
3 changes: 2 additions & 1 deletion input/input_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
69 changes: 38 additions & 31 deletions input/input_mapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

memset(handle->keys, 0, sizeof(handle->keys));

for (i = 0; i < RARCH_CUSTOM_BIND_LIST_END; i++)
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)
);*/

if (MAPPER_GET_KEY(mapper_ptr, id))
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(handle, id))
*ret |= 1;
}
break;
default:
break;
}

return;
}
1 change: 1 addition & 0 deletions input/input_mapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 7ac5eda

Please sign in to comment.