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.
This commit is contained in:
Sally Coolatta 2021-12-25 08:58:21 -05:00
parent d6d561f0e8
commit 7684f5980a
4 changed files with 81 additions and 64 deletions

View file

@ -652,21 +652,38 @@ INT16 G_SoftwareClipAimingPitch(INT32 *aiming)
return (INT16)((*aiming)>>16);
}
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)
{
@ -676,6 +693,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++)
@ -688,14 +710,7 @@ INT32 G_PlayerInputAnalog(UINT8 p, INT32 gc, boolean menu)
continue;
}
value = KeyValue(p, key);
bound = true;
if (gc == gc_a || gc == gc_b || gc == gc_c)
{
// Handle spindash key
value = max(value, KeyValue(p, gamecontrol[p][gc_abc][i]));
}
value = KeyValue(p, key, false);
if (value >= deadzone)
{
@ -703,7 +718,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
@ -719,13 +734,7 @@ INT32 G_PlayerInputAnalog(UINT8 p, INT32 gc, boolean menu)
continue;
}
value = KeyValue(p, key);
if (gc == gc_a || gc == gc_b || gc == gc_c)
{
// Handle spindash key
value = max(value, KeyValue(p, gamecontroldefault[gc_abc][i]));
}
value = KeyValue(p, key, true);
if (value >= deadzone)
{

View file

@ -33,7 +33,7 @@ consvar_t cv_controlperkey = CVAR_INIT ("controlperkey", "One", CV_SAVE, onecont
// current state of the keys
// FRACUNIT 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
@ -67,6 +67,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.
//
@ -77,18 +92,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)
{
@ -103,8 +108,7 @@ void G_MapEventsToControls(event_t *ev)
break;
}
}
if (devicePlayer == INT32_MAX)
else
{
return;
}
@ -114,7 +118,7 @@ void G_MapEventsToControls(event_t *ev)
case ev_keydown:
if (ev->data1 < NUMINPUTS)
{
gamekeydown[devicePlayer][ev->data1] = FRACUNIT;
gamekeydown[ev->device][ev->data1] = FRACUNIT;
}
#ifdef PARANOIA
else
@ -127,7 +131,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
@ -147,28 +151,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;
@ -200,14 +204,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);
}
}
@ -217,14 +221,14 @@ void G_MapEventsToControls(event_t *ev)
if (ev->data3 < 0)
{
// Up
gamekeydown[devicePlayer][KEY_AXIS1 + i + 2] = abs(ev->data3);
gamekeydown[devicePlayer][KEY_AXIS1 + i + 3] = 0;
gamekeydown[ev->device][KEY_AXIS1 + i + 2] = abs(ev->data3);
gamekeydown[ev->device][KEY_AXIS1 + i + 3] = 0;
}
else
{
// Down
gamekeydown[devicePlayer][KEY_AXIS1 + i + 2] = 0;
gamekeydown[devicePlayer][KEY_AXIS1 + i + 3] = abs(ev->data3);
gamekeydown[ev->device][KEY_AXIS1 + i + 2] = 0;
gamekeydown[ev->device][KEY_AXIS1 + i + 3] = abs(ev->data3);
}
}

View file

@ -84,9 +84,8 @@ extern consvar_t cv_controlperkey;
// 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
@ -114,6 +113,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);

View file

@ -1931,7 +1931,8 @@ void M_CharacterSelectInit(INT32 choice)
for (i = 0; i < MAXSPLITSCREENPLAYERS; i++)
{
// Un-set all devices upon entering this menu.
cv_usejoystick[i].value = -1;
CV_SetValue(&cv_usejoystick[i], -1);
CONS_Printf("Device for %d set to %d\n", i, -1);
}
PLAY_CharSelectDef.prevMenu = currentMenu;
@ -2047,14 +2048,16 @@ static void M_HandlePressStart(setup_player_t *p, UINT8 num)
if (M_DeviceAvailable(i, setup_numplayers) == true)
{
// Available!! Let's use this one!!
cv_usejoystick[setup_numplayers].value = i;
CV_SetValue(&cv_usejoystick[setup_numplayers], i);
CONS_Printf("Device for %d set to %d\n", setup_numplayers, i);
for (j = setup_numplayers+1; j < MAXSPLITSCREENPLAYERS; j++)
{
if (cv_usejoystick[j].value == i)
{
// Un-set devices for other players.
cv_usejoystick[j].value = -1;
CV_SetValue(&cv_usejoystick[j], -1);
CONS_Printf("Device for %d set to %d\n", j, -1);
}
}
@ -2144,7 +2147,7 @@ static void M_HandleCharRotate(setup_player_t *p, UINT8 num)
{
UINT8 numclones = setup_chargrid[p->gridx][p->gridy].numskins;
if (G_PlayerInputDown(num, gc_right, true) == true)
if (menucmd[num].dpad_lr > 0)
{
p->clonenum++;
if (p->clonenum >= numclones)
@ -2153,7 +2156,7 @@ static void M_HandleCharRotate(setup_player_t *p, UINT8 num)
p->delay = CSROTATETICS;
S_StartSound(NULL, sfx_s3kc3s);
}
else if (G_PlayerInputDown(num, gc_left, true) == true)
else if (menucmd[num].dpad_lr < 0)
{
p->clonenum--;
if (p->clonenum < 0)
@ -2163,13 +2166,13 @@ static void M_HandleCharRotate(setup_player_t *p, UINT8 num)
S_StartSound(NULL, sfx_s3kc3s);
}
if (G_PlayerInputDown(num, gc_a, true) == true || G_PlayerInputDown(num, gc_start, true) == true)
if ((menucmd[num].buttons & MBT_A) || (menucmd[num].buttons & MBT_X) /*|| (menucmd[num].buttons & MBT_START)*/)
{
p->mdepth = CSSTEP_COLORS;
S_StartSound(NULL, sfx_s3k63);
M_SetMenuDelay(num);
}
else if (G_PlayerInputDown(num, gc_b, true) == true)
else if ((menucmd[num].buttons & MBT_B) || (menucmd[num].buttons & MBT_Y))
{
p->mdepth = CSSTEP_CHARS;
S_StartSound(NULL, sfx_s3k5b);
@ -2179,7 +2182,7 @@ static void M_HandleCharRotate(setup_player_t *p, UINT8 num)
static void M_HandleColorRotate(setup_player_t *p, UINT8 num)
{
if (G_PlayerInputDown(num, gc_right, true) == true)
if (menucmd[num].dpad_lr > 0)
{
p->color++;
if (p->color >= numskincolors)
@ -2188,7 +2191,7 @@ static void M_HandleColorRotate(setup_player_t *p, UINT8 num)
M_SetMenuDelay(num); //CSROTATETICS
S_StartSound(NULL, sfx_s3k5b); //sfx_s3kc3s
}
else if (G_PlayerInputDown(num, gc_left, true) == true)
else if (menucmd[num].dpad_lr < 0)
{
p->color--;
if (p->color < 1)
@ -2198,7 +2201,7 @@ static void M_HandleColorRotate(setup_player_t *p, UINT8 num)
S_StartSound(NULL, sfx_s3k5b); //sfx_s3kc3s
}
if (G_PlayerInputDown(num, gc_a, true) == true || G_PlayerInputDown(num, gc_start, true) == true)
if ((menucmd[num].buttons & MBT_A) || (menucmd[num].buttons & MBT_X) /*|| (menucmd[num].buttons & MBT_START)*/)
{
p->mdepth = CSSTEP_READY;
p->delay = TICRATE;
@ -2206,7 +2209,7 @@ static void M_HandleColorRotate(setup_player_t *p, UINT8 num)
S_StartSound(NULL, sfx_s3k4e);
M_SetMenuDelay(num);
}
else if (G_PlayerInputDown(num, gc_b, true) == true)
else if ((menucmd[num].buttons & MBT_B) || (menucmd[num].buttons & MBT_Y))
{
if (setup_chargrid[p->gridx][p->gridy].numskins == 1)
p->mdepth = CSSTEP_CHARS; // Skip clones menu