void SDLFrontend::initJoystickAndHaptic () { if (_haptic != nullptr) { SDL_HapticClose(_haptic); _haptic = nullptr; } const int joysticks = SDL_NumJoysticks(); SDL_Haptic *haptic = nullptr; for (int i = 0; i < joysticks; i++) { const char *name; if (SDL_IsGameController(i)) { name = SDL_GameControllerNameForIndex(i); } else { name = SDL_JoystickNameForIndex(i); } SDL_Joystick *joystick = SDL_JoystickOpen(i); info(LOG_CLIENT, String::format("found joystick %s", name ? name : "Unknown Joystick")); info(LOG_CLIENT, String::format("joystick axes: %i", SDL_JoystickNumAxes(joystick))); info(LOG_CLIENT, String::format("joystick hats: %i", SDL_JoystickNumHats(joystick))); info(LOG_CLIENT, String::format("joystick balls: %i", SDL_JoystickNumBalls(joystick))); info(LOG_CLIENT, String::format("joystick buttons: %i", SDL_JoystickNumButtons(joystick))); if (haptic == nullptr) haptic = SDL_HapticOpenFromJoystick(joystick); } if (!joysticks) { info(LOG_CLIENT, "no joysticks found"); } info(LOG_CLIENT, String::format("found %i touch device(s)", SDL_GetNumTouchDevices())); info(LOG_CLIENT, String::format("%i haptic devices", SDL_NumHaptics())); if (haptic == nullptr && SDL_MouseIsHaptic()) { haptic = SDL_HapticOpenFromMouse(); } if (haptic != nullptr) { const bool rumbleSupported = SDL_HapticRumbleSupported(haptic) && SDL_HapticRumbleInit(haptic) == 0; if (rumbleSupported) { info(LOG_CLIENT, "rumble support"); _haptic = haptic; } } if (_haptic == nullptr) { info(LOG_CLIENT, "no rumble support"); } }
/* * Initializes the backend */ void IN_Init(void) { Com_Printf("------- input initialization -------\n"); mouse_x = mouse_y = 0; #if SDL_VERSION_ATLEAST(2, 0, 0) joystick_yaw = joystick_pitch = joystick_forwardmove = joystick_sidemove = 0; #endif exponential_speedup = Cvar_Get("exponential_speedup", "0", CVAR_ARCHIVE); freelook = Cvar_Get("freelook", "1", 0); in_grab = Cvar_Get("in_grab", "2", CVAR_ARCHIVE); lookstrafe = Cvar_Get("lookstrafe", "0", 0); m_filter = Cvar_Get("m_filter", "0", CVAR_ARCHIVE); m_up = Cvar_Get("m_up", "1", 0); m_forward = Cvar_Get("m_forward", "1", 0); m_pitch = Cvar_Get("m_pitch", "0.022", 0); m_side = Cvar_Get("m_side", "0.8", 0); m_yaw = Cvar_Get("m_yaw", "0.022", 0); sensitivity = Cvar_Get("sensitivity", "3", 0); #if SDL_VERSION_ATLEAST(2, 0, 0) joy_haptic_magnitude = Cvar_Get("joy_haptic_magnitude", "0.0", CVAR_ARCHIVE); joy_yawsensitivity = Cvar_Get("joy_yawsensitivity", "1.0", CVAR_ARCHIVE); joy_pitchsensitivity = Cvar_Get("joy_pitchsensitivity", "1.0", CVAR_ARCHIVE); joy_forwardsensitivity = Cvar_Get("joy_forwardsensitivity", "1.0", CVAR_ARCHIVE); joy_sidesensitivity = Cvar_Get("joy_sidesensitivity", "1.0", CVAR_ARCHIVE); joy_upsensitivity = Cvar_Get("joy_upsensitivity", "1.0", CVAR_ARCHIVE); joy_axis_leftx = Cvar_Get("joy_axis_leftx", "sidemove", CVAR_ARCHIVE); joy_axis_lefty = Cvar_Get("joy_axis_lefty", "forwardmove", CVAR_ARCHIVE); joy_axis_rightx = Cvar_Get("joy_axis_rightx", "yaw", CVAR_ARCHIVE); joy_axis_righty = Cvar_Get("joy_axis_righty", "pitch", CVAR_ARCHIVE); joy_axis_triggerleft = Cvar_Get("joy_axis_triggerleft", "triggerleft", CVAR_ARCHIVE); joy_axis_triggerright = Cvar_Get("joy_axis_triggerright", "triggerright", CVAR_ARCHIVE); joy_axis_leftx_threshold = Cvar_Get("joy_axis_leftx_threshold", "0.15", CVAR_ARCHIVE); joy_axis_lefty_threshold = Cvar_Get("joy_axis_lefty_threshold", "0.15", CVAR_ARCHIVE); joy_axis_rightx_threshold = Cvar_Get("joy_axis_rightx_threshold", "0.15", CVAR_ARCHIVE); joy_axis_righty_threshold = Cvar_Get("joy_axis_righty_threshold", "0.15", CVAR_ARCHIVE); joy_axis_triggerleft_threshold = Cvar_Get("joy_axis_triggerleft_threshold", "0.15", CVAR_ARCHIVE); joy_axis_triggerright_threshold = Cvar_Get("joy_axis_triggerright_threshold", "0.15", CVAR_ARCHIVE); #endif vid_fullscreen = Cvar_Get("vid_fullscreen", "0", CVAR_ARCHIVE); windowed_mouse = Cvar_Get("windowed_mouse", "1", CVAR_USERINFO | CVAR_ARCHIVE); Cmd_AddCommand("+mlook", IN_MLookDown); Cmd_AddCommand("-mlook", IN_MLookUp); #if SDL_VERSION_ATLEAST(2, 0, 0) SDL_StartTextInput(); #else SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); #endif #if SDL_VERSION_ATLEAST(2, 0, 0) /* joystik init */ if (!SDL_WasInit(SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC)) { if (SDL_Init(SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC) == -1) { Com_Printf ("Couldn't init SDL joystick: %s.\n", SDL_GetError ()); } else { Com_Printf ("%i joysticks were found.\n", SDL_NumJoysticks()); if (SDL_NumJoysticks() > 0) { int i; for (i=0; i<SDL_NumJoysticks(); i ++) { joystick = SDL_JoystickOpen(i); Com_Printf ("The name of the joystick is '%s'\n", SDL_JoystickName(joystick)); Com_Printf ("Number of Axes: %d\n", SDL_JoystickNumAxes(joystick)); Com_Printf ("Number of Buttons: %d\n", SDL_JoystickNumButtons(joystick)); Com_Printf ("Number of Balls: %d\n", SDL_JoystickNumBalls(joystick)); Com_Printf ("Number of Hats: %d\n", SDL_JoystickNumHats(joystick)); joystick_haptic = SDL_HapticOpenFromJoystick(joystick); if (joystick_haptic == NULL) Com_Printf ("Most likely joystick isn't haptic\n"); else IN_Haptic_Effects_Info(); if(SDL_IsGameController(i)) { SDL_GameControllerButtonBind backBind; controller = SDL_GameControllerOpen(i); Com_Printf ("Controller settings: %s\n", SDL_GameControllerMapping(controller)); Com_Printf ("Controller axis: \n"); Com_Printf (" * leftx = %s\n", joy_axis_leftx->string); Com_Printf (" * lefty = %s\n", joy_axis_lefty->string); Com_Printf (" * rightx = %s\n", joy_axis_rightx->string); Com_Printf (" * righty = %s\n", joy_axis_righty->string); Com_Printf (" * triggerleft = %s\n", joy_axis_triggerleft->string); Com_Printf (" * triggerright = %s\n", joy_axis_triggerright->string); Com_Printf ("Controller thresholds: \n"); Com_Printf (" * leftx = %f\n", joy_axis_leftx_threshold->value); Com_Printf (" * lefty = %f\n", joy_axis_lefty_threshold->value); Com_Printf (" * rightx = %f\n", joy_axis_rightx_threshold->value); Com_Printf (" * righty = %f\n", joy_axis_righty_threshold->value); Com_Printf (" * triggerleft = %f\n", joy_axis_triggerleft_threshold->value); Com_Printf (" * triggerright = %f\n", joy_axis_triggerright_threshold->value); backBind = SDL_GameControllerGetBindForButton(controller, SDL_CONTROLLER_BUTTON_BACK); if (backBind.bindType == SDL_CONTROLLER_BINDTYPE_BUTTON) { back_button_id = backBind.value.button; Com_Printf ("\nBack button JOY%d will be unbindable.\n", back_button_id+1); } break; } else { char joystick_guid[256] = {0}; SDL_JoystickGUID guid; guid = SDL_JoystickGetDeviceGUID(i); SDL_JoystickGetGUIDString(guid, joystick_guid, 255); Com_Printf ("For use joystic as game contoller please set SDL_GAMECONTROLLERCONFIG:\n"); Com_Printf ("e.g.: SDL_GAMECONTROLLERCONFIG='%s,%s,leftx:a0,lefty:a1,rightx:a2,righty:a3,back:b1,...\n", joystick_guid, SDL_JoystickName(joystick)); } } } else { joystick_haptic = SDL_HapticOpenFromMouse(); if (joystick_haptic == NULL) Com_Printf ("Most likely mouse isn't haptic\n"); else IN_Haptic_Effects_Info(); } } } #endif Com_Printf("------------------------------------\n\n"); }