コード例 #1
0
ファイル: InputBuffer.cs プロジェクト: xubingyue/xnamugen
        public ButtonState GetState(Int32 index, CommandElement element)
        {
            if (index < 0 || index >= Size)
            {
                throw new ArgumentNullException("index");
            }
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            PlayerButton current  = m_buffer.ReverseGet(index);
            PlayerButton previous = (index != Size - 1) ? m_buffer.ReverseGet(index + 1) : 0;

            Boolean current_state  = GetButtonState(current, element);
            Boolean previous_state = GetButtonState(previous, element);

            if (current_state)
            {
                return(previous_state ? ButtonState.Down : ButtonState.Pressed);
            }
            else
            {
                return(previous_state ? ButtonState.Released : ButtonState.Up);
            }
        }
コード例 #2
0
ファイル: CommandChecker.cs プロジェクト: xubingyue/xnamugen
        static Int32 ScanForMatch(Command command, Int32 element_index, InputBuffer input, Int32 input_index)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            CommandElement element = command.Elements[element_index];

            Int32 scanlength = Math.Min(input.Size, command.Time);

            for (Int32 i = input_index; i < scanlength; ++i)
            {
                //Only check for the last element at the top of the input buffer
                if (element_index == command.Elements.Count - 1)
                {
                    if (element.TriggerOnRelease == null)
                    {
                        if (i != input_index)
                        {
                            return(Int32.MinValue);
                        }
                    }
                    else
                    {
                        if (i - 1 != input_index && i != input_index)
                        {
                            return(Int32.MinValue);
                        }
                    }
                }

                if (ElementMatch(element, input, i) == true)
                {
                    //If no match, confirm CommandElement.NothingElse before going back a tick in the input.
                    if (element_index < command.Elements.Count - 1)
                    {
                        CommandElement nextelement = command.Elements[element_index + 1];
                        if (nextelement.NothingElse == true && input.AreIdentical(input_index, i) == false)
                        {
                            continue;
                        }
                    }

                    return(i);
                }
            }

            return(Int32.MinValue);
        }
