Example #1
0
        public void PostUpdate(ulong updateTick, float deltaTime)
        {
            // Apply post-processing to controls.
            foreach (InputControl control in Controls.IgnoreNulls())
            {
                if (control.RawValue != null)
                {
                    control.UpdateWithValue(control.RawValue.Value, updateTick);
                }
                else if (control.PreValue != null)
                {
                    control.UpdateWithValue(ProcessAnalogControlValue(control, deltaTime), updateTick);
                }

                control.PostUpdate(updateTick);

                if (control.HasChanged)
                {
                    LastChangeTick = updateTick;
                }
            }

            // Update two-axis controls.
            LeftStick.Update(LeftStickX, LeftStickY, updateTick);
            RightStick.Update(RightStickX, RightStickY, updateTick);

            Vector2 dpv = DPadVector;

            DPad.Update(dpv.x, dpv.y, updateTick);
        }
Example #2
0
        internal void ProcessRightStick()
        {
            var x = Utility.ValueFromSides(RightStickLeft.NextRawValue, RightStickRight.NextRawValue);
            var y = Utility.ValueFromSides(RightStickDown.NextRawValue, RightStickUp.NextRawValue, InputManager.InvertYAxis);

            Vector2 v;

            if (RawSticks)
            {
                v = new Vector2(x, y);
            }
            else
            {
                var lowerDeadZone = Utility.Max(RightStickLeft.LowerDeadZone, RightStickRight.LowerDeadZone, RightStickUp.LowerDeadZone, RightStickDown.LowerDeadZone);
                var upperDeadZone = Utility.Min(RightStickLeft.UpperDeadZone, RightStickRight.UpperDeadZone, RightStickUp.UpperDeadZone, RightStickDown.UpperDeadZone);
                v = Utility.ApplyCircularDeadZone(x, y, lowerDeadZone, upperDeadZone);
            }

            RightStick.Raw = true;
            RightStick.UpdateWithAxes(v.X, v.Y);

            RightStickX.Raw = true;
            RightStickX.CommitWithValue(v.X);

            RightStickY.Raw = true;
            RightStickY.CommitWithValue(v.Y);

            RightStickLeft.SetValue(RightStick.Left.Value);
            RightStickRight.SetValue(RightStick.Right.Value);
            RightStickUp.SetValue(RightStick.Up.Value);
            RightStickDown.SetValue(RightStick.Down.Value);
        }
Example #3
0
        public void Commit(ulong updateTick, float deltaTime)
        {
            int controlCount = Controls.Length;

            for (int i = 0; i < controlCount; i++)
            {
                var control = Controls[i];
                if (control != null)
                {
                    control.Commit();

                    if (control.HasChanged)
                    {
                        LastChangeTick = updateTick;
                    }
                }
            }

            if (IsKnown)
            {
                GetControl(InputControlType.Command).CommitWithState(AnyCommandControlIsPressed(), updateTick, deltaTime);
            }

            LeftStickX.CommitWithSides(LeftStickLeft, LeftStickRight, updateTick, deltaTime);
            LeftStickY.CommitWithSides(LeftStickDown, LeftStickUp, updateTick, deltaTime, InputManager.InvertYAxis);
            LeftStick.UpdateWithAxes(LeftStickX, LeftStickY, updateTick, deltaTime);

            RightStickX.CommitWithSides(RightStickLeft, RightStickRight, updateTick, deltaTime);
            RightStickY.CommitWithSides(RightStickDown, RightStickUp, updateTick, deltaTime, InputManager.InvertYAxis);
            RightStick.UpdateWithAxes(RightStickX, RightStickY, updateTick, deltaTime);

            DPadX.CommitWithSides(DPadLeft, DPadRight, updateTick, deltaTime);
            DPadY.CommitWithSides(DPadDown, DPadUp, updateTick, deltaTime, InputManager.InvertYAxis);
            DPad.UpdateWithAxes(DPadX, DPadY, updateTick, deltaTime);
        }
Example #4
0
        public void ClearInputState()
        {
            LeftStickX.ClearInputState();
            LeftStickY.ClearInputState();
            LeftStick.ClearInputState();

            RightStickX.ClearInputState();
            RightStickY.ClearInputState();
            RightStick.ClearInputState();

            DPadX.ClearInputState();
            DPadY.ClearInputState();
            DPad.ClearInputState();

            var controlCount = Controls.Length;

            for (int i = 0; i < controlCount; i++)
            {
                var control = Controls[i];
                if (control != null)
                {
                    control.ClearInputState();
                }
            }
        }
