@@ -44,6 +44,7 @@ Maryland 20850 USA.
4444#include " sys/sys_events.h"
4545
4646static Log::Logger mouseLog (" client.mouse" , " " );
47+ static Log::Logger controllerLog = Log::Logger(" client.controller" , " " , Log::Level::NOTICE);
4748
4849static cvar_t *in_keyboardDebug = nullptr ;
4950
@@ -58,8 +59,6 @@ static cvar_t *in_joystickNo = nullptr;
5859static cvar_t *in_joystickUseAnalog = nullptr ;
5960static cvar_t *in_gameControllerTriggerDeadzone = nullptr ;
6061
61- static cvar_t *in_gameControllerDebug = nullptr ;
62-
6362static SDL_Window *window = nullptr ;
6463
6564
@@ -576,36 +575,28 @@ static void IN_InitJoystick()
576575
577576 if ( !in_joystick->integer )
578577 {
579- Log::Debug ( " Joystick is not active." );
580-
581- if ( !gamepad )
582- {
583- Log::Debug ( " Gamepad is not active." );
584- }
585-
578+ controllerLog.Verbose ( " Game controllers disabled" );
586579 return ;
587580 }
588581
589582 if ( !SDL_WasInit ( SDL_INIT_JOYSTICK ) )
590583 {
591- Log::Debug ( " Calling SDL_Init(SDL_INIT_JOYSTICK)..." );
584+ controllerLog. Verbose ( " Calling SDL_Init(SDL_INIT_JOYSTICK)..." );
592585
593586 if ( !SDL_Init ( SDL_INIT_JOYSTICK ) )
594587 {
595- Log:: Warn ( " SDL_Init(SDL_INIT_JOYSTICK) failed: %s" , SDL_GetError () );
588+ controllerLog. Warn ( " SDL_Init(SDL_INIT_JOYSTICK) failed: %s" , SDL_GetError () );
596589 return ;
597590 }
598-
599- Log::Debug ( " SDL_Init(SDL_INIT_JOYSTICK) passed." );
600591 }
601592
602593 int total = 0 ;
603594 SDL_JoystickID* ids = SDL_GetJoysticks ( &total );
604- Log::Debug ( " %d possible joysticks " , total );
595+ controllerLog. Notice ( " %d possible joystick(s): " , total );
605596
606597 for ( int i = 0 ; i < total; i++ )
607598 {
608- Log::Debug ( " [%d] %s" , i, JoystickNameForID ( ids[i] ) );
599+ controllerLog. Notice ( " [%d] %s" , i, JoystickNameForID ( ids[i] ) );
609600 }
610601
611602 in_joystickNo = Cvar_Get ( " in_joystickNo" , " 0" , 0 );
@@ -629,7 +620,7 @@ static void IN_InitJoystick()
629620
630621 if ( stick == nullptr )
631622 {
632- Log::Debug ( " No joystick opened: %s. " , SDL_GetError () );
623+ controllerLog. Warn ( " No joystick opened: %s" , SDL_GetError () );
633624 return ;
634625 }
635626
@@ -643,14 +634,14 @@ static void IN_InitJoystick()
643634 }
644635 }
645636
646- Log::Debug ( " Joystick %d opened" , in_joystickNo->integer );
647- Log::Debug ( " Name: %s" , JoystickNameForID ( id ) );
648- Log::Debug ( " Axes: %d" , SDL_GetNumJoystickAxes ( stick ) );
649- Log::Debug ( " Hats: %d" , SDL_GetNumJoystickHats ( stick ) );
650- Log::Debug ( " Buttons: %d" , SDL_GetNumJoystickButtons ( stick ) );
651- Log::Debug ( " Balls: %d" , SDL_GetNumJoystickBalls ( stick ) );
652- Log::Debug ( " Use Analog: %s" , in_joystickUseAnalog->integer ? " Yes" : " No" );
653- Log::Debug ( " Use SDL2 GameController mappings: %s" , gamepad ? " Yes" : " No" );
637+ controllerLog. Notice ( " Joystick %d opened" , in_joystickNo->integer );
638+ controllerLog. Verbose ( " Name: %s" , JoystickNameForID ( id ) );
639+ controllerLog. Verbose ( " Axes: %d" , SDL_GetNumJoystickAxes ( stick ) );
640+ controllerLog. Verbose ( " Hats: %d" , SDL_GetNumJoystickHats ( stick ) );
641+ controllerLog. Verbose ( " Buttons: %d" , SDL_GetNumJoystickButtons ( stick ) );
642+ controllerLog. Verbose ( " Balls: %d" , SDL_GetNumJoystickBalls ( stick ) );
643+ controllerLog. Verbose ( " Use Analog: %s" , in_joystickUseAnalog->integer ? " Yes" : " No" );
644+ controllerLog. Verbose ( " Use SDL GameController mappings: %s" , gamepad ? " Yes" : " No" );
654645
655646 SDL_GamepadEventsEnabled ();
656647}
@@ -963,11 +954,7 @@ static void IN_GameControllerAxis( SDL_GamepadAxis controllerAxis, joystickAxis_
963954 }
964955 else
965956 {
966- if ( in_gameControllerDebug->integer )
967- {
968- Log::Notice ( " GameController axis %i = %f" , controllerAxis, f );
969- }
970-
957+ controllerLog.Debug ( " GameController axis %i = %f" , controllerAxis, f );
971958 Com_QueueEvent ( Util::make_unique<Sys::JoystickEvent>(Util::ordinal (gameAxis), static_cast <int >(f * scale)) );
972959 }
973960}
@@ -988,23 +975,21 @@ static int IN_GameControllerAxisToButton( SDL_GamepadAxis controllerAxis, keyNum
988975 if ( ( axes & ( 1 << controllerAxis ) ) && !( stick_state.oldaxes & ( 1 << controllerAxis ) ) )
989976 {
990977 QueueKeyEvent ( key, true );
991- if ( in_gameControllerDebug->integer )
992- {
993- Log::Notice ( " GameController axis = %s to key = Q:0x%02x(%s), value = %f" ,
994- SDL_GetGamepadStringForAxis ( controllerAxis ), key,
995- Keyboard::KeyToString ( Key (key) ), f );
996- }
978+ controllerLog.DoDebugCode ( [&] {
979+ controllerLog.Debug ( " GameController axis = %s to key = Q:0x%02x(%s), value = %f" ,
980+ SDL_GetGamepadStringForAxis ( controllerAxis ), key,
981+ Keyboard::KeyToString ( Key (key) ), f );
982+ });
997983 }
998984
999985 if ( !( axes & ( 1 << controllerAxis ) ) && ( stick_state.oldaxes & ( 1 << controllerAxis ) ) )
1000986 {
1001987 QueueKeyEvent ( key, false );
1002- if ( in_gameControllerDebug->integer )
1003- {
1004- Log::Notice ( " GameController axis = %s to key = Q:0x%02x(%s), value = %f" ,
1005- SDL_GetGamepadStringForAxis ( controllerAxis ), key,
1006- Keyboard::KeyToString ( Key (key) ), f );
1007- }
988+ controllerLog.DoDebugCode ( [&] {
989+ controllerLog.Debug ( " GameController axis = %s to key = Q:0x%02x(%s), value = %f" ,
990+ SDL_GetGamepadStringForAxis ( controllerAxis ), key,
991+ Keyboard::KeyToString ( Key (key) ), f );
992+ });
1008993 }
1009994
1010995 return axes;
@@ -1036,12 +1021,11 @@ static void IN_GameControllerMove()
10361021 {
10371022 QueueKeyEvent ( Util::enum_cast<keyNum_t>(K_CONTROLLER_A + i), pressed );
10381023
1039- if ( in_gameControllerDebug->integer )
1040- {
1041- Log::Notice ( " GameController button %s = %s" ,
1042- SDL_GetGamepadStringForButton ( Util::enum_cast< SDL_GamepadButton >(i) ),
1043- pressed ? " Pressed" : " Released" );
1044- }
1024+ controllerLog.DoDebugCode ([&] {
1025+ controllerLog.Debug ( " GameController button %s = %s" ,
1026+ SDL_GetGamepadStringForButton ( Util::enum_cast< SDL_GamepadButton >(i) ),
1027+ pressed ? " Pressed" : " Released" );
1028+ });
10451029
10461030 stick_state.buttons [ i ] = pressed;
10471031 }
@@ -1323,7 +1307,6 @@ void IN_Init( void *windowData )
13231307 in_joystickThreshold = Cvar_Get ( " in_joystickThreshold" , " 0.15" , 0 );
13241308 in_gameControllerTriggerDeadzone = Cvar_Get ( " in_gameControllerTriggerDeadzone" , " 0.5" , 0 );
13251309
1326- in_gameControllerDebug = Cvar_Get ( " in_gameControllerDebug" , " 0" , CVAR_TEMP );
13271310 SDL_StartTextInput ( window );
13281311 IN_SetMouseMode ( MouseMode::SystemCursor );
13291312
0 commit comments