Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First steps to fixing gamepad/joystick support #83

Merged
merged 4 commits into from
Aug 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading