public unsafe SdlJoystick(SdlInputContext ctx, int currentIndex, int instanceId) { _ctx = ctx; InstanceId = instanceId; ActualIndex = currentIndex; _joystick = _ctx.Sdl.JoystickOpen(currentIndex); _buttons = new Button[0]; // arrays will be sized appropriately later _axes = new Axis[0]; _hats = new Hat[0]; }
public GameControllerSDL(InputSourceSDL source, int deviceIndex) { Source = source; joystick = SDL.JoystickOpen(deviceIndex); Id = Guid.NewGuid(); // Should be unique var joystickGUID = SDL.JoystickGetGUID(joystick); // Will identify the type of controller ProductId = *(Guid *)&joystickGUID; Name = SDL.JoystickNameS(joystick); InstanceId = SDL.JoystickInstanceID(joystick); for (int i = 0; i < SDL.JoystickNumButtons(joystick); i++) { buttonInfos.Add(new GameControllerButtonInfo { Name = $"Button {i}" }); } for (int i = 0; i < SDL.JoystickNumAxes(joystick); i++) { axisInfos.Add(new GameControllerAxisInfo { Name = $"Axis {i}" }); } for (int i = 0; i < SDL.JoystickNumHats(joystick); i++) { povControllerInfos.Add(new GameControllerDirectionInfo { Name = $"Hat {i}" }); } InitializeButtonStates(); }