public Gamepad(IntPtr pmJoystick) { pName= "Unknown Gamepad"; pJoystick= pmJoystick; if(Sdl.SDL_JoystickIsHaptic(pJoystick)== 1) pHaptic= Sdl.SDL_HapticOpenFromJoystick(pJoystick); else pHaptic= IntPtr.Zero; bRumble= (Sdl.SDL_HapticRumbleSupported(pHaptic)== Sdl.SDL_TRUE); if(bRumble) bRumble= (Sdl.SDL_HapticRumbleInit(pHaptic)== 0); if(bRumble) Console.WriteLine("HAPTIC_RUMBLE SUPPORTED"); buttons= new FList<GamepadButton>(); dpads= new FList<GamepadDpad>(); sticks= new FList<GamepadStick>(); buttonsHeld= GBL.NONE; for(int i= 0; i< Sdl.SDL_JoystickNumButtons(pJoystick); i++) buttons.add(new GamepadButton(pJoystick, i)); for(int i= 0; i< Sdl.SDL_JoystickNumHats(pJoystick); i++) dpads.add(new GamepadDpad(pJoystick, i)); for(int i= 0; i< (int)(Sdl.SDL_JoystickNumAxes(joystick)/2f); i++) { if(mapStick(Sdl.SDL_JoystickGetAxis(joystick, i*2))== -1) { triggers.add(new GamepadTrigger(joystick, i*2)); triggers.add(new GamepadTrigger(joystick, (i*2)+1)); } else sticks.add(new GamepadStick(pJoystick, i*2, (i*2)+1)); } }
// Initiates the input internal static void init(Game pmGame) { game= pmGame; Sdl.SDL_Init(Sdl.SDL_INIT_JOYSTICK); game.window.viewport.LostFocus+= onLostFocus; game.window.viewport.GotFocus+= onGotFocus; bFocused= true; pUseFocus= true; mhelper= new MouseHelper(game.window.viewport); khelper= new KeyboardHelper(game.window.viewport); gamepadDetector= new FList<GamepadInfo>(); gamepadDetector.add(new GamepadInfo(15, 0, 3, typeof(Xbox360Gamepad))); gamepadDetector.add(new GamepadInfo(12, 1, 2, typeof(PS2Gamepad))); if(Sdl.SDL_NumJoysticks()> 0) { gamepad= getGamepadNoQuit(0); } }