mirror of
https://github.com/libretro/RetroArch
synced 2025-03-18 04:21:19 +00:00
Cleanups/rewrites
This commit is contained in:
parent
090063cc35
commit
7a2d09b4bf
@ -27,13 +27,8 @@
|
|||||||
|
|
||||||
#include <compat/strl.h>
|
#include <compat/strl.h>
|
||||||
#include <compat/posix_string.h>
|
#include <compat/posix_string.h>
|
||||||
#include <retro_miscellaneous.h>
|
|
||||||
#include <libretro.h>
|
#include <libretro.h>
|
||||||
|
|
||||||
#ifdef HAVE_MENU
|
|
||||||
#include "../menu/menu_driver.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
#include "../config.h"
|
#include "../config.h"
|
||||||
#endif
|
#endif
|
||||||
@ -46,38 +41,6 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "../configuration.h"
|
#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 input_mapper_poll(input_mapper_t *handle,
|
||||||
void *ol_pointer,
|
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
|
/* 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 */
|
if the key was used by any player before releasing */
|
||||||
else if (!key_event[j])
|
else if (!key_event[j])
|
||||||
{
|
|
||||||
input_keyboard_event(false,
|
input_keyboard_event(false,
|
||||||
remap_button,
|
remap_button,
|
||||||
0, 0, RETRO_DEVICE_KEYBOARD);
|
0, 0, RETRO_DEVICE_KEYBOARD);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -223,12 +184,6 @@ void input_mapper_poll(input_mapper_t *handle,
|
|||||||
remap_axis_bind] =
|
remap_axis_bind] =
|
||||||
current_axis_value * invert;
|
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 <boolean.h>
|
||||||
#include <retro_common_api.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
|
RETRO_BEGIN_DECLS
|
||||||
|
|
||||||
typedef struct input_mapper input_mapper_t;
|
typedef struct input_mapper
|
||||||
|
{
|
||||||
input_mapper_t *input_mapper_new(void);
|
/* Left X, Left Y, Right X, Right Y */
|
||||||
|
int16_t analog_value[MAX_USERS][8];
|
||||||
void input_mapper_free(input_mapper_t *handle);
|
/* 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 input_mapper_poll(input_mapper_t *handle,
|
||||||
void *overlay_pointer,
|
void *overlay_pointer,
|
||||||
@ -41,16 +48,6 @@ void input_mapper_poll(input_mapper_t *handle,
|
|||||||
unsigned max_users,
|
unsigned max_users,
|
||||||
bool poll_overlay);
|
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
|
RETRO_END_DECLS
|
||||||
|
|
||||||
#endif
|
#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)
|
if (settings->bools.input_remap_binds_enable && input_driver_mapper)
|
||||||
input_mapper_state(input_driver_mapper,
|
if (BIT256_GET(input_driver_mapper->buttons[port], id))
|
||||||
&res, port, device, idx, id);
|
res = 1;
|
||||||
|
|
||||||
/* Don't allow turbo for D-pad. */
|
/* Don't allow turbo for D-pad. */
|
||||||
if ((id < RETRO_DEVICE_ID_JOYPAD_UP || id > RETRO_DEVICE_ID_JOYPAD_RIGHT))
|
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;
|
break;
|
||||||
|
|
||||||
case RETRO_DEVICE_KEYBOARD:
|
case RETRO_DEVICE_KEYBOARD:
|
||||||
@ -10934,8 +10930,9 @@ static int16_t input_state_device(
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (settings->bools.input_remap_binds_enable && input_driver_mapper)
|
if (settings->bools.input_remap_binds_enable && input_driver_mapper)
|
||||||
input_mapper_state(input_driver_mapper,
|
if (id < RETROK_LAST)
|
||||||
&res, port, device, idx, id);
|
if (MAPPER_GET_KEY(input_driver_mapper, id))
|
||||||
|
res |= 1;
|
||||||
|
|
||||||
break;
|
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;
|
break;
|
||||||
|
|
||||||
case RETRO_DEVICE_ANALOG:
|
case RETRO_DEVICE_ANALOG:
|
||||||
@ -11050,8 +11043,23 @@ static int16_t input_state_device(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (settings->bools.input_remap_binds_enable && input_driver_mapper)
|
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;
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -12579,7 +12583,7 @@ static void input_driver_deinit_remote(void)
|
|||||||
static void input_driver_deinit_mapper(void)
|
static void input_driver_deinit_mapper(void)
|
||||||
{
|
{
|
||||||
if (input_driver_mapper)
|
if (input_driver_mapper)
|
||||||
input_mapper_free(input_driver_mapper);
|
free(input_driver_mapper);
|
||||||
input_driver_mapper = NULL;
|
input_driver_mapper = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -12605,18 +12609,23 @@ static bool input_driver_init_remote(void)
|
|||||||
|
|
||||||
static bool input_driver_init_mapper(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)
|
if (!settings->bools.input_remap_binds_enable)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
input_driver_mapper = input_mapper_new();
|
handle = (input_mapper_t*)calloc(1, sizeof(*input_driver_mapper));
|
||||||
|
|
||||||
if (input_driver_mapper)
|
if (!handle)
|
||||||
return true;
|
{
|
||||||
|
RARCH_ERR("Failed to initialize input mapper.\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
RARCH_ERR("Failed to initialize input mapper.\n");
|
input_driver_mapper = handle;
|
||||||
return false;
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool input_driver_grab_mouse(void)
|
bool input_driver_grab_mouse(void)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user