Skip to content

Commit 2f7b04e

Browse files
committed
Migrate cvar in_joystickNo to new style
Also mark it latched and don't modify the value if it is out of range.
1 parent 7024cc0 commit 2f7b04e

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/engine/sys/sdl_input.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Maryland 20850 USA.
4141
#include "qcommon/qcommon.h"
4242
#include "qcommon/sys.h"
4343
#include "framework/CommandSystem.h"
44+
#include "framework/CvarSystem.h"
4445
#include "sys/sys_events.h"
4546

4647
static Log::Logger mouseLog("client.mouse", "");
@@ -55,7 +56,7 @@ static cvar_t *in_nograb;
5556

5657
static cvar_t *in_joystick = nullptr;
5758
static cvar_t *in_joystickThreshold = nullptr;
58-
static cvar_t *in_joystickNo = nullptr;
59+
static Cvar::Cvar<int> in_joystickNo("in_joystickNo", "which game controller to use", Cvar::NONE, 0);
5960
static cvar_t *in_joystickUseAnalog = nullptr;
6061
static cvar_t *in_gameControllerTriggerDeadzone = nullptr;
6162

@@ -565,6 +566,8 @@ IN_InitJoystick
565566
*/
566567
static void IN_InitJoystick()
567568
{
569+
Cvar::Latch( in_joystickNo );
570+
568571
if ( stick != nullptr )
569572
{
570573
SDL_CloseJoystick( stick );
@@ -599,7 +602,6 @@ static void IN_InitJoystick()
599602
controllerLog.Notice( "[%d] %s", i, JoystickNameForID( ids[i] ) );
600603
}
601604

602-
in_joystickNo = Cvar_Get( "in_joystickNo", "0", 0 );
603605
in_joystickUseAnalog = Cvar_Get( "in_joystickUseAnalog", "0", 0 );
604606

605607
if ( total <= 0 )
@@ -608,12 +610,13 @@ static void IN_InitJoystick()
608610
return;
609611
}
610612

611-
if ( in_joystickNo->integer < 0 || in_joystickNo->integer >= total )
613+
int stickIndex = in_joystickNo.Get();
614+
if ( stickIndex < 0 || stickIndex >= total )
612615
{
613-
Cvar_Set( "in_joystickNo", "0" );
616+
stickIndex = 0;
614617
}
615618

616-
SDL_JoystickID id = ids[ in_joystickNo->integer ];
619+
SDL_JoystickID id = ids[ stickIndex ];
617620
SDL_free( ids );
618621

619622
stick = SDL_OpenJoystick( id );
@@ -634,7 +637,7 @@ static void IN_InitJoystick()
634637
}
635638
}
636639

637-
controllerLog.Notice( "Joystick %d opened", in_joystickNo->integer );
640+
controllerLog.Notice( "Joystick %d opened", stickIndex );
638641
controllerLog.Verbose( "Name: %s", JoystickNameForID( id ) );
639642
controllerLog.Verbose( "Axes: %d", SDL_GetNumJoystickAxes( stick ) );
640643
controllerLog.Verbose( "Hats: %d", SDL_GetNumJoystickHats( stick ) );

0 commit comments

Comments
 (0)