コード例 #1
0
 private void DebugState(JoystickState tmpJstate)
 {
     if (!tmpJstate.Equals(jState))
     {
         Debug.WriteLine($"Joystick State:\t{tmpJstate}");
     }
 }
コード例 #2
0
        internal override void UpdateInput(bool isActive)
        {
            if (!GameBase.Instance.IsActive)
            {
                return;
            }

            // get state of all connected devices, and choose the deviceIndex
            int connectedDeviceIndex = -1;
            int changedDeviceIndex   = -1;

            for (int i = 0; i < DEVICE_COUNT; i++)
            {
                if (deviceIsConnected[i])
                {
                    JoystickState s = Joystick.GetState(i);
                    if (s.IsConnected)
                    {
                        // the first device that has changed state will be chosen as the new deviceIndex
                        if (changedDeviceIndex == -1 && !s.Equals(lastState[i]))
                        {
                            changedDeviceIndex = i;
                        }

                        // otherwise choose a connected device, preferring the one that was chosen last
                        if (i == deviceIndex || connectedDeviceIndex == -1)
                        {
                            connectedDeviceIndex = i;
                        }
                    }
                    lastState[i] = s;
                }
            }
            deviceIndex = changedDeviceIndex != -1 ? changedDeviceIndex : connectedDeviceIndex;

            // pass structs by ref to avoid pointless copying
            if (deviceIndex != -1)
            {
                updateDevice(ref lastCapabilities[deviceIndex], ref lastState[deviceIndex], ref firstState[deviceIndex]);
            }
        }
コード例 #3
0
        //* ────________________________________*
        //* methods ───────────────────────────────-*

        //* -----------------------------------------------------------------------*
        /// <summary>ボタン入力を検出します。</summary>
        /// <remarks>
        /// 注意: このメソッドを呼び出すと、自動的に登録されているクラスに対して
        /// <c>update()</c>が実行されます。レガシ ゲームパッドが高位入力管理クラスにて
        /// アクティブの状態でこのメソッドを呼び出すと、高位入力側の判定が
        /// 1フレーム分欠落します。
        /// </remarks>
        ///
        /// <param name="gameTime">前フレームが開始してからの経過時間。</param>
        /// <returns>
        /// ボタン入力が検出されたデバイスの管理クラス。検出しなかった場合、<c>null</c>。
        /// </returns>
        public CLegacyInput detectInput(GameTime gameTime)
        {
            CLegacyInput result    = null;
            int          threshold =
                (int)CInterpolate.lerpClampLinear(0, CLegacyInput.RANGE, this.threshold, 1);

            for (int i = inputList.Count; --i >= 0 && result == null;)
            {
                CLegacyInput input = inputList[i];
                input.update(gameTime);
                JoystickState state = input.nowInputState;
                if (state.Equals(input.prevInputState) && (
                        Array.Exists <byte>(state.GetButtons(), b => b != 0) ||
                        Math.Abs(state.X) >= threshold ||
                        Math.Abs(state.Y) >= threshold ||
                        Math.Abs(state.Z) >= threshold))
                {
                    result = input;
                }
            }
            return(result);
        }
