Joystick: Remove the leftover separate slider handling

This commit is contained in:
Alexander Babikov
2024-02-18 16:37:46 +05:00
parent 1e23813057
commit d789292f65
5 changed files with 16 additions and 51 deletions

View File

@@ -36,7 +36,6 @@
#define POV_X 0x80000000 #define POV_X 0x80000000
#define POV_Y 0x40000000 #define POV_Y 0x40000000
#define SLIDER 0x20000000
#define AXIS_NOT_PRESENT -99999 #define AXIS_NOT_PRESENT -99999
@@ -50,7 +49,6 @@ typedef struct plat_joystick_t {
int a[8]; int a[8];
int b[32]; int b[32];
int p[4]; int p[4];
int s[2];
struct { struct {
char name[260]; char name[260];
@@ -67,15 +65,9 @@ typedef struct plat_joystick_t {
int id; int id;
} pov[4]; } pov[4];
struct {
char name[260];
int id;
} slider[2];
int nr_axes; int nr_axes;
int nr_buttons; int nr_buttons;
int nr_povs; int nr_povs;
int nr_sliders;
} plat_joystick_t; } plat_joystick_t;
typedef struct joystick_t { typedef struct joystick_t {

View File

@@ -118,19 +118,12 @@ JoystickConfiguration::on_comboBoxDevice_currentIndexChanged(int index)
Models::AddEntry(model, QString("%1 (Y axis)").arg(plat_joystick_state[joystick].pov[d].name), 0); Models::AddEntry(model, QString("%1 (Y axis)").arg(plat_joystick_state[joystick].pov[d].name), 0);
} }
for (int d = 0; d < plat_joystick_state[joystick].nr_sliders; d++) {
Models::AddEntry(model, plat_joystick_state[joystick].slider[d].name, 0);
}
int nr_axes = plat_joystick_state[joystick].nr_axes; int nr_axes = plat_joystick_state[joystick].nr_axes;
int nr_povs = plat_joystick_state[joystick].nr_povs;
int mapping = joystick_state[joystick_nr].axis_mapping[c]; int mapping = joystick_state[joystick_nr].axis_mapping[c];
if (mapping & POV_X) if (mapping & POV_X)
cbox->setCurrentIndex(nr_axes + (mapping & 3) * 2); cbox->setCurrentIndex(nr_axes + (mapping & 3) * 2);
else if (mapping & POV_Y) else if (mapping & POV_Y)
cbox->setCurrentIndex(nr_axes + (mapping & 3) * 2 + 1); cbox->setCurrentIndex(nr_axes + (mapping & 3) * 2 + 1);
else if (mapping & SLIDER)
cbox->setCurrentIndex(nr_axes + nr_povs * 2 + (mapping & 3));
else else
cbox->setCurrentIndex(mapping); cbox->setCurrentIndex(mapping);

View File

@@ -137,22 +137,16 @@ get_axis(JoystickConfiguration &jc, int axis, int joystick_nr)
{ {
int axis_sel = jc.selectedAxis(axis); int axis_sel = jc.selectedAxis(axis);
int nr_axes = plat_joystick_state[joystick_state[joystick_nr].plat_joystick_nr - 1].nr_axes; int nr_axes = plat_joystick_state[joystick_state[joystick_nr].plat_joystick_nr - 1].nr_axes;
int nr_povs = plat_joystick_state[joystick_state[joystick_nr].plat_joystick_nr - 1].nr_povs;
if (axis_sel < nr_axes) { if (axis_sel < nr_axes) {
return axis_sel; return axis_sel;
} }
axis_sel -= nr_axes; axis_sel -= nr_axes;
if (axis_sel < nr_povs * 2) { if (axis_sel & 1)
if (axis_sel & 1) return POV_Y | (axis_sel >> 1);
return POV_Y | (axis_sel >> 1); else
else return POV_X | (axis_sel >> 1);
return POV_X | (axis_sel >> 1);
}
axis_sel -= nr_povs;
return SLIDER | (axis_sel >> 1);
} }
static int static int

View File

@@ -36,6 +36,7 @@
plat_joystick_t plat_joystick_state[MAX_PLAT_JOYSTICKS]; plat_joystick_t plat_joystick_state[MAX_PLAT_JOYSTICKS];
joystick_t joystick_state[MAX_JOYSTICKS]; joystick_t joystick_state[MAX_JOYSTICKS];
int joysticks_present = 0; int joysticks_present = 0;
int has_slider = 0;
static LPDIRECTINPUT8 lpdi; static LPDIRECTINPUT8 lpdi;
static LPDIRECTINPUTDEVICE8 lpdi_joystick[2] = { NULL, NULL }; static LPDIRECTINPUTDEVICE8 lpdi_joystick[2] = { NULL, NULL };
@@ -98,6 +99,10 @@ DIEnumDeviceObjectsCallback(
state->axis[state->nr_axes].id = 4; state->axis[state->nr_axes].id = 4;
else if (lpddoi->guidType == GUID_RzAxis) else if (lpddoi->guidType == GUID_RzAxis)
state->axis[state->nr_axes].id = 5; state->axis[state->nr_axes].id = 5;
else if (lpddoi->guidType == GUID_Slider) {
state->axis[state->nr_axes].id = 6 + has_slider;
has_slider++;
}
state->nr_axes++; state->nr_axes++;
} }
} else if (lpddoi->guidType == GUID_Button) { } else if (lpddoi->guidType == GUID_Button) {
@@ -112,13 +117,6 @@ DIEnumDeviceObjectsCallback(
joystick_log("POV %i : %s %x %x\n", state->nr_povs, state->pov[state->nr_povs].name, lpddoi->dwOfs, lpddoi->dwType); joystick_log("POV %i : %s %x %x\n", state->nr_povs, state->pov[state->nr_povs].name, lpddoi->dwOfs, lpddoi->dwType);
state->nr_povs++; state->nr_povs++;
} }
} else if (lpddoi->guidType == GUID_Slider) {
if (state->nr_sliders < 2) {
memcpy(state->slider[state->nr_sliders].name, lpddoi->tszName, strlen(lpddoi->tszName) + 1);
state->slider[state->nr_sliders].id = state->nr_sliders | SLIDER;
joystick_log("Slider %i : %s %x %x\n", state->nr_sliders, state->slider[state->nr_sliders].name, lpddoi->dwOfs, lpddoi->dwType);
state->nr_sliders++;
}
} }
return DIENUM_CONTINUE; return DIENUM_CONTINUE;
@@ -170,6 +168,7 @@ joystick_init()
joystick_log(" Buttons = %i\n", devcaps.dwButtons); joystick_log(" Buttons = %i\n", devcaps.dwButtons);
joystick_log(" POVs = %i\n", devcaps.dwPOVs); joystick_log(" POVs = %i\n", devcaps.dwPOVs);
has_slider = 0;
lpdi_joystick[c]->EnumObjects(DIEnumDeviceObjectsCallback, &plat_joystick_state[c], DIDFT_ALL); lpdi_joystick[c]->EnumObjects(DIEnumDeviceObjectsCallback, &plat_joystick_state[c], DIDFT_ALL);
if (FAILED(lpdi_joystick[c]->SetCooperativeLevel(hwndMain, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE))) if (FAILED(lpdi_joystick[c]->SetCooperativeLevel(hwndMain, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE)))
@@ -234,8 +233,6 @@ joystick_get_axis(int joystick_nr, int mapping)
return 0; return 0;
else else
return -cos((2 * M_PI * (double) pov) / 36000.0) * 32767; return -cos((2 * M_PI * (double) pov) / 36000.0) * 32767;
} else if (mapping & SLIDER) {
return plat_joystick_state[joystick_nr].s[mapping & 3];
} else } else
return plat_joystick_state[joystick_nr].a[plat_joystick_state[joystick_nr].axis[mapping].id]; return plat_joystick_state[joystick_nr].a[plat_joystick_state[joystick_nr].axis[mapping].id];
} }
@@ -269,8 +266,8 @@ joystick_process(void)
plat_joystick_state[c].a[3] = joystate.lRx; plat_joystick_state[c].a[3] = joystate.lRx;
plat_joystick_state[c].a[4] = joystate.lRy; plat_joystick_state[c].a[4] = joystate.lRy;
plat_joystick_state[c].a[5] = joystate.lRz; plat_joystick_state[c].a[5] = joystate.lRz;
plat_joystick_state[c].s[0] = joystate.rglSlider[0]; plat_joystick_state[c].a[6] = joystate.rglSlider[0];
plat_joystick_state[c].s[1] = joystate.rglSlider[1]; plat_joystick_state[c].a[7] = joystate.rglSlider[1];
for (b = 0; b < 16; b++) for (b = 0; b < 16; b++)
plat_joystick_state[c].b[b] = joystate.rgbButtons[b] & 0x80; plat_joystick_state[c].b[b] = joystate.rgbButtons[b] & 0x80;

