diff --git a/rott/rt_in.c b/rott/rt_in.c index 90f39fa..72b928d 100644 --- a/rott/rt_in.c +++ b/rott/rt_in.c @@ -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; @@ -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) { @@ -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"); @@ -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; @@ -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]; }