コード例 #4
0
        List <string> ShowDirectInputState(Joystick device)
        {
            JoystickState state = null;

            if (device != null)
            {
                try
                {
                    device.Acquire();
                    state = device.GetCurrentState();
                }
                catch (Exception ex)
                {
                    var error = ex;
                }
            }

            if (state == null || state.Equals(oldState))
            {
                return(actions);
            }

            // Fill axis.
            Axis[0] = state.X;
            Axis[1] = state.Y;
            Axis[2] = state.Z;
            Axis[3] = state.RotationX;
            Axis[4] = state.RotationY;
            Axis[5] = state.RotationZ;

            oldState = state;
            actions.Clear();
            // X-axis.
            DiAxisTable.Rows[0][1] = state.X;
            DiAxisTable.Rows[0][2] = state.RotationX;
            DiAxisTable.Rows[0][3] = state.AccelerationX;
            DiAxisTable.Rows[0][4] = state.AngularAccelerationX;
            DiAxisTable.Rows[0][5] = state.ForceX;
            DiAxisTable.Rows[0][6] = state.TorqueX;
            DiAxisTable.Rows[0][7] = state.VelocityX;
            DiAxisTable.Rows[0][8] = state.AngularVelocityX;
            // Y-axis.
            DiAxisTable.Rows[1][1] = state.Y;
            DiAxisTable.Rows[1][2] = state.RotationY;
            DiAxisTable.Rows[1][3] = state.AccelerationY;
            DiAxisTable.Rows[1][4] = state.AngularAccelerationY;
            DiAxisTable.Rows[1][5] = state.ForceY;
            DiAxisTable.Rows[1][6] = state.TorqueY;
            DiAxisTable.Rows[1][7] = state.VelocityY;
            DiAxisTable.Rows[1][8] = state.AngularVelocityY;
            // Z-axis.
            DiAxisTable.Rows[2][1] = state.Z;
            DiAxisTable.Rows[2][2] = state.RotationZ;
            DiAxisTable.Rows[2][3] = state.AccelerationZ;
            DiAxisTable.Rows[2][4] = state.AngularAccelerationZ;
            DiAxisTable.Rows[2][5] = state.ForceZ;
            DiAxisTable.Rows[2][6] = state.TorqueZ;
            DiAxisTable.Rows[2][7] = state.VelocityZ;
            DiAxisTable.Rows[2][8] = state.AngularVelocityZ;

            var rows = DiAxisTable.Rows;
            var cols = DiAxisTable.Columns;
            int v;
            int axisNum;

            for (int r = 0; r < rows.Count; r++)
            {
                for (int c = 1; c < cols.Count; c++)
                {
                    if (System.DBNull.Value == rows[r][c])
                    {
                        continue;
                    }
                    v       = (int)rows[r][c];
                    axisNum = (c - 1) * rows.Count + r + 1;
                    addAction(actions, v, "Axis", axisNum);
                }
            }

            bool[] buttons = state.Buttons;
            DiButtonsTextBox.Text = "";
            if (buttons != null)
            {
                for (int i = 0; i < buttons.Length; i++)
                {
                    if (buttons[i])
                    {
                        actions.Add(string.Format("Button {0}", i + 1));
                        if (DiButtonsTextBox.Text.Length > 0)
                        {
                            DiButtonsTextBox.Text += " ";
                        }
                        DiButtonsTextBox.Text += (i + 1).ToString("00");
                    }
                }
            }
            // Sliders
            var sNum = 1;

            ProcessSlider(actions, state.Sliders, DiUvSliderTextBox, ref sNum);
            ProcessSlider(actions, state.AccelerationSliders, DiASliderTextBox, ref sNum);
            ProcessSlider(actions, state.ForceSliders, DiFSliderTextBox, ref sNum);
            ProcessSlider(actions, state.VelocitySliders, DiVSliderTextBox, ref sNum);

            // Point of view buttons
            int[] dPad = state.PointOfViewControllers;
            DiDPadTextBox.Text = "";
            if (dPad != null)
            {
                for (int i = 0; i < dPad.Length; i++)
                {
                    v = dPad[i];
                    if (DiDPadTextBox.Text.Length > 0)
                    {
                        DiDPadTextBox.Text += " ";
                    }
                    if (v != -1)
                    {
                        DiDPadTextBox.Text += "[" + i + "," + v.ToString() + "]";
                        if ((DPadEnum)v == DPadEnum.Up)
                        {
                            actions.Add(string.Format("DPad {0} {1}", i + 1, DPadEnum.Up.ToString()));
                        }
                        if ((DPadEnum)v == DPadEnum.Right)
                        {
                            actions.Add(string.Format("DPad {0} {1}", i + 1, DPadEnum.Right.ToString()));
                        }
                        if ((DPadEnum)v == DPadEnum.Down)
                        {
                            actions.Add(string.Format("DPad {0} {1}", i + 1, DPadEnum.Down.ToString()));
                        }
                        if ((DPadEnum)v == DPadEnum.Left)
                        {
                            actions.Add(string.Format("DPad {0} {1}", i + 1, DPadEnum.Left.ToString()));
                        }
                    }
                }
            }
            return(actions);
        }