View File

@@ -54,9 +54,6 @@ rebuild_axis_button_selections(HWND hdlg)
sprintf(s, "%s (Y axis)", plat_joystick_state[joystick - 1].pov[d].name); sprintf(s, "%s (Y axis)", plat_joystick_state[joystick - 1].pov[d].name);
SendMessage(h, CB_ADDSTRING, 0, (LPARAM) (LPCSTR) s); SendMessage(h, CB_ADDSTRING, 0, (LPARAM) (LPCSTR) s);
} }
for (d = 0; d < plat_joystick_state[joystick - 1].nr_sliders; d++) {
SendMessage(h, CB_ADDSTRING, 0, (LPARAM) (LPCSTR) plat_joystick_state[joystick - 1].slider[d].name);
}
SendMessage(h, CB_SETCURSEL, sel, 0); SendMessage(h, CB_SETCURSEL, sel, 0);
EnableWindow(h, TRUE); EnableWindow(h, TRUE);
} else } else
@@ -111,21 +108,15 @@ get_axis(HWND hdlg, int id)
HWND h = GetDlgItem(hdlg, id); HWND h = GetDlgItem(hdlg, id);
int axis_sel = SendMessage(h, CB_GETCURSEL, 0, 0); int axis_sel = SendMessage(h, CB_GETCURSEL, 0, 0);
int nr_axes = plat_joystick_state[joystick_state[joystick_nr].plat_joystick_nr - 1].nr_axes; int nr_axes = plat_joystick_state[joystick_state[joystick_nr].plat_joystick_nr - 1].nr_axes;
int nr_povs = plat_joystick_state[joystick_state[joystick_nr].plat_joystick_nr - 1].nr_povs;
if (axis_sel < nr_axes) if (axis_sel < nr_axes)
return axis_sel; return axis_sel;
axis_sel -= nr_axes; axis_sel -= nr_axes;
if (axis_sel < nr_povs * 2) { if (axis_sel & 1)
if (axis_sel & 1) return POV_Y | (axis_sel >> 1);
return POV_Y | (axis_sel >> 1); else
else return POV_X | (axis_sel >> 1);
return POV_X | (axis_sel >> 1);
}
axis_sel -= nr_povs;
return SLIDER | (axis_sel >> 1);
} }
static int static int
@@ -188,8 +179,6 @@ joystickconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, UNUSED(LPARAM lPa
SendMessage(h, CB_SETCURSEL, nr_axes + (mapping & 3) * 2, 0); SendMessage(h, CB_SETCURSEL, nr_axes + (mapping & 3) * 2, 0);
else if (mapping & POV_Y) else if (mapping & POV_Y)
SendMessage(h, CB_SETCURSEL, nr_axes + (mapping & 3) * 2 + 1, 0); SendMessage(h, CB_SETCURSEL, nr_axes + (mapping & 3) * 2 + 1, 0);
else if (mapping & SLIDER)
SendMessage(h, CB_SETCURSEL, nr_axes + nr_povs * 2 + (mapping & 3), 0);
else else
SendMessage(h, CB_SETCURSEL, mapping, 0); SendMessage(h, CB_SETCURSEL, mapping, 0);
id += 2; id += 2;