X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=vid_sdl.c;h=12214d2ab5b70cfa962ce8ff797188de247cae28;hb=d23a5a8ad9808df4a18b8db7ff64face3af3ef8e;hp=20fd0d2d501c2ef228b45e19a55a397d9566ff21;hpb=48669036b4be979d997c27227942ed9c430277d5;p=xonotic%2Fdarkplaces.git diff --git a/vid_sdl.c b/vid_sdl.c index 20fd0d2d..12214d2a 100644 --- a/vid_sdl.c +++ b/vid_sdl.c @@ -30,7 +30,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include #include -static cvar_t apple_mouse_noaccel = {CVAR_SAVE, "apple_mouse_noaccel", "1", "disables mouse acceleration while DarkPlaces is active"}; +static cvar_t apple_mouse_noaccel = {CVAR_CLIENT | CVAR_SAVE, "apple_mouse_noaccel", "1", "disables mouse acceleration while DarkPlaces is active"}; static qboolean vid_usingnoaccel; static double originalMouseSpeed = -1.0; io_connect_t IN_GetIOHandle(void) @@ -72,6 +72,8 @@ static qboolean vid_hasfocus = false; static qboolean vid_isfullscreen; static qboolean vid_usingvsync = false; static SDL_Joystick *vid_sdljoystick = NULL; +static SDL_GameController *vid_sdlgamecontroller = NULL; +static cvar_t joy_sdl2_trigger_deadzone = {CVAR_SAVE | CVAR_CLIENT, "joy_sdl2_trigger_deadzone", "0.5", "deadzone for triggers to be registered as key presses"}; // GAME_STEELSTORM specific static cvar_t *steelstorm_showing_map = NULL; // detect but do not create the cvar static cvar_t *steelstorm_showing_mousecursor = NULL; // detect but do not create the cvar @@ -692,14 +694,31 @@ void VID_BuildJoyState(vid_joystate_t *joystate) { SDL_Joystick *joy = vid_sdljoystick; int j; - int numaxes; - int numbuttons; - numaxes = SDL_JoystickNumAxes(joy); - for (j = 0;j < numaxes;j++) - joystate->axis[j] = SDL_JoystickGetAxis(joy, j) * (1.0f / 32767.0f); - numbuttons = SDL_JoystickNumButtons(joy); - for (j = 0;j < numbuttons;j++) - joystate->button[j] = SDL_JoystickGetButton(joy, j); + + if (vid_sdlgamecontroller) + { + for (j = 0; j <= SDL_CONTROLLER_AXIS_MAX; ++j) + { + joystate->axis[j] = SDL_GameControllerGetAxis(vid_sdlgamecontroller, j) * (1.0f / 32767.0f); + } + for (j = 0; j < SDL_CONTROLLER_BUTTON_MAX; ++j) + joystate->button[j] = SDL_GameControllerGetButton(vid_sdlgamecontroller, j); + // emulate joy buttons for trigger "axes" + joystate->button[SDL_CONTROLLER_BUTTON_MAX] = VID_JoyState_GetAxis(joystate, SDL_CONTROLLER_AXIS_TRIGGERLEFT, 1, joy_sdl2_trigger_deadzone.value) > 0.0f; + joystate->button[SDL_CONTROLLER_BUTTON_MAX+1] = VID_JoyState_GetAxis(joystate, SDL_CONTROLLER_AXIS_TRIGGERRIGHT, 1, joy_sdl2_trigger_deadzone.value) > 0.0f; + } + else + + { + int numaxes; + int numbuttons; + numaxes = SDL_JoystickNumAxes(joy); + for (j = 0;j < numaxes;j++) + joystate->axis[j] = SDL_JoystickGetAxis(joy, j) * (1.0f / 32767.0f); + numbuttons = SDL_JoystickNumButtons(joy); + for (j = 0;j < numbuttons;j++) + joystate->button[j] = SDL_JoystickGetButton(joy, j); + } } VID_Shared_BuildJoyState_Finish(joystate); @@ -875,7 +894,7 @@ static void IN_Move_TouchScreen_Quake(void) if (!VID_ShowingKeyboard()) { // user entered a command, close the console now - Con_ToggleConsole_f(); + Con_ToggleConsole_f(&cmd_client); } VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, NULL, &buttons[15], (keynum_t)0, NULL, 0, 0, 0, true); VID_TouchscreenArea( 0, 0, 0, 0, 0, NULL , 0.0f, NULL, move, &buttons[0], K_MOUSE4, NULL, 0, 0, 0, true); @@ -1156,11 +1175,11 @@ void Sys_SendKeyEvents( void ) vid.width = event.window.data1; vid.height = event.window.data2; #ifdef SDL_R_RESTART - // better not call R_Modules_Restart from here directly, as this may wreak havoc... + // better not call R_Modules_Restart_f from here directly, as this may wreak havoc... // so, let's better queue it for next frame if(!sdl_needs_restart) { - Cbuf_AddText("\nr_restart\n"); + Cbuf_AddText(&cmd_client, "\nr_restart\n"); sdl_needs_restart = true; } #endif @@ -1309,6 +1328,7 @@ void VID_Init (void) #ifdef DP_MOBILETOUCH Cvar_SetValueQuick(&vid_touchscreen, 1); #endif + Cvar_RegisterVariable(&joy_sdl2_trigger_deadzone); #ifdef SDL_R_RESTART R_RegisterModule("SDL", sdl_start, sdl_shutdown, sdl_newmap, NULL, NULL); @@ -1317,7 +1337,7 @@ void VID_Init (void) if (SDL_Init(SDL_INIT_VIDEO) < 0) Sys_Error ("Failed to init SDL video subsystem: %s", SDL_GetError()); vid_sdl_initjoysticksystem = SDL_InitSubSystem(SDL_INIT_JOYSTICK) >= 0; - if (vid_sdl_initjoysticksystem) + if (!vid_sdl_initjoysticksystem) Con_Printf("Failed to init SDL joystick subsystem: %s\n", SDL_GetError()); vid_isfullscreen = false; } @@ -1348,14 +1368,26 @@ void VID_EnableJoystick(qboolean enable) vid_sdljoystickindex = sdlindex; // close SDL joystick if active if (vid_sdljoystick) + { SDL_JoystickClose(vid_sdljoystick); - vid_sdljoystick = NULL; + vid_sdljoystick = NULL; + } + if (vid_sdlgamecontroller) + { + SDL_GameControllerClose(vid_sdlgamecontroller); + vid_sdlgamecontroller = NULL; + } if (sdlindex >= 0) { vid_sdljoystick = SDL_JoystickOpen(sdlindex); if (vid_sdljoystick) { const char *joystickname = SDL_JoystickName(vid_sdljoystick); + if (SDL_IsGameController(vid_sdljoystickindex)) + { + vid_sdlgamecontroller = SDL_GameControllerOpen(vid_sdljoystickindex); + Con_DPrintf("Using SDL GameController mappings for Joystick %i\n", index); + } Con_Printf("Joystick %i opened (SDL_Joystick %i is \"%s\" with %i axes, %i buttons, %i balls)\n", index, sdlindex, joystickname, (int)SDL_JoystickNumAxes(vid_sdljoystick), (int)SDL_JoystickNumButtons(vid_sdljoystick), (int)SDL_JoystickNumBalls(vid_sdljoystick)); } else @@ -1585,8 +1617,8 @@ extern cvar_t gl_info_driver; qboolean VID_InitMode(viddef_mode_t *mode) { // GAME_STEELSTORM specific - steelstorm_showing_map = Cvar_FindVar("steelstorm_showing_map"); - steelstorm_showing_mousecursor = Cvar_FindVar("steelstorm_showing_mousecursor"); + steelstorm_showing_map = Cvar_FindVar(&cvars_all, "steelstorm_showing_map", ~0); + steelstorm_showing_mousecursor = Cvar_FindVar(&cvars_all, "steelstorm_showing_mousecursor", ~0); if (!SDL_WasInit(SDL_INIT_VIDEO) && SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) Sys_Error ("Failed to init SDL video subsystem: %s", SDL_GetError());