示例#1
0
        public void RebuildFunctionNodes()
        {
            if (m_nodes.Count < 2)
            {
                throw new Exception("A function graph always needs at least 2 nodes, Entry and Return");
            }
            CFunctionGraphEntryNode entryNode = m_nodes[0] as CFunctionGraphEntryNode;

            if (entryNode == null)
            {
                throw new Exception("First node in the function graph was not a entry node");
            }
            entryNode.RebuildNode(InputParameters);

            CFunctionGraphReturnNode returnNode = m_nodes[1] as CFunctionGraphReturnNode;

            if (returnNode == null)
            {
                throw new Exception("Second node in the function graph was not a return node");
            }
            returnNode.RebuildNode(OutputParameters);

            NumInputValues  = InputParameters.Count;
            NumOutputValues = OutputParameters.Count;

            FunctionNodesRebuilt?.Invoke();
        }
示例#2
0
        public CCustomFunctionGraph()
        {
            CFunctionGraphEntryNode entryNode = new CFunctionGraphEntryNode(InputParameters);

            m_nodes.Add(entryNode);

            CFunctionGraphReturnNode returnNode = new CFunctionGraphReturnNode(OutputParameters);

            returnNode.NodePosX = 400;
            m_nodes.Add(returnNode);

            NumInputValues  = InputParameters.Count;
            NumOutputValues = OutputParameters.Count;
        }
        public CInterfaceFunctionGraph(CKlaxScriptInterfaceFunction interfaceFunction)
        {
            InterfaceFunctionGuid = interfaceFunction.Guid;

            CFunctionGraphEntryNode entryNode = new CFunctionGraphEntryNode(interfaceFunction.InputParameters);

            m_nodes.Add(entryNode);

            CFunctionGraphReturnNode returnNode = new CFunctionGraphReturnNode(interfaceFunction.OutputParameters);

            returnNode.NodePosX = 400;
            m_nodes.Add(returnNode);

            NumInputValues  = interfaceFunction.InputParameters.Count;
            NumOutputValues = interfaceFunction.OutputParameters.Count;
        }
示例#4
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;
        }