mirror of
https://github.com/libretro/RetroArch.git
synced 2025-04-02 10:51:52 -04:00
(RARCH_CONSOLE) Control refactor - add post_init and set_analog_to_dpad_mapping
members
This commit is contained in:
parent
e13b2e1cb5
commit
bf9980d8bc
12 changed files with 136 additions and 74 deletions
|
@ -24,11 +24,13 @@
|
|||
#include <input/input.h>
|
||||
#include <usb/usbmain.h>
|
||||
|
||||
static struct controller_data_s pad[4];
|
||||
#define MAX_PADS
|
||||
|
||||
static struct controller_data_s pad[MAX_PADS];
|
||||
static void xenon360_input_poll(void *data)
|
||||
{
|
||||
(void)data;
|
||||
for (unsigned i = 0; i < 4; i++)
|
||||
for (unsigned i = 0; i < MAX_PADS; i++)
|
||||
{
|
||||
usb_do_poll();
|
||||
get_controller_data(&pad[i], i);
|
||||
|
@ -117,12 +119,18 @@ static bool xenon360_key_pressed(void *data, int key)
|
|||
return false;
|
||||
}
|
||||
|
||||
static void xenon360_input_set_default_keybind_lut(void) {}
|
||||
static void xenon360_input_set_analog_dpad_mapping(unsigned map_dpad_enum, unsigned controller_id) {}
|
||||
|
||||
const input_driver_t input_xenon360 = {
|
||||
.init = xenon360_input_init,
|
||||
.poll = xenon360_input_poll,
|
||||
.input_state = xenon360_input_state,
|
||||
.key_pressed = xenon360_key_pressed,
|
||||
.free = xenon360_free_input,
|
||||
.set_default_keybind_lut = xenon360_input_set_default_keybind_lut,
|
||||
.set_analog_dpad_mapping = xenon360_input_set_analog_dpad_mapping,
|
||||
.max_pads = MAX_PADS,
|
||||
.ident = "xenon360",
|
||||
};
|
||||
|
||||
|
|
|
@ -19,12 +19,14 @@
|
|||
|
||||
#include <xtl.h>
|
||||
|
||||
#define MAX_PADS 4
|
||||
|
||||
#include "../driver.h"
|
||||
#include "../general.h"
|
||||
#include "../libretro.h"
|
||||
#include "xinput_360_input.h"
|
||||
|
||||
static uint64_t state[4];
|
||||
static uint64_t state[MAX_PADS];
|
||||
static unsigned pads_connected;
|
||||
|
||||
const struct platform_bind platform_keys[] = {
|
||||
|
@ -70,7 +72,7 @@ static void xinput_input_poll(void *data)
|
|||
|
||||
pads_connected = 0;
|
||||
|
||||
for (unsigned i = 0; i < 4; i++)
|
||||
for (unsigned i = 0; i < MAX_PADS; i++)
|
||||
{
|
||||
XINPUT_STATE state_tmp;
|
||||
unsigned long retval;
|
||||
|
@ -110,7 +112,7 @@ static void xinput_input_free_input(void *data)
|
|||
|
||||
#include "../console/retroarch_console.h"
|
||||
|
||||
void xdk360_input_map_dpad_to_stick(uint32_t map_dpad_enum, uint32_t controller_id)
|
||||
static void xinput_input_set_analog_dpad_mapping(unsigned map_dpad_enum, unsigned controller_id)
|
||||
{
|
||||
switch(map_dpad_enum)
|
||||
{
|
||||
|
@ -137,12 +139,15 @@ void xdk360_input_map_dpad_to_stick(uint32_t map_dpad_enum, uint32_t controller_
|
|||
|
||||
static void* xinput_input_init(void)
|
||||
{
|
||||
for(unsigned i = 0; i < 4; i++)
|
||||
xdk360_input_map_dpad_to_stick(g_settings.input.dpad_emulation[i], i);
|
||||
|
||||
return (void*)-1;
|
||||
}
|
||||
|
||||
static void xinput_input_post_init(void)
|
||||
{
|
||||
for(unsigned i = 0; i < MAX_PADS; i++)
|
||||
xinput_input_analog_pad_mapping(g_settings.input.dpad_emulation[i], i);
|
||||
}
|
||||
|
||||
static bool xinput_input_key_pressed(void *data, int key)
|
||||
{
|
||||
(void)data;
|
||||
|
@ -232,5 +237,8 @@ const input_driver_t input_xinput =
|
|||
xinput_input_key_pressed,
|
||||
xinput_input_free_input,
|
||||
xinput_set_default_keybind_lut,
|
||||
xinput_input_set_analog_dpad_mapping,
|
||||
xinput_input_post_init,
|
||||
MAX_PADS,
|
||||
"xinput"
|
||||
};
|
||||
|
|
|
@ -70,6 +70,4 @@ enum xdk_device_id
|
|||
|
||||
#define DEADZONE (16000)
|
||||
|
||||
extern void xdk360_input_map_dpad_to_stick(uint32_t map_dpad_enum, uint32_t controller_id);
|
||||
|
||||
#endif
|
||||
|
|
3
driver.h
3
driver.h
|
@ -161,6 +161,9 @@ typedef struct input_driver
|
|||
void (*free)(void *data);
|
||||
#ifdef RARCH_CONSOLE
|
||||
void (*set_default_keybind_lut)(void);
|
||||
void (*set_analog_dpad_mapping)(unsigned map_dpad_enum, unsigned controller_id);
|
||||
void (*post_init)(void);
|
||||
unsigned max_pads;
|
||||
#endif
|
||||
const char *ident;
|
||||
} input_driver_t;
|
||||
|
|
12
input/null.c
12
input/null.c
|
@ -21,6 +21,12 @@ static void *null_input_init(void)
|
|||
return (void*)-1;
|
||||
}
|
||||
|
||||
#ifdef RARCH_CONSOLE
|
||||
static void null_input_post_init(void)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
static void null_input_poll(void *data)
|
||||
{
|
||||
(void)data;
|
||||
|
@ -52,7 +58,8 @@ static void null_input_free(void *data)
|
|||
}
|
||||
|
||||
#ifdef RARCH_CONSOLE
|
||||
static void null_set_default_keybind_lut(void) {}
|
||||
static void null_set_default_keybind_lut(void) { }
|
||||
static void null_set_analog_dpad_mapping(unsigned map_dpad_enum, unsigned controller_id) { }
|
||||
#endif
|
||||
|
||||
const input_driver_t input_null = {
|
||||
|
@ -63,6 +70,9 @@ const input_driver_t input_null = {
|
|||
null_input_free,
|
||||
#ifdef RARCH_CONSOLE
|
||||
null_set_default_keybind_lut,
|
||||
null_set_analog_dpad_mapping,
|
||||
null_input_post_init,
|
||||
2,
|
||||
#endif
|
||||
"null",
|
||||
};
|
||||
|
|
|
@ -251,6 +251,8 @@ int main(int argc, char *argv[])
|
|||
snprintf(tmp_path, sizeof(tmp_path), "%s/", default_paths.core_dir);
|
||||
rarch_configure_libretro(&input_ps3, tmp_path, default_paths.executable_extension);
|
||||
|
||||
input_ps3.post_init();
|
||||
|
||||
#if(CELL_SDK_VERSION > 0x340000)
|
||||
if (g_console.screenshots_enable)
|
||||
{
|
||||
|
|
|
@ -373,24 +373,7 @@ void oskutil_unload(oskutil_params *params)
|
|||
RetroArch PS3 INPUT DRIVER
|
||||
============================================================ */
|
||||
|
||||
static void ps3_free_input(void *data)
|
||||
{
|
||||
(void)data;
|
||||
//cellPadEnd();
|
||||
}
|
||||
|
||||
static void* ps3_input_initialize(void)
|
||||
{
|
||||
cellPadInit(MAX_PADS);
|
||||
#ifdef HAVE_MOUSE
|
||||
cellMouseInit(MAX_MICE);
|
||||
#endif
|
||||
for(unsigned i = 0; i < MAX_PADS; i++)
|
||||
ps3_input_map_dpad_to_stick(g_settings.input.dpad_emulation[i], i);
|
||||
return (void*)-1;
|
||||
}
|
||||
|
||||
void ps3_input_map_dpad_to_stick(uint32_t map_dpad_enum, uint32_t controller_id)
|
||||
static void ps3_input_set_analog_dpad_mapping(unsigned map_dpad_enum, unsigned controller_id)
|
||||
{
|
||||
switch(map_dpad_enum)
|
||||
{
|
||||
|
@ -415,6 +398,27 @@ void ps3_input_map_dpad_to_stick(uint32_t map_dpad_enum, uint32_t controller_id)
|
|||
}
|
||||
}
|
||||
|
||||
static void ps3_free_input(void *data)
|
||||
{
|
||||
(void)data;
|
||||
//cellPadEnd();
|
||||
}
|
||||
|
||||
static void* ps3_input_initialize(void)
|
||||
{
|
||||
cellPadInit(MAX_PADS);
|
||||
#ifdef HAVE_MOUSE
|
||||
cellMouseInit(MAX_MICE);
|
||||
#endif
|
||||
return (void*)-1;
|
||||
}
|
||||
|
||||
static void ps3_input_post_init(void)
|
||||
{
|
||||
for(unsigned i = 0; i < MAX_PADS; i++)
|
||||
ps3_input_set_analog_dpad_mapping(g_settings.input.dpad_emulation[i], i);
|
||||
}
|
||||
|
||||
static bool ps3_key_pressed(void *data, int key)
|
||||
{
|
||||
(void)data;
|
||||
|
@ -497,6 +501,9 @@ const input_driver_t input_ps3 = {
|
|||
.key_pressed = ps3_key_pressed,
|
||||
.free = ps3_free_input,
|
||||
.set_default_keybind_lut = ps3_set_default_keybind_lut,
|
||||
.set_analog_dpad_mapping = ps3_input_set_analog_dpad_mapping,
|
||||
.post_init = ps3_input_post_init,
|
||||
.max_pads = MAX_PADS,
|
||||
.ident = "ps3",
|
||||
};
|
||||
|
||||
|
|
|
@ -135,8 +135,6 @@
|
|||
|
||||
uint64_t cell_pad_input_poll_device(uint32_t id);
|
||||
|
||||
void ps3_input_map_dpad_to_stick(uint32_t map_dpad_enum, uint32_t controller_id);
|
||||
|
||||
#ifdef HAVE_OSKUTIL
|
||||
|
||||
typedef struct
|
||||
|
|
|
@ -214,6 +214,8 @@ int main(void)
|
|||
input_wii.init();
|
||||
rarch_input_set_controls_default(&input_wii);
|
||||
|
||||
input_wii.post_init();
|
||||
|
||||
rgui_handle_t *rgui = rgui_init("",
|
||||
menu_framebuf, RGUI_WIDTH * sizeof(uint16_t),
|
||||
_binary_console_font_bmp_start, folder_cb, NULL);
|
||||
|
|
|
@ -35,7 +35,9 @@
|
|||
|
||||
#define JOYSTICK_THRESHOLD 64
|
||||
|
||||
static uint64_t pad_state[4];
|
||||
#define MAX_PADS 4
|
||||
|
||||
static uint64_t pad_state[MAX_PADS];
|
||||
|
||||
const struct platform_bind platform_keys[] = {
|
||||
{ WII_GC_A, "GC A button" },
|
||||
|
@ -136,7 +138,7 @@ static int16_t wii_input_state(void *data, const struct retro_keybind **binds,
|
|||
(void)data;
|
||||
(void)index;
|
||||
|
||||
if (port >= 4 || device != RETRO_DEVICE_JOYPAD)
|
||||
if (port >= MAX_PADS || device != RETRO_DEVICE_JOYPAD)
|
||||
return 0;
|
||||
|
||||
return (binds[port][id].joykey & pad_state[port]) ? 1 : 0;
|
||||
|
@ -152,7 +154,7 @@ static void reset_callback(void)
|
|||
g_quit = true;
|
||||
}
|
||||
|
||||
void wii_input_map_dpad_to_stick(uint32_t map_dpad_enum, uint32_t controller_id)
|
||||
static void wii_input_set_analog_dpad_mapping(unsigned map_dpad_enum, unsigned controller_id)
|
||||
{
|
||||
// TODO: how do we choose a classic controller configuration over a gc controller one?
|
||||
switch(map_dpad_enum)
|
||||
|
@ -186,11 +188,15 @@ static void *wii_input_initialize(void)
|
|||
#endif
|
||||
SYS_SetResetCallback(reset_callback);
|
||||
SYS_SetPowerCallback(reset_callback);
|
||||
for(unsigned i = 0; i < 4; i++)
|
||||
wii_input_map_dpad_to_stick(g_settings.input.dpad_emulation[i], i);
|
||||
return (void*)-1;
|
||||
}
|
||||
|
||||
static void wii_input_post_init(void)
|
||||
{
|
||||
for(unsigned i = 0; i < MAX_PADS; i++)
|
||||
wii_input_set_analog_dpad_mapping(g_settings.input.dpad_emulation[i], i);
|
||||
}
|
||||
|
||||
#define wii_stick_x(x) ((s8)((sin((x).ang * M_PI / 180.0f)) * (x).mag * 128.0f))
|
||||
#define wii_stick_y(x) ((s8)((cos((x).ang * M_PI / 180.0f)) * (x).mag * 128.0f))
|
||||
|
||||
|
@ -203,7 +209,7 @@ static void wii_input_poll(void *data)
|
|||
unsigned wpads = WPAD_ScanPads();
|
||||
#endif
|
||||
|
||||
for (unsigned port = 0; port < 4; port++)
|
||||
for (unsigned port = 0; port < MAX_PADS; port++)
|
||||
{
|
||||
uint64_t state = 0;
|
||||
if (port < pads)
|
||||
|
@ -395,5 +401,8 @@ const input_driver_t input_wii = {
|
|||
.key_pressed = wii_key_pressed,
|
||||
.free = wii_free_input,
|
||||
.set_default_keybind_lut = wii_set_default_keybind_lut,
|
||||
.set_analog_dpad_mapping = wii_input_set_analog_dpad_mapping,
|
||||
.post_init = wii_input_post_init,
|
||||
.max_pads = MAX_PADS,
|
||||
.ident = "wii",
|
||||
};
|
||||
|
|
|
@ -21,16 +21,18 @@
|
|||
#include <xtl.h>
|
||||
#endif
|
||||
|
||||
#define MAX_PADS 4
|
||||
|
||||
#include "../driver.h"
|
||||
#include "../general.h"
|
||||
#include "../libretro.h"
|
||||
#include "xinput_xbox_input.h"
|
||||
|
||||
static uint64_t real_state[4];
|
||||
HANDLE gamepads[4];
|
||||
static uint64_t real_state[MAX_PADS];
|
||||
HANDLE gamepads[MAX_PADS];
|
||||
DWORD dwDeviceMask;
|
||||
bool bInserted[4];
|
||||
bool bRemoved[4];
|
||||
bool bInserted[MAX_PADS];
|
||||
bool bRemoved[MAX_PADS];
|
||||
|
||||
const struct platform_bind platform_keys[] = {
|
||||
{ XINPUT1_GAMEPAD_B, "B button" },
|
||||
|
@ -82,10 +84,10 @@ static void xinput_input_poll(void *data)
|
|||
|
||||
pads_connected = 0;
|
||||
|
||||
for (unsigned i = 0; i < 4; i++)
|
||||
for (unsigned i = 0; i < MAX_PADS; i++)
|
||||
{
|
||||
XINPUT_STATE state[4];
|
||||
XINPUT_CAPABILITIES caps[4];
|
||||
XINPUT_STATE state[MAX_PADS];
|
||||
XINPUT_CAPABILITIES caps[MAX_PADS];
|
||||
(void)caps;
|
||||
real_state[i] = 0;
|
||||
// handle removed devices
|
||||
|
@ -162,36 +164,6 @@ static void xinput_input_free_input(void *data)
|
|||
(void)data;
|
||||
}
|
||||
|
||||
static void* xinput_input_init(void)
|
||||
{
|
||||
XInitDevices(0, NULL);
|
||||
|
||||
dwDeviceMask = XGetDevices(XDEVICE_TYPE_GAMEPAD);
|
||||
|
||||
//Check the device status
|
||||
switch(XGetDeviceEnumerationStatus())
|
||||
{
|
||||
case XDEVICE_ENUMERATION_IDLE:
|
||||
RARCH_LOG("Input state status: XDEVICE_ENUMERATION_IDLE\n");
|
||||
break;
|
||||
case XDEVICE_ENUMERATION_BUSY:
|
||||
RARCH_LOG("Input state status: XDEVICE_ENUMERATION_BUSY\n");
|
||||
break;
|
||||
}
|
||||
|
||||
while(XGetDeviceEnumerationStatus() == XDEVICE_ENUMERATION_BUSY) {}
|
||||
|
||||
return (void*)-1;
|
||||
}
|
||||
|
||||
static bool xinput_input_key_pressed(void *data, int key)
|
||||
{
|
||||
(void)data;
|
||||
bool retval = false;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
static void xinput_set_default_keybind_lut(void)
|
||||
{
|
||||
rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_B] = platform_keys[XDK_DEVICE_ID_JOYPAD_A].joykey;
|
||||
|
@ -219,6 +191,46 @@ static void xinput_set_default_keybind_lut(void)
|
|||
rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_R3] = platform_keys[XDK_DEVICE_ID_RSTICK_THUMB].joykey;
|
||||
}
|
||||
|
||||
static void xinput_input_set_analog_dpad_mapping(unsigned map_dpad_enum, unsigned controller_id)
|
||||
{
|
||||
}
|
||||
|
||||
static void* xinput_input_init(void)
|
||||
{
|
||||
XInitDevices(0, NULL);
|
||||
|
||||
dwDeviceMask = XGetDevices(XDEVICE_TYPE_GAMEPAD);
|
||||
|
||||
//Check the device status
|
||||
switch(XGetDeviceEnumerationStatus())
|
||||
{
|
||||
case XDEVICE_ENUMERATION_IDLE:
|
||||
RARCH_LOG("Input state status: XDEVICE_ENUMERATION_IDLE\n");
|
||||
break;
|
||||
case XDEVICE_ENUMERATION_BUSY:
|
||||
RARCH_LOG("Input state status: XDEVICE_ENUMERATION_BUSY\n");
|
||||
break;
|
||||
}
|
||||
|
||||
while(XGetDeviceEnumerationStatus() == XDEVICE_ENUMERATION_BUSY) {}
|
||||
|
||||
return (void*)-1;
|
||||
}
|
||||
|
||||
static void xinput_input_post_init(void)
|
||||
{
|
||||
for(unsigned i = 0; i < MAX_PADS; i++)
|
||||
xinput_input_set_analog_pad_mapping(g_settings.input.dpad_emulation[i], i);
|
||||
}
|
||||
|
||||
static bool xinput_input_key_pressed(void *data, int key)
|
||||
{
|
||||
(void)data;
|
||||
bool retval = false;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
const input_driver_t input_xinput =
|
||||
{
|
||||
xinput_input_init,
|
||||
|
@ -227,5 +239,8 @@ const input_driver_t input_xinput =
|
|||
xinput_input_key_pressed,
|
||||
xinput_input_free_input,
|
||||
xinput_set_default_keybind_lut,
|
||||
xinput_input_set_analog_dpad_mapping,
|
||||
xinput_input_post_init,
|
||||
MAX_PADS,
|
||||
"xinput"
|
||||
};
|
||||
|
|
|
@ -128,6 +128,8 @@ int main(int argc, char *argv[])
|
|||
input_xinput.init();
|
||||
rarch_configure_libretro(&input_xinput, default_paths.filesystem_root_dir, default_paths.executable_extension);
|
||||
|
||||
input_xinput.post_init();
|
||||
|
||||
#if defined(HAVE_D3D8) || defined(HAVE_D3D9)
|
||||
video_xdk_d3d.start();
|
||||
#else
|
||||
|
|
Loading…
Add table
Reference in a new issue