Exemplo n.º 1
0
        public void Invoke(ControlOutput output)
        {
            Ensure.That(nameof(output)).IsNotNull(output);

            var connection = output.connection;

            if (connection == null)
            {
                return;
            }

            var input = connection.destination;

            var recursionNode = new RecursionNode(output, stack);

            BeforeInvoke(output, recursionNode);

            var nextPort = InvokeDelegate(input);

            if (nextPort != null)
            {
                Invoke(nextPort);
            }

            AfterInvoke(output, recursionNode);
        }
Exemplo n.º 2
0
        protected override void Definition()
        {
            base.Definition();
            finished = ControlOutput("finished");

            Succession(enter, finished);
        }
Exemplo n.º 3
0
        protected override void Definition()
        {
            enter = ControlInput(nameof(enter), Enter);

            selector = ValueInput <T>(nameof(selector));

            Requirement(selector, enter);

            branches = new List <KeyValuePair <T, ControlOutput> >();

            foreach (var option in options)
            {
                var key = "%" + option;

                if (!controlOutputs.Contains(key))
                {
                    var branch = ControlOutput(key);
                    branches.Add(new KeyValuePair <T, ControlOutput>(option, branch));
                    Succession(enter, branch);
                }
            }

            @default = ControlOutput(nameof(@default));
            Succession(enter, @default);
        }
Exemplo n.º 4
0
        private RecursionNode BeforeInvoke(ControlOutput output, RecursionNode recursionNode)
        {
            try
            {
                recursion?.Enter(recursionNode);
            }
            catch (StackOverflowException ex)
            {
                output.unit.HandleException(stack, ex);
                throw;
            }

            var connection = output.connection;
            var input      = connection.destination;

            if (enableDebug)
            {
                var connectionEditorData = stack.GetElementDebugData <IUnitConnectionDebugData>(connection);
                var inputUnitEditorData  = stack.GetElementDebugData <IUnitDebugData>(input.unit);

                connectionEditorData.lastInvokeFrame = EditorTimeBinding.frame;
                connectionEditorData.lastInvokeTime  = EditorTimeBinding.time;
                inputUnitEditorData.lastInvokeFrame  = EditorTimeBinding.frame;
                inputUnitEditorData.lastInvokeTime   = EditorTimeBinding.time;
            }

            return(recursionNode);
        }
Exemplo n.º 5
0
        protected override void Definition()
        {
            enter = ControlInput("enter", ProcessInternal);
            exit  = ControlOutput("exit");

            Succession(enter, exit);
        }
Exemplo n.º 6
0
        private IEnumerator Coroutine(ControlOutput startPort)
        {
            try
            {
                foreach (var instruction in InvokeCoroutine(startPort))
                {
                    if (coroutineStopRequested)
                    {
                        yield break;
                    }

                    yield return(instruction);

                    if (coroutineStopRequested)
                    {
                        yield break;
                    }
                }
            }
            finally
            {
                // Manual disposal might have already occurred from StopCoroutine,
                // so we have to avoid double disposal, which would throw.
                if (!disposed)
                {
                    Dispose();
                }
            }
        }
Exemplo n.º 7
0
        protected override void Definition()
        {
            enter = ControlInput(nameof(enter), Enter);
            exit  = ControlOutput(nameof(exit));

            Succession(enter, exit);
        }
Exemplo n.º 8
0
        protected ControlOutput ControlOutput(string key)
        {
            EnsureUniqueOutput(key);
            var port = new ControlOutput(key);

            controlOutputs.Add(port);
            return(port);
        }
Exemplo n.º 9
0
        protected override void Definition()
        {
            enter = ControlInputCoroutine(nameof(enter), Loop, LoopCoroutine);
            exit  = ControlOutput(nameof(exit));
            body  = ControlOutput(nameof(body));

            Succession(enter, body);
            Succession(enter, exit);
        }
Exemplo n.º 10
0
        protected override void Definition()
        {
            enter = ControlInput(nameof(enter), Enter);
            reset = ControlInput(nameof(reset), Reset);
            once  = ControlOutput(nameof(once));
            after = ControlOutput(nameof(after));

            Succession(enter, once);
            Succession(enter, after);
        }
Exemplo n.º 11
0
        protected override void Definition()
        {
            start = ControlInput(nameof(start), Start);
            stop  = ControlInput(nameof(stop), Stop);

            started = ControlOutput(nameof(started));
            stopped = ControlOutput(nameof(stopped));

            Succession(start, started);
            Succession(stop, stopped);
        }
