Ejemplo n.º 1
0
        public void Update()
        {
            // If not connected, nothing to update
            if (!Connected)
            {
                return;
            }

            // If same packet, nothing to update
            State state = Controller.GetState();

            if (lastPacket == state.PacketNumber)
            {
                return;
            }
            lastPacket = state.PacketNumber;

            var gamepadState = state.Gamepad;

            // Shoulders
            LeftShoulder  = (gamepadState.Buttons & GamepadButtonFlags.LeftShoulder) != 0;
            RightShoulder = (gamepadState.Buttons & GamepadButtonFlags.RightShoulder) != 0;

            // Triggers
            LeftTrigger  = gamepadState.LeftTrigger / (float)byte.MaxValue;
            RightTrigger = gamepadState.RightTrigger / (float)byte.MaxValue;

            // Buttons
            Start = (gamepadState.Buttons & GamepadButtonFlags.Start) != 0;
            Back  = (gamepadState.Buttons & GamepadButtonFlags.Back) != 0;

            A = (gamepadState.Buttons & GamepadButtonFlags.A) != 0;
            B = (gamepadState.Buttons & GamepadButtonFlags.B) != 0;
            X = (gamepadState.Buttons & GamepadButtonFlags.X) != 0;
            Y = (gamepadState.Buttons & GamepadButtonFlags.Y) != 0;

            // D-Pad
            DPad = new DPadState((gamepadState.Buttons & GamepadButtonFlags.DPadUp) != 0,
                                 (gamepadState.Buttons & GamepadButtonFlags.DPadDown) != 0,
                                 (gamepadState.Buttons & GamepadButtonFlags.DPadLeft) != 0,
                                 (gamepadState.Buttons & GamepadButtonFlags.DPadRight) != 0);

            LeftStickX = gamepadState.LeftThumbX;
            LeftStickY = gamepadState.LeftThumbY;

            RightStickX = gamepadState.RightThumbX;
            RightStickY = gamepadState.RightThumbY;

            // Thumbsticks
            LeftStick = new ThumbstickState(
                Normalize(gamepadState.LeftThumbX, gamepadState.LeftThumbY, SlimDX.XInput.Gamepad.GamepadLeftThumbDeadZone),
                (gamepadState.Buttons & GamepadButtonFlags.LeftThumb) != 0);
            RightStick = new ThumbstickState(
                Normalize(gamepadState.RightThumbX, gamepadState.RightThumbY, SlimDX.XInput.Gamepad.GamepadRightThumbDeadZone),
                (gamepadState.Buttons & GamepadButtonFlags.RightThumb) != 0);

            int GuideFlag = (1 << 10);

            Guide = (((int)gamepadState.Buttons) & GuideFlag) != 0;
        }
