Joystick: Replace magic numbers for maximum axes/buttons/POVs with macros
This commit is contained in:
@@ -24,6 +24,10 @@
|
||||
#define MAX_PLAT_JOYSTICKS 8
|
||||
#define MAX_JOYSTICKS 4
|
||||
|
||||
#define MAX_JOY_AXES 8
|
||||
#define MAX_JOY_BUTTONS 32
|
||||
#define MAX_JOY_POVS 4
|
||||
|
||||
#define JS_TYPE_NONE 0
|
||||
#define JS_TYPE_2AXIS_4BUTTON 1
|
||||
#define JS_TYPE_2AXIS_6BUTTON 2
|
||||
@@ -46,24 +50,24 @@
|
||||
typedef struct plat_joystick_t {
|
||||
char name[260];
|
||||
|
||||
int a[8];
|
||||
int b[32];
|
||||
int p[4];
|
||||
int a[MAX_JOY_AXES];
|
||||
int b[MAX_JOY_BUTTONS];
|
||||
int p[MAX_JOY_POVS];
|
||||
|
||||
struct {
|
||||
char name[260];
|
||||
int id;
|
||||
} axis[8];
|
||||
} axis[MAX_JOY_AXES];
|
||||
|
||||
struct {
|
||||
char name[260];
|
||||
int id;
|
||||
} button[32];
|
||||
} button[MAX_JOY_BUTTONS];
|
||||
|
||||
struct {
|
||||
char name[260];
|
||||
int id;
|
||||
} pov[4];
|
||||
} pov[MAX_JOY_POVS];
|
||||
|
||||
int nr_axes;
|
||||
int nr_buttons;
|
||||
@@ -71,14 +75,14 @@ typedef struct plat_joystick_t {
|
||||
} plat_joystick_t;
|
||||
|
||||
typedef struct joystick_t {
|
||||
int axis[8];
|
||||
int button[32];
|
||||
int pov[4];
|
||||
int axis[MAX_JOY_AXES];
|
||||
int button[MAX_JOY_BUTTONS];
|
||||
int pov[MAX_JOY_POVS];
|
||||
|
||||
int plat_joystick_nr;
|
||||
int axis_mapping[8];
|
||||
int button_mapping[32];
|
||||
int pov_mapping[4][2];
|
||||
int axis_mapping[MAX_JOY_AXES];
|
||||
int button_mapping[MAX_JOY_BUTTONS];
|
||||
int pov_mapping[MAX_JOY_POVS][2];
|
||||
} joystick_t;
|
||||
|
||||
typedef struct joystick_if_t {
|
||||
@@ -96,9 +100,9 @@ typedef struct joystick_if_t {
|
||||
int button_count;
|
||||
int pov_count;
|
||||
int max_joysticks;
|
||||
const char *axis_names[8];
|
||||
const char *button_names[32];
|
||||
const char *pov_names[4];
|
||||
const char *axis_names[MAX_JOY_AXES];
|
||||
const char *button_names[MAX_JOY_BUTTONS];
|
||||
const char *pov_names[MAX_JOY_POVS];
|
||||
} joystick_if_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@@ -88,14 +88,14 @@ typedef struct {
|
||||
USHORT bitsize;
|
||||
LONG max;
|
||||
LONG min;
|
||||
} axis[8];
|
||||
} axis[MAX_JOY_AXES];
|
||||
|
||||
struct raw_pov_t {
|
||||
USAGE usage;
|
||||
USHORT link;
|
||||
LONG max;
|
||||
LONG min;
|
||||
} pov[4];
|
||||
} pov[MAX_JOY_POVS];
|
||||
} raw_joystick_t;
|
||||
|
||||
plat_joystick_t plat_joystick_state[MAX_PLAT_JOYSTICKS];
|
||||
@@ -108,7 +108,7 @@ raw_joystick_t raw_joystick_state[MAX_PLAT_JOYSTICKS];
|
||||
void
|
||||
joystick_add_button(raw_joystick_t *rawjoy, plat_joystick_t *joy, USAGE usage)
|
||||
{
|
||||
if (joy->nr_buttons >= 32)
|
||||
if (joy->nr_buttons >= MAX_JOY_BUTTONS)
|
||||
return;
|
||||
if (usage < 1 || usage > 128)
|
||||
return;
|
||||
@@ -121,7 +121,7 @@ joystick_add_button(raw_joystick_t *rawjoy, plat_joystick_t *joy, USAGE usage)
|
||||
void
|
||||
joystick_add_axis(raw_joystick_t *rawjoy, plat_joystick_t *joy, PHIDP_VALUE_CAPS prop)
|
||||
{
|
||||
if (joy->nr_axes >= 8)
|
||||
if (joy->nr_axes >= MAX_JOY_AXES)
|
||||
return;
|
||||
|
||||
switch (prop->Range.UsageMin) {
|
||||
@@ -206,7 +206,7 @@ joystick_add_axis(raw_joystick_t *rawjoy, plat_joystick_t *joy, PHIDP_VALUE_CAPS
|
||||
void
|
||||
joystick_add_pov(raw_joystick_t *rawjoy, plat_joystick_t *joy, PHIDP_VALUE_CAPS prop)
|
||||
{
|
||||
if (joy->nr_povs >= 4)
|
||||
if (joy->nr_povs >= MAX_JOY_POVS)
|
||||
return;
|
||||
|
||||
sprintf(joy->pov[joy->nr_povs].name, "POV %d", joy->nr_povs + 1);
|
||||
|
@@ -84,7 +84,7 @@ DIEnumDeviceObjectsCallback(
|
||||
plat_joystick_t *state = (plat_joystick_t *) pvRef;
|
||||
|
||||
if (lpddoi->guidType == GUID_XAxis || lpddoi->guidType == GUID_YAxis || lpddoi->guidType == GUID_ZAxis || lpddoi->guidType == GUID_RxAxis || lpddoi->guidType == GUID_RyAxis || lpddoi->guidType == GUID_RzAxis) {
|
||||
if (state->nr_axes < 8) {
|
||||
if (state->nr_axes < MAX_JOY_AXES) {
|
||||
memcpy(state->axis[state->nr_axes].name, lpddoi->tszName, strlen(lpddoi->tszName) + 1);
|
||||
joystick_log("Axis %i : %s %x %x\n", state->nr_axes, state->axis[state->nr_axes].name, lpddoi->dwOfs, lpddoi->dwType);
|
||||
if (lpddoi->guidType == GUID_XAxis)
|
||||
@@ -106,13 +106,13 @@ DIEnumDeviceObjectsCallback(
|
||||
state->nr_axes++;
|
||||
}
|
||||
} else if (lpddoi->guidType == GUID_Button) {
|
||||
if (state->nr_buttons < 32) {
|
||||
if (state->nr_buttons < MAX_JOY_BUTTONS) {
|
||||
memcpy(state->button[state->nr_buttons].name, lpddoi->tszName, strlen(lpddoi->tszName) + 1);
|
||||
joystick_log("Button %i : %s %x %x\n", state->nr_buttons, state->button[state->nr_buttons].name, lpddoi->dwOfs, lpddoi->dwType);
|
||||
state->nr_buttons++;
|
||||
}
|
||||
} else if (lpddoi->guidType == GUID_POV) {
|
||||
if (state->nr_povs < 4) {
|
||||
if (state->nr_povs < MAX_JOY_POVS) {
|
||||
memcpy(state->pov[state->nr_povs].name, lpddoi->tszName, strlen(lpddoi->tszName) + 1);
|
||||
joystick_log("POV %i : %s %x %x\n", state->nr_povs, state->pov[state->nr_povs].name, lpddoi->dwOfs, lpddoi->dwType);
|
||||
state->nr_povs++;
|
||||
@@ -269,10 +269,10 @@ joystick_process(void)
|
||||
plat_joystick_state[c].a[6] = joystate.rglSlider[0];
|
||||
plat_joystick_state[c].a[7] = joystate.rglSlider[1];
|
||||
|
||||
for (b = 0; b < 16; b++)
|
||||
for (b = 0; b < MAX_JOY_BUTTONS; b++)
|
||||
plat_joystick_state[c].b[b] = joystate.rgbButtons[b] & 0x80;
|
||||
|
||||
for (b = 0; b < 4; b++)
|
||||
for (b = 0; b < MAX_JOY_POVS; b++)
|
||||
plat_joystick_state[c].p[b] = joystate.rgdwPOV[b];
|
||||
// joystick_log("joystick %i - x=%i y=%i b[0]=%i b[1]=%i %i\n", c, joystick_state[c].x, joystick_state[c].y, joystick_state[c].b[0], joystick_state[c].b[1], joysticks_present);
|
||||
}
|
||||
|
@@ -88,14 +88,14 @@ typedef struct {
|
||||
USHORT bitsize;
|
||||
LONG max;
|
||||
LONG min;
|
||||
} axis[8];
|
||||
} axis[MAX_JOY_AXES];
|
||||
|
||||
struct raw_pov_t {
|
||||
USAGE usage;
|
||||
USHORT link;
|
||||
LONG max;
|
||||
LONG min;
|
||||
} pov[4];
|
||||
} pov[MAX_JOY_POVS];
|
||||
} raw_joystick_t;
|
||||
|
||||
plat_joystick_t plat_joystick_state[MAX_PLAT_JOYSTICKS];
|
||||
@@ -108,7 +108,7 @@ raw_joystick_t raw_joystick_state[MAX_PLAT_JOYSTICKS];
|
||||
void
|
||||
joystick_add_button(raw_joystick_t *rawjoy, plat_joystick_t *joy, USAGE usage)
|
||||
{
|
||||
if (joy->nr_buttons >= 32)
|
||||
if (joy->nr_buttons >= MAX_JOY_BUTTONS)
|
||||
return;
|
||||
if (usage < 1 || usage > 128)
|
||||
return;
|
||||
@@ -121,7 +121,7 @@ joystick_add_button(raw_joystick_t *rawjoy, plat_joystick_t *joy, USAGE usage)
|
||||
void
|
||||
joystick_add_axis(raw_joystick_t *rawjoy, plat_joystick_t *joy, PHIDP_VALUE_CAPS prop)
|
||||
{
|
||||
if (joy->nr_axes >= 8)
|
||||
if (joy->nr_axes >= MAX_JOY_AXES)
|
||||
return;
|
||||
|
||||
switch (prop->Range.UsageMin) {
|
||||
@@ -206,7 +206,7 @@ joystick_add_axis(raw_joystick_t *rawjoy, plat_joystick_t *joy, PHIDP_VALUE_CAPS
|
||||
void
|
||||
joystick_add_pov(raw_joystick_t *rawjoy, plat_joystick_t *joy, PHIDP_VALUE_CAPS prop)
|
||||
{
|
||||
if (joy->nr_povs >= 4)
|
||||
if (joy->nr_povs >= MAX_JOY_POVS)
|
||||
return;
|
||||
|
||||
sprintf(joy->pov[joy->nr_povs].name, "POV %d", joy->nr_povs + 1);
|
||||
|
Reference in New Issue
Block a user