Example #5
0
        void ProcessRightStick(ulong updateTick, float deltaTime)
        {
            var x = Utility.ValueFromSides(RightStickLeft.NextRawValue, RightStickRight.NextRawValue);
            var y = Utility.ValueFromSides(RightStickDown.NextRawValue, RightStickUp.NextRawValue, InputManager.InvertYAxis);

            Vector2 v;

            if (RawSticks || RightStickLeft.Raw || RightStickRight.Raw || RightStickUp.Raw || RightStickDown.Raw)
            {
                v = new Vector2(x, y);
            }
            else
            {
                var lowerDeadZone = Utility.Max(RightStickLeft.LowerDeadZone, RightStickRight.LowerDeadZone, RightStickUp.LowerDeadZone, RightStickDown.LowerDeadZone);
                var upperDeadZone = Utility.Min(RightStickLeft.UpperDeadZone, RightStickRight.UpperDeadZone, RightStickUp.UpperDeadZone, RightStickDown.UpperDeadZone);
                v = Utility.ApplyCircularDeadZone(x, y, lowerDeadZone, upperDeadZone);
            }

            RightStick.Raw = true;
            RightStick.UpdateWithAxes(v.x, v.y, updateTick, deltaTime);

            RightStickX.Raw = true;
            RightStickX.CommitWithValue(v.x, updateTick, deltaTime);

            RightStickY.Raw = true;
            RightStickY.CommitWithValue(v.y, updateTick, deltaTime);

            RightStickLeft.SetValue(RightStick.Left.Value, updateTick);
            RightStickRight.SetValue(RightStick.Right.Value, updateTick);
            RightStickUp.SetValue(RightStick.Up.Value, updateTick);
            RightStickDown.SetValue(RightStick.Down.Value, updateTick);
        }
Example #6
0
    public PlayerInput(int ID) : base()
    {
        player = ReInput.players.GetPlayer(ID);


        EventManager.Subscribe <InputActionEventData>(RewiredInputProvider.EVT_INPUT_PRESS, (input) =>
        {
            if (isActive)
            {
                switch (input.actionId)
                {
                case RewiredConsts.Action.MoveHorizontal:
                    LeftStick.SetX(input.GetAxis());
                    LeftStick.Press();
                    break;

                case RewiredConsts.Action.MoveVertical:
                    LeftStick.SetY(input.GetAxis());
                    LeftStick.Press();
                    break;

                case RewiredConsts.Action.CameraHorizontal:
                    RightStick.SetX(input.GetAxis());
                    RightStick.Press();
                    break;

                case RewiredConsts.Action.CameraVertical:
                    RightStick.SetY(input.GetAxis());
                    RightStick.Press();
                    break;
                }
            }
        });
    }
        public ControllerXbox360(params int[] joystickId)
        {
            AddButton(Controls.A);
            AddButton(Controls.B);
            AddButton(Controls.X);
            AddButton(Controls.Y);
            AddButton(Controls.RB);
            AddButton(Controls.LB);
            AddButton(Controls.LStickClick);
            AddButton(Controls.RStickClick);
            AddButton(Controls.Start);
            AddButton(Controls.Back);
            AddButton(Controls.RT);
            AddButton(Controls.LT);
            AddButton(Controls.Up);
            AddButton(Controls.Down);
            AddButton(Controls.Left);
            AddButton(Controls.Right);

            AddAxis(Controls.LStick);
            AddAxis(Controls.RStick);
            AddAxis(Controls.DPad);
            AddAxis(Controls.Triggers);

            foreach (var joy in joystickId)
            {
                A.AddJoyButton(0, joy);
                B.AddJoyButton(1, joy);
                X.AddJoyButton(2, joy);
                Y.AddJoyButton(3, joy);
                LB.AddJoyButton(4, joy);
                RB.AddJoyButton(5, joy);
                Back.AddJoyButton(6, joy);
                Start.AddJoyButton(7, joy);
                LeftStickClick.AddJoyButton(8, joy);
                RightStickClick.AddJoyButton(9, joy);

                RT.AddAxisButton(AxisButton.ZMinus, joy);
                LT.AddAxisButton(AxisButton.ZPlus, joy);

                LeftStick.AddJoyAxis(JoyAxis.X, JoyAxis.Y, joy);
                RightStick.AddJoyAxis(JoyAxis.U, JoyAxis.R, joy);
                DPad.AddJoyAxis(JoyAxis.PovX, JoyAxis.PovY, joy);
                Triggers.AddJoyAxis(JoyAxis.Z, JoyAxis.Z, joy);

                Up
                .AddAxisButton(AxisButton.YMinus, joy)
                .AddAxisButton(AxisButton.PovYMinus, joy);
                Down
                .AddAxisButton(AxisButton.YPlus, joy)
                .AddAxisButton(AxisButton.PovYPlus, joy);
                Right
                .AddAxisButton(AxisButton.XPlus, joy)
                .AddAxisButton(AxisButton.PovXPlus, joy);
                Left
                .AddAxisButton(AxisButton.XMinus, joy)
                .AddAxisButton(AxisButton.PovXMinus, joy);
            }
        }
