Esempio n. 1
0
        private bool IsEntered(IState state, Recursion recursion)
        {
            if (state.isStart)
            {
                return(true);
            }

            if (!recursion?.TryEnter(state) ?? false)
            {
                return(false);
            }

            foreach (var incomingTransition in state.incomingTransitions)
            {
                if (IsEntered(incomingTransition.source, recursion) && incomingTransition.Analysis <StateTransitionAnalysis>(context).isTraversed)
                {
                    recursion?.Exit(state);
                    return(true);
                }
            }

            recursion?.Exit(state);

            return(false);
        }
Esempio n. 2
0
        public static IEnumerable <IUnit> GetUnitsRecursive(this FlowGraph flowGraph, Recursion recursion)
        {
            Ensure.That(nameof(flowGraph)).IsNotNull(flowGraph);

            if (!recursion?.TryEnter(flowGraph) ?? false)
            {
                yield break;
            }

            foreach (var unit in flowGraph.units)
            {
                yield return(unit);

                var nestedGraph = (unit as SubgraphUnit)?.nest.graph;

                if (nestedGraph != null)
                {
                    foreach (var nestedUnit in GetUnitsRecursive(nestedGraph, recursion))
                    {
                        yield return(nestedUnit);
                    }
                }
            }

            recursion?.Exit(flowGraph);
        }
Esempio n. 3
0
        private static bool IsEntered(IUnit unit, Recursion recursion)
        {
            if (unit.isControlRoot)
            {
                return(true);
            }

            foreach (var controlInput in unit.controlInputs)
            {
                if (!controlInput.isPredictable || controlInput.couldBeEntered)
                {
                    return(true);
                }
            }

            foreach (var valueOutput in unit.valueOutputs)
            {
                if (!recursion?.TryEnter(valueOutput) ?? false)
                {
                    continue;
                }

                var valueOutputEntered = valueOutput.validConnections.Any(c => IsEntered(c.destination.unit, recursion));

                recursion?.Exit(valueOutput);

                if (valueOutputEntered)
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 4
0
        public bool IsPredictable(Recursion recursion)
        {
            if (unit.isControlRoot)
            {
                return(true);
            }

            if (!recursion?.TryEnter(this) ?? false)
            {
                return(false);
            }

            var isPredictable = unit.relations.WithDestination(this).Where(r => r.source is ControlInput).All(r => ((ControlInput)r.source).IsPredictable(recursion));

            recursion?.Exit(this);

            return(isPredictable);
        }
Esempio n. 5
0
        public bool IsPredictable(Recursion recursion)
        {
            if (!hasValidConnection)
            {
                return(true);
            }

            if (!recursion?.TryEnter(this) ?? false)
            {
                return(false);
            }

            var isPredictable = validConnectedPorts.All(cop => cop.IsPredictable(recursion));

            recursion?.Exit(this);

            return(isPredictable);
        }
Esempio n. 6
0
        private static IEnumerable <string> GetScriptGuids(Recursion recursion, Type type)
        {
            if (!recursion?.TryEnter(type) ?? false)
            {
                yield break;
            }

            if (typesToGuids.ContainsKey(type))
            {
                foreach (var guid in typesToGuids[type])
                {
                    yield return(guid);
                }
            }

            // Recurse inside the type.
            // For example, a List<Enemy> or an Enemy[] type should return the script GUID for Enemy.
            if (type.IsGenericType)
            {
                foreach (var genericArgument in type.GetGenericArguments())
                {
                    foreach (var genericGuid in GetScriptGuids(recursion, genericArgument))
                    {
                        yield return(genericGuid);
                    }
                }
            }
            else if (type.HasElementType)
            {
                foreach (var genericGuid in GetScriptGuids(recursion, type.GetElementType()))
                {
                    yield return(genericGuid);
                }
            }

            recursion?.Exit(type);
        }
Esempio n. 7
0
 private void AfterInvoke(ControlOutput output, RecursionNode recursionNode)
 {
     recursion?.Exit(recursionNode);
 }