コード例 #3
0
        private static bool ElementMatch(CommandElement element, InputBuffer input, int input_index)
        {
            var state = input.GetState(input_index, element);

            if (element.HeldDown)
            {
                var result = state == ButtonState.Down || state == ButtonState.Pressed;
                return(result);
            }

            if (element.TriggerOnRelease != null)
            {
                if (input_index >= input.Size)
                {
                    return(false);
                }

                if (input_index == 0 || input.GetState(input_index - 1, element) != ButtonState.Released)
                {
                    return(false);
                }

                var holdcount = 1;
                for (var i = input_index + 1; i < input.Size; ++i, ++holdcount)
                {
                    if (input.GetState(i, element) != ButtonState.Down)
                    {
                        break;
                    }
                }

                if (holdcount < element.TriggerOnRelease.Value)
                {
                    return(false);
                }
            }
            else
            {
                if (state != ButtonState.Pressed)
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #4
0
        private bool SuccessiveDirectionCheck(CommandElement last, CommandElement now)
        {
            if (last != now)
            {
                return(false);
            }
            if (last.Direction == CommandDirection.None || last.Direction == CommandDirection.B4Way || last.Direction == CommandDirection.D4Way || last.Direction == CommandDirection.F4Way || last.Direction == CommandDirection.U4Way)
            {
                return(false);
            }
            if (last.Buttons != CommandButton.None || last.HeldDown || last.NothingElse || last.TriggerOnRelease != null)
            {
                return(false);
            }

            return(true);
        }
コード例 #5
0
ファイル: CommandChecker.cs プロジェクト: xubingyue/xnamugen
        static Boolean ElementMatch(CommandElement element, InputBuffer input, Int32 input_index)
        {
            ButtonState state = input.GetState(input_index, element);

            if (element.HeldDown == true)
            {
                Boolean result = (state == ButtonState.Down || state == ButtonState.Pressed);
                return(result);
            }
            else if (element.TriggerOnRelease != null)
            {
                if (input_index >= input.Size)
                {
                    return(false);
                }

                if (input_index == 0 || input.GetState(input_index - 1, element) != ButtonState.Released)
                {
                    return(false);
                }

                Int32 holdcount = 1;
                for (Int32 i = input_index + 1; i < input.Size; ++i, ++holdcount)
                {
                    if (input.GetState(i, element) != ButtonState.Down)
                    {
                        break;
                    }
                }

                if (holdcount < element.TriggerOnRelease.Value)
                {
                    return(false);
                }
            }
            else
            {
                if (state != ButtonState.Pressed)
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #6
0
        public ButtonState GetState(int index, CommandElement element)
        {
            if (index < 0 || index >= Size)
            {
                throw new ArgumentNullException(nameof(index));
            }
            if (element == null)
            {
                throw new ArgumentNullException(nameof(element));
            }

            var current  = m_buffer.ReverseGet(index);
            var previous = index != Size - 1 ? m_buffer.ReverseGet(index + 1) : 0;

            var currentState  = GetButtonState(current, element);
            var previousState = GetButtonState(previous, element);

            if (currentState)
            {
                return(previousState ? ButtonState.Down : ButtonState.Pressed);
            }

            return(previousState ? ButtonState.Released : ButtonState.Up);
        }
コード例 #7
0
ファイル: InputBuffer.cs プロジェクト: xubingyue/xnamugen
 Boolean GetButtonState(PlayerButton inputelement, CommandElement commandelement)
 {
     return(((inputelement & commandelement.MatchHash1) == commandelement.MatchHash1) && ((inputelement & commandelement.MatchHash2) == 0));
 }
コード例 #8
0
 private bool GetButtonState(PlayerButton inputelement, CommandElement commandelement)
 {
     return((inputelement & commandelement.MatchHash1) == commandelement.MatchHash1 && (inputelement & commandelement.MatchHash2) == 0);
 }
コード例 #9
0
        private ReadOnlyList <CommandElement> ParseCommandText(string text)
        {
            if (text == null)
            {
                throw new ArgumentNullException(nameof(text));
            }

            var elements = new List <CommandElement>();

            CommandElement lastelement = null;

            foreach (var token in text.Split(','))
            {
                if (string.IsNullOrEmpty(token))
                {
                    continue;
                }

                var helddown    = false;
                var nothingelse = false;
                int?triggertime = null;
                var dir         = CommandDirection.None;
                var buttons     = CommandButton.None;

                if (token.IndexOf('~') != -1)
                {
                    var time  = 0;
                    var match = m_numberregex.Match(token);
                    if (match.Success)
                    {
                        int.TryParse(match.Groups[1].Value, out time);
                    }

                    triggertime = time;
                }

                if (token.IndexOf('/') != -1)
                {
                    helddown = true;
                }

                if (token.IndexOf('>') != -1)
                {
                    nothingelse = true;
                }

                if (token.IndexOf("$B") != -1)
                {
                    dir = CommandDirection.B4Way;
                }
                else if (token.IndexOf("$U") != -1)
                {
                    dir = CommandDirection.U4Way;
                }
                else if (token.IndexOf("$F") != -1)
                {
                    dir = CommandDirection.F4Way;
                }
                else if (token.IndexOf("$D") != -1)
                {
                    dir = CommandDirection.D4Way;
                }
                else if (token.IndexOf("DB") != -1)
                {
                    dir = CommandDirection.DB;
                }
                else if (token.IndexOf("DF") != -1)
                {
                    dir = CommandDirection.DF;
                }
                else if (token.IndexOf("UF") != -1)
                {
                    dir = CommandDirection.UF;
                }
                else if (token.IndexOf("UF") != -1)
                {
                    dir = CommandDirection.UF;
                }
                else if (token.IndexOf("D+B") != -1)
                {
                    dir = CommandDirection.DB;
                }
                else if (token.IndexOf("D+F") != -1)
                {
                    dir = CommandDirection.DF;
                }
                else if (token.IndexOf("U+B") != -1)
                {
                    dir = CommandDirection.UB;
                }
                else if (token.IndexOf("U+F") != -1)
                {
                    dir = CommandDirection.UF;
                }
                else if (token.IndexOf("D") != -1)
                {
                    dir = CommandDirection.D;
                }
                else if (token.IndexOf("F") != -1)
                {
                    dir = CommandDirection.F;
                }
                else if (token.IndexOf("U") != -1)
                {
                    dir = CommandDirection.U;
                }
                else if (token.IndexOf("B") != -1)
                {
                    dir = CommandDirection.B;
                }

                if (token.IndexOf("a") != -1)
                {
                    buttons |= CommandButton.A;
                }
                if (token.IndexOf("b") != -1)
                {
                    buttons |= CommandButton.B;
                }
                if (token.IndexOf("c") != -1)
                {
                    buttons |= CommandButton.C;
                }
                if (token.IndexOf("x") != -1)
                {
                    buttons |= CommandButton.X;
                }
                if (token.IndexOf("y") != -1)
                {
                    buttons |= CommandButton.Y;
                }
                if (token.IndexOf("z") != -1)
                {
                    buttons |= CommandButton.Z;
                }
                if (token.IndexOf("s") != -1)
                {
                    buttons |= CommandButton.Taunt;
                }

                var element = new CommandElement(dir, buttons, triggertime, helddown, nothingelse);

                if (lastelement != null && SuccessiveDirectionCheck(lastelement, element))
                {
                    var newelement1 = new CommandElement(element.Direction, CommandButton.None, 0, false, true);
                    var newelement2 = new CommandElement(element.Direction, CommandButton.None, null, false, true);

                    elements.Add(newelement1);
                    elements.Add(newelement2);
                }
                else
                {
                    elements.Add(element);
                }

                lastelement = element;
            }

            return(new ReadOnlyList <CommandElement>(elements));
        }