/// <summary> /// Adds a new execution pin. This should only be called upon editor callback. /// </summary> /// <param name="context">Context which contains all editor node actions that need to be executed after this call</param> /// <param name="newPin">The new execution pin that should be added</param> /// <param name="index">The index at which the execution pin should be inserted</param> /// <param name="bIsIn">Whether the pin acts as in or output</param> protected void AddExecutionPin(CNodeChangeContext context, CExecutionPin newPin, int index, bool bIsIn) { if (bIsIn) { InExecutionPins.Add(newPin); } else { OutExecutionPins.Add(newPin); } context.Actions.Add(new CAddPinChangeAction(newPin, index, bIsIn)); }
private void AddExecutionPins() { CExecutionPin execute = new CExecutionPin() { Name = "In", TargetNode = null }; InExecutionPins.Add(execute); CExecutionPin done = new CExecutionPin() { Name = "Out", TargetNode = null }; OutExecutionPins.Add(done); }
public CExecuteFunctionNode() { CExecutionPin execute = new CExecutionPin() { Name = "In", TargetNode = null }; InExecutionPins.Add(execute); CExecutionPin done = new CExecutionPin() { Name = "Out", TargetNode = null }; OutExecutionPins.Add(done); }
protected void Execute(object[] eventArgs) { if (m_nodes.Count <= 0) { return; } if (!(m_nodes[0] is CReceiveEventNode eventTargetNode)) { throw new Exception("The first node of an event graph must always be a ReceiveEventNode"); } PrepareStack(); m_inParameterBuffer.Clear(); m_outParameterBuffer.Clear(); if (eventArgs != null) { foreach (object arg in eventArgs) { m_inParameterBuffer.Add(arg); } } CGraph oldContextGraph = s_nodeExecutionContext.graph; CExecutionPin oldCalledPin = s_nodeExecutionContext.calledPin; s_nodeExecutionContext.graph = this; s_nodeExecutionContext.calledPin = null; CExecutionPin nextExecPin = eventTargetNode.Execute(s_nodeExecutionContext, m_inParameterBuffer, m_outParameterBuffer); m_inParameterBuffer.Clear(); if (nextExecPin != null && nextExecPin.TargetNode != null) { AddOutParametersToStack(eventTargetNode.OutParameterStackIndex, eventTargetNode.GetOutParameterCount()); m_outParameterBuffer.Clear(); Execute(nextExecPin.TargetNode, nextExecPin); } s_nodeExecutionContext.graph = oldContextGraph; s_nodeExecutionContext.calledPin = oldCalledPin; }
protected override void OnImplicitChanged() { InExecutionPins.Clear(); OutExecutionPins.Clear(); if (!IsImplicit) { CExecutionPin execute = new CExecutionPin() { Name = "In", TargetNode = null }; InExecutionPins.Add(execute); CExecutionPin done = new CExecutionPin() { Name = "Out", TargetNode = null }; OutExecutionPins.Add(done); } }
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; }
/// <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); }