Example #8
0
 public void Update(float delta)
 {
     if (!controllerInitted)
     {
         return;
     }
     RightStick.Update();
     LeftStick.Update();
 }
Example #9
0
        public void Draw(SpriteBatch spriteBatch)
        {
            DrawStringCentered($"L", LeftStick.StartLocation, Color.Black, spriteBatch);
            DrawStringCentered($"L@L", LeftStick.GetPositionVector(aliveZoneSize), Color.Black, spriteBatch);


            DrawStringCentered($"R", RightStick.StartLocation, Color.Black, spriteBatch);
            DrawStringCentered($"R@R", RightStick.GetPositionVector(aliveZoneSize), Color.Black, spriteBatch);
        }
Example #10
0
        public void ClearInputState()
        {
            LeftStick.ClearInputState();
            RightStick.ClearInputState();
            DPad.ClearInputState();
            int count = Controls.Count;

            for (int i = 0; i < count; i++)
            {
                Controls[i]?.ClearInputState();
            }
        }
Example #11
0
        public void Update(float delta)
        {
            GameController.Update(delta);
            PcController.Update(delta);
            PcAltController.Update(delta);

            RightStick.Update();
            LeftStick.Update();

            //Updating Dpad to use it's joystick emulator
            _actionDPad.Update(delta);
            //Updating KeyboardOnlyDpad to use it's joystick emulator
            _keyboardDPad.Update(delta);

            UpdateSticks();
        }
Example #12
0
        public void ClearInputState()
        {
            LeftStick.ClearInputState();
            RightStick.ClearInputState();
            DPad.ClearInputState();

            var controlsCount = Controls.Count;

            for (var i = 0; i < controlsCount; i++)
            {
                var control = Controls[i];
                if (control != null)
                {
                    control.ClearInputState();
                }
            }
        }
Example #13
0
        public ControllerPS3(params int[] joystickId)
        {
            AddButton(Controls.Triangle);
            AddButton(Controls.Circle);
            AddButton(Controls.Cross);
            AddButton(Controls.Square);
            AddButton(Controls.R1);
            AddButton(Controls.L1);
            AddButton(Controls.L3);
            AddButton(Controls.R3);
            AddButton(Controls.Start);
            AddButton(Controls.Select);
            AddButton(Controls.R2);
            AddButton(Controls.L2);

            AddAxis(Controls.LStick);
            AddAxis(Controls.RStick);
            AddAxis(Controls.DPad);

            foreach (var joy in joystickId)
            {
                Triangle.AddJoyButton(0, joy);
                Circle.AddJoyButton(1, joy);
                Cross.AddJoyButton(2, joy);
                Square.AddJoyButton(3, joy);
                L2.AddJoyButton(4, joy);
                R2.AddJoyButton(5, joy);
                L1.AddJoyButton(6, joy);
                R1.AddJoyButton(7, joy);
                Select.AddJoyButton(8, joy);
                Start.AddJoyButton(9, joy);
                L3.AddJoyButton(10, joy);
                R3.AddJoyButton(11, joy);

                R2.AddAxisButton(AxisButton.ZMinus, joy);
                L2.AddAxisButton(AxisButton.ZPlus, joy);

                LeftStick.AddJoyAxis(JoyAxis.X, JoyAxis.Y, joy);
                RightStick.AddJoyAxis(JoyAxis.U, JoyAxis.R, joy);
                DPad.AddJoyAxis(JoyAxis.PovX, JoyAxis.PovY, joy);
            }
        }
