Example #1
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();
                }
            }
        }
Example #2
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);

            try
            {
                var nextPort = InvokeDelegate(input);

                if (nextPort != null)
                {
                    Invoke(nextPort);
                }
            }
            finally
            {
                AfterInvoke(output, recursionNode);
            }
        }
Example #3
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);
        }
Example #4
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);
        }
Example #5
0
        protected ControlOutput ControlOutput(string key)
        {
            EnsureUniqueOutput(key);
            var port = new ControlOutput(key);

            controlOutputs.Add(port);
            return(port);
        }
Example #6
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);
        }
        protected void Connect(ControlOutput source, ControlInput destination)
        {
            Undo.IncrementCurrentGroup();
            LudiqEditorUtility.editedObject.BeginOverride(m_Reference.serializedObject);
            var widget            = new ControlOutputWidget(m_Canvas, source);
            var connectMethodInfo = GetConnectionMethodInfo(widget.GetType());

            connectMethodInfo?.Invoke(widget, new object[] { widget.port, destination });
            LudiqEditorUtility.editedObject.EndOverride();
        }
        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);
        }
Example #9
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);
        }
Example #10
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);
        }
Example #11
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);
        }
Example #12
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);
        }
Example #13
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);
        }
Example #14
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);
        }
Example #15
0
 public void Run(ControlOutput port)
 {
     Invoke(port);
     Dispose();
 }
Example #16
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;
            }
        }
Example #17
0
 private void AfterInvoke(ControlOutput output, RecursionNode recursionNode)
 {
     recursion?.Exit(recursionNode);
 }
Example #18
0
 protected override void Definition()
 {
     enter = ControlInputCoroutine(nameof(enter), Await);
     exit  = ControlOutput(nameof(exit));
     Succession(enter, exit);
 }
Example #19
0
 /// <summary>
 /// Triggering the source may trigger the destination.
 /// </summary>
 protected void Succession(ControlInput source, ControlOutput destination)
 {
     Relation(source, destination);
 }