Ejemplo n.º 2
0
        public void Update()
        {
            // If not connected, nothing to update
            if (!Connected)
            {
                return;
            }

            var state = Controller.GetState();

            // If same packet, nothing to update
            if (lastPacket == state.PacketNumber)
            {
                return;
            }

            lastPacket = state.PacketNumber;

            var gamepadState = state.Gamepad;

            // Shoulders
            LeftShoulder  = (gamepadState.Buttons & GamepadButtonFlags.LeftShoulder) != 0;
            RightShoulder = (gamepadState.Buttons & GamepadButtonFlags.RightShoulder) != 0;

            // Triggers
            LeftTrigger  = gamepadState.LeftTrigger / (float)byte.MaxValue;
            RightTrigger = gamepadState.RightTrigger / (float)byte.MaxValue;

            // Buttons
            Start = (gamepadState.Buttons & GamepadButtonFlags.Start) != 0;
            Back  = (gamepadState.Buttons & GamepadButtonFlags.Back) != 0;

            A = (gamepadState.Buttons & GamepadButtonFlags.A) != 0;
            B = (gamepadState.Buttons & GamepadButtonFlags.B) != 0;
            X = (gamepadState.Buttons & GamepadButtonFlags.X) != 0;
            Y = (gamepadState.Buttons & GamepadButtonFlags.Y) != 0;

            // D-Pad
            DPad = new DPadState(
                (gamepadState.Buttons & GamepadButtonFlags.DPadUp) != 0,
                (gamepadState.Buttons & GamepadButtonFlags.DPadDown) != 0,
                (gamepadState.Buttons & GamepadButtonFlags.DPadLeft) != 0,
                (gamepadState.Buttons & GamepadButtonFlags.DPadRight) != 0);

            // Thumbsticks
            LeftStick = new ThumbstickState(
                //Normalize(gamepadState.LeftThumbX, gamepadState.LeftThumbY, Gamepad.GamepadLeftThumbDeadZone),
                new Vector2(gamepadState.LeftThumbX, gamepadState.LeftThumbY),
                (gamepadState.Buttons & GamepadButtonFlags.LeftThumb) != 0);
            RightStick = new ThumbstickState(
                //Normalize(gamepadState.RightThumbX, gamepadState.RightThumbY, Gamepad.GamepadRightThumbDeadZone),
                new Vector2(gamepadState.RightThumbX, gamepadState.RightThumbY),
                (gamepadState.Buttons & GamepadButtonFlags.RightThumb) != 0);
        }
Ejemplo n.º 3
0
        protected Device(LogicalPlayerIndex logicalPlayerIndex, DeviceType type, int index)
        {
            Type = type;
            _index = index;

            mapping = new Dictionary<MappingButtons, ButtonState>();
            ThumbStickRight = new ThumbstickState();
            ThumbStickLeft = new ThumbstickState();

            rumbles = new Rumble[4];
            for (int i = 0; i < rumbles.Length; i++)
            {
                rumbles[i] = new Rumble(0);
            }

            RumbleAssignation();
        }
Ejemplo n.º 4
0
        protected Device(LogicalPlayerIndex logicalPlayerIndex, DeviceType type, int index)
        {
            Type   = type;
            _index = index;

            mapping         = new Dictionary <MappingButtons, ButtonState>();
            ThumbStickRight = new ThumbstickState();
            ThumbStickLeft  = new ThumbstickState();

            rumbles = new Rumble[4];
            for (int i = 0; i < rumbles.Length; i++)
            {
                rumbles[i] = new Rumble(0);
            }

            RumbleAssignation();
        }