Example #14
0
    void CheckInput()
    {
        if (!lockDirection)
        {
            Vector3 RightStick;

            RightStick.x = Input.GetAxis("RHorizontal" + (int)m_PlayerNumber);
            RightStick.y = 0;
            RightStick.z = Input.GetAxis("RVertical" + (int)m_PlayerNumber);

            RightStick.Normalize();

            Aim = RightStick.magnitude == 0.0f ? Aim : RightStick;

            //Move the pointer.
            Pointer.LookAt(Pointer.position + RightStick);
        }

        Vector3 LeftStick;

        LeftStick.x = Input.GetAxis("LHorizontal" + (int)m_PlayerNumber);
        LeftStick.y = 0;
        LeftStick.z = Input.GetAxis("LVertical" + (int)m_PlayerNumber);

        //Move the Player
        if (lockMovement)
        {
            if (!lockDirection)
            {
                MoveStraight();
            }
        }
        else
        {
            MovePlayer(LeftStick);
            currentDirection = LeftStick.normalized;
        }

//        CheckForPowerInput();
    }
Example #15
0
        public void PostUpdate(ulong updateTick, float deltaTime)
        {
            // Apply post-processing to controls.
            int controlCount = Controls.GetLength(0);

            for (int i = 0; i < controlCount; i++)
            {
                var control = Controls[i];
                if (control != null)
                {
                    if (control.RawValue.HasValue)
                    {
                        control.UpdateWithValue(control.RawValue.Value, updateTick);
                    }
                    else
                    if (control.PreValue.HasValue)
                    {
                        control.UpdateWithValue(ProcessAnalogControlValue(control, deltaTime), updateTick);
                    }

                    control.PostUpdate(updateTick);

                    if (control.HasChanged)
                    {
                        LastChangeTick = updateTick;
                    }
                }
            }

            // Update two-axis controls.
            LeftStick.Update(LeftStickX, LeftStickY, updateTick);
            RightStick.Update(RightStickX, RightStickY, updateTick);

            var dpv = DPadVector;

            DPad.Update(dpv.x, dpv.y, updateTick);
        }
Example #16
0
 public void PressRightStick(float x, float y)
 {
     RightStick.SetX(x);
     RightStick.SetY(y);
     RightStick.Press();
 }
