(DInput) Cleanups
This commit is contained in:
parent
bbcc863270
commit
748886c5e5
|
@ -36,45 +36,28 @@
|
||||||
#include "../../verbosity.h"
|
#include "../../verbosity.h"
|
||||||
#include "dinput_joypad.h"
|
#include "dinput_joypad.h"
|
||||||
|
|
||||||
/* For DIJOYSTATE2 struct, rgbButtons will always have 128 elements */
|
|
||||||
#define ARRAY_SIZE_RGB_BUTTONS 128
|
|
||||||
|
|
||||||
#ifndef NUM_HATS
|
|
||||||
#define NUM_HATS 4
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct dinput_joypad_data
|
|
||||||
{
|
|
||||||
LPDIRECTINPUTDEVICE8 joypad;
|
|
||||||
DIJOYSTATE2 joy_state;
|
|
||||||
char* joy_name;
|
|
||||||
char* joy_friendly_name;
|
|
||||||
int32_t vid;
|
|
||||||
int32_t pid;
|
|
||||||
LPDIRECTINPUTEFFECT rumble_iface[2];
|
|
||||||
DIEFFECT rumble_props;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* TODO/FIXME - static globals */
|
/* TODO/FIXME - static globals */
|
||||||
static struct dinput_joypad_data g_pads[MAX_USERS];
|
static struct dinput_joypad_data g_pads[MAX_USERS];
|
||||||
static unsigned g_joypad_cnt;
|
static unsigned g_joypad_cnt;
|
||||||
#ifdef HAVE_XINPUT
|
#ifdef HAVE_XINPUT
|
||||||
static unsigned g_last_xinput_pad_idx;
|
static unsigned g_last_xinput_pad_idx;
|
||||||
#endif
|
|
||||||
|
|
||||||
static const GUID common_xinput_guids[] = {
|
static const GUID common_xinput_guids[] = {
|
||||||
{MAKELONG(0x28DE, 0x11FF),0x0000,0x0000,{0x00,0x00,0x50,0x49,0x44,0x56,0x49,0x44}}, /* Valve streaming pad */
|
{MAKELONG(0x28DE, 0x11FF),0x0000,0x0000,{0x00,0x00,0x50,0x49,0x44,0x56,0x49,0x44}}, /* Valve streaming pad */
|
||||||
{MAKELONG(0x045E, 0x02A1),0x0000,0x0000,{0x00,0x00,0x50,0x49,0x44,0x56,0x49,0x44}}, /* Wired 360 pad */
|
{MAKELONG(0x045E, 0x02A1),0x0000,0x0000,{0x00,0x00,0x50,0x49,0x44,0x56,0x49,0x44}}, /* Wired 360 pad */
|
||||||
{MAKELONG(0x045E, 0x028E),0x0000,0x0000,{0x00,0x00,0x50,0x49,0x44,0x56,0x49,0x44}} /* wireless 360 pad */
|
{MAKELONG(0x045E, 0x028E),0x0000,0x0000,{0x00,0x00,0x50,0x49,0x44,0x56,0x49,0x44}} /* wireless 360 pad */
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
/* forward declarations */
|
/* forward declarations */
|
||||||
void dinput_destroy_context(void);
|
void dinput_destroy_context(void);
|
||||||
bool dinput_init_context(void);
|
bool dinput_init_context(void);
|
||||||
|
|
||||||
|
extern LPDIRECTINPUT8 g_dinput_ctx;
|
||||||
|
|
||||||
|
#ifdef HAVE_XINPUT
|
||||||
extern bool g_xinput_block_pads;
|
extern bool g_xinput_block_pads;
|
||||||
extern int g_xinput_pad_indexes[MAX_USERS];
|
extern int g_xinput_pad_indexes[MAX_USERS];
|
||||||
extern LPDIRECTINPUT8 g_dinput_ctx;
|
|
||||||
|
|
||||||
bool dinput_joypad_get_vidpid_from_xinput_index(
|
bool dinput_joypad_get_vidpid_from_xinput_index(
|
||||||
int32_t index, int32_t *vid,
|
int32_t index, int32_t *vid,
|
||||||
|
@ -102,6 +85,7 @@ bool dinput_joypad_get_vidpid_from_xinput_index(
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static void dinput_joypad_destroy(void)
|
static void dinput_joypad_destroy(void)
|
||||||
{
|
{
|
||||||
|
@ -171,23 +155,21 @@ static void dinput_create_rumble_effects(struct dinput_joypad_data *pad)
|
||||||
pad->rumble_props.rgdwAxes = &axis;
|
pad->rumble_props.rgdwAxes = &axis;
|
||||||
pad->rumble_props.rglDirection = &direction;
|
pad->rumble_props.rglDirection = &direction;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
if (IDirectInputDevice8_CreateEffect(pad->joypad, GUID_ConstantForce,
|
|
||||||
&pad->rumble_props, &pad->rumble_iface[0], NULL) != DI_OK)
|
|
||||||
RARCH_WARN("[DINPUT]: Strong rumble unavailable.\n");
|
|
||||||
#else
|
|
||||||
if (IDirectInputDevice8_CreateEffect(pad->joypad, &GUID_ConstantForce,
|
|
||||||
&pad->rumble_props, &pad->rumble_iface[0], NULL) != DI_OK)
|
|
||||||
RARCH_WARN("[DINPUT]: Strong rumble unavailable.\n");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
axis = DIJOFS_Y;
|
axis = DIJOFS_Y;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
if (IDirectInputDevice8_CreateEffect(pad->joypad, GUID_ConstantForce,
|
||||||
|
&pad->rumble_props, &pad->rumble_iface[0], NULL) != DI_OK)
|
||||||
|
RARCH_WARN("[DINPUT]: Strong rumble unavailable.\n");
|
||||||
|
|
||||||
if (IDirectInputDevice8_CreateEffect(pad->joypad, GUID_ConstantForce,
|
if (IDirectInputDevice8_CreateEffect(pad->joypad, GUID_ConstantForce,
|
||||||
&pad->rumble_props, &pad->rumble_iface[1], NULL) != DI_OK)
|
&pad->rumble_props, &pad->rumble_iface[1], NULL) != DI_OK)
|
||||||
RARCH_WARN("[DINPUT]: Weak rumble unavailable.\n");
|
RARCH_WARN("[DINPUT]: Weak rumble unavailable.\n");
|
||||||
#else
|
#else
|
||||||
|
if (IDirectInputDevice8_CreateEffect(pad->joypad, &GUID_ConstantForce,
|
||||||
|
&pad->rumble_props, &pad->rumble_iface[0], NULL) != DI_OK)
|
||||||
|
RARCH_WARN("[DINPUT]: Strong rumble unavailable.\n");
|
||||||
|
|
||||||
if (IDirectInputDevice8_CreateEffect(pad->joypad, &GUID_ConstantForce,
|
if (IDirectInputDevice8_CreateEffect(pad->joypad, &GUID_ConstantForce,
|
||||||
&pad->rumble_props, &pad->rumble_iface[1], NULL) != DI_OK)
|
&pad->rumble_props, &pad->rumble_iface[1], NULL) != DI_OK)
|
||||||
RARCH_WARN("[DINPUT]: Weak rumble unavailable.\n");
|
RARCH_WARN("[DINPUT]: Weak rumble unavailable.\n");
|
||||||
|
@ -311,7 +293,6 @@ static const char *dinput_joypad_name(unsigned port)
|
||||||
{
|
{
|
||||||
if (port < MAX_USERS)
|
if (port < MAX_USERS)
|
||||||
return g_pads[port].joy_name;
|
return g_pads[port].joy_name;
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -321,9 +302,6 @@ static BOOL CALLBACK enum_joypad_cb(const DIDEVICEINSTANCE *inst, void *p)
|
||||||
bool is_xinput_pad;
|
bool is_xinput_pad;
|
||||||
#endif
|
#endif
|
||||||
LPDIRECTINPUTDEVICE8 *pad = NULL;
|
LPDIRECTINPUTDEVICE8 *pad = NULL;
|
||||||
|
|
||||||
(void)p;
|
|
||||||
|
|
||||||
if (g_joypad_cnt == MAX_USERS)
|
if (g_joypad_cnt == MAX_USERS)
|
||||||
return DIENUM_STOP;
|
return DIENUM_STOP;
|
||||||
|
|
||||||
|
@ -341,7 +319,8 @@ static BOOL CALLBACK enum_joypad_cb(const DIDEVICEINSTANCE *inst, void *p)
|
||||||
g_pads[g_joypad_cnt].joy_name = strdup((const char*)inst->tszProductName);
|
g_pads[g_joypad_cnt].joy_name = strdup((const char*)inst->tszProductName);
|
||||||
g_pads[g_joypad_cnt].joy_friendly_name = strdup((const char*)inst->tszInstanceName);
|
g_pads[g_joypad_cnt].joy_friendly_name = strdup((const char*)inst->tszInstanceName);
|
||||||
|
|
||||||
/* there may be more useful info in the GUID so leave this here for a while */
|
/* there may be more useful info in the GUID,
|
||||||
|
* so leave this here for a while */
|
||||||
#if 0
|
#if 0
|
||||||
printf("Guid = {%08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX}\n",
|
printf("Guid = {%08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX}\n",
|
||||||
inst->guidProduct.Data1,
|
inst->guidProduct.Data1,
|
||||||
|
@ -407,8 +386,6 @@ static bool dinput_joypad_init(void *data)
|
||||||
{
|
{
|
||||||
unsigned i;
|
unsigned i;
|
||||||
|
|
||||||
(void)data;
|
|
||||||
|
|
||||||
if (!dinput_init_context())
|
if (!dinput_init_context())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -418,7 +395,9 @@ static bool dinput_joypad_init(void *data)
|
||||||
|
|
||||||
for (i = 0; i < MAX_USERS; ++i)
|
for (i = 0; i < MAX_USERS; ++i)
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_XINPUT
|
||||||
g_xinput_pad_indexes[i] = -1;
|
g_xinput_pad_indexes[i] = -1;
|
||||||
|
#endif
|
||||||
g_pads[i].joy_name = NULL;
|
g_pads[i].joy_name = NULL;
|
||||||
g_pads[i].joy_friendly_name = NULL;
|
g_pads[i].joy_friendly_name = NULL;
|
||||||
}
|
}
|
||||||
|
@ -437,7 +416,9 @@ static int16_t dinput_joypad_button_state(
|
||||||
if (hat_dir)
|
if (hat_dir)
|
||||||
{
|
{
|
||||||
unsigned h = GET_HAT(joykey);
|
unsigned h = GET_HAT(joykey);
|
||||||
if (h < NUM_HATS)
|
|
||||||
|
/* 4 is number of hats */
|
||||||
|
if (h < 4)
|
||||||
{
|
{
|
||||||
unsigned pov = pad->joy_state.rgdwPOV[h];
|
unsigned pov = pad->joy_state.rgdwPOV[h];
|
||||||
switch (hat_dir)
|
switch (hat_dir)
|
||||||
|
@ -612,9 +593,12 @@ static void dinput_joypad_poll(void)
|
||||||
unsigned j;
|
unsigned j;
|
||||||
HRESULT ret;
|
HRESULT ret;
|
||||||
struct dinput_joypad_data *pad = &g_pads[i];
|
struct dinput_joypad_data *pad = &g_pads[i];
|
||||||
|
#ifdef HAVE_XINPUT
|
||||||
bool polled = g_xinput_pad_indexes[i] < 0;
|
bool polled = g_xinput_pad_indexes[i] < 0;
|
||||||
|
if (!polled)
|
||||||
if (!pad || !pad->joypad || !polled)
|
continue;
|
||||||
|
#endif
|
||||||
|
if (!pad || !pad->joypad)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
pad->joy_state.lX = 0;
|
pad->joy_state.lX = 0;
|
||||||
|
|
|
@ -22,8 +22,25 @@
|
||||||
#include <boolean.h>
|
#include <boolean.h>
|
||||||
#include <retro_common_api.h>
|
#include <retro_common_api.h>
|
||||||
|
|
||||||
|
#include <dinput.h>
|
||||||
|
|
||||||
|
/* For DIJOYSTATE2 struct, rgbButtons will always have 128 elements */
|
||||||
|
#define ARRAY_SIZE_RGB_BUTTONS 128
|
||||||
|
|
||||||
RETRO_BEGIN_DECLS
|
RETRO_BEGIN_DECLS
|
||||||
|
|
||||||
|
struct dinput_joypad_data
|
||||||
|
{
|
||||||
|
LPDIRECTINPUTDEVICE8 joypad;
|
||||||
|
DIJOYSTATE2 joy_state;
|
||||||
|
char* joy_name;
|
||||||
|
char* joy_friendly_name;
|
||||||
|
int32_t vid;
|
||||||
|
int32_t pid;
|
||||||
|
LPDIRECTINPUTEFFECT rumble_iface[2];
|
||||||
|
DIEFFECT rumble_props;
|
||||||
|
};
|
||||||
|
|
||||||
bool dinput_joypad_get_vidpid_from_xinput_index(
|
bool dinput_joypad_get_vidpid_from_xinput_index(
|
||||||
int32_t index, int32_t *vid,
|
int32_t index, int32_t *vid,
|
||||||
int32_t *pid, int32_t *dinput_index);
|
int32_t *pid, int32_t *dinput_index);
|
||||||
|
|
Loading…
Reference in New Issue