Ejemplo n.º 5
0
        public void Update(float dt)
        {
            ThumbstickState old_l = LeftStick;
            ThumbstickState old_r = RightStick;

            // If not connected, nothing to update
            if (!Connected) return;

            if (_vibrationTime > _elapsed)
            {
                _elapsed += dt;
            }
            else
            {
                _elapsed = 0;
                _vibrationTime = 0;
                Vibrate(0, 0);
            }

            // If same packet, nothing to update
            State state = Controller.GetState();
            if (lastPacket == state.PacketNumber) return;
            lastPacket = state.PacketNumber;

            var gamepadState = state.Gamepad;

            // Shoulders
            LeftShoulder = (gamepadState.Buttons & GamepadButtonFlags.LeftShoulder) != 0;
            RightShoulder = (gamepadState.Buttons & GamepadButtonFlags.RightShoulder) != 0;

            // Triggers
            LeftTrigger = gamepadState.LeftTrigger / (float)byte.MaxValue;
            RightTrigger = gamepadState.RightTrigger / (float)byte.MaxValue;

            // Buttons
            Start = (gamepadState.Buttons & GamepadButtonFlags.Start) != 0;
            Back = (gamepadState.Buttons & GamepadButtonFlags.Back) != 0;

            A = (gamepadState.Buttons & GamepadButtonFlags.A) != 0;
            B = (gamepadState.Buttons & GamepadButtonFlags.B) != 0;
            X = (gamepadState.Buttons & GamepadButtonFlags.X) != 0;
            Y = (gamepadState.Buttons & GamepadButtonFlags.Y) != 0;

            // D-Pad
            DPad = new DPadState((gamepadState.Buttons & GamepadButtonFlags.DPadUp) != 0,
                                 (gamepadState.Buttons & GamepadButtonFlags.DPadDown) != 0,
                                 (gamepadState.Buttons & GamepadButtonFlags.DPadLeft) != 0,
                                 (gamepadState.Buttons & GamepadButtonFlags.DPadRight) != 0);

            // Thumbsticks
            LeftStick = new ThumbstickState(
                Normalize(gamepadState.LeftThumbX, gamepadState.LeftThumbY, Gamepad.LeftThumbDeadZone),
                (gamepadState.Buttons & GamepadButtonFlags.LeftThumb) != 0);
            RightStick = new ThumbstickState(
                Normalize(gamepadState.RightThumbX, gamepadState.RightThumbY, Gamepad.RightThumbDeadZone),
                (gamepadState.Buttons & GamepadButtonFlags.RightThumb) != 0);

            foreach (var flag in Enum.GetValues(typeof(GamepadButtonFlags)))
            {
                if (OnButtonUp != null)
                    if ((old_state.Buttons & (GamepadButtonFlags)flag) != 0 && (gamepadState.Buttons & (GamepadButtonFlags)flag) == 0)
                        OnButtonUp(this, (GamepadButtonFlags)((GamepadButtonFlags)flag));
                if (OnButtonPress != null)
                {
                    if ((old_state.Buttons & (GamepadButtonFlags)flag) == 0 && (gamepadState.Buttons & (GamepadButtonFlags)flag) != 0)
                        OnButtonPress(this, (GamepadButtonFlags)((GamepadButtonFlags)flag));
                }
                if (OnButtonDown != null)
                    if ((gamepadState.Buttons & (GamepadButtonFlags)flag) != 0)
                        OnButtonDown(this, (GamepadButtonFlags)gamepadState.Buttons);
            }

            if (OnLeftTrigger != null)
                if (gamepadState.LeftTrigger != old_state.LeftTrigger)
                    OnLeftTrigger(this, new TriggerState(LeftTrigger, LeftTrigger - (old_state.LeftTrigger / (float)byte.MaxValue)));
            if (OnRightTrigger != null)
                if (gamepadState.RightTrigger != old_state.RightTrigger)
                    OnRightTrigger(this, new TriggerState(RightTrigger, RightTrigger - (old_state.RightTrigger / (float)byte.MaxValue)));

            if (OnLeftStick != null)
                if (LeftStick.Position != old_l.Position || LeftStick.Clicked != old_l.Clicked)
                    OnLeftStick(this, LeftStick, LeftStick.Position - old_l.Position);
            if (OnRightStick != null)
                if (RightStick.Position != old_r.Position || RightStick.Clicked != old_r.Clicked)
                    OnRightStick(this, RightStick, RightStick.Position - old_r.Position);

            old_state = gamepadState;
        }
