Ejemplo n.º 1
0
        public void Commit(ulong updateTick, float deltaTime)
        {
            // We need to do some processing for known controllers to ensure all
            // the various control aliases holding directional values are calculated
            // optimally with circular deadzones and then set properly everywhere.
            if (IsKnown)
            {
                ProcessLeftStick(updateTick, deltaTime);
                ProcessRightStick(updateTick, deltaTime);
                ProcessDPad(updateTick, deltaTime);
            }

            // Commit all control values.
            var controlsCount = Controls.Count;

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

            // Calculate the Command alias state for known devices and commit it.
            if (IsKnown)
            {
                var passive = true;
                var pressed = false;
                for (var i = (int)InputControlType.Back; i <= (int)InputControlType.Mute; i++)
                {
                    var control = ControlsByTarget[i];
                    if (control != null && control.IsPressed)
                    {
                        pressed = true;
                        if (!control.Passive)
                        {
                            passive = false;
                        }
                    }
                }

                Command.Passive = passive;
                Command.CommitWithState(pressed, updateTick, deltaTime);

                if (hasLeftCommandControl)
                {
                    LeftCommand.Passive = leftCommandSource.Passive;
                    LeftCommand.CommitWithState(leftCommandSource.IsPressed, updateTick, deltaTime);
                }

                if (hasRightCommandControl)
                {
                    RightCommand.Passive = rightCommandSource.Passive;
                    RightCommand.CommitWithState(rightCommandSource.IsPressed, updateTick, deltaTime);
                }
            }

            // If any non-passive controls provide input, flag the device active.
            IsActive = false;
            for (var i = 0; i < controlsCount; i++)
            {
                var control = Controls[i];
                if (control != null && control.HasInput && !control.Passive)
                {
                    LastInputTick = updateTick;
                    IsActive      = true;
                }
            }
        }