Skip to content

Commit

Permalink
Turn with the left stick X axis if there is only one stick
Browse files Browse the repository at this point in the history
  • Loading branch information
lazd committed Oct 19, 2018
1 parent 22bf620 commit 090c843
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions id_in.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ static KeyboardDef KbdDefs = {
static SDL_Joystick *Joystick;
static SDL_GameController *GameController;
int JoyNumButtons;
int JoyNumAxes;
static int JoyNumHats;

static bool GrabInput = false;
Expand Down Expand Up @@ -434,6 +435,7 @@ IN_Startup(void)

if(Joystick)
{
JoyNumAxes = SDL_JoystickNumAxes(Joystick);
JoyNumButtons = SDL_JoystickNumButtons(Joystick);
if(JoyNumButtons > 32) JoyNumButtons = 32; // only up to 32 buttons are supported
JoyNumHats = SDL_JoystickNumHats(Joystick);
Expand Down
1 change: 1 addition & 0 deletions id_in.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ extern volatile boolean Paused;
extern volatile char LastASCII;
extern /*volatile*/ ScanCode LastScan;
extern int JoyNumButtons;
extern int JoyNumAxes;
extern boolean forcegrabmouse;


Expand Down
9 changes: 6 additions & 3 deletions wl_agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,15 @@ void ControlMovement (objtype *ob)

int joyx, joyy;
float joyfactor = 1;
if (joystickenabled) {
bool joystrafe = false;
if (joystickenabled && JoyNumAxes >= 4) {
// Enable strafing with the left stick if we have two sticks
joystrafe = true;
IN_GetJoyDelta (&joyx, &joyy, SDL_CONTROLLER_AXIS_LEFTX, SDL_CONTROLLER_AXIS_RIGHTY);
joyfactor = abs(joyx) / 127.0;
}

if(buttonstate[bt_strafeleft] || (joystickenabled && joyx < -JOYDEADZONE))
if(buttonstate[bt_strafeleft] || (joystrafe && joyx < -JOYDEADZONE))
{
angle = ob->angle + ANGLES/4;
if(angle >= ANGLES)
Expand All @@ -190,7 +193,7 @@ void ControlMovement (objtype *ob)
Thrust(angle, (int32_t) (joyfactor * BASEMOVE * MOVESCALE * tics));
}

if(buttonstate[bt_straferight] || (joystickenabled && joyx > JOYDEADZONE))
if(buttonstate[bt_straferight] || (joystrafe && joyx > JOYDEADZONE))
{
angle = ob->angle - ANGLES/4;
if(angle < 0)
Expand Down
3 changes: 2 additions & 1 deletion wl_play.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@ void PollJoystickMove (void)
{
int joyx, joyy;

IN_GetJoyDelta (&joyx, &joyy, SDL_CONTROLLER_AXIS_RIGHTX, SDL_CONTROLLER_AXIS_LEFTY);
// Turn with the left stick X axis if there is only one stick
IN_GetJoyDelta (&joyx, &joyy, JoyNumAxes >= 4 ? SDL_CONTROLLER_AXIS_RIGHTX : SDL_CONTROLLER_AXIS_LEFTX, SDL_CONTROLLER_AXIS_LEFTY);

int delta = buttonstate[bt_run] ? RUNMOVE * tics : BASEMOVE * tics;

Expand Down

0 comments on commit 090c843

Please sign in to comment.