Ejemplo n.º 6
0
       /* public void Vibrate(float leftMotor, float rightMotor)
        {
            Controller.SetVibration(
                new Vibration
                {
                    LeftMotorSpeed = (ushort) (MathHelper.Saturate(leftMotor) * ushort.MaxValue),
                    RightMotorSpeed = (ushort) (MathHelper.Saturate(rightMotor) * ushort.MaxValue)
                });
        }*/

        public void Update()
        {
            // If not connected, nothing to update
            if (!Connected)
            {
                return;
            }

            var state = Controller.GetState();

            // If same packet, nothing to update
            if (lastPacket == state.PacketNumber)
            {
                return;
            }

            lastPacket = state.PacketNumber;
            var gamepadState = state.Gamepad;

            // Shoulders
            LeftShoulder = (gamepadState.Buttons & GamepadButtonFlags.LeftShoulder) != 0;
            RightShoulder = (gamepadState.Buttons & GamepadButtonFlags.RightShoulder) != 0;
            // Triggers
            LeftTrigger = gamepadState.LeftTrigger / (float) byte.MaxValue;
            RightTrigger = gamepadState.RightTrigger / (float) byte.MaxValue;

            // Buttons
            Start = (gamepadState.Buttons & GamepadButtonFlags.Start) != 0;
            Back = (gamepadState.Buttons & GamepadButtonFlags.Back) != 0;

            A = (gamepadState.Buttons & GamepadButtonFlags.A) != 0;
            B = (gamepadState.Buttons & GamepadButtonFlags.B) != 0;
            X = (gamepadState.Buttons & GamepadButtonFlags.X) != 0;
            Y = (gamepadState.Buttons & GamepadButtonFlags.Y) != 0;

            // D-Pad
            DPad = new DPadState(
                (gamepadState.Buttons & GamepadButtonFlags.DPadUp) != 0,
                (gamepadState.Buttons & GamepadButtonFlags.DPadDown) != 0,
                (gamepadState.Buttons & GamepadButtonFlags.DPadLeft) != 0,
                (gamepadState.Buttons & GamepadButtonFlags.DPadRight) != 0);

            // Thumbsticks
            LeftStick = new ThumbstickState(
                //Normalize(gamepadState.LeftThumbX, gamepadState.LeftThumbY, Gamepad.GamepadLeftThumbDeadZone),
                new Vector2(gamepadState.LeftThumbX, gamepadState.LeftThumbY),
                (gamepadState.Buttons & GamepadButtonFlags.LeftThumb) != 0);
            RightStick = new ThumbstickState(
                //Normalize(gamepadState.RightThumbX, gamepadState.RightThumbY, Gamepad.GamepadRightThumbDeadZone),
                new Vector2(gamepadState.RightThumbX, gamepadState.RightThumbY),
                (gamepadState.Buttons & GamepadButtonFlags.RightThumb) != 0);
        }
Ejemplo n.º 7
0
        public void Update()
        {
            // nothing to update section ------
            if (!Connected) return;
            State state = Controller.GetState();
            if (lastPacket == state.PacketNumber) return;
            lastPacket = state.PacketNumber;
            // --------------------------------

            var gamepadState = state.Gamepad;

            // Shoulders
            LeftShoulder = (gamepadState.Buttons & GamepadButtonFlags.LeftShoulder) != 0;
            RightShoulder = (gamepadState.Buttons & GamepadButtonFlags.RightShoulder) != 0;

            //Triggers
            LeftTrigger = gamepadState.LeftTrigger;
            RightTrigger = gamepadState.RightTrigger;

            // Triggers
            LeftTrigger = gamepadState.LeftTrigger;
            RightTrigger = gamepadState.RightTrigger;

            // Buttons
            Start = (gamepadState.Buttons & GamepadButtonFlags.Start) != 0;
            Back = (gamepadState.Buttons & GamepadButtonFlags.Back) != 0;

            A = (gamepadState.Buttons & GamepadButtonFlags.A) != 0;
            B = (gamepadState.Buttons & GamepadButtonFlags.B) != 0;
            X = (gamepadState.Buttons & GamepadButtonFlags.X) != 0;
            Y = (gamepadState.Buttons & GamepadButtonFlags.Y) != 0;

            // D-Pad
            DPad = new DPadState((gamepadState.Buttons & GamepadButtonFlags.DPadUp) != 0,
                                (gamepadState.Buttons & GamepadButtonFlags.DPadDown) != 0,
                                (gamepadState.Buttons & GamepadButtonFlags.DPadLeft) != 0,
                                (gamepadState.Buttons & GamepadButtonFlags.DPadRight) != 0);

            // Thumbsticks
            LeftStick = new ThumbstickState(
                Normalize(gamepadState.LeftThumbX, gamepadState.LeftThumbY, Gamepad.GamepadLeftThumbDeadZone),
                (gamepadState.Buttons & GamepadButtonFlags.LeftThumb) != 0);
            RightStick = new ThumbstickState(
                Normalize(gamepadState.RightThumbX, gamepadState.RightThumbY, Gamepad.GamepadRightThumbDeadZone),
                (gamepadState.Buttons & GamepadButtonFlags.RightThumb) != 0);
        }
