mirror of
https://github.com/libretro/RetroArch
synced 2025-03-17 10:21:26 +00:00
Cleanups/rewrites
This commit is contained in:
parent
090063cc35
commit
7a2d09b4bf
@ -27,13 +27,8 @@
|
||||
|
||||
#include <compat/strl.h>
|
||||
#include <compat/posix_string.h>
|
||||
#include <retro_miscellaneous.h>
|
||||
#include <libretro.h>
|
||||
|
||||
#ifdef HAVE_MENU
|
||||
#include "../menu/menu_driver.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "../config.h"
|
||||
#endif
|
||||
@ -46,38 +41,6 @@
|
||||
#endif
|
||||
|
||||
#include "../configuration.h"
|
||||
#include "../msg_hash.h"
|
||||
#include "../verbosity.h"
|
||||
|
||||
#define MAPPER_GET_KEY(state, key) (((state)->keys[(key) / 32] >> ((key) % 32)) & 1)
|
||||
#define MAPPER_SET_KEY(state, key) (state)->keys[(key) / 32] |= 1 << ((key) % 32)
|
||||
|
||||
struct input_mapper
|
||||
{
|
||||
/* Left X, Left Y, Right X, Right Y */
|
||||
int16_t analog_value[MAX_USERS][8];
|
||||
/* the whole keyboard state */
|
||||
uint32_t keys[RETROK_LAST / 32 + 1];
|
||||
/* This is a bitmask of (1 << key_bind_id). */
|
||||
input_bits_t buttons[MAX_USERS];
|
||||
};
|
||||
|
||||
input_mapper_t *input_mapper_new(void)
|
||||
{
|
||||
input_mapper_t* handle = (input_mapper_t*)
|
||||
calloc(1, sizeof(*handle));
|
||||
|
||||
if (!handle)
|
||||
return NULL;
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
void input_mapper_free(input_mapper_t *handle)
|
||||
{
|
||||
if (handle)
|
||||
free (handle);
|
||||
}
|
||||
|
||||
void input_mapper_poll(input_mapper_t *handle,
|
||||
void *ol_pointer,
|
||||
@ -131,11 +94,9 @@ void input_mapper_poll(input_mapper_t *handle,
|
||||
/* key_event tracks if a key is pressed for ANY PLAYER, so we must check
|
||||
if the key was used by any player before releasing */
|
||||
else if (!key_event[j])
|
||||
{
|
||||
input_keyboard_event(false,
|
||||
remap_button,
|
||||
0, 0, RETRO_DEVICE_KEYBOARD);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -223,12 +184,6 @@ void input_mapper_poll(input_mapper_t *handle,
|
||||
remap_axis_bind] =
|
||||
current_axis_value * invert;
|
||||
}
|
||||
#if 0
|
||||
RARCH_LOG("axis %d(%d) remapped to axis %d val %d\n",
|
||||
j, k,
|
||||
remap_axis - RARCH_FIRST_CUSTOM_BIND,
|
||||
current_axis_value);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -239,44 +194,3 @@ void input_mapper_poll(input_mapper_t *handle,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void input_mapper_state(
|
||||
input_mapper_t *handle,
|
||||
int16_t *ret,
|
||||
unsigned port,
|
||||
unsigned device,
|
||||
unsigned idx,
|
||||
unsigned id)
|
||||
{
|
||||
switch (device)
|
||||
{
|
||||
case RETRO_DEVICE_JOYPAD:
|
||||
if (BIT256_GET(handle->buttons[port], id))
|
||||
*ret = 1;
|
||||
break;
|
||||
case RETRO_DEVICE_ANALOG:
|
||||
if (idx < 2 && id < 2)
|
||||
{
|
||||
int val = 0;
|
||||
unsigned offset = 0 + (idx * 4) + (id * 2);
|
||||
int val1 = handle->analog_value[port][offset];
|
||||
int val2 = handle->analog_value[port][offset+1];
|
||||
|
||||
if (val1)
|
||||
val = val1;
|
||||
else if (val2)
|
||||
val = val2;
|
||||
|
||||
if (val1 || val2)
|
||||
*ret |= val;
|
||||
}
|
||||
break;
|
||||
case RETRO_DEVICE_KEYBOARD:
|
||||
if (id < RETROK_LAST)
|
||||
if (MAPPER_GET_KEY(handle, id))
|
||||
*ret |= 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -27,13 +27,20 @@
|
||||
#include <boolean.h>
|
||||
#include <retro_common_api.h>
|
||||
|
||||
#define MAPPER_GET_KEY(state, key) (((state)->keys[(key) / 32] >> ((key) % 32)) & 1)
|
||||
#define MAPPER_SET_KEY(state, key) (state)->keys[(key) / 32] |= 1 << ((key) % 32)
|
||||
|
||||
RETRO_BEGIN_DECLS
|
||||
|
||||
typedef struct input_mapper input_mapper_t;
|
||||
|
||||
input_mapper_t *input_mapper_new(void);
|
||||
|
||||
void input_mapper_free(input_mapper_t *handle);
|
||||
typedef struct input_mapper
|
||||
{
|
||||
/* Left X, Left Y, Right X, Right Y */
|
||||
int16_t analog_value[MAX_USERS][8];
|
||||
/* the whole keyboard state */
|
||||
uint32_t keys[RETROK_LAST / 32 + 1];
|
||||
/* This is a bitmask of (1 << key_bind_id). */
|
||||
input_bits_t buttons[MAX_USERS];
|
||||
} input_mapper_t;
|
||||
|
||||
void input_mapper_poll(input_mapper_t *handle,
|
||||
void *overlay_pointer,
|
||||
@ -41,16 +48,6 @@ void input_mapper_poll(input_mapper_t *handle,
|
||||
unsigned max_users,
|
||||
bool poll_overlay);
|
||||
|
||||
bool input_mapper_key_pressed(input_mapper_t *handle, int key);
|
||||
|
||||
void input_mapper_state(
|
||||
input_mapper_t *handle,
|
||||
int16_t *ret,
|
||||
unsigned port,
|
||||
unsigned device,
|
||||
unsigned idx,
|
||||
unsigned id);
|
||||
|
||||
RETRO_END_DECLS
|
||||
|
||||
#endif
|
||||
|
59
retroarch.c
59
retroarch.c
@ -10857,8 +10857,8 @@ static int16_t input_state_device(
|
||||
}
|
||||
|
||||
if (settings->bools.input_remap_binds_enable && input_driver_mapper)
|
||||
input_mapper_state(input_driver_mapper,
|
||||
&res, port, device, idx, id);
|
||||
if (BIT256_GET(input_driver_mapper->buttons[port], id))
|
||||
res = 1;
|
||||
|
||||
/* Don't allow turbo for D-pad. */
|
||||
if ((id < RETRO_DEVICE_ID_JOYPAD_UP || id > RETRO_DEVICE_ID_JOYPAD_RIGHT))
|
||||
@ -10907,10 +10907,6 @@ static int16_t input_state_device(
|
||||
}
|
||||
}
|
||||
|
||||
if (settings->bools.input_remap_binds_enable && input_driver_mapper)
|
||||
input_mapper_state(input_driver_mapper,
|
||||
&res, port, device, idx, id);
|
||||
|
||||
break;
|
||||
|
||||
case RETRO_DEVICE_KEYBOARD:
|
||||
@ -10934,8 +10930,9 @@ static int16_t input_state_device(
|
||||
#endif
|
||||
|
||||
if (settings->bools.input_remap_binds_enable && input_driver_mapper)
|
||||
input_mapper_state(input_driver_mapper,
|
||||
&res, port, device, idx, id);
|
||||
if (id < RETROK_LAST)
|
||||
if (MAPPER_GET_KEY(input_driver_mapper, id))
|
||||
res |= 1;
|
||||
|
||||
break;
|
||||
|
||||
@ -10959,10 +10956,6 @@ static int16_t input_state_device(
|
||||
}
|
||||
}
|
||||
|
||||
if (settings->bools.input_remap_binds_enable && input_driver_mapper)
|
||||
input_mapper_state(input_driver_mapper,
|
||||
&res, port, device, idx, id);
|
||||
|
||||
break;
|
||||
|
||||
case RETRO_DEVICE_ANALOG:
|
||||
@ -11050,8 +11043,23 @@ static int16_t input_state_device(
|
||||
}
|
||||
|
||||
if (settings->bools.input_remap_binds_enable && input_driver_mapper)
|
||||
input_mapper_state(input_driver_mapper,
|
||||
&res, port, device, idx, id);
|
||||
{
|
||||
if (idx < 2 && id < 2)
|
||||
{
|
||||
int val = 0;
|
||||
unsigned offset = 0 + (idx * 4) + (id * 2);
|
||||
int val1 = input_driver_mapper->analog_value[port][offset];
|
||||
int val2 = input_driver_mapper->analog_value[port][offset+1];
|
||||
|
||||
if (val1)
|
||||
val = val1;
|
||||
else if (val2)
|
||||
val = val2;
|
||||
|
||||
if (val1 || val2)
|
||||
res |= val;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@ -11075,10 +11083,6 @@ static int16_t input_state_device(
|
||||
}
|
||||
}
|
||||
|
||||
if (settings->bools.input_remap_binds_enable && input_driver_mapper)
|
||||
input_mapper_state(input_driver_mapper,
|
||||
&res, port, device, idx, id);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@ -12579,7 +12583,7 @@ static void input_driver_deinit_remote(void)
|
||||
static void input_driver_deinit_mapper(void)
|
||||
{
|
||||
if (input_driver_mapper)
|
||||
input_mapper_free(input_driver_mapper);
|
||||
free(input_driver_mapper);
|
||||
input_driver_mapper = NULL;
|
||||
}
|
||||
|
||||
@ -12605,18 +12609,23 @@ static bool input_driver_init_remote(void)
|
||||
|
||||
static bool input_driver_init_mapper(void)
|
||||
{
|
||||
settings_t *settings = configuration_settings;
|
||||
input_mapper_t *handle = NULL;
|
||||
settings_t *settings = configuration_settings;
|
||||
|
||||
if (!settings->bools.input_remap_binds_enable)
|
||||
return false;
|
||||
|
||||
input_driver_mapper = input_mapper_new();
|
||||
handle = (input_mapper_t*)calloc(1, sizeof(*input_driver_mapper));
|
||||
|
||||
if (input_driver_mapper)
|
||||
return true;
|
||||
if (!handle)
|
||||
{
|
||||
RARCH_ERR("Failed to initialize input mapper.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
RARCH_ERR("Failed to initialize input mapper.\n");
|
||||
return false;
|
||||
input_driver_mapper = handle;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool input_driver_grab_mouse(void)
|
||||
|
Loading…
x
Reference in New Issue
Block a user