mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-10 16:03:15 -04:00
WIP on mapping physical controller ports to virtual input ports
This commit is contained in:
parent
ce7c077ca9
commit
87c89ba973
16
src/Input.c
16
src/Input.c
@ -436,6 +436,22 @@ void Gamepad_Tick(float delta) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Gamepad_MapPort(long deviceID) {
|
||||||
|
int port;
|
||||||
|
|
||||||
|
for (port = 0; port < INPUT_MAX_GAMEPADS; port++)
|
||||||
|
{
|
||||||
|
if (Gamepad_States[port].deviceID == deviceID) return port;
|
||||||
|
|
||||||
|
if (Gamepad_States[port].deviceID != 0) continue;
|
||||||
|
Gamepad_States[port].deviceID = deviceID;
|
||||||
|
return port;
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger_Abort("Not enough controllers");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*-----------------------------------------------------Base handlers-------------------------------------------------------*
|
*-----------------------------------------------------Base handlers-------------------------------------------------------*
|
||||||
|
@ -202,10 +202,12 @@ void Gamepad_Tick(float delta);
|
|||||||
#define GAMEPAD_BTN_COUNT (INPUT_COUNT - GAMEPAD_BEG_BTN)
|
#define GAMEPAD_BTN_COUNT (INPUT_COUNT - GAMEPAD_BEG_BTN)
|
||||||
|
|
||||||
struct GamepadState {
|
struct GamepadState {
|
||||||
|
long deviceID;
|
||||||
float axisX[2], axisY[2];
|
float axisX[2], axisY[2];
|
||||||
cc_bool pressed[GAMEPAD_BTN_COUNT];
|
cc_bool pressed[GAMEPAD_BTN_COUNT];
|
||||||
float holdtime[GAMEPAD_BTN_COUNT];
|
float holdtime[GAMEPAD_BTN_COUNT];
|
||||||
};
|
};
|
||||||
extern struct GamepadState Gamepad_States[INPUT_MAX_GAMEPADS];
|
extern struct GamepadState Gamepad_States[INPUT_MAX_GAMEPADS];
|
||||||
|
int Gamepad_MapPort(long deviceID);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -277,7 +277,7 @@ void Gamepads_Process(float delta) {
|
|||||||
maple_device_t* cont;
|
maple_device_t* cont;
|
||||||
cont_state_t* state;
|
cont_state_t* state;
|
||||||
|
|
||||||
for (int port = 0; port < INPUT_MAX_GAMEPADS; port++)
|
for (int i = 0; i < INPUT_MAX_GAMEPADS; i++)
|
||||||
{
|
{
|
||||||
cont = maple_enum_type(port, MAPLE_FUNC_CONTROLLER);
|
cont = maple_enum_type(port, MAPLE_FUNC_CONTROLLER);
|
||||||
if (!cont) return;
|
if (!cont) return;
|
||||||
@ -287,6 +287,7 @@ void Gamepads_Process(float delta) {
|
|||||||
int dual_analog = cont_has_capabilities(cont, CONT_CAPABILITIES_DUAL_ANALOG);
|
int dual_analog = cont_has_capabilities(cont, CONT_CAPABILITIES_DUAL_ANALOG);
|
||||||
if(dual_analog == -1) dual_analog = 0;
|
if(dual_analog == -1) dual_analog = 0;
|
||||||
|
|
||||||
|
int port = Gamepad_MapPort(i + 10);
|
||||||
HandleButtons(port, state->buttons);
|
HandleButtons(port, state->buttons);
|
||||||
HandleController(port, dual_analog, state, delta);
|
HandleController(port, dual_analog, state, delta);
|
||||||
}
|
}
|
||||||
|
@ -137,22 +137,23 @@ static void ProcessPAD_Buttons(int port, int mods) {
|
|||||||
Gamepad_SetButton(port, CCPAD_DOWN, mods & PAD_BUTTON_DOWN);
|
Gamepad_SetButton(port, CCPAD_DOWN, mods & PAD_BUTTON_DOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ProcessPADInput(int port, float delta) {
|
static void ProcessPADInput(int i, float delta) {
|
||||||
PADStatus pads[4];
|
PADStatus pads[4];
|
||||||
PAD_Read(pads);
|
PAD_Read(pads);
|
||||||
int error = pads[port].err;
|
int error = pads[i].err;
|
||||||
|
|
||||||
if (error == 0) {
|
if (error == 0) {
|
||||||
gc_pads[port] = pads[port]; // new state arrived
|
gc_pads[i] = pads[i]; // new state arrived
|
||||||
} else if (error == PAD_ERR_TRANSFER) {
|
} else if (error == PAD_ERR_TRANSFER) {
|
||||||
// usually means still busy transferring state - use last state
|
// usually means still busy transferring state - use last state
|
||||||
} else {
|
} else {
|
||||||
return; // not connected, still busy, etc
|
return; // not connected, still busy, etc
|
||||||
}
|
}
|
||||||
|
|
||||||
ProcessPAD_Buttons(0, gc_pads[port].button);
|
int port = Gamepad_MapPort(i + 10);
|
||||||
ProcessPAD_Joystick(0, PAD_AXIS_LEFT, gc_pads[port].stickX, gc_pads[port].stickY, delta);
|
ProcessPAD_Buttons(port, gc_pads[i].button);
|
||||||
ProcessPAD_Joystick(0, PAD_AXIS_RIGHT, gc_pads[port].substickX, gc_pads[port].substickY, delta);
|
ProcessPAD_Joystick(port, PAD_AXIS_LEFT, gc_pads[i].stickX, gc_pads[i].stickY, delta);
|
||||||
|
ProcessPAD_Joystick(port, PAD_AXIS_RIGHT, gc_pads[i].substickX, gc_pads[i].substickY, delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -306,7 +307,8 @@ void Gamepads_Init(void) {
|
|||||||
|
|
||||||
#if defined HW_RVL
|
#if defined HW_RVL
|
||||||
WPAD_Init();
|
WPAD_Init();
|
||||||
WPAD_SetDataFormat(0, WPAD_FMT_BTNS_ACC_IR);
|
for (int i = 0; i < 4; i++)
|
||||||
|
WPAD_SetDataFormat(i, WPAD_FMT_BTNS_ACC_IR);
|
||||||
#endif
|
#endif
|
||||||
PAD_Init();
|
PAD_Init();
|
||||||
}
|
}
|
||||||
@ -333,8 +335,7 @@ static void ProcessWPAD_Buttons(int port, int mods) {
|
|||||||
Gamepad_SetButton(port, CCPAD_DOWN, mods & WPAD_BUTTON_DOWN);
|
Gamepad_SetButton(port, CCPAD_DOWN, mods & WPAD_BUTTON_DOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ProcessNunchuck_Game(int port, int mods, float delta) {
|
static void ProcessNunchuck_Game(int port, WPADData* wd, int mods, float delta) {
|
||||||
WPADData* wd = WPAD_Data(0);
|
|
||||||
joystick_t analog = wd->exp.nunchuk.js;
|
joystick_t analog = wd->exp.nunchuk.js;
|
||||||
|
|
||||||
Gamepad_SetButton(port, CCPAD_L, mods & WPAD_NUNCHUK_BUTTON_C);
|
Gamepad_SetButton(port, CCPAD_L, mods & WPAD_NUNCHUK_BUTTON_C);
|
||||||
@ -401,8 +402,7 @@ static void ProcessClassicButtons(int port, int mods) {
|
|||||||
Gamepad_SetButton(port, CCPAD_ZR, mods & CLASSIC_CTRL_BUTTON_ZR);
|
Gamepad_SetButton(port, CCPAD_ZR, mods & CLASSIC_CTRL_BUTTON_ZR);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ProcessClassicInput(int port, float delta) {
|
static void ProcessClassicInput(int port, WPADData* wd, float delta) {
|
||||||
WPADData* wd = WPAD_Data(0);
|
|
||||||
classic_ctrl_t ctrls = wd->exp.classic;
|
classic_ctrl_t ctrls = wd->exp.classic;
|
||||||
int mods = ctrls.btns | ctrls.btns_held;
|
int mods = ctrls.btns | ctrls.btns_held;
|
||||||
|
|
||||||
@ -411,19 +411,22 @@ static void ProcessClassicInput(int port, float delta) {
|
|||||||
ProcessClassic_Joystick(port, PAD_AXIS_RIGHT, &ctrls.rjs, delta);
|
ProcessClassic_Joystick(port, PAD_AXIS_RIGHT, &ctrls.rjs, delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ProcessWPADInput(int port, float delta) {
|
static void ProcessWPADInput(int i, float delta) {
|
||||||
WPAD_ScanPads();
|
WPAD_ScanPads();
|
||||||
u32 type;
|
u32 type;
|
||||||
int res = WPAD_Probe(port, &type);
|
int res = WPAD_Probe(i, &type);
|
||||||
if (res) return;
|
if (res) return;
|
||||||
u32 mods = WPAD_ButtonsDown(port) | WPAD_ButtonsHeld(port);
|
|
||||||
|
u32 mods = WPAD_ButtonsDown(i) | WPAD_ButtonsHeld(i);
|
||||||
|
int port = Gamepad_MapPort(i + 20);
|
||||||
|
WPADData* wd = WPAD_Data(i);
|
||||||
|
|
||||||
if (type == WPAD_EXP_CLASSIC) {
|
if (type == WPAD_EXP_CLASSIC) {
|
||||||
ProcessClassicInput(port, delta);
|
ProcessClassicInput(port, wd, delta);
|
||||||
} else if (launcherMode) {
|
} else if (launcherMode) {
|
||||||
ProcessWPAD_Buttons(port, mods);
|
ProcessWPAD_Buttons(port, mods);
|
||||||
} else if (type == WPAD_EXP_NUNCHUK) {
|
} else if (type == WPAD_EXP_NUNCHUK) {
|
||||||
ProcessNunchuck_Game(port, mods, delta);
|
ProcessNunchuck_Game(port, wd, mods, delta);
|
||||||
} else {
|
} else {
|
||||||
ProcessWPAD_Buttons(port, mods);
|
ProcessWPAD_Buttons(port, mods);
|
||||||
}
|
}
|
||||||
@ -432,17 +435,17 @@ static void ProcessWPADInput(int port, float delta) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Gamepads_Process(float delta) {
|
void Gamepads_Process(float delta) {
|
||||||
for (int port = 0; port < INPUT_MAX_GAMEPADS; port++)
|
for (int i = 0; i < INPUT_MAX_GAMEPADS; i++)
|
||||||
{
|
{
|
||||||
ProcessWPADInput(port, delta);
|
ProcessWPADInput(i, delta);
|
||||||
ProcessPADInput( port, delta);
|
ProcessPADInput( i, delta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
void Gamepads_Process(float delta) {
|
void Gamepads_Process(float delta) {
|
||||||
for (int port = 0; port < INPUT_MAX_GAMEPADS; port++)
|
for (int i = 0; i < INPUT_MAX_GAMEPADS; i++)
|
||||||
{
|
{
|
||||||
ProcessPADInput(port, delta);
|
ProcessPADInput(i, delta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -137,11 +137,12 @@ static void ProcessAnalogInput(int port, joypad_inputs_t* inputs, float delta) {
|
|||||||
void Gamepads_Process(float delta) {
|
void Gamepads_Process(float delta) {
|
||||||
joypad_poll();
|
joypad_poll();
|
||||||
|
|
||||||
for (int port = 0; port < INPUT_MAX_GAMEPADS; port++)
|
for (int i = 0; i < INPUT_MAX_GAMEPADS; i++)
|
||||||
{
|
{
|
||||||
if (!joypad_is_connected(port)) continue;
|
if (!joypad_is_connected(port)) continue;
|
||||||
|
int port = Gamepad_MapPort(i + 10);
|
||||||
|
|
||||||
joypad_inputs_t inputs = joypad_get_inputs(port);
|
joypad_inputs_t inputs = joypad_get_inputs(i);
|
||||||
HandleButtons(port, inputs.btn);
|
HandleButtons(port, inputs.btn);
|
||||||
ProcessAnalogInput(port, &inputs, delta);
|
ProcessAnalogInput(port, &inputs, delta);
|
||||||
}
|
}
|
||||||
|
@ -323,11 +323,12 @@ static void ProcessPadInput(int port, float delta, padData* pad) {
|
|||||||
|
|
||||||
void Gamepads_Process(float delta) {
|
void Gamepads_Process(float delta) {
|
||||||
ioPadGetInfo(&pad_info);
|
ioPadGetInfo(&pad_info);
|
||||||
for (int port = 0; port < INPUT_MAX_GAMEPADS; port++)
|
for (int i = 0; i < INPUT_MAX_GAMEPADS; i++)
|
||||||
{
|
{
|
||||||
if (!pad_info.status[port]) continue;
|
if (!pad_info.status[i]) continue;
|
||||||
|
ioPadGetData(i, &pad_data);
|
||||||
|
|
||||||
ioPadGetData(port, &pad_data);
|
int port = Gamepad_MapPort(i + 10);
|
||||||
ProcessPadInput(port, delta, &pad_data);
|
ProcessPadInput(port, delta, &pad_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -484,9 +484,7 @@ void Gamepads_Init(void) {
|
|||||||
LoadControllers();
|
LoadControllers();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ProcessGamepadButtons(int port) {
|
static void ProcessGamepadButtons(int port, SDL_GameController* gp) {
|
||||||
SDL_GameController* gp = controllers[port];
|
|
||||||
|
|
||||||
Gamepad_SetButton(port, CCPAD_1, SDL_GameControllerGetButton(gp, SDL_CONTROLLER_BUTTON_A));
|
Gamepad_SetButton(port, CCPAD_1, SDL_GameControllerGetButton(gp, SDL_CONTROLLER_BUTTON_A));
|
||||||
Gamepad_SetButton(port, CCPAD_2, SDL_GameControllerGetButton(gp, SDL_CONTROLLER_BUTTON_B));
|
Gamepad_SetButton(port, CCPAD_2, SDL_GameControllerGetButton(gp, SDL_CONTROLLER_BUTTON_B));
|
||||||
Gamepad_SetButton(port, CCPAD_3, SDL_GameControllerGetButton(gp, SDL_CONTROLLER_BUTTON_X));
|
Gamepad_SetButton(port, CCPAD_3, SDL_GameControllerGetButton(gp, SDL_CONTROLLER_BUTTON_X));
|
||||||
@ -509,8 +507,7 @@ static void ProcessGamepadButtons(int port) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define PAD_AXIS_SCALE 32768.0f
|
#define PAD_AXIS_SCALE 32768.0f
|
||||||
static void ProcessJoystick(int port, int axis, float delta) {
|
static void ProcessJoystick(int port, SDL_GameController* gp, int axis, float delta) {
|
||||||
SDL_GameController* gp = controllers[port];
|
|
||||||
int x = SDL_GameControllerGetAxis(gp, axis == PAD_AXIS_LEFT ? SDL_CONTROLLER_AXIS_LEFTX : SDL_CONTROLLER_AXIS_RIGHTX);
|
int x = SDL_GameControllerGetAxis(gp, axis == PAD_AXIS_LEFT ? SDL_CONTROLLER_AXIS_LEFTX : SDL_CONTROLLER_AXIS_RIGHTX);
|
||||||
int y = SDL_GameControllerGetAxis(gp, axis == PAD_AXIS_LEFT ? SDL_CONTROLLER_AXIS_LEFTY : SDL_CONTROLLER_AXIS_RIGHTY);
|
int y = SDL_GameControllerGetAxis(gp, axis == PAD_AXIS_LEFT ? SDL_CONTROLLER_AXIS_LEFTY : SDL_CONTROLLER_AXIS_RIGHTY);
|
||||||
|
|
||||||
@ -522,13 +519,15 @@ static void ProcessJoystick(int port, int axis, float delta) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Gamepads_Process(float delta) {
|
void Gamepads_Process(float delta) {
|
||||||
for (int port = 0; port < INPUT_MAX_GAMEPADS; port++)
|
for (int i = 0; i < INPUT_MAX_GAMEPADS; i++)
|
||||||
{
|
{
|
||||||
if (!controllers[port]) continue;
|
SDL_GameController* gp = controllers[i];
|
||||||
|
if (!gp) continue;
|
||||||
|
int port = Gamepad_MapPort(i + 10);
|
||||||
|
|
||||||
ProcessGamepadButtons(port);
|
ProcessGamepadButtons(port, gp);
|
||||||
ProcessJoystick(port, PAD_AXIS_LEFT, delta);
|
ProcessJoystick(port, gp, PAD_AXIS_LEFT, delta);
|
||||||
ProcessJoystick(port, PAD_AXIS_RIGHT, delta);
|
ProcessJoystick(port, gp, PAD_AXIS_RIGHT, delta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -517,9 +517,7 @@ void Gamepads_Init(void) {
|
|||||||
LoadControllers();
|
LoadControllers();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ProcessGamepadButtons(int port) {
|
static void ProcessGamepadButtons(int port, SDL_Gamepad* gp) {
|
||||||
SDL_Gamepad* gp = controllers[port];
|
|
||||||
|
|
||||||
Gamepad_SetButton(port, CCPAD_1, SDL_GetGamepadButton(gp, SDL_GAMEPAD_BUTTON_SOUTH));
|
Gamepad_SetButton(port, CCPAD_1, SDL_GetGamepadButton(gp, SDL_GAMEPAD_BUTTON_SOUTH));
|
||||||
Gamepad_SetButton(port, CCPAD_2, SDL_GetGamepadButton(gp, SDL_GAMEPAD_BUTTON_EAST));
|
Gamepad_SetButton(port, CCPAD_2, SDL_GetGamepadButton(gp, SDL_GAMEPAD_BUTTON_EAST));
|
||||||
Gamepad_SetButton(port, CCPAD_3, SDL_GetGamepadButton(gp, SDL_GAMEPAD_BUTTON_WEST));
|
Gamepad_SetButton(port, CCPAD_3, SDL_GetGamepadButton(gp, SDL_GAMEPAD_BUTTON_WEST));
|
||||||
@ -542,8 +540,7 @@ static void ProcessGamepadButtons(int port) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define PAD_AXIS_SCALE 32768.0f
|
#define PAD_AXIS_SCALE 32768.0f
|
||||||
static void ProcessJoystick(int port, int axis, float delta) {
|
static void ProcessJoystick(int port, SDL_Gamepad* gp, int axis, float delta) {
|
||||||
SDL_Gamepad* gp = controllers[port];
|
|
||||||
int x = SDL_GetGamepadAxis(gp, axis == PAD_AXIS_LEFT ? SDL_GAMEPAD_AXIS_LEFTX : SDL_GAMEPAD_AXIS_RIGHTX);
|
int x = SDL_GetGamepadAxis(gp, axis == PAD_AXIS_LEFT ? SDL_GAMEPAD_AXIS_LEFTX : SDL_GAMEPAD_AXIS_RIGHTX);
|
||||||
int y = SDL_GetGamepadAxis(gp, axis == PAD_AXIS_LEFT ? SDL_GAMEPAD_AXIS_LEFTY : SDL_GAMEPAD_AXIS_RIGHTY);
|
int y = SDL_GetGamepadAxis(gp, axis == PAD_AXIS_LEFT ? SDL_GAMEPAD_AXIS_LEFTY : SDL_GAMEPAD_AXIS_RIGHTY);
|
||||||
|
|
||||||
@ -555,13 +552,15 @@ static void ProcessJoystick(int port, int axis, float delta) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Gamepads_Process(float delta) {
|
void Gamepads_Process(float delta) {
|
||||||
for (int port = 0; port < INPUT_MAX_GAMEPADS; port++)
|
for (int i = 0; i < INPUT_MAX_GAMEPADS; i++)
|
||||||
{
|
{
|
||||||
if (!controllers[port]) continue;
|
SDL_Gamepad* gp = controllers[i];
|
||||||
|
if (!gp) continue;
|
||||||
|
int port = Gamepad_MapPort(i + 10);
|
||||||
|
|
||||||
ProcessGamepadButtons(port);
|
ProcessGamepadButtons(port, gp);
|
||||||
ProcessJoystick(port, PAD_AXIS_LEFT, delta);
|
ProcessJoystick(port, gp, PAD_AXIS_LEFT, delta);
|
||||||
ProcessJoystick(port, PAD_AXIS_RIGHT, delta);
|
ProcessJoystick(port, gp, PAD_AXIS_RIGHT, delta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user