コード例 #5
0
ファイル: DirectInputControl.cs プロジェクト: suvjunmd/x360ce
        /// <summary>
        /// Update DirectInput control from DirectInput device.
        /// </summary>
        /// <param name="device">DirectInput device.</param>
        /// <returns>List of buttons/DPad pressed, axis/sliders turned.</returns>
        void ShowDirectInputState(JoystickState state)
        {
            if (state == null || state.Equals(oldState)) return;

            // Fill axis.
            Axis[0] = state.X;
            Axis[1] = state.Y;
            Axis[2] = state.Z;
            Axis[3] = state.RotationX;
            Axis[4] = state.RotationY;
            Axis[5] = state.RotationZ;

            oldState = state;
            //actions.Clear();
            // X-axis.
            DiAxisTable.Rows[0][1] = state.X;
            DiAxisTable.Rows[0][2] = state.RotationX;
            DiAxisTable.Rows[0][3] = state.AccelerationX;
            DiAxisTable.Rows[0][4] = state.AngularAccelerationX;
            DiAxisTable.Rows[0][5] = state.ForceX;
            DiAxisTable.Rows[0][6] = state.TorqueX;
            DiAxisTable.Rows[0][7] = state.VelocityX;
            DiAxisTable.Rows[0][8] = state.AngularVelocityX;
            // Y-axis.
            DiAxisTable.Rows[1][1] = state.Y;
            DiAxisTable.Rows[1][2] = state.RotationY;
            DiAxisTable.Rows[1][3] = state.AccelerationY;
            DiAxisTable.Rows[1][4] = state.AngularAccelerationY;
            DiAxisTable.Rows[1][5] = state.ForceY;
            DiAxisTable.Rows[1][6] = state.TorqueY;
            DiAxisTable.Rows[1][7] = state.VelocityY;
            DiAxisTable.Rows[1][8] = state.AngularVelocityY;
            // Z-axis.
            DiAxisTable.Rows[2][1] = state.Z;
            DiAxisTable.Rows[2][2] = state.RotationZ;
            DiAxisTable.Rows[2][3] = state.AccelerationZ;
            DiAxisTable.Rows[2][4] = state.AngularAccelerationZ;
            DiAxisTable.Rows[2][5] = state.ForceZ;
            DiAxisTable.Rows[2][6] = state.TorqueZ;
            DiAxisTable.Rows[2][7] = state.VelocityZ;
            DiAxisTable.Rows[2][8] = state.AngularVelocityZ;

            var rows = DiAxisTable.Rows;
            var cols = DiAxisTable.Columns;
            int v;
            int axisNum;
            for (int r = 0; r < rows.Count; r++)
            {
                for (int c = 1; c < cols.Count; c++)
                {
                    if (System.DBNull.Value == rows[r][c]) continue;
                    v = (int)rows[r][c];
                    axisNum = (c - 1) * rows.Count + r + 1;
                    //addAction(actions, v, "Axis", axisNum);
                }
            }

            bool[] buttons = state.Buttons;
            DiButtonsTextBox.Text = "";
            if (buttons != null)
            {
                for (int i = 0; i < buttons.Length; i++)
                {
                    if (buttons[i])
                    {
                        //actions.Add(string.Format("Button {0}", i + 1));
                        if (DiButtonsTextBox.Text.Length > 0) DiButtonsTextBox.Text += " ";
                        DiButtonsTextBox.Text += (i + 1).ToString("00");
                    }
                }
            }
            // Sliders
            ProcessSlider(state.Sliders, DiUvSliderTextBox);
            ProcessSlider(state.AccelerationSliders, DiASliderTextBox);
            ProcessSlider(state.ForceSliders, DiFSliderTextBox);
            ProcessSlider(state.VelocitySliders, DiVSliderTextBox);

            // Point of view buttons
            int[] dPad = state.PointOfViewControllers;
            DiDPadTextBox.Text = "";
            if (dPad != null)
            {
                for (int i = 0; i < dPad.Length; i++)
                {
                    v = dPad[i];
                    if (DiDPadTextBox.Text.Length > 0) DiDPadTextBox.Text += " ";
                    if (v != -1)
                    {
                        DiDPadTextBox.Text += "[" + i + "," + v.ToString() + "]";
                        //if ((DPadEnum)v == DPadEnum.Up) actions.Add(string.Format("DPad {0} {1}", i + 1, DPadEnum.Up.ToString()));
                        //if ((DPadEnum)v == DPadEnum.Right) actions.Add(string.Format("DPad {0} {1}", i + 1, DPadEnum.Right.ToString()));
                        //if ((DPadEnum)v == DPadEnum.Down) actions.Add(string.Format("DPad {0} {1}", i + 1, DPadEnum.Down.ToString()));
                        //if ((DPadEnum)v == DPadEnum.Left) actions.Add(string.Format("DPad {0} {1}", i + 1, DPadEnum.Left.ToString()));
                    }
                }
            }
            //return actions;
        }