Skip to content

Commit

Permalink
First steps to fixing gamepad/joystick support (#83)
Browse files Browse the repository at this point in the history
* hey it works kinda

* remove debug printfs

* remove debug printfs... 2

* remove unused var
  • Loading branch information
erysdren authored Aug 22, 2024
1 parent 42ab8dd commit 6d145a4
Showing 1 changed file with 34 additions and 8 deletions.
42 changes: 34 additions & 8 deletions rott/rt_in.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ static int sdl_mouse_delta_y = 0;
static unsigned short sdl_mouse_button_mask = 0;
static int sdl_total_sticks = 0;
static unsigned short *sdl_stick_button_state = NULL;
static unsigned short sdl_sticks_joybits = 0;
static int sdl_mouse_grabbed = 0;
extern boolean sdl_fullscreen;

Expand Down Expand Up @@ -381,6 +380,25 @@ static int sdl_key_filter(const SDL_Event *event)
return(0);
} /* sdl_key_filter */

static int sdl_joystick_button_filter(const SDL_Event *event)
{
if (event->jbutton.which >= sdl_total_sticks)
return 0;

if (event->jbutton.button >= 16)
return 0;

if (event->type == SDL_JOYBUTTONDOWN)
{
sdl_stick_button_state[event->jbutton.which] |= (1 << event->jbutton.button);
}
else if (event->type == SDL_JOYBUTTONUP)
{
sdl_stick_button_state[event->jbutton.which] &= ~(1 << event->jbutton.button);
}

return 0;
}

static int root_sdl_event_filter(const SDL_Event *event)
{
Expand All @@ -395,6 +413,9 @@ static int root_sdl_event_filter(const SDL_Event *event)
case SDL_MOUSEBUTTONUP:
case SDL_MOUSEBUTTONDOWN:
return(sdl_mouse_button_filter(event));
case SDL_JOYBUTTONUP:
case SDL_JOYBUTTONDOWN:
return(sdl_joystick_button_filter(event));
case SDL_QUIT:
/* !!! rcg TEMP */
fprintf(stderr, "\n\n\nSDL_QUIT!\n\n\n");
Expand Down Expand Up @@ -509,8 +530,17 @@ void IN_GetJoyAbs (unsigned short joy, unsigned short *xp, unsigned short *yp)

if (joy < sdl_total_sticks)
{
Joy_x = SDL_JoystickGetAxis (sdl_joysticks[joy], 0);
Joy_y = SDL_JoystickGetAxis (sdl_joysticks[joy], 1);
Sint32 jx, jy;

jx = (Sint32)SDL_JoystickGetAxis (sdl_joysticks[joy], 0) + SDL_JOYSTICK_AXIS_MAX;
jy = (Sint32)SDL_JoystickGetAxis (sdl_joysticks[joy], 1) + SDL_JOYSTICK_AXIS_MAX;

jx = ((float)jx / 65536.0f) * MaxJoyValue;
jy = ((float)jy / 65536.0f) * MaxJoyValue;

Joy_x = (unsigned short)jx;
Joy_y = (unsigned short)jy;

} else {
Joy_x = 0;
Joy_y = 0;
Expand Down Expand Up @@ -1046,11 +1076,7 @@ boolean IN_UserInput (long delay)

byte IN_JoyButtons (void)
{
unsigned int joybits = 0;

joybits = sdl_sticks_joybits;

return (byte) joybits;
return (byte)sdl_stick_button_state[joystickport];
}


Expand Down

0 comments on commit 6d145a4

Please sign in to comment.