Skip to content

Commit 090c843

Browse files
committed
Turn with the left stick X axis if there is only one stick
1 parent 22bf620 commit 090c843

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

id_in.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ static KeyboardDef KbdDefs = {
5959
static SDL_Joystick *Joystick;
6060
static SDL_GameController *GameController;
6161
int JoyNumButtons;
62+
int JoyNumAxes;
6263
static int JoyNumHats;
6364

6465
static bool GrabInput = false;
@@ -434,6 +435,7 @@ IN_Startup(void)
434435

435436
if(Joystick)
436437
{
438+
JoyNumAxes = SDL_JoystickNumAxes(Joystick);
437439
JoyNumButtons = SDL_JoystickNumButtons(Joystick);
438440
if(JoyNumButtons > 32) JoyNumButtons = 32; // only up to 32 buttons are supported
439441
JoyNumHats = SDL_JoystickNumHats(Joystick);

id_in.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ extern volatile boolean Paused;
142142
extern volatile char LastASCII;
143143
extern /*volatile*/ ScanCode LastScan;
144144
extern int JoyNumButtons;
145+
extern int JoyNumAxes;
145146
extern boolean forcegrabmouse;
146147

147148

wl_agent.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,15 @@ void ControlMovement (objtype *ob)
174174

175175
int joyx, joyy;
176176
float joyfactor = 1;
177-
if (joystickenabled) {
177+
bool joystrafe = false;
178+
if (joystickenabled && JoyNumAxes >= 4) {
179+
// Enable strafing with the left stick if we have two sticks
180+
joystrafe = true;
178181
IN_GetJoyDelta (&joyx, &joyy, SDL_CONTROLLER_AXIS_LEFTX, SDL_CONTROLLER_AXIS_RIGHTY);
179182
joyfactor = abs(joyx) / 127.0;
180183
}
181184

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

193-
if(buttonstate[bt_straferight] || (joystickenabled && joyx > JOYDEADZONE))
196+
if(buttonstate[bt_straferight] || (joystrafe && joyx > JOYDEADZONE))
194197
{
195198
angle = ob->angle - ANGLES/4;
196199
if(angle < 0)

wl_play.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,8 @@ void PollJoystickMove (void)
364364
{
365365
int joyx, joyy;
366366

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

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

0 commit comments

Comments
 (0)