Exemplo n.º 1
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);
                }
            }

            // Loop through generic arguments.
            // For example, a List<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);
                    }
                }
            }
        }
Exemplo 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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
        private bool CanPredict(ValueOutput output)
        {
            // Shortcircuit the expensive check if the port isn't marked as predictable
            if (!output.supportsPrediction)
            {
                return(false);
            }

            var recursionNode = new RecursionNode(output, stack);

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

            // Check each value dependency
            foreach (var relation in output.unit.relations.WithDestination(output))
            {
                if (relation.source is ValueInput)
                {
                    var source = (ValueInput)relation.source;

                    if (!CanPredict(source))
                    {
                        recursion?.Exit(recursionNode);
                        return(false);
                    }
                }
            }

            var value = CanPredictDelegate(output);

            recursion?.Exit(recursionNode);

            return(value);
        }