Exemplo n.º 12
0
        protected override void Definition()
        {
            enter     = ControlInput(nameof(enter), Enter);
            input     = ValueInput <object>(nameof(input)).AllowsNull();
            ifNotNull = ControlOutput(nameof(ifNotNull));
            ifNull    = ControlOutput(nameof(ifNull));

            Requirement(input, enter);
            Succession(enter, ifNotNull);
            Succession(enter, ifNull);
        }
Exemplo n.º 13
0
        protected override void Definition()
        {
            enter  = ControlInput(nameof(enter), Store);
            input  = ValueInput <object>(nameof(input));
            output = ValueOutput <object>(nameof(output));
            exit   = ControlOutput(nameof(exit));

            Requirement(input, enter);
            Assignment(enter, output);
            Succession(enter, exit);
        }
Exemplo n.º 14
0
        protected override void Definition()
        {
            enterTrue  = ControlInput("true", ProcessTrue);
            enterFalse = ControlInput("false", ProcessFalse);
            exit       = ControlOutput("exit");

            valueOut = ValueOutput("value", (flow) => m_value);

            Succession(enterTrue, exit);
            Succession(enterFalse, exit);
        }
Exemplo n.º 15
0
        protected override void Definition()
        {
            enter            = ControlInput(nameof(enter), Clear);
            dictionaryInput  = ValueInput <IDictionary>(nameof(dictionaryInput));
            dictionaryOutput = ValueOutput <IDictionary>(nameof(dictionaryOutput));
            exit             = ControlOutput(nameof(exit));

            Requirement(dictionaryInput, enter);
            Assignment(enter, dictionaryOutput);
            Succession(enter, exit);
        }
Exemplo n.º 16
0
        protected override void Definition()
        {
            enter     = ControlInput(nameof(enter), Enter);
            condition = ValueInput <bool>(nameof(condition));
            ifTrue    = ControlOutput(nameof(ifTrue));
            ifFalse   = ControlOutput(nameof(ifFalse));

            Requirement(condition, enter);
            Succession(enter, ifTrue);
            Succession(enter, ifFalse);
        }
Exemplo n.º 17
0
        protected override void Definition()
        {
            enter      = ControlInput(nameof(enter), Clear);
            listInput  = ValueInput <IList>(nameof(listInput));
            listOutput = ValueOutput <IList>(nameof(listOutput));
            exit       = ControlOutput(nameof(exit));

            Requirement(listInput, enter);
            Assignment(enter, listOutput);
            Succession(enter, exit);
        }
Exemplo n.º 18
0
        protected override void Definition()
        {
            enter     = ControlInput("enter", Enter);
            condition = ValueInput <bool>("condition");
            ifTrue    = ControlOutput("ifTrue");
            ifFalse   = ControlOutput("ifFalse");
            onNext    = ControlOutput("onNext");

            Relation(enter, ifTrue);
            Relation(enter, ifFalse);
            Relation(enter, onNext);
            Relation(condition, enter);
        }
Exemplo n.º 19
0
        protected override void Definition()
        {
            enter = ControlInput(nameof(enter), Set);
            list  = ValueInput <IList>(nameof(list));
            index = ValueInput(nameof(index), 0);
            item  = ValueInput <object>(nameof(item));
            exit  = ControlOutput(nameof(exit));

            Requirement(list, enter);
            Requirement(index, enter);
            Requirement(item, enter);
            Succession(enter, exit);
        }
Exemplo n.º 20
0
        protected override void Definition()
        {
            enter      = ControlInput(nameof(enter), Set);
            dictionary = ValueInput <IDictionary>(nameof(dictionary));
            key        = ValueInput <object>(nameof(key));
            value      = ValueInput <object>(nameof(value));
            exit       = ControlOutput(nameof(exit));

            Requirement(dictionary, enter);
            Requirement(key, enter);
            Requirement(value, enter);
            Succession(enter, exit);
        }
Exemplo n.º 21
0
        private IEnumerable InvokeCoroutine(ControlOutput output)
        {
            var connection = output.connection;

            if (connection == null)
            {
                yield break;
            }

            var input = connection.destination;

            var recursionNode = new RecursionNode(output, stack);

            BeforeInvoke(output, recursionNode);

            if (input.supportsCoroutine)
            {
                foreach (var instruction in InvokeCoroutineDelegate(input))
                {
                    if (instruction is ControlOutput)
                    {
                        foreach (var unwrappedInstruction in InvokeCoroutine((ControlOutput)instruction))
                        {
                            yield return(unwrappedInstruction);
                        }
                    }
                    else
                    {
                        yield return(instruction);
                    }
                }
            }
            else
            {
                ControlOutput nextPort = InvokeDelegate(input);

                if (nextPort != null)
                {
                    foreach (var instruction in InvokeCoroutine(nextPort))
                    {
                        yield return(instruction);
                    }
                }
            }

            AfterInvoke(output, recursionNode);
        }
