Beispiel #1
0
        public void Tick()
        {
            Hands hd = CtrlInput.GetHandD();

            bool[] kd = CtrlInput.GetIsKeyPushed() ?? new bool[CtrlInput.KeyArrSizeMax];

            if (!Equals(h, hd))
            {
                if (hd.R != h.R)
                {
                    LM(Axis.Reverser, hd.R);                                  //更新時のみ適用
                }
                if (hd.B == 0 && hd.P == 0 && (hd.BPos != 0 || hd.PPos != 0)) // 無段階入力用
                {
                    // B=0, P=0にセットされていた場合のみ, 無段階入力を受け付ける

                    hd.P = (int)Math.Round(hd.PPos * MaxP[hd.PPos < 0 ? Axis.Negative : Axis.Positive], MidpointRounding.AwayFromZero);
                    hd.B = (int)Math.Round(hd.BPos * MaxB, MidpointRounding.AwayFromZero);
                }

                if (h.P != hd.P)
                {
                    LM(Axis.Power, hd.P); //更新時のみ適用
                }
                //先にPを適用してからBを適用 => ワンハンドル車を2ハンドルで運転したとき, Pを投入しながらBを投入された場合にBのみを有効化するため
                if (h.B != hd.B) //更新時のみ適用
                {
                    LM(Axis.Brake, hd.B);

                    if (hd.B == 0) //Bが0のとき, Pを再適用することでワンハンドルでも正常に動作するようにする (B0でハンドルが0にセットされてしまうため)
                    {
                        LM(Axis.Power, hd.P);
                    }
                }

                //履歴をセット
                h = hd;
            }

            for (int i = 0; i < 20; i++)
            {
                if (k[i] != kd[i])
                {
                    KE(i, kd[i]);
                }
            }

            k = kd;
        }
        public void OnUpdateFrame()
        {
            if (EBUpdated)
            {
                KU(Controls[EBIndex]); EBUpdated = false;
            }
            if (HandBIndex != null)
            {
                KU(Controls[PMaxIndex + HandBIndex ?? 0]); HandBIndex = null;
            }
            if (HandPIndex != null)
            {
                KU(Controls[HandPIndex ?? 0]); HandPIndex = null;
            }
            if (HandRIndex != null)
            {
                KU(Controls[RevNIndex + HandRIndex ?? 0]); HandRIndex = null;
            }

            Hands h = CtrlInput.GetHandD();

            if (h.P > hd.P)
            {
                h.P = hd.P;
            }
            if (h.B == 0 && h.P == 0 && (h.BPos != 0 || h.PPos != 0))
            {
                h.P = (int)Math.Round(h.PPos * hd.P, MidpointRounding.AwayFromZero);
                h.B = (int)Math.Round(h.BPos * hd.B, MidpointRounding.AwayFromZero);
            }

            if (!Equals(h.B, chp.B))
            {
                if (h.B >= (hd.B + 1))
                {
                    KD(Controls[EBIndex]);
                    EBUpdated = true;
                }
                else
                {
                    if (h.B >= PMaxIndex)
                    {
                        h.B = PMaxIndex - 1;
                    }
                    KD(Controls[PMaxIndex + h.B]);
                    HandBIndex = h.B;
                }
            }

            if (!Equals(h.P, LastPPos))
            {
                if (h.P >= PMaxIndex)
                {
                    h.P = PMaxIndex - 1;
                }
                KD(Controls[h.P]);
                HandPIndex = h.P;
                LastPPos   = h.P;
            }

            if (!Equals(h.R, chp.R))
            {
                KD(Controls[RevNIndex + h.R]); HandRIndex = h.R;
            }

            //bool[] KeyI = CI.GetIsKeyPushed();
        }