Exemplo n.º 1
0
        private void ExecuteImplicitNode(CNode implicitNode)
        {
            m_inParameterBuffer.Clear();
            m_outParameterBuffer.Clear();
            // We first execute all implicit nodes
            for (int i = 0; i < implicitNode.GetInParameterCount(); i++)
            {
                CInputPin inputPin = implicitNode.InputPins[i];
                if (inputPin.SourceNode != null && inputPin.SourceNode.IsImplicit)
                {
                    ExecuteImplicitNode(inputPin.SourceNode);
                }
            }

            // Afterwards the parameters are added to the buffer
            for (int i = 0; i < implicitNode.GetInParameterCount(); i++)
            {
                int stackIndex = implicitNode.InputPins[i].StackIndex;
                if (stackIndex >= 0)
                {
                    m_inParameterBuffer.Add(m_stack[stackIndex]);
                }
                else
                {
                    m_inParameterBuffer.Add(null);
                }
            }

            // After all input parameters are resolved we execute the node and add it's output parameters to the stack
            implicitNode.Execute(s_nodeExecutionContext, m_inParameterBuffer, m_outParameterBuffer);

            AddOutParametersToStack(implicitNode.OutParameterStackIndex, implicitNode.GetOutParameterCount());
            m_inParameterBuffer.Clear();
            m_outParameterBuffer.Clear();
        }
Exemplo n.º 2
0
        public void Execute(List <object> inValues, List <object> outValues)
        {
            if (m_nodes.Count <= 0)
            {
                return;
            }

            CFunctionGraphEntryNode entryNode = m_nodes[0] as CFunctionGraphEntryNode;

            if (entryNode == null)
            {
                throw new Exception("The first node of a function graph has to be an entry node");
            }

            if (inValues.Count != NumInputValues)
            {
                throw new Exception($"Number of input values does not match the expected number on inputs. In Count was {inValues.Count} expected was {NumInputValues}");
            }

            outValues.Clear();
            outValues.Capacity = NumOutputValues;

            PrepareStack();
            m_inParameterBuffer.Clear();
            m_outParameterBuffer.Clear();

            foreach (var inValue in inValues)
            {
                m_inParameterBuffer.Add(inValue);
            }

            CGraph        oldContextGraph = s_nodeExecutionContext.graph;
            CExecutionPin oldCalledPin    = s_nodeExecutionContext.calledPin;

            s_nodeExecutionContext.graph     = this;
            s_nodeExecutionContext.calledPin = null;

            CExecutionPin nextExecPin = entryNode.Execute(s_nodeExecutionContext, m_inParameterBuffer, m_outParameterBuffer);

            if (nextExecPin?.TargetNode != null)
            {
                AddOutParametersToStack(entryNode.OutParameterStackIndex, entryNode.GetOutParameterCount());
                CNode lastNode = Execute(nextExecPin.TargetNode, nextExecPin);
                if (lastNode is CFunctionGraphReturnNode)
                {
                    // Out buffer contains the return values of the return nodes
                    foreach (var outValue in m_outParameterBuffer)
                    {
                        outValues.Add(outValue);
                    }
                }
                else
                {
                    for (int i = 0; i < NumOutputValues; i++)
                    {
                        outValues.Add(null);
                    }
                }
            }

            s_nodeExecutionContext.graph     = oldContextGraph;
            s_nodeExecutionContext.calledPin = oldCalledPin;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Executes the graph, returns the last node executed
        /// </summary>
        /// <param name="startNode"></param>
        /// <param name="firstPin"></param>
        /// <returns></returns>
        protected CNode Execute(CNode startNode, CExecutionPin firstPin)
        {
            s_nodeExecutionContext.graph = this;

            CExecutionPin nextExecutionPin = firstPin;
            CNode         nextNode         = startNode;

            while (nextNode != null)
            {
                m_inParameterBuffer.Clear();
                m_outParameterBuffer.Clear();

                CNode nodeToExecute = nextNode;
                s_nodeExecutionContext.calledPin = null;

                // We first execute all implicit nodes
                for (int i = 0; i < nodeToExecute.GetInParameterCount(); i++)
                {
                    CInputPin inputPin = nodeToExecute.InputPins[i];
                    if (inputPin.SourceNode != null && inputPin.SourceNode.IsImplicit)
                    {
                        ExecuteImplicitNode(inputPin.SourceNode);
                    }
                }

                // Afterwards the parameters are added to the buffer
                for (int i = 0; i < nodeToExecute.GetInParameterCount(); i++)
                {
                    int stackIndex = nodeToExecute.InputPins[i].StackIndex;
                    if (stackIndex >= 0)
                    {
                        m_inParameterBuffer.Add(m_stack[stackIndex]);
                    }
                    else
                    {
                        m_inParameterBuffer.Add(null);
                    }
                }

                s_nodeExecutionContext.calledPin = nextExecutionPin != null ? nextExecutionPin.TargetPin : null;
                nextExecutionPin = nodeToExecute.Execute(s_nodeExecutionContext, m_inParameterBuffer, m_outParameterBuffer);

                if (nextExecutionPin == null || nextExecutionPin.TargetNode == null)
                {
                    nextExecutionPin = null;

                    int count = m_returnPointNodes.Count;
                    if (count > 0)
                    {
                        nextNode = m_returnPointNodes[count - 1];
                        m_returnPointNodes.RemoveAt(count - 1);
                        continue;
                    }
                    else
                    {
                        return(nextNode);
                    }
                }

                nextNode = nextExecutionPin.TargetNode;
                AddOutParametersToStack(nodeToExecute.OutParameterStackIndex, nodeToExecute.GetOutParameterCount());
            }

            return(null);
        }
Exemplo n.º 4
0
 public void RemoveReturnPointNode(CNode node)
 {
     m_returnPointNodes.Remove(node);
 }
Exemplo n.º 5
0
 public void AddReturnPointNode(CNode node)
 {
     m_returnPointNodes.Add(node);
 }