Beispiel #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);
            }
        }
Beispiel #2
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;
        }