Example #17
0
        public void Update(GameTime gameTime)
        {
            var dt = (float)gameTime.ElapsedGameTime.TotalMilliseconds;

            totalTime += dt;

            var           state = TouchPanel.GetState();
            TouchLocation?leftTouch = null, rightTouch = null;

            if (tapStartCount > state.Count)
            {
                tapStartCount = state.Count;
            }

            foreach (TouchLocation loc in state)
            {
                if (loc.State == TouchLocationState.Released)
                {
                    int tapStartId = -1;
                    for (int i = 0; i < tapStartCount; ++i)
                    {
                        if (tapStarts[i].Id == loc.Id)
                        {
                            tapStartId = i;
                            break;
                        }
                    }
                    if (tapStartId >= 0)
                    {
                        for (int i = tapStartId; i < tapStartCount - 1; ++i)
                        {
                            tapStarts[i] = tapStarts[i + 1];
                        }
                        tapStartCount--;
                    }
                    continue;
                }
                else if (loc.State == TouchLocationState.Pressed && tapStartCount < tapStarts.Length)
                {
                    tapStarts[tapStartCount] = new TapStart(loc.Id, totalTime, loc.Position);
                    tapStartCount++;
                }

                if (LeftStick.touchLocation.HasValue && loc.Id == LeftStick.touchLocation.Value.Id)
                {
                    leftTouch = loc;
                    continue;
                }
                if (RightStick.touchLocation.HasValue && loc.Id == RightStick.touchLocation.Value.Id)
                {
                    rightTouch = loc;
                    continue;
                }

                if (!loc.TryGetPreviousLocation(out TouchLocation locPrev))
                {
                    locPrev = loc;
                }

                if (!LeftStick.touchLocation.HasValue)
                {
                    if (LeftStick.StartRegion.Contains((int)locPrev.Position.X, (int)locPrev.Position.Y))
                    {
                        if (LeftStick.Style == TouchStickStyle.Fixed)
                        {
                            if (Vector2.Distance(locPrev.Position, LeftStick.StartLocation) < aliveZoneSize)
                            {
                                leftTouch = locPrev;
                            }
                        }
                        else
                        {
                            leftTouch = locPrev;
                            LeftStick.StartLocation = leftTouch.Value.Position;
                            if (LeftStick.StartLocation.X < LeftStick.StartRegion.Left + edgeSpacing)
                            {
                                LeftStick.StartLocation.X = LeftStick.StartRegion.Left + edgeSpacing;
                            }
                            if (LeftStick.StartLocation.Y > LeftStick.StartRegion.Bottom - edgeSpacing)
                            {
                                LeftStick.StartLocation.Y = LeftStick.StartRegion.Bottom - edgeSpacing;
                            }
                        }
                        continue;
                    }
                }

                if (!RightStick.touchLocation.HasValue && locPrev.Id != RightStick.lastExcludedRightTouchId)
                {
                    if (RightStick.StartRegion.Contains((int)locPrev.Position.X, (int)locPrev.Position.Y))
                    {
                        bool excluded = false;
                        foreach (Rectangle r in RightStick.startExcludeRegions)
                        {
                            if (r.Contains((int)locPrev.Position.X, (int)locPrev.Position.Y))
                            {
                                excluded = true;
                                RightStick.lastExcludedRightTouchId = locPrev.Id;
                                continue;
                            }
                        }
                        if (excluded)
                        {
                            continue;
                        }
                        RightStick.lastExcludedRightTouchId = -1;
                        if (RightStick.Style == TouchStickStyle.Fixed)
                        {
                            if (Vector2.Distance(locPrev.Position, RightStick.StartLocation) < aliveZoneSize)
                            {
                                rightTouch = locPrev;
                            }
                        }
                        else
                        {
                            rightTouch = locPrev;
                            RightStick.StartLocation = rightTouch.Value.Position;
                            if (RightStick.StartLocation.X > RightStick.StartRegion.Right - edgeSpacing)
                            {
                                RightStick.StartLocation.X = RightStick.StartRegion.Right - edgeSpacing;
                            }
                            if (RightStick.StartLocation.Y > RightStick.StartRegion.Bottom - edgeSpacing)
                            {
                                RightStick.StartLocation.Y = RightStick.StartRegion.Bottom - edgeSpacing;
                            }
                        }
                        continue;
                    }
                }
            }

            LeftStick.Update(state, leftTouch, dt);
            RightStick.Update(state, rightTouch, dt);
        }
Example #18
0
        public void Update(TimeSpan elapsed)
        {
            if (!Connected)
            {
                return;
            }

            State state        = Controller.GetState();
            var   gamepadState = state.Gamepad;

            // Sadly we can't really use the packet information because everything is temporal
            // Even if everything stayed the same, that's valid data (elapsed time goes up, etc.)

            // Vibration
            if (leftMotor.Active)
            {
                leftMotor = UpdateMotor(leftMotor, elapsed);
            }
            if (rightMotor.Active)
            {
                rightMotor = UpdateMotor(rightMotor, elapsed);
            }

            if (leftMotor.LastAmount != leftMotor.CurrentAmount || rightMotor.LastAmount != rightMotor.CurrentAmount)
            {
                Controller.SetVibration(new Vibration
                {
                    LeftMotorSpeed  = (ushort)(leftMotor.CurrentAmount * ushort.MaxValue),
                    RightMotorSpeed = (ushort)(rightMotor.CurrentAmount * ushort.MaxValue)
                });
            }

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

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

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

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

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

            // Thumb sticks
            LeftStick = LeftStick.NextState(
                Normalize(gamepadState.LeftThumbX, gamepadState.LeftThumbY, Gamepad.GamepadLeftThumbDeadZone),
                (gamepadState.Buttons & GamepadButtonFlags.LeftThumb) != 0, elapsed);
            RightStick = RightStick.NextState(
                Normalize(gamepadState.RightThumbX, gamepadState.RightThumbY, Gamepad.GamepadRightThumbDeadZone),
                (gamepadState.Buttons & GamepadButtonFlags.RightThumb) != 0, elapsed);
        }