bool Joystick::open(int deviceindex) { close(); joyhandle = SDL_JoystickOpen(deviceindex); if (joyhandle) { instanceid = SDL_JoystickInstanceID(joyhandle); // SDL_JoystickGetGUIDString uses 32 bytes plus the null terminator. char cstr[33]; SDL_JoystickGUID sdlguid = SDL_JoystickGetGUID(joyhandle); SDL_JoystickGetGUIDString(sdlguid, cstr, (int) sizeof(cstr)); pguid = std::string(cstr); // See if SDL thinks this is a Game Controller. openGamepad(deviceindex); // Prefer the Joystick name for consistency. const char *joyname = SDL_JoystickName(joyhandle); if (!joyname && controller) joyname = SDL_GameControllerName(controller); if (joyname) name = joyname; } return isConnected(); }
void Input::init( SDL_Window* _window ) { int x, y; window = _window; SDL_GetMouseState(&x, &y); Input::mouse_position.set((float)x, (float)y); Input::keystate = SDL_GetKeyboardState(NULL); for (int i = 0; i < 4; ++i) { //open gamepads _joy[i] = openGamepad(i); updateGamepadState(_joy[i], gamepads[i]); } }