Example #1
0
        public GlfwGamepad(int i)
        {
            var hasState = GlfwProvider.GLFW.Value.GetGamepadState(i, out var state);

            Index        = i;
            _buttons     = (Button *)Marshal.AllocHGlobal(GamepadButtonCount * sizeof(Button));
            _thumbsticks = (Thumbstick *)Marshal.AllocHGlobal(GamepadThumbstickCount * sizeof(Thumbstick));
            _triggers    = (Trigger *)Marshal.AllocHGlobal(GamepadTriggerCount * sizeof(Trigger));
            Buttons      = new GlfwReadOnlyList <Button>(_buttons, GamepadButtonCount);
            Thumbsticks  = new GlfwReadOnlyList <Thumbstick>(_thumbsticks, GamepadThumbstickCount);
            Triggers     = new GlfwReadOnlyList <Trigger>(_triggers, GamepadTriggerCount);

            _connected = hasState;

            for (int j = 0; j < GamepadButtonCount; j++)
            {
                _buttons[j] = new Button((ButtonName)j, j, hasState && state.Buttons[j] == (int)InputAction.Press);
            }

            for (int j = 0; j < GamepadThumbstickCount; j++)
            {
                _thumbsticks[j] = new Thumbstick(j, 0, 0);
            }

            for (int j = 0; j < GamepadTriggerCount; j++)
            {
                _triggers[j] = new Trigger(j, 0);
            }
        }
Example #2
0
        internal unsafe JoystickState(IJoystick joystick)
        {
            Name        = joystick.Name;
            Index       = joystick.Index;
            IsConnected = joystick.IsConnected;
            var axes    = joystick.Axes;
            var buttons = joystick.Buttons;
            var hats    = joystick.Hats;

            _axes    = (Axis *)Marshal.AllocHGlobal((_axisCount = axes.Count) * sizeof(Axis));
            _buttons = (Button *)Marshal.AllocHGlobal((_buttonCount = buttons.Count) * sizeof(Button));
            _hats    = (Hat *)Marshal.AllocHGlobal((_hatCount = hats.Count) * sizeof(Hat));
            for (var i = 0; i < _axisCount; i++)
            {
                _axes[i] = axes[i];
            }

            for (var i = 0; i < _buttonCount; i++)
            {
                _buttons[i] = buttons[i];
            }

            for (var i = 0; i < _hatCount; i++)
            {
                _hats[i] = hats[i];
            }

            Deadzone = joystick.Deadzone;
        }
Example #3
0
        public unsafe GlfwJoystick(int i)
        {
            Index    = i;
            _axes    = (Axis *)Marshal.AllocHGlobal(0);
            _buttons = (Button *)Marshal.AllocHGlobal(0);
            _hats    = (Hat *)Marshal.AllocHGlobal(0);
            Axes     = new GlfwReadOnlyList <Axis>(_axes, 0);
            Buttons  = new GlfwReadOnlyList <Button>(_buttons, 0);
            Hats     = new GlfwReadOnlyList <Hat>(_hats, 0);

            _connected = IsConnected;
        }
Example #4
0
        internal unsafe GamepadState(IGamepad gamepad)
        {
            Name        = gamepad.Name;
            Index       = gamepad.Index;
            IsConnected = gamepad.IsConnected;
            var buttons     = gamepad.Buttons;
            var thumbsticks = gamepad.Thumbsticks;
            var triggers    = gamepad.Triggers;

            _buttons     = (Button *)Marshal.AllocHGlobal((_buttonCount = buttons.Count) * sizeof(Button));
            _thumbsticks = (Thumbstick *)Marshal.AllocHGlobal
                               ((_thumbstickCount = thumbsticks.Count) * sizeof(Thumbstick));
            _triggers = (Trigger *)Marshal.AllocHGlobal((_triggerCount = triggers.Count) * sizeof(Trigger));
            Deadzone  = gamepad.Deadzone;
        }