From 11bd4c453ea13cd19b8a447482c55c31ee424e38 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Sat, 25 Dec 2021 08:58:21 -0500 Subject: [PATCH] Almost multiplayer char select For some reason gamepads have not been registering buttons for a while, which makes this pretty hard to continue. Not sure if it's to do with how the menu cmd is generated, or something deeper in the SDL code. --- src/g_game.c | 35 ++++++++++++++++++++++++------ src/g_input.c | 60 +++++++++++++++++++++++++++------------------------ src/g_input.h | 5 +++-- 3 files changed, 63 insertions(+), 37 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index 53cc4c967..512eb8667 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -786,21 +786,38 @@ bound: return false; } -static INT32 KeyValue(UINT8 p, INT32 key) +static INT32 KeyValue(UINT8 p, INT32 key, boolean menu) { + INT32 deviceID; + if (key <= 0 || key >= NUMINPUTS) { return 0; } - return gamekeydown[p][key]; + if (menu == false) + { + deviceID = cv_usejoystick[p].value; + if (deviceID < 0 || deviceID >= MAXDEVICES) + { + return 0; + } + + return gamekeydown[deviceID][key]; + } + else + { + // Use keyboard as alternative for P1 menu. + return gamekeydown[0][key]; + } + + return 0; } INT32 G_PlayerInputAnalog(UINT8 p, INT32 gc, boolean menu) { INT32 i; INT32 deadzone = 0; - boolean bound = false; if (p >= MAXSPLITSCREENPLAYERS) { @@ -810,6 +827,11 @@ INT32 G_PlayerInputAnalog(UINT8 p, INT32 gc, boolean menu) return 0; } + if (p > splitscreen) + { + return 0; + } + deadzone = (JOYAXISRANGE * cv_deadzone[p].value) / FRACUNIT; for (i = 0; i < MAXINPUTMAPPING; i++) @@ -822,8 +844,7 @@ INT32 G_PlayerInputAnalog(UINT8 p, INT32 gc, boolean menu) continue; } - value = KeyValue(p, key); - bound = true; + value = KeyValue(p, key, false); if (value >= deadzone) { @@ -831,7 +852,7 @@ INT32 G_PlayerInputAnalog(UINT8 p, INT32 gc, boolean menu) } } - if (menu == true && bound == false) + if (p == 0 && menu == true) { // We don't want menus to become unnavigable if people unbind // all of their controls, so use the default control scheme in @@ -847,7 +868,7 @@ INT32 G_PlayerInputAnalog(UINT8 p, INT32 gc, boolean menu) continue; } - value = KeyValue(p, key); + value = KeyValue(p, key, true); if (value >= deadzone) { diff --git a/src/g_input.c b/src/g_input.c index 24c9c8b39..f2043f585 100644 --- a/src/g_input.c +++ b/src/g_input.c @@ -36,7 +36,7 @@ consvar_t cv_turnsmooth = CVAR_INIT ("turnsmoothing", "Slow", CV_SAVE, turnsmoot // current state of the keys // JOYAXISRANGE for fully pressed, 0 for not pressed -INT32 gamekeydown[MAXSPLITSCREENPLAYERS][NUMINPUTS]; +INT32 gamekeydown[MAXDEVICES][NUMINPUTS]; boolean deviceResponding[MAXDEVICES]; // two key codes (or virtual key) per game control @@ -66,6 +66,21 @@ const INT32 gcl_full[num_gcl_full] = { }; */ +INT32 G_GetDevicePlayer(INT32 deviceID) +{ + INT32 i; + + for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) + { + if (deviceID == cv_usejoystick[i].value) + { + return i; + } + } + + return -1; +} + // // Remaps the inputs to game controls. // @@ -76,18 +91,8 @@ const INT32 gcl_full[num_gcl_full] = { void G_MapEventsToControls(event_t *ev) { INT32 i; - INT32 devicePlayer = INT32_MAX; - for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) - { - if (ev->device == cv_usejoystick[i].value) - { - devicePlayer = i; - break; - } - } - - if (ev->device >= 0 && ev->device <= MAXGAMEPADS) + if (ev->device >= 0 && ev->device < MAXDEVICES) { switch (ev->type) { @@ -102,8 +107,7 @@ void G_MapEventsToControls(event_t *ev) break; } } - - if (devicePlayer == INT32_MAX) + else { return; } @@ -113,7 +117,7 @@ void G_MapEventsToControls(event_t *ev) case ev_keydown: if (ev->data1 < NUMINPUTS) { - gamekeydown[devicePlayer][ev->data1] = JOYAXISRANGE; + gamekeydown[ev->device][ev->data1] = JOYAXISRANGE; } #ifdef PARANOIA else @@ -126,7 +130,7 @@ void G_MapEventsToControls(event_t *ev) case ev_keyup: if (ev->data1 < NUMINPUTS) { - gamekeydown[devicePlayer][ev->data1] = 0; + gamekeydown[ev->device][ev->data1] = 0; } #ifdef PARANOIA else @@ -146,28 +150,28 @@ void G_MapEventsToControls(event_t *ev) if (ev->data2 < 0) { // Left - gamekeydown[devicePlayer][KEY_MOUSEMOVE + 2] = abs(ev->data2); - gamekeydown[devicePlayer][KEY_MOUSEMOVE + 3] = 0; + gamekeydown[ev->device][KEY_MOUSEMOVE + 2] = abs(ev->data2); + gamekeydown[ev->device][KEY_MOUSEMOVE + 3] = 0; } else { // Right - gamekeydown[devicePlayer][KEY_MOUSEMOVE + 2] = 0; - gamekeydown[devicePlayer][KEY_MOUSEMOVE + 3] = abs(ev->data2); + gamekeydown[ev->device][KEY_MOUSEMOVE + 2] = 0; + gamekeydown[ev->device][KEY_MOUSEMOVE + 3] = abs(ev->data2); } // Y axis if (ev->data3 < 0) { // Up - gamekeydown[devicePlayer][KEY_MOUSEMOVE] = abs(ev->data3); - gamekeydown[devicePlayer][KEY_MOUSEMOVE + 1] = 0; + gamekeydown[ev->device][KEY_MOUSEMOVE] = abs(ev->data3); + gamekeydown[ev->device][KEY_MOUSEMOVE + 1] = 0; } else { // Down - gamekeydown[devicePlayer][KEY_MOUSEMOVE] = 0; - gamekeydown[devicePlayer][KEY_MOUSEMOVE + 1] = abs(ev->data3); + gamekeydown[ev->device][KEY_MOUSEMOVE] = 0; + gamekeydown[ev->device][KEY_MOUSEMOVE + 1] = abs(ev->data3); } break; @@ -196,14 +200,14 @@ void G_MapEventsToControls(event_t *ev) if (ev->data2 < 0) { // Left - gamekeydown[devicePlayer][KEY_AXIS1 + i] = abs(ev->data2); - gamekeydown[devicePlayer][KEY_AXIS1 + i + 1] = 0; + gamekeydown[ev->device][KEY_AXIS1 + i] = abs(ev->data2); + gamekeydown[ev->device][KEY_AXIS1 + i + 1] = 0; } else { // Right - gamekeydown[devicePlayer][KEY_AXIS1 + i] = 0; - gamekeydown[devicePlayer][KEY_AXIS1 + i + 1] = abs(ev->data2); + gamekeydown[ev->device][KEY_AXIS1 + i] = 0; + gamekeydown[ev->device][KEY_AXIS1 + i + 1] = abs(ev->data2); } break; diff --git a/src/g_input.h b/src/g_input.h index 500b27268..ee4ac4000 100644 --- a/src/g_input.h +++ b/src/g_input.h @@ -90,9 +90,8 @@ extern consvar_t cv_controlperkey, cv_turnsmooth; // current state of the keys: JOYAXISRANGE or 0 when boolean. // Or anything inbetween for analog values -extern INT32 gamekeydown[MAXSPLITSCREENPLAYERS][NUMINPUTS]; - #define MAXDEVICES (MAXGAMEPADS + 1) // Gamepads + keyboard & mouse +extern INT32 gamekeydown[MAXDEVICES][NUMINPUTS]; extern boolean deviceResponding[MAXDEVICES]; // several key codes (or virtual key) per game control @@ -118,6 +117,8 @@ extern const INT32 gcl_full[num_gcl_full]; // peace to my little coder fingers! // check a gamecontrol being active or not +INT32 G_GetDevicePlayer(INT32 deviceID); + // remaps the input event to a game control. void G_MapEventsToControls(event_t *ev);