Ejemplo n.º 8
0
        public override void Update(GameTime gameTime)
        {
            if (!ServiceHelper.Game.IsActive)
            {
                return;
            }
            this.Reset();
            if (this.keyboard)
            {
                this.KeyboardState.Update(Keyboard.GetState(), gameTime);
                this.Movement      = new Vector2(FezButtonStateExtensions.IsDown(this.KeyboardState.Right) ? 1f : (FezButtonStateExtensions.IsDown(this.KeyboardState.Left) ? -1f : 0.0f), FezButtonStateExtensions.IsDown(this.KeyboardState.Up) ? 1f : (FezButtonStateExtensions.IsDown(this.KeyboardState.Down) ? -1f : 0.0f));
                this.FreeLook      = new Vector2(FezButtonStateExtensions.IsDown(this.KeyboardState.LookRight) ? 1f : (FezButtonStateExtensions.IsDown(this.KeyboardState.LookLeft) ? -1f : 0.0f), FezButtonStateExtensions.IsDown(this.KeyboardState.LookUp) ? 1f : (FezButtonStateExtensions.IsDown(this.KeyboardState.LookDown) ? -1f : 0.0f));
                this.Back          = this.KeyboardState.OpenMap;
                this.Start         = this.KeyboardState.Pause;
                this.Jump          = this.KeyboardState.Jump;
                this.GrabThrow     = this.KeyboardState.GrabThrow;
                this.CancelTalk    = this.KeyboardState.CancelTalk;
                this.Down          = this.KeyboardState.Down;
                this.ExactUp       = this.Up = this.KeyboardState.Up;
                this.Left          = this.KeyboardState.Left;
                this.Right         = this.KeyboardState.Right;
                this.OpenInventory = this.KeyboardState.OpenInventory;
                this.RotateLeft    = this.KeyboardState.RotateLeft;
                this.RotateRight   = this.KeyboardState.RotateRight;
                this.MapZoomIn     = this.KeyboardState.MapZoomIn;
                this.MapZoomOut    = this.KeyboardState.MapZoomOut;
                this.FpsToggle     = this.KeyboardState.FpViewToggle;
                this.ClampLook     = this.KeyboardState.ClampLook;
            }
            if (this.gamepad)
            {
                PlayerIndex[] players = ControllerIndexExtensions.GetPlayers(ControllerIndex.Any);
                for (int index = 0; index < players.Length; ++index)
                {
                    GamepadState gamepadState = this.GamepadsManager[players[index]];
                    if (!gamepadState.Connected)
                    {
                        if (gamepadState.NewlyDisconnected && this.ActiveControllerDisconnected != null)
                        {
                            this.ActiveControllerDisconnected(players[index]);
                        }
                    }
                    else
                    {
                        this.ClampLook = FezMath.Coalesce <FezButtonState>(this.ClampLook, gamepadState.RightStick.Clicked.State, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
                        this.FpsToggle = FezMath.Coalesce <FezButtonState>(this.FpsToggle, gamepadState.LeftStick.Clicked.State, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
                        Vector2 second1 = Vector2.Clamp(ThumbstickState.CircleToSquare(gamepadState.LeftStick.Position), -Vector2.One, Vector2.One);
                        Vector2 second2 = Vector2.Clamp(ThumbstickState.CircleToSquare(gamepadState.RightStick.Position), -Vector2.One, Vector2.One);
                        this.Movement      = FezMath.Coalesce <Vector2>(this.Movement, second1, gamepadState.DPad.Direction);
                        this.FreeLook      = FezMath.Coalesce <Vector2>(this.FreeLook, second2);
                        this.Back          = FezMath.Coalesce <FezButtonState>(this.Back, gamepadState.Back, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
                        this.Start         = FezMath.Coalesce <FezButtonState>(this.Start, gamepadState.Start, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
                        this.Jump          = FezMath.Coalesce <FezButtonState>(this.Jump, gamepadState.A.State, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
                        this.GrabThrow     = FezMath.Coalesce <FezButtonState>(this.GrabThrow, gamepadState.X.State, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
                        this.CancelTalk    = FezMath.Coalesce <FezButtonState>(this.CancelTalk, gamepadState.B.State, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
                        this.OpenInventory = FezMath.Coalesce <FezButtonState>(this.OpenInventory, gamepadState.Y.State, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
                        this.Up            = FezMath.Coalesce <FezButtonState>(this.Up, gamepadState.DPad.Up.State, gamepadState.LeftStick.Up.State, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
                        this.Down          = FezMath.Coalesce <FezButtonState>(this.Down, gamepadState.DPad.Down.State, gamepadState.LeftStick.Down.State, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
                        this.Left          = FezMath.Coalesce <FezButtonState>(this.Left, gamepadState.DPad.Left.State, gamepadState.LeftStick.Left.State, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
                        this.Right         = FezMath.Coalesce <FezButtonState>(this.Right, gamepadState.DPad.Right.State, gamepadState.LeftStick.Right.State, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
                        this.ExactUp       = FezMath.Coalesce <FezButtonState>(this.ExactUp, gamepadState.ExactUp, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
                        this.MapZoomIn     = FezMath.Coalesce <FezButtonState>(this.MapZoomIn, gamepadState.RightShoulder.State, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
                        this.MapZoomOut    = FezMath.Coalesce <FezButtonState>(this.MapZoomOut, gamepadState.LeftShoulder.State, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
                        if (this.StrictRotation)
                        {
                            this.RotateLeft  = FezMath.Coalesce <FezButtonState>(this.RotateLeft, gamepadState.LeftTrigger.State, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
                            this.RotateRight = FezMath.Coalesce <FezButtonState>(this.RotateRight, gamepadState.RightTrigger.State, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
                        }
                        else
                        {
                            this.RotateLeft  = FezMath.Coalesce <FezButtonState>(this.RotateLeft, gamepadState.LeftShoulder.State, gamepadState.LeftTrigger.State, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
                            this.RotateRight = FezMath.Coalesce <FezButtonState>(this.RotateRight, gamepadState.RightShoulder.State, gamepadState.RightTrigger.State, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
                        }
                    }
                }
            }
            if (!this.mouse)
            {
                return;
            }
            this.MouseState.Update(gameTime);
            Vector2 second = Vector2.Zero;

            switch (this.MouseState.LeftButton.State)
            {
            case MouseButtonStates.DragStarted:
                this.lastMouseCenter = new Vector2((float)this.MouseState.LeftButton.DragState.Movement.X, (float)-this.MouseState.LeftButton.DragState.Movement.Y);
                break;

            case MouseButtonStates.Dragging:
                Vector2 vector2 = new Vector2((float)this.MouseState.LeftButton.DragState.Movement.X, (float)-this.MouseState.LeftButton.DragState.Movement.Y);
                second = (this.lastMouseCenter - vector2) / 32f;
                this.lastMouseCenter = vector2;
                break;
            }
            this.FreeLook   = FezMath.Coalesce <Vector2>(this.FreeLook, second);
            this.MapZoomIn  = FezMath.Coalesce <FezButtonState>(this.MapZoomIn, this.MouseState.WheelTurnedUp, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
            this.MapZoomOut = FezMath.Coalesce <FezButtonState>(this.MapZoomOut, this.MouseState.WheelTurnedDown, (IEqualityComparer <FezButtonState>)FezButtonStateComparer.Default);
        }