Exemplo n.º 22
0
        public void StartCoroutine(ControlOutput port, ICollection <Flow> registry = null)
        {
            isCoroutine = true;

            coroutineRunner = stack.component;

            if (coroutineRunner == null)
            {
                coroutineRunner = CoroutineRunner.instance;
            }

            activeCoroutinesRegistry = registry;

            activeCoroutinesRegistry?.Add(this);

            // We have to store the enumerator because Coroutine itself
            // can't be cast to IDisposable, which we'll need when stopping.
            coroutineEnumerator = Coroutine(port);

            coroutineRunner.StartCoroutine(coroutineEnumerator);
        }
Exemplo n.º 23
0
        protected override void Definition()
        {
            enter = ControlInput(nameof(enter), Trigger);

            exit = ControlOutput(nameof(exit));

            name = ValueInput(nameof(name), string.Empty);

            target = ValueInput <FlowMachine>(nameof(target), flowmachine);

            arguments = new List <ValueInput>();

            for (var i = 0; i < argumentCount; i++)
            {
                var argument = ValueInput <object>("argument_" + i);
                arguments.Add(argument);
                Relation(argument, enter);
            }

            Relation(enter, exit);
            Relation(name, enter);
            Relation(target, enter);
        }
Exemplo n.º 24
0
 /// <summary>
 /// Triggering the source may trigger the destination.
 /// </summary>
 protected void Succession(ControlInput source, ControlOutput destination)
 {
     Relation(source, destination);
 }
Exemplo n.º 25
0
 protected void InvokeControlOutput(ControlOutput output)
 {
     Flow.New(graphReference)?.Invoke(output);
 }
Exemplo n.º 26
0
 private void AfterInvoke(ControlOutput output, RecursionNode recursionNode)
 {
     recursion?.Exit(recursionNode);
 }
Exemplo n.º 27
0
 public void Run(ControlOutput port)
 {
     Invoke(port);
     Dispose();
 }
Exemplo n.º 28
0
        protected override void Definition()
        {
            base.Definition();

            inputParameters       = new Dictionary <int, ValueInput>();
            outputParameters      = new Dictionary <int, ValueOutput>();
            useExpandedParameters = true;

            enter = ControlInput(nameof(enter), Enter);
            exit  = ControlOutput(nameof(exit));
            Succession(enter, exit);

            if (member.requiresTarget)
            {
                Requirement(target, enter);
            }

            if (supportsChaining && chainable)
            {
                targetOutput = ValueOutput(member.targetType, nameof(targetOutput));
                Assignment(enter, targetOutput);
            }

            if (member.isGettable)
            {
                result = ValueOutput(member.type, nameof(result), Result);

                if (member.requiresTarget)
                {
                    Requirement(target, result);
                }
            }

            var parameterInfos = member.GetParameterInfos().ToArray();

            parameterCount = parameterInfos.Length;

            for (int parameterIndex = 0; parameterIndex < parameterCount; parameterIndex++)
            {
                var parameterInfo = parameterInfos[parameterIndex];

                var parameterType = parameterInfo.UnderlyingParameterType();

                if (!parameterInfo.HasOutModifier())
                {
                    var inputParameterKey = "%" + parameterInfo.Name;

                    var inputParameter = ValueInput(parameterType, inputParameterKey);

                    inputParameters.Add(parameterIndex, inputParameter);

                    inputParameter.SetDefaultValue(parameterInfo.PseudoDefaultValue());

                    if (parameterInfo.AllowsNull())
                    {
                        inputParameter.AllowsNull();
                    }

                    Requirement(inputParameter, enter);

                    if (member.isGettable)
                    {
                        Requirement(inputParameter, result);
                    }
                }

                if (parameterInfo.ParameterType.IsByRef || parameterInfo.IsOut)
                {
                    var outputParameterKey = "&" + parameterInfo.Name;

                    var outputParameter = ValueOutput(parameterType, outputParameterKey);

                    outputParameters.Add(parameterIndex, outputParameter);

                    Assignment(enter, outputParameter);

                    useExpandedParameters = false;
                }
            }

            if (inputParameters.Count > 5)
            {
                useExpandedParameters = false;
            }
        }