Skip to content

Commit 1250369

Browse files
committed
Migrate in_* cvars to new style
Fixes #983. Written with the help of https://github.com/slipher/source-tools/blob/master/cvar_migrate.py.
1 parent 2f7b04e commit 1250369

File tree

1 file changed

+17
-27
lines changed

1 file changed

+17
-27
lines changed

src/engine/sys/sdl_input.cpp

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,18 @@ Maryland 20850 USA.
4747
static Log::Logger mouseLog("client.mouse", "");
4848
static Log::Logger controllerLog = Log::Logger("client.controller", "", Log::Level::NOTICE);
4949

50-
static cvar_t *in_keyboardDebug = nullptr;
50+
static Cvar::Cvar<bool> in_keyboardDebug("in_keyboardDebug", "log debug info about key presses", Cvar::NONE, false);
5151

5252
static SDL_Joystick *stick = nullptr;
5353
static SDL_Gamepad *gamepad = nullptr;
5454

55-
static cvar_t *in_nograb;
55+
static Cvar::Cvar<bool> in_nograb("in_nograb", "disable mouse grabbing and cursor hiding", Cvar::NONE, false);
5656

57-
static cvar_t *in_joystick = nullptr;
58-
static cvar_t *in_joystickThreshold = nullptr;
57+
static Cvar::Cvar<bool> in_joystick("in_joystick", "enable game controller", Cvar::NONE, false);
58+
static Cvar::Cvar<float> in_joystickThreshold("in_joystickThreshold", "ignore analog stick deflections less than this", Cvar::NONE, 0.15);
5959
static Cvar::Cvar<int> in_joystickNo("in_joystickNo", "which game controller to use", Cvar::NONE, 0);
60-
static cvar_t *in_joystickUseAnalog = nullptr;
61-
static cvar_t *in_gameControllerTriggerDeadzone = nullptr;
60+
static Cvar::Cvar<bool> in_joystickUseAnalog("in_joystickUseAnalog", "something about joystick control style", Cvar::NONE, false);
61+
static Cvar::Cvar<float> in_gameControllerTriggerDeadzone("in_gameControllerTriggerDeadzone", "how far trigger must be pulled for key down event", Cvar::NONE, 0.5);
6262

6363
static SDL_Window *window = nullptr;
6464

@@ -392,7 +392,7 @@ static Keyboard::Key IN_TranslateSDLToQ3Key( SDL_KeyboardEvent *event, bool down
392392
}
393393
}
394394

