Forum

Joystick Snippet reference for ericw

Discuss programming topics for the various GPL'd game engine sources.

Moderator: InsideQC Admins

Joystick Snippet reference for ericw

Postby Baker » Tue Apr 17, 2018 3:31 am

Code: Select all
static cbool IN_Joystick_Consider_Opened (SDL_Joystick *joy_consider)
{ DEBUG_ASSERT (!joy_active_controller); {
   int buttons = SDL_JoystickNumButtons(joy_consider);
   const char *joyname = SDL_JoystickName (joy_consider);   

   if (buttons >= 4) {
      // Set the 3 variables
      joy_active_controller   = joy_consider;
      joy_active_instance_idx   = SDL_JoystickInstanceID(joy_consider);
      c_strlcpy (joy_active_name, joy_active_name);

      Con_SafePrintLinef ("Controller detected: " QUOTED_S " with instance id %d", joy_active_name, joy_active_instance_idx);
      return true;
   }
   
   Con_WarningLinef ("Ignoring controller due to lack of buttons: %s", joyname != NULL ? joyname : "NULL");

   if (SDL_JoystickGetAttached(joy_consider)) {
      SDL_JoystickClose(joy_consider);
   } else {
      Con_SafePrintLinef ("Joystick not attached"); // Does this happen
   }
   return false;
}}
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
User avatar
Baker
 
Posts: 3660
Joined: Tue Mar 14, 2006 5:15 am

Return to Engine Programming

Who is online

Users browsing this forum: No registered users and 1 guest