mirror of
https://github.com/libretro/RetroArch
synced 2025-03-28 19:20:35 +00:00
Transfer code over from retroarch.c to input_driver.c
This commit is contained in:
parent
5b1872f6be
commit
67defbcf26
@ -796,3 +796,133 @@ input_remote_t *input_driver_init_remote(
|
||||
num_active_users);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_OVERLAY
|
||||
bool input_overlay_add_inputs_inner(overlay_desc_t *desc,
|
||||
input_overlay_state_t *ol_state, unsigned port)
|
||||
{
|
||||
switch(desc->type)
|
||||
{
|
||||
case OVERLAY_TYPE_BUTTONS:
|
||||
{
|
||||
unsigned i;
|
||||
bool all_buttons_pressed = false;
|
||||
|
||||
/* Check each bank of the mask */
|
||||
for (i = 0; i < ARRAY_SIZE(desc->button_mask.data); ++i)
|
||||
{
|
||||
/* Get bank */
|
||||
uint32_t bank_mask = BITS_GET_ELEM(desc->button_mask,i);
|
||||
unsigned id = i * 32;
|
||||
|
||||
/* Worth pursuing? Have we got any bits left in here? */
|
||||
while (bank_mask)
|
||||
{
|
||||
/* If this bit is set then we need to query the pad
|
||||
* The button must be pressed.*/
|
||||
if (bank_mask & 1)
|
||||
{
|
||||
/* Light up the button if pressed */
|
||||
if (ol_state ?
|
||||
!BIT256_GET(ol_state->buttons, id) :
|
||||
!input_state_internal(port, RETRO_DEVICE_JOYPAD, 0, id))
|
||||
{
|
||||
/* We need ALL of the inputs to be active,
|
||||
* abort. */
|
||||
desc->updated = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
all_buttons_pressed = true;
|
||||
desc->updated = true;
|
||||
}
|
||||
|
||||
bank_mask >>= 1;
|
||||
++id;
|
||||
}
|
||||
}
|
||||
|
||||
return all_buttons_pressed;
|
||||
}
|
||||
|
||||
case OVERLAY_TYPE_ANALOG_LEFT:
|
||||
case OVERLAY_TYPE_ANALOG_RIGHT:
|
||||
{
|
||||
float analog_x;
|
||||
float analog_y;
|
||||
float dx;
|
||||
float dy;
|
||||
|
||||
if (ol_state)
|
||||
{
|
||||
unsigned index_offset = (desc->type == OVERLAY_TYPE_ANALOG_RIGHT) ? 2 : 0;
|
||||
analog_x = (float)ol_state->analog[index_offset];
|
||||
analog_y = (float)ol_state->analog[index_offset + 1];
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned index = (desc->type == OVERLAY_TYPE_ANALOG_RIGHT) ?
|
||||
RETRO_DEVICE_INDEX_ANALOG_RIGHT : RETRO_DEVICE_INDEX_ANALOG_LEFT;
|
||||
|
||||
analog_x = input_state_internal(port, RETRO_DEVICE_ANALOG,
|
||||
index, RETRO_DEVICE_ID_ANALOG_X);
|
||||
analog_y = input_state_internal(port, RETRO_DEVICE_ANALOG,
|
||||
index, RETRO_DEVICE_ID_ANALOG_Y);
|
||||
}
|
||||
|
||||
dx = (analog_x / (float)0x8000) * (desc->range_x / 2.0f);
|
||||
dy = (analog_y / (float)0x8000) * (desc->range_y / 2.0f);
|
||||
|
||||
/* Only modify overlay delta_x/delta_y values
|
||||
* if we are monitoring input from a physical
|
||||
* controller */
|
||||
if (!ol_state)
|
||||
{
|
||||
desc->delta_x = dx;
|
||||
desc->delta_y = dy;
|
||||
}
|
||||
|
||||
/* Maybe use some option here instead of 0, only display
|
||||
* changes greater than some magnitude */
|
||||
if ((dx * dx) > 0 || (dy * dy) > 0)
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
|
||||
case OVERLAY_TYPE_KEYBOARD:
|
||||
if (ol_state ?
|
||||
OVERLAY_GET_KEY(ol_state, desc->retro_key_idx) :
|
||||
input_state_internal(port, RETRO_DEVICE_KEYBOARD, 0, desc->retro_key_idx))
|
||||
{
|
||||
desc->updated = true;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool input_overlay_add_inputs(input_overlay_t *ol,
|
||||
bool show_touched, unsigned port)
|
||||
{
|
||||
unsigned i;
|
||||
bool button_pressed = false;
|
||||
input_overlay_state_t *ol_state = &ol->overlay_state;
|
||||
|
||||
if (!ol_state)
|
||||
return false;
|
||||
|
||||
for (i = 0; i < ol->active->size; i++)
|
||||
{
|
||||
overlay_desc_t *desc = &(ol->active->descs[i]);
|
||||
button_pressed |= input_overlay_add_inputs_inner(desc,
|
||||
show_touched ? ol_state : NULL, port);
|
||||
}
|
||||
|
||||
return button_pressed;
|
||||
}
|
||||
#endif
|
||||
|
@ -34,6 +34,9 @@
|
||||
|
||||
#include "input_defines.h"
|
||||
#include "input_types.h"
|
||||
#ifdef HAVE_OVERLAY
|
||||
#include "input_overlay.h"
|
||||
#endif
|
||||
|
||||
#include "../msg_hash.h"
|
||||
#include "include/hid_types.h"
|
||||
@ -722,6 +725,9 @@ input_remote_t *input_driver_init_remote(
|
||||
void input_remote_free(input_remote_t *handle, unsigned max_users);
|
||||
#endif
|
||||
|
||||
int16_t input_state_internal(unsigned port, unsigned device,
|
||||
unsigned idx, unsigned id);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
const struct retro_keybind *input_config_get_bind_auto(unsigned port, unsigned id);
|
||||
|
@ -27,6 +27,11 @@
|
||||
|
||||
#include "input_driver.h"
|
||||
|
||||
#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 MAX_VISIBILITY 32
|
||||
|
||||
RETRO_BEGIN_DECLS
|
||||
|
||||
/* Overlay driver acts as a medium between input drivers
|
||||
@ -111,6 +116,46 @@ enum overlay_show_input_type
|
||||
OVERLAY_SHOW_INPUT_LAST
|
||||
};
|
||||
|
||||
struct overlay_desc
|
||||
{
|
||||
struct texture_image image;
|
||||
|
||||
enum overlay_hitbox hitbox;
|
||||
enum overlay_type type;
|
||||
|
||||
bool updated;
|
||||
bool movable;
|
||||
|
||||
unsigned next_index;
|
||||
unsigned image_index;
|
||||
|
||||
float alpha_mod;
|
||||
float range_mod;
|
||||
float analog_saturate_pct;
|
||||
float range_x, range_y;
|
||||
float range_x_mod, range_y_mod;
|
||||
float mod_x, mod_y, mod_w, mod_h;
|
||||
float delta_x, delta_y;
|
||||
float x;
|
||||
float y;
|
||||
/* These are 'raw' x/y values shifted
|
||||
* by a user-configured offset (c.f.
|
||||
* OVERLAY_X/Y_SEPARATION). Used to determine
|
||||
* correct hitbox locations. By default,
|
||||
* will be equal to x/y */
|
||||
float x_shift;
|
||||
float y_shift;
|
||||
|
||||
/* This is a retro_key value for keyboards */
|
||||
unsigned retro_key_idx;
|
||||
|
||||
/* This is a bit mask of all input binds to set with this overlay control */
|
||||
input_bits_t button_mask;
|
||||
|
||||
char next_index_name[64];
|
||||
};
|
||||
|
||||
|
||||
struct overlay
|
||||
{
|
||||
struct overlay_desc *descs;
|
||||
@ -169,43 +214,33 @@ struct overlay
|
||||
char name[64];
|
||||
};
|
||||
|
||||
struct overlay_desc
|
||||
typedef struct input_overlay_state
|
||||
{
|
||||
struct texture_image image;
|
||||
uint32_t keys[RETROK_LAST / 32 + 1];
|
||||
/* Left X, Left Y, Right X, Right Y */
|
||||
int16_t analog[4];
|
||||
/* This is a bitmask of (1 << key_bind_id). */
|
||||
input_bits_t buttons;
|
||||
} input_overlay_state_t;
|
||||
|
||||
enum overlay_hitbox hitbox;
|
||||
enum overlay_type type;
|
||||
struct input_overlay
|
||||
{
|
||||
struct overlay *overlays;
|
||||
const struct overlay *active;
|
||||
void *iface_data;
|
||||
const video_overlay_interface_t *iface;
|
||||
input_overlay_state_t overlay_state;
|
||||
|
||||
bool updated;
|
||||
bool movable;
|
||||
size_t index;
|
||||
size_t size;
|
||||
|
||||
unsigned next_index;
|
||||
unsigned image_index;
|
||||
|
||||
float alpha_mod;
|
||||
float range_mod;
|
||||
float analog_saturate_pct;
|
||||
float range_x, range_y;
|
||||
float range_x_mod, range_y_mod;
|
||||
float mod_x, mod_y, mod_w, mod_h;
|
||||
float delta_x, delta_y;
|
||||
float x;
|
||||
float y;
|
||||
/* These are 'raw' x/y values shifted
|
||||
* by a user-configured offset (c.f.
|
||||
* OVERLAY_X/Y_SEPARATION). Used to determine
|
||||
* correct hitbox locations. By default,
|
||||
* will be equal to x/y */
|
||||
float x_shift;
|
||||
float y_shift;
|
||||
enum overlay_status state;
|
||||
|
||||
/* This is a retro_key value for keyboards */
|
||||
unsigned retro_key_idx;
|
||||
|
||||
/* This is a bit mask of all input binds to set with this overlay control */
|
||||
input_bits_t button_mask;
|
||||
|
||||
char next_index_name[64];
|
||||
bool enable;
|
||||
bool blocked;
|
||||
bool alive;
|
||||
};
|
||||
|
||||
/* Holds general layout information for an
|
||||
@ -261,6 +296,26 @@ void input_overlay_free_overlay(struct overlay *overlay);
|
||||
|
||||
void input_overlay_set_visibility(int overlay_idx,enum overlay_visibility vis);
|
||||
|
||||
/**
|
||||
* input_overlay_add_inputs:
|
||||
* @desc : pointer to overlay description
|
||||
* @ol_state : pointer to overlay state. If valid, inputs
|
||||
* that are actually 'touched' on the overlay
|
||||
* itself will displayed. If NULL, inputs from
|
||||
* the device connected to 'port' will be displayed.
|
||||
* @port : when ol_state is NULL, specifies the port of
|
||||
* the input device from which input will be
|
||||
* displayed.
|
||||
*
|
||||
* Adds inputs from current_input to the overlay, so it's displayed
|
||||
* returns true if an input that is pressed will change the overlay
|
||||
*/
|
||||
bool input_overlay_add_inputs_inner(overlay_desc_t *desc,
|
||||
input_overlay_state_t *ol_state, unsigned port);
|
||||
|
||||
bool input_overlay_add_inputs(input_overlay_t *ol,
|
||||
bool show_touched, unsigned port);
|
||||
|
||||
RETRO_END_DECLS
|
||||
|
||||
#endif
|
||||
|
168
retroarch.c
168
retroarch.c
@ -18631,148 +18631,6 @@ static bool bsv_movie_check(struct rarch_state *p_rarch,
|
||||
static bool video_driver_overlay_interface(
|
||||
const video_overlay_interface_t **iface);
|
||||
|
||||
/**
|
||||
* input_overlay_add_inputs:
|
||||
* @desc : pointer to overlay description
|
||||
* @ol_state : pointer to overlay state. If valid, inputs
|
||||
* that are actually 'touched' on the overlay
|
||||
* itself will displayed. If NULL, inputs from
|
||||
* the device connected to 'port' will be displayed.
|
||||
* @port : when ol_state is NULL, specifies the port of
|
||||
* the input device from which input will be
|
||||
* displayed.
|
||||
*
|
||||
* Adds inputs from current_input to the overlay, so it's displayed
|
||||
* returns true if an input that is pressed will change the overlay
|
||||
*/
|
||||
static bool input_overlay_add_inputs_inner(overlay_desc_t *desc,
|
||||
input_overlay_state_t *ol_state, unsigned port)
|
||||
{
|
||||
switch(desc->type)
|
||||
{
|
||||
case OVERLAY_TYPE_BUTTONS:
|
||||
{
|
||||
unsigned i;
|
||||
bool all_buttons_pressed = false;
|
||||
|
||||
/* Check each bank of the mask */
|
||||
for (i = 0; i < ARRAY_SIZE(desc->button_mask.data); ++i)
|
||||
{
|
||||
/* Get bank */
|
||||
uint32_t bank_mask = BITS_GET_ELEM(desc->button_mask,i);
|
||||
unsigned id = i * 32;
|
||||
|
||||
/* Worth pursuing? Have we got any bits left in here? */
|
||||
while (bank_mask)
|
||||
{
|
||||
/* If this bit is set then we need to query the pad
|
||||
* The button must be pressed.*/
|
||||
if (bank_mask & 1)
|
||||
{
|
||||
/* Light up the button if pressed */
|
||||
if (ol_state ?
|
||||
!BIT256_GET(ol_state->buttons, id) :
|
||||
!input_state_internal(port, RETRO_DEVICE_JOYPAD, 0, id))
|
||||
{
|
||||
/* We need ALL of the inputs to be active,
|
||||
* abort. */
|
||||
desc->updated = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
all_buttons_pressed = true;
|
||||
desc->updated = true;
|
||||
}
|
||||
|
||||
bank_mask >>= 1;
|
||||
++id;
|
||||
}
|
||||
}
|
||||
|
||||
return all_buttons_pressed;
|
||||
}
|
||||
|
||||
case OVERLAY_TYPE_ANALOG_LEFT:
|
||||
case OVERLAY_TYPE_ANALOG_RIGHT:
|
||||
{
|
||||
float analog_x;
|
||||
float analog_y;
|
||||
float dx;
|
||||
float dy;
|
||||
|
||||
if (ol_state)
|
||||
{
|
||||
unsigned index_offset = (desc->type == OVERLAY_TYPE_ANALOG_RIGHT) ? 2 : 0;
|
||||
analog_x = (float)ol_state->analog[index_offset];
|
||||
analog_y = (float)ol_state->analog[index_offset + 1];
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned index = (desc->type == OVERLAY_TYPE_ANALOG_RIGHT) ?
|
||||
RETRO_DEVICE_INDEX_ANALOG_RIGHT : RETRO_DEVICE_INDEX_ANALOG_LEFT;
|
||||
|
||||
analog_x = input_state_internal(port, RETRO_DEVICE_ANALOG,
|
||||
index, RETRO_DEVICE_ID_ANALOG_X);
|
||||
analog_y = input_state_internal(port, RETRO_DEVICE_ANALOG,
|
||||
index, RETRO_DEVICE_ID_ANALOG_Y);
|
||||
}
|
||||
|
||||
dx = (analog_x / (float)0x8000) * (desc->range_x / 2.0f);
|
||||
dy = (analog_y / (float)0x8000) * (desc->range_y / 2.0f);
|
||||
|
||||
/* Only modify overlay delta_x/delta_y values
|
||||
* if we are monitoring input from a physical
|
||||
* controller */
|
||||
if (!ol_state)
|
||||
{
|
||||
desc->delta_x = dx;
|
||||
desc->delta_y = dy;
|
||||
}
|
||||
|
||||
/* Maybe use some option here instead of 0, only display
|
||||
* changes greater than some magnitude */
|
||||
if ((dx * dx) > 0 || (dy * dy) > 0)
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
|
||||
case OVERLAY_TYPE_KEYBOARD:
|
||||
if (ol_state ?
|
||||
OVERLAY_GET_KEY(ol_state, desc->retro_key_idx) :
|
||||
input_state_internal(port, RETRO_DEVICE_KEYBOARD, 0, desc->retro_key_idx))
|
||||
{
|
||||
desc->updated = true;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool input_overlay_add_inputs(input_overlay_t *ol,
|
||||
bool show_touched, unsigned port)
|
||||
{
|
||||
unsigned i;
|
||||
bool button_pressed = false;
|
||||
input_overlay_state_t *ol_state = &ol->overlay_state;
|
||||
|
||||
if (!ol_state)
|
||||
return false;
|
||||
|
||||
for (i = 0; i < ol->active->size; i++)
|
||||
{
|
||||
overlay_desc_t *desc = &(ol->active->descs[i]);
|
||||
button_pressed |= input_overlay_add_inputs_inner(desc,
|
||||
show_touched ? ol_state : NULL, port);
|
||||
}
|
||||
|
||||
return button_pressed;
|
||||
}
|
||||
|
||||
static void input_overlay_parse_layout(
|
||||
const struct overlay *ol,
|
||||
const overlay_layout_desc_t *layout_desc,
|
||||
@ -20798,13 +20656,13 @@ static int16_t input_state_device(
|
||||
return res;
|
||||
}
|
||||
|
||||
static int16_t input_state_internal(unsigned port, unsigned device,
|
||||
int16_t input_state_internal(unsigned port, unsigned device,
|
||||
unsigned idx, unsigned id)
|
||||
{
|
||||
rarch_joypad_info_t joypad_info;
|
||||
unsigned mapped_port;
|
||||
struct rarch_state *p_rarch = &rarch_st;
|
||||
input_driver_state_t *input_driver_st = &p_rarch->input_driver_state;
|
||||
input_driver_state_t *input_driver_st = &p_rarch->input_driver_state;
|
||||
settings_t *settings = p_rarch->configuration_settings;
|
||||
float input_analog_deadzone = settings->floats.input_analog_deadzone;
|
||||
float input_analog_sensitivity = settings->floats.input_analog_sensitivity;
|
||||
@ -20966,12 +20824,12 @@ static int16_t input_state_internal(unsigned port, unsigned device,
|
||||
else
|
||||
{
|
||||
int16_t port_result_abs = (port_result >= 0) ?
|
||||
port_result : -port_result;
|
||||
port_result : -port_result;
|
||||
int16_t result_abs = (result >= 0) ?
|
||||
result : -result;
|
||||
result : -result;
|
||||
|
||||
result = (port_result_abs > result_abs) ?
|
||||
port_result : result;
|
||||
if (port_result_abs > result_abs)
|
||||
result = port_result;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -20983,7 +20841,8 @@ static int16_t input_state_internal(unsigned port, unsigned device,
|
||||
if (BSV_MOVIE_IS_PLAYBACK_OFF())
|
||||
{
|
||||
result = swap_if_big16(result);
|
||||
intfstream_write(p_rarch->bsv_movie_state_handle->file, &result, 2);
|
||||
intfstream_write(
|
||||
p_rarch->bsv_movie_state_handle->file, &result, 2);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -21013,7 +20872,9 @@ static int16_t input_state(unsigned port, unsigned device,
|
||||
if (BSV_MOVIE_IS_PLAYBACK_ON())
|
||||
{
|
||||
int16_t bsv_result = 0;
|
||||
if (intfstream_read(p_rarch->bsv_movie_state_handle->file, &bsv_result, 2) == 2)
|
||||
if (intfstream_read(
|
||||
p_rarch->bsv_movie_state_handle->file,
|
||||
&bsv_result, 2) == 2)
|
||||
{
|
||||
#ifdef HAVE_CHEEVOS
|
||||
rcheevos_pause_hardcore();
|
||||
@ -21030,9 +20891,9 @@ static int16_t input_state(unsigned port, unsigned device,
|
||||
|
||||
/* Register any analog stick input requests for
|
||||
* this 'virtual' (core) port */
|
||||
if ((device == RETRO_DEVICE_ANALOG) &&
|
||||
((idx == RETRO_DEVICE_INDEX_ANALOG_LEFT) ||
|
||||
(idx == RETRO_DEVICE_INDEX_ANALOG_RIGHT)))
|
||||
if ( (device == RETRO_DEVICE_ANALOG) &&
|
||||
( (idx == RETRO_DEVICE_INDEX_ANALOG_LEFT) ||
|
||||
(idx == RETRO_DEVICE_INDEX_ANALOG_RIGHT)))
|
||||
p_rarch->input_driver_analog_requested[port] = true;
|
||||
|
||||
#ifdef HAVE_BSV_MOVIE
|
||||
@ -37136,4 +36997,3 @@ enum retro_language frontend_driver_get_user_language(void)
|
||||
return RETRO_LANGUAGE_ENGLISH;
|
||||
return frontend->get_user_language();
|
||||
}
|
||||
|
||||
|
@ -96,13 +96,6 @@
|
||||
#define DEFAULT_NETWORK_GAMEPAD_PORT 55400
|
||||
#define UDP_FRAME_PACKETS 16
|
||||
|
||||
#ifdef HAVE_OVERLAY
|
||||
#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 MAX_VISIBILITY 32
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
#define VIDEO_DRIVER_IS_THREADED_INTERNAL() ((!video_driver_is_hw_context() && p_rarch->video_driver_threaded) ? true : false)
|
||||
#else
|
||||
@ -1114,38 +1107,6 @@ typedef struct my_list_t
|
||||
int size;
|
||||
} my_list;
|
||||
|
||||
#ifdef HAVE_OVERLAY
|
||||
typedef struct input_overlay_state
|
||||
{
|
||||
uint32_t keys[RETROK_LAST / 32 + 1];
|
||||
/* Left X, Left Y, Right X, Right Y */
|
||||
int16_t analog[4];
|
||||
/* This is a bitmask of (1 << key_bind_id). */
|
||||
input_bits_t buttons;
|
||||
} input_overlay_state_t;
|
||||
|
||||
struct input_overlay
|
||||
{
|
||||
struct overlay *overlays;
|
||||
const struct overlay *active;
|
||||
void *iface_data;
|
||||
const video_overlay_interface_t *iface;
|
||||
input_overlay_state_t overlay_state;
|
||||
|
||||
size_t index;
|
||||
size_t size;
|
||||
|
||||
unsigned next_index;
|
||||
|
||||
enum overlay_status state;
|
||||
|
||||
bool enable;
|
||||
bool blocked;
|
||||
bool alive;
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct turbo_buttons turbo_buttons_t;
|
||||
|
||||
/* Turbo support. */
|
||||
|
@ -63,8 +63,6 @@ static bool secondary_core_ensure_exists(struct rarch_state *p_rarch,
|
||||
static int16_t input_state_get_last(unsigned port,
|
||||
unsigned device, unsigned index, unsigned id);
|
||||
#endif
|
||||
static int16_t input_state_internal(unsigned port, unsigned device,
|
||||
unsigned idx, unsigned id);
|
||||
static int16_t input_state(unsigned port, unsigned device,
|
||||
unsigned idx, unsigned id);
|
||||
static void video_driver_frame(const void *data, unsigned width,
|
||||
|
Loading…
x
Reference in New Issue
Block a user