395-
if ( in_keyboardDebug->integer )
395+
if ( in_keyboardDebug.Get() )
396396
{
397397
IN_PrintKey( event->mod, event->scancode, event->key, key, down );
398398
}
@@ -434,7 +434,7 @@ static bool MouseModeAllowed( MouseMode mode )
434434
*/
435435
void IN_SetMouseMode(MouseMode newMode)
436436
{
437-
if ( in_nograb->integer && newMode == MouseMode::Deltas )
437+
if ( in_nograb.Get() && newMode == MouseMode::Deltas )
438438
{
439439
newMode = MouseMode::SystemCursor;
440440
}
@@ -566,6 +566,7 @@ IN_InitJoystick
566566
*/
567567
static void IN_InitJoystick()
568568
{
569+
Cvar::Latch( in_joystick );
569570
Cvar::Latch( in_joystickNo );
570571

571572
if ( stick != nullptr )
@@ -576,7 +577,7 @@ static void IN_InitJoystick()
576577
stick = nullptr;
577578
stick_state = {};
578579

579-
if ( !in_joystick->integer )
580+
if ( !in_joystick.Get() )
580581
{
581582
controllerLog.Verbose( "Game controllers disabled" );
582583
return;
@@ -602,8 +603,6 @@ static void IN_InitJoystick()
602603
controllerLog.Notice( "[%d] %s", i, JoystickNameForID( ids[i] ) );
603604
}
604605

605-
in_joystickUseAnalog = Cvar_Get( "in_joystickUseAnalog", "0", 0 );
606-
607606
if ( total <= 0 )
608607
{
609608
SDL_free( ids );
@@ -643,7 +642,7 @@ static void IN_InitJoystick()
643642
controllerLog.Verbose( "Hats: %d", SDL_GetNumJoystickHats( stick ) );
644643
controllerLog.Verbose( "Buttons: %d", SDL_GetNumJoystickButtons( stick ) );
645644
controllerLog.Verbose( "Balls: %d", SDL_GetNumJoystickBalls( stick ) );
646-
controllerLog.Verbose( "Use Analog: %s", in_joystickUseAnalog->integer ? "Yes" : "No" );
645+
controllerLog.Verbose( "Use Analog: %s", in_joystickUseAnalog.Get() ? "Yes" : "No" );
647646
controllerLog.Verbose( "Use SDL GameController mappings: %s", gamepad ? "Yes" : "No" );
648647

649648
SDL_GamepadEventsEnabled();
@@ -896,15 +895,15 @@ static void IN_JoyMove()
896895
{
897896
Sint16 axis = SDL_GetJoystickAxis( stick, i );
898897

899-
if ( !in_joystickUseAnalog->integer )
898+
if ( !in_joystickUseAnalog.Get() )
900899
{
901900
float f = ( ( float ) axis ) / 32767.0f;
902901

903-
if ( f < -in_joystickThreshold->value )
902+
if ( f < -in_joystickThreshold.Get() )
904903
{
905904
axes |= ( 1 << ( i * 2 ) );
906905
}
907-
else if ( f > in_joystickThreshold->value )
906+
else if ( f > in_joystickThreshold.Get() )
908907
{
909908
axes |= ( 1 << ( ( i * 2 ) + 1 ) );
910909
}
@@ -913,7 +912,7 @@ static void IN_JoyMove()
913912
{
914913
float f = ( ( float ) abs( axis ) ) / 32767.0f;
915914

916-
if ( f < in_joystickThreshold->value ) { axis = 0; }
915+
if ( f < in_joystickThreshold.Get() ) { axis = 0; }
917916

918917
if ( axis != stick_state.oldaaxes[ i ] )
919918
{
@@ -951,7 +950,7 @@ static void IN_GameControllerAxis( SDL_GamepadAxis controllerAxis, joystickAxis_
951950
Sint16 axis = SDL_GetGamepadAxis( gamepad, controllerAxis );
952951
float f = ( ( float ) axis ) / 32767.0f;
953952

954-
if ( f > -in_joystickThreshold->value && f < in_joystickThreshold->value )
953+
if ( f > -in_joystickThreshold.Get() && f < in_joystickThreshold.Get() )
955954
{
956955
Com_QueueEvent( Util::make_unique<Sys::JoystickEvent>(Util::ordinal(gameAxis), 0) );
957956
}
@@ -970,7 +969,7 @@ static int IN_GameControllerAxisToButton( SDL_GamepadAxis controllerAxis, keyNum
970969
Sint16 axis = SDL_GetGamepadAxis( gamepad, controllerAxis );
971970
float f = ( ( float ) axis ) / 32767.0f;
972971

973-
if ( f > in_gameControllerTriggerDeadzone->value )
972+
if ( f > in_gameControllerTriggerDeadzone.Get() )
974973
{
975974
axes |= ( 1 << ( controllerAxis ) );
976975
}
@@ -1301,15 +1300,6 @@ void IN_Init( void *windowData )
13011300

13021301
Log::Debug( "------- Input Initialization -------" );
13031302

1304-
in_keyboardDebug = Cvar_Get( "in_keyboardDebug", "0", CVAR_TEMP );
1305-
1306-
// mouse variables
1307-
in_nograb = Cvar_Get( "in_nograb", "0", 0 );
1308-
1309-
in_joystick = Cvar_Get( "in_joystick", "0", CVAR_LATCH );
1310-
in_joystickThreshold = Cvar_Get( "in_joystickThreshold", "0.15", 0 );
1311-
in_gameControllerTriggerDeadzone = Cvar_Get( "in_gameControllerTriggerDeadzone", "0.5", 0);
1312-
13131303
SDL_StartTextInput( window );
13141304
IN_SetMouseMode( MouseMode::SystemCursor );
13151305

0 commit comments

Comments
 (0)