Initial code for joystick port instancing
This commit is contained in:
@@ -41,7 +41,7 @@ JoystickConfiguration::JoystickConfiguration(int type, int joystick_nr, QWidget
|
||||
Models::AddEntry(model, plat_joystick_state[c].name, c + 1);
|
||||
}
|
||||
|
||||
ui->comboBoxDevice->setCurrentIndex(joystick_state[joystick_nr].plat_joystick_nr);
|
||||
ui->comboBoxDevice->setCurrentIndex(joystick_state[0][joystick_nr].plat_joystick_nr);
|
||||
layout()->setSizeConstraint(QLayout::SetFixedSize);
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ JoystickConfiguration::on_comboBoxDevice_currentIndexChanged(int index)
|
||||
}
|
||||
|
||||
int nr_axes = plat_joystick_state[joystick].nr_axes;
|
||||
int mapping = joystick_state[joystick_nr].axis_mapping[c];
|
||||
int mapping = joystick_state[0][joystick_nr].axis_mapping[c];
|
||||
if (mapping & POV_X)
|
||||
cbox->setCurrentIndex(nr_axes + (mapping & 3) * 2);
|
||||
else if (mapping & POV_Y)
|
||||
@@ -147,7 +147,7 @@ JoystickConfiguration::on_comboBoxDevice_currentIndexChanged(int index)
|
||||
Models::AddEntry(model, plat_joystick_state[joystick].button[d].name, 0);
|
||||
}
|
||||
|
||||
cbox->setCurrentIndex(joystick_state[joystick_nr].button_mapping[c]);
|
||||
cbox->setCurrentIndex(joystick_state[0][joystick_nr].button_mapping[c]);
|
||||
|
||||
ui->ct->addWidget(label, row, 0);
|
||||
ui->ct->addWidget(cbox, row, 1);
|
||||
@@ -179,7 +179,7 @@ JoystickConfiguration::on_comboBoxDevice_currentIndexChanged(int index)
|
||||
Models::AddEntry(model, plat_joystick_state[joystick].axis[d].name, 0);
|
||||
}
|
||||
|
||||
int mapping = joystick_state[joystick_nr].pov_mapping[c / 2][c & 1];
|
||||
int mapping = joystick_state[0][joystick_nr].pov_mapping[c / 2][c & 1];
|
||||
int nr_povs = plat_joystick_state[joystick].nr_povs;
|
||||
if (mapping & POV_X)
|
||||
cbox->setCurrentIndex((mapping & 3) * 2);
|
||||
|
||||
@@ -136,7 +136,7 @@ static int
|
||||
get_axis(JoystickConfiguration &jc, int axis, int joystick_nr)
|
||||
{
|
||||
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[0][joystick_nr].plat_joystick_nr - 1].nr_axes;
|
||||
|
||||
if (axis_sel < nr_axes) {
|
||||
return axis_sel;
|
||||
@@ -153,7 +153,7 @@ static int
|
||||
get_pov(JoystickConfiguration &jc, int pov, int joystick_nr)
|
||||
{
|
||||
int pov_sel = jc.selectedPov(pov);
|
||||
int nr_povs = plat_joystick_state[joystick_state[joystick_nr].plat_joystick_nr - 1].nr_povs * 2;
|
||||
int nr_povs = plat_joystick_state[joystick_state[0][joystick_nr].plat_joystick_nr - 1].nr_povs * 2;
|
||||
|
||||
if (pov_sel < nr_povs) {
|
||||
if (pov_sel & 1)
|
||||
@@ -176,19 +176,19 @@ updateJoystickConfig(int type, int joystick_nr, QWidget *parent)
|
||||
break;
|
||||
}
|
||||
|
||||
joystick_state[joystick_nr].plat_joystick_nr = jc.selectedDevice();
|
||||
if (joystick_state[joystick_nr].plat_joystick_nr) {
|
||||
joystick_state[0][joystick_nr].plat_joystick_nr = jc.selectedDevice();
|
||||
if (joystick_state[0][joystick_nr].plat_joystick_nr) {
|
||||
for (int axis_nr = 0; axis_nr < joystick_get_axis_count(type); axis_nr++) {
|
||||
joystick_state[joystick_nr].axis_mapping[axis_nr] = get_axis(jc, axis_nr, joystick_nr);
|
||||
joystick_state[0][joystick_nr].axis_mapping[axis_nr] = get_axis(jc, axis_nr, joystick_nr);
|
||||
}
|
||||
|
||||
for (int button_nr = 0; button_nr < joystick_get_button_count(type); button_nr++) {
|
||||
joystick_state[joystick_nr].button_mapping[button_nr] = jc.selectedButton(button_nr);
|
||||
joystick_state[0][joystick_nr].button_mapping[button_nr] = jc.selectedButton(button_nr);
|
||||
}
|
||||
|
||||
for (int pov_nr = 0; pov_nr < joystick_get_pov_count(type) * 2; pov_nr += 2) {
|
||||
joystick_state[joystick_nr].pov_mapping[pov_nr][0] = get_pov(jc, pov_nr, joystick_nr);
|
||||
joystick_state[joystick_nr].pov_mapping[pov_nr][1] = get_pov(jc, pov_nr + 1, joystick_nr);
|
||||
joystick_state[0][joystick_nr].pov_mapping[pov_nr][0] = get_pov(jc, pov_nr, joystick_nr);
|
||||
joystick_state[0][joystick_nr].pov_mapping[pov_nr][1] = get_pov(jc, pov_nr + 1, joystick_nr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,13 +8,13 @@
|
||||
*
|
||||
* SDL2 joystick interface.
|
||||
*
|
||||
*
|
||||
*
|
||||
* Authors: Sarah Walker, <https://pcem-emulator.co.uk/>
|
||||
* Joakim L. Gilje <jgilje@jgilje.net>
|
||||
* Joakim L. Gilje, <jgilje@jgilje.net>
|
||||
* Jasmine Iwanek, jriwanek@gmail.com>
|
||||
*
|
||||
* Copyright 2017-2021 Sarah Walker
|
||||
* Copyright 2021 Joakim L. Gilje
|
||||
* Copyright 2017-2021 Sarah Walker.
|
||||
* Copyright 2021 Joakim L. Gilje.
|
||||
* Copyright 2021-2025 Jasmine Iwanek.
|
||||
*/
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
@@ -33,8 +33,8 @@
|
||||
#include <86box/gameport.h>
|
||||
#include <86box/plat_unused.h>
|
||||
|
||||
int joysticks_present;
|
||||
joystick_t joystick_state[MAX_JOYSTICKS];
|
||||
int joysticks_present = 0;
|
||||
joystick_t joystick_state[GAMEPORT_MAX][MAX_JOYSTICKS];
|
||||
plat_joystick_t plat_joystick_state[MAX_PLAT_JOYSTICKS];
|
||||
static SDL_Joystick *sdl_joy[MAX_PLAT_JOYSTICKS];
|
||||
|
||||
@@ -89,7 +89,7 @@ joystick_close(void)
|
||||
}
|
||||
|
||||
static int
|
||||
joystick_get_axis(int joystick_nr, int mapping)
|
||||
joystick_get_axis(int gameport, int joystick_nr, int mapping)
|
||||
{
|
||||
if (mapping & POV_X) {
|
||||
switch (plat_joystick_state[joystick_nr].p[mapping & 3]) {
|
||||
@@ -144,44 +144,44 @@ joystick_process(void)
|
||||
|
||||
#if 0
|
||||
pclog("joystick %i - x=%i y=%i b[0]=%i b[1]=%i %i\n", js,
|
||||
joystick_state[js].x,
|
||||
joystick_state[js].y,
|
||||
joystick_state[js].b[0],
|
||||
joystick_state[js].b[1],
|
||||
joystick_state[0][js].x,
|
||||
joystick_state[0][js].y,
|
||||
joystick_state[0][js].b[0],
|
||||
joystick_state[0][js].b[1],
|
||||
joysticks_present);
|
||||
#endif
|
||||
}
|
||||
|
||||
for (int js = 0; js < joystick_get_max_joysticks(joystick_type); js++) {
|
||||
if (joystick_state[js].plat_joystick_nr) {
|
||||
int joystick_nr = joystick_state[js].plat_joystick_nr - 1;
|
||||
if (joystick_state[0][js].plat_joystick_nr) {
|
||||
int joystick_nr = joystick_state[0][js].plat_joystick_nr - 1;
|
||||
|
||||
for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type); axis_nr++)
|
||||
joystick_state[js].axis[axis_nr] = joystick_get_axis(joystick_nr, joystick_state[js].axis_mapping[axis_nr]);
|
||||
joystick_state[0][js].axis[axis_nr] = joystick_get_axis(0, joystick_nr, joystick_state[0][js].axis_mapping[axis_nr]);
|
||||
|
||||
for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type); button_nr++)
|
||||
joystick_state[js].button[button_nr] = plat_joystick_state[joystick_nr].b[joystick_state[js].button_mapping[button_nr]];
|
||||
joystick_state[0][js].button[button_nr] = plat_joystick_state[joystick_nr].b[joystick_state[0][js].button_mapping[button_nr]];
|
||||
|
||||
for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type); pov_nr++) {
|
||||
int x = joystick_get_axis(joystick_nr, joystick_state[js].pov_mapping[pov_nr][0]);
|
||||
int y = joystick_get_axis(joystick_nr, joystick_state[js].pov_mapping[pov_nr][1]);
|
||||
int x = joystick_get_axis(0, joystick_nr, joystick_state[0][js].pov_mapping[pov_nr][0]);
|
||||
int y = joystick_get_axis(0, joystick_nr, joystick_state[0][js].pov_mapping[pov_nr][1]);
|
||||
double angle = (atan2((double) y, (double) x) * 360.0) / (2 * M_PI);
|
||||
double magnitude = sqrt((double) x * (double) x + (double) y * (double) y);
|
||||
|
||||
if (magnitude < 16384)
|
||||
joystick_state[js].pov[pov_nr] = -1;
|
||||
joystick_state[0][js].pov[pov_nr] = -1;
|
||||
else
|
||||
joystick_state[js].pov[pov_nr] = ((int) angle + 90 + 360) % 360;
|
||||
joystick_state[0][js].pov[pov_nr] = ((int) angle + 90 + 360) % 360;
|
||||
}
|
||||
} else {
|
||||
for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type); axis_nr++)
|
||||
joystick_state[js].axis[axis_nr] = 0;
|
||||
joystick_state[0][js].axis[axis_nr] = 0;
|
||||
|
||||
for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type); button_nr++)
|
||||
joystick_state[js].button[button_nr] = 0;
|
||||
joystick_state[0][js].button[button_nr] = 0;
|
||||
|
||||
for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type); pov_nr++)
|
||||
joystick_state[js].pov[pov_nr] = -1;
|
||||
joystick_state[0][js].pov[pov_nr] = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,15 +8,13 @@
|
||||
*
|
||||
* RawInput joystick interface.
|
||||
*
|
||||
*
|
||||
*
|
||||
* Authors: Miran Grca, <mgrca8@gmail.com>
|
||||
* GH Cao, <driver1998.ms@outlook.com>
|
||||
* Jasmine Iwanek,
|
||||
* Jasmine Iwanek, <jriwanek@gmail.com>
|
||||
*
|
||||
* Copyright 2016-2018 Miran Grca.
|
||||
* Copyright 2020 GH Cao.
|
||||
* Copyright 2021-2023 Jasmine Iwanek.
|
||||
* Copyright 2021-2025 Jasmine Iwanek.
|
||||
*/
|
||||
#include <windows.h>
|
||||
#include <windowsx.h>
|
||||
@@ -98,9 +96,9 @@ typedef struct {
|
||||
} pov[MAX_JOY_POVS];
|
||||
} raw_joystick_t;
|
||||
|
||||
plat_joystick_t plat_joystick_state[MAX_PLAT_JOYSTICKS];
|
||||
joystick_t joystick_state[MAX_JOYSTICKS];
|
||||
int joysticks_present = 0;
|
||||
joystick_t joystick_state[GAMEPORT_MAX][MAX_JOYSTICKS];
|
||||
plat_joystick_t plat_joystick_state[MAX_PLAT_JOYSTICKS];
|
||||
|
||||
raw_joystick_t raw_joystick_state[MAX_PLAT_JOYSTICKS];
|
||||
|
||||
@@ -419,7 +417,7 @@ win_joystick_handle(PRAWINPUT raw)
|
||||
|
||||
if (r == HIDP_STATUS_SUCCESS) {
|
||||
for (int i = 0; i < usage_length; i++) {
|
||||
int button = raw_joystick_state[j].usage_button[usage_list[i]];
|
||||
int button = raw_joystick_state[j].usage_button[usage_list[i]];
|
||||
plat_joystick_state[j].b[button] = 128;
|
||||
}
|
||||
}
|
||||
@@ -455,7 +453,7 @@ win_joystick_handle(PRAWINPUT raw)
|
||||
|
||||
plat_joystick_state[j].a[axis_nr] = value;
|
||||
#if 0
|
||||
joystick_log("%s %-06d ", plat_joystick_state[j].axis[axis_nr].name, plat_joystick_state[j].a[axis_nr]);
|
||||
joystick_log("%s %-06d ", plat_joystick_state[0][j].axis[axis_nr].name, plat_joystick_state[j].a[axis_nr]);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -477,7 +475,7 @@ win_joystick_handle(PRAWINPUT raw)
|
||||
plat_joystick_state[j].p[pov_nr] = value;
|
||||
|
||||
#if 0
|
||||
joystick_log("%s %-3d ", plat_joystick_state[j].pov[pov_nr].name, plat_joystick_state[j].p[pov_nr]);
|
||||
joystick_log("%s %-3d ", plat_joystick_state[0][j].pov[pov_nr].name, plat_joystick_state[j].p[pov_nr]);
|
||||
#endif
|
||||
}
|
||||
#if 0
|
||||
@@ -512,35 +510,35 @@ joystick_process(void)
|
||||
return;
|
||||
|
||||
for (int js = 0; js < joystick_get_max_joysticks(joystick_type); js++) {
|
||||
if (joystick_state[js].plat_joystick_nr) {
|
||||
int joystick_nr = joystick_state[js].plat_joystick_nr - 1;
|
||||
if (joystick_state[0][js].plat_joystick_nr) {
|
||||
int joystick_nr = joystick_state[0][js].plat_joystick_nr - 1;
|
||||
|
||||
for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type); axis_nr++)
|
||||
joystick_state[js].axis[axis_nr] = joystick_get_axis(joystick_nr, joystick_state[js].axis_mapping[axis_nr]);
|
||||
joystick_state[0][js].axis[axis_nr] = joystick_get_axis(joystick_nr, joystick_state[0][js].axis_mapping[axis_nr]);
|
||||
|
||||
for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type); button_nr++)
|
||||
joystick_state[js].button[button_nr] = plat_joystick_state[joystick_nr].b[joystick_state[js].button_mapping[button_nr]];
|
||||
joystick_state[0][js].button[button_nr] = plat_joystick_state[joystick_nr].b[joystick_state[0][js].button_mapping[button_nr]];
|
||||
|
||||
for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type); pov_nr++) {
|
||||
int x = joystick_get_axis(joystick_nr, joystick_state[js].pov_mapping[pov_nr][0]);
|
||||
int y = joystick_get_axis(joystick_nr, joystick_state[js].pov_mapping[pov_nr][1]);
|
||||
int x = joystick_get_axis(joystick_nr, joystick_state[0][js].pov_mapping[pov_nr][0]);
|
||||
int y = joystick_get_axis(joystick_nr, joystick_state[0][js].pov_mapping[pov_nr][1]);
|
||||
double angle = (atan2((double) y, (double) x) * 360.0) / (2 * M_PI);
|
||||
double magnitude = sqrt((double) x * (double) x + (double) y * (double) y);
|
||||
|
||||
if (magnitude < 16384)
|
||||
joystick_state[js].pov[pov_nr] = -1;
|
||||
joystick_state[0][js].pov[pov_nr] = -1;
|
||||
else
|
||||
joystick_state[js].pov[pov_nr] = ((int) angle + 90 + 360) % 360;
|
||||
joystick_state[0][js].pov[pov_nr] = ((int) angle + 90 + 360) % 360;
|
||||
}
|
||||
} else {
|
||||
for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type); axis_nr++)
|
||||
joystick_state[js].axis[axis_nr] = 0;
|
||||
joystick_state[0][js].axis[axis_nr] = 0;
|
||||
|
||||
for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type); button_nr++)
|
||||
joystick_state[js].button[button_nr] = 0;
|
||||
joystick_state[0][js].button[button_nr] = 0;
|
||||
|
||||
for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type); pov_nr++)
|
||||
joystick_state[js].pov[pov_nr] = -1;
|
||||
joystick_state[0][js].pov[pov_nr] = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user