hack and a half but joystick works now

This commit is contained in:
ashifolfi 2022-11-23 12:23:51 -05:00
parent 741b1f415d
commit 8f5f5c1e22

View file

@ -48,6 +48,9 @@
#include "md5.h"
#include "m_perfstats.h"
// aaaaaa
#include "i_joy.h"
#ifndef NONET
// cl loading screen
#include "v_video.h"
@ -650,6 +653,22 @@ static UINT8 Snake_GetOppositeDir(UINT8 dir)
return 12 + 5 - dir;
}
event_t *snakejoyevents[MAXEVENTS];
UINT16 joyeventcount = 0;
// I'm screaming the hack is clean - ashi
static boolean Snake_Joy_Grabber(event_t *ev)
{
if (ev->type == ev_joystick && ev->key == 0)
{
snakejoyevents[joyeventcount] = ev;
joyeventcount++;
return true;
}
else
return false;
}
static void Snake_FindFreeSlot(UINT8 *freex, UINT8 *freey, UINT8 headx, UINT8 heady)
{
UINT8 x, y;
@ -676,6 +695,9 @@ static void Snake_Handle(void)
UINT8 x, y;
UINT8 oldx, oldy;
UINT16 i;
UINT16 j;
UINT16 joystate = 0;
static INT32 pjoyx = 0, pjoyy = 0;
// Handle retry
if (snake->gameover && (PLAYER1INPUTDOWN(GC_JUMP) || gamekeydown[KEY_ENTER]))
@ -704,23 +726,57 @@ static void Snake_Handle(void)
oldx = snake->snakex[1];
oldy = snake->snakey[1];
// process the input events in here dear lord
for (j = 0; j < joyeventcount; j++)
{
event_t *ev = snakejoyevents[j];
const INT32 jdeadzone = (JOYAXISRANGE * cv_digitaldeadzone.value) / FRACUNIT;
if (ev->y != INT32_MAX)
{
if (Joystick.bGamepadStyle || abs(ev->y) > jdeadzone)
{
if (ev->y < 0 && pjoyy >= 0)
joystate = 1;
else if (ev->y > 0 && pjoyy <= 0)
joystate = 2;
pjoyy = ev->y;
}
else
pjoyy = 0;
}
if (ev->x != INT32_MAX)
{
if (Joystick.bGamepadStyle || abs(ev->x) > jdeadzone)
{
if (ev->x < 0 && pjoyx >= 0)
joystate = 3;
else if (ev->x > 0 && pjoyx <= 0)
joystate = 4;
pjoyx = ev->x;
}
else
pjoyx = 0;
}
}
// Update direction
if (PLAYER1INPUTDOWN(GC_STRAFELEFT) || gamekeydown[KEY_LEFTARROW] || JoyAxis(JA_STRAFE) > 0)
if (PLAYER1INPUTDOWN(GC_STRAFELEFT) || gamekeydown[KEY_LEFTARROW] || joystate == 3)
{
if (snake->snakelength < 2 || x <= oldx)
snake->snakedir[0] = 1;
}
else if (PLAYER1INPUTDOWN(GC_STRAFERIGHT) || gamekeydown[KEY_RIGHTARROW] || JoyAxis(JA_STRAFE) < 0)
else if (PLAYER1INPUTDOWN(GC_STRAFERIGHT) || gamekeydown[KEY_RIGHTARROW] || joystate == 4)
{
if (snake->snakelength < 2 || x >= oldx)
snake->snakedir[0] = 2;
}
else if (PLAYER1INPUTDOWN(GC_FORWARD) || gamekeydown[KEY_UPARROW] || JoyAxis(JA_MOVE) > 0)
else if (PLAYER1INPUTDOWN(GC_FORWARD) || gamekeydown[KEY_UPARROW] || joystate == 1)
{
if (snake->snakelength < 2 || y <= oldy)
snake->snakedir[0] = 3;
}
else if (PLAYER1INPUTDOWN(GC_BACKWARD) || gamekeydown[KEY_DOWNARROW] || JoyAxis(JA_MOVE) < 0)
else if (PLAYER1INPUTDOWN(GC_BACKWARD) || gamekeydown[KEY_DOWNARROW] || joystate == 2)
{
if (snake->snakelength < 2 || y >= oldy)
snake->snakedir[0] = 4;
@ -2073,7 +2129,7 @@ static boolean CL_FinishedFileList(void)
"Download of %s additional content\nis required to join.\n"
"\n"
"Press ENTER to continue\nor ESC to cancel.\n"
), "1111"), M_ConfirmConnect, MM_EVENTHANDLER);
), downloadsize), M_ConfirmConnect, MM_EVENTHANDLER);
Z_Free(downloadsize);
cl_mode = CL_CONFIRMCONNECT;
@ -2380,8 +2436,12 @@ static boolean CL_ServerConnectionTicker(const char *tmpsave, tic_t *oldtic, tic
D_ProcessEvents(); //needed for menu system to receive inputs
else
{
// my hand has been forced and I am dearly sorry for this awful hack :vomit:
for (; eventtail != eventhead; eventtail = (eventtail+1) & (MAXEVENTS-1))
G_MapEventsToControls(&events[eventtail]);
{
if (!Snake_Joy_Grabber(&events[eventtail]))
G_MapEventsToControls(&events[eventtail]);
}
}
if (gamekeydown[KEY_ESCAPE] || gamekeydown[KEY_JOY1+1] || cl_mode == CL_ABORTED)