Esempio 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();
        }
Esempio n. 2
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);
        }