/// <summary> /// /// </summary> /// <returns></returns> public override ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_) { ProcessingInfo info = new ProcessingInfo(); info.State = ActionNode.LogicState.Ok; object objCond = GetValueFromSlot((int)NodeSlotId.VarCond); if (objCond == null) { info.State = ActionNode.LogicState.Warning; info.ErrorMessage = "Please connect a variable node into the slot Condition"; LogManager.Instance.WriteLine(LogVerbosity.Warning, "{0} : Branch failed. {1}.", Title, info.ErrorMessage); } if (objCond != null) { bool cond = (bool)objCond; if (cond == true) { ActivateOutputLink(context_, (int)NodeSlotId.OutTrue); } else { ActivateOutputLink(context_, (int)NodeSlotId.OutFalse); } } return info; }
/// <summary> /// /// </summary> /// <returns></returns> public override ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_) { ProcessingInfo info = new ProcessingInfo(); info.State = ActionNode.LogicState.Ok; MemoryStackItem memoryItem = context_.CurrentFrame.GetValueFromID(Id); if (memoryItem == null) { memoryItem = context_.CurrentFrame.Allocate(Id, false); } if (slot_.ID == (int)NodeSlotId.InReset) { memoryItem.Value = false; } else if (slot_.ID == (int)NodeSlotId.InEnter) { if ((bool)memoryItem.Value == false) { memoryItem.Value = true; ActivateOutputLink(context_, (int)NodeSlotId.Out); } } return(info); }
/// <summary> /// /// </summary> /// <returns></returns> public override ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_) { ProcessingInfo info = new ProcessingInfo(); info.State = ActionNode.LogicState.Ok; object val = GetValueFromSlot((int)NodeSlotId.Message); if (val == null) { info.State = ActionNode.LogicState.Warning; info.ErrorMessage = "Please connect a string variable node"; LogManager.Instance.WriteLine(LogVerbosity.Warning, "{0} : No message display because no variable node connected. {1}.", Title, info.ErrorMessage); } else { LogManager.Instance.WriteLine(LogVerbosity.Info, val.ToString()); } ActivateOutputLink(context_, (int)NodeSlotId.Out); return(info); }
/// <summary> /// Triggers data to be retrieved from a pipeline for aggregation /// </summary> /// <param name="store">pipelines data store</param> /// <param name="triggeredBy">node who's data will be collected</param> public void StoreData(DataStore store, int triggeredBy) { NodeSlot slot = NodeSlot.Invalid; foreach (NodeSlot dependentSlot in graphNode.Dependencies) { if (dependentSlot.NodeId == triggeredBy) { slot = dependentSlot; } } if (NodeSlot.isInvalid(slot)) { return; } byte[] newData = store.getData(slot); lock (updateLock) { data[triggeredBy].Add(newData); } if (ReadyToTrigger()) { Console.WriteLine("Sync Block done, " + (data.Count * parallelism) + " results collected"); StoreResultData(); TriggerPipelines(); } }
/// <summary> /// /// </summary> /// <returns></returns> public override ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_) { ProcessingInfo info = new ProcessingInfo(); info.State = ActionNode.LogicState.Ok; MemoryStackItem memoryItem = context_.CurrentFrame.GetValueFromID(Id); if (memoryItem == null) { memoryItem = context_.CurrentFrame.Allocate(Id, true); } if (slot_.ID == (int)NodeSlotId.InEnter) { bool val = (bool)memoryItem.Value; memoryItem.Value = !((bool)memoryItem.Value); SetValueInSlot((int)NodeSlotId.VarOutIsA, val); if (val == true) { ActivateOutputLink(context_, (int)NodeSlotId.OutA); } else { ActivateOutputLink(context_, (int)NodeSlotId.OutB); } } return(info); }
/// <summary> /// /// </summary> /// <returns></returns> public override ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_) { ProcessingInfo info = new ProcessingInfo(); info.State = ActionNode.LogicState.Ok; object objCond = GetValueFromSlot((int)NodeSlotId.VarCond); if (objCond == null) { info.State = ActionNode.LogicState.Warning; info.ErrorMessage = "Please connect a variable node into the slot Condition"; LogManager.Instance.WriteLine(LogVerbosity.Warning, "{0} : Branch failed. {1}.", Title, info.ErrorMessage); } if (objCond != null) { bool cond = (bool)objCond; if (cond == true) { ActivateOutputLink(context_, (int)NodeSlotId.OutTrue); } else { ActivateOutputLink(context_, (int)NodeSlotId.OutFalse); } } return(info); }
/// <summary> /// /// </summary> /// <returns></returns> public override ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_) { ProcessingInfo info = new ProcessingInfo(); info.State = ActionNode.LogicState.Ok; ActivateOutputLink(context_, (int)NodeSlotId.Out); context_.RegisterNextSequence(GetFunction(), typeof(OnEnterFunctionEvent), null); return info; }
/// <summary> /// /// </summary> /// <returns></returns> public override ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_) { ProcessingInfo info = new ProcessingInfo(); info.State = ActionNode.LogicState.Ok; ActivateOutputLink(context_, (int)NodeSlotId.Out); context_.RegisterNextSequence(GetFunction(), typeof(OnEnterFunctionEvent), null); return(info); }
void AddControl <T1>(BaseTextControl <T1> field, NodeSlot slot) { if (slot is IHasValue <T1> ) { field.value = ((IHasValue <T1>)slot).value; } field.OnValueChanged(OnValueChange); Add(field); }
void AddControl <T1>(TextInputBaseField <T1> field, NodeSlot slot) { if (slot is IHasValue <T1> value) { field.value = value.value; } field.RegisterValueChangedCallback(OnValueChange); Add(field); }
/// <summary> /// /// </summary> /// <param name="name"></param> public ConnectorViewModel(NodeSlot slot) { if (slot == null) { throw new InvalidOperationException("ConnectorViewModel() NodeSlot is null"); } SourceSlot = slot; SourceSlot.PropertyChanged += new PropertyChangedEventHandler(OnSlotPropertyChanged); }
/// <summary> /// /// </summary> /// <returns></returns> public override ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_) { ProcessingInfo info = new ProcessingInfo(); info.State = ActionNode.LogicState.Ok; object intVal = GetValueFromSlot((int)NodeSlotId.Delay); if (intVal == null) { info.State = ActionNode.LogicState.Ok; info.ErrorMessage = "Please connect a integer variable node"; LogManager.Instance.WriteLine(LogVerbosity.Error, "{0} : {1}.", Title, info.ErrorMessage); return(info); } MemoryStackItem memoryItem = context_.CurrentFrame.GetValueFromID(Id); if (memoryItem == null) { memoryItem = context_.CurrentFrame.Allocate(Id, TimeSpan.Zero); } TimeSpan startTime = (TimeSpan)memoryItem.Value; int delay = (int)intVal; double delayDouble = ((double)delay) / 1000.0; TimeSpan t = DateTime.Now.TimeOfDay.Subtract(startTime); double totalSecs = t.TotalSeconds; //this is the first time, so we set the current time if (startTime == TimeSpan.Zero) { totalSecs = 0.0; startTime = DateTime.Now.TimeOfDay; memoryItem.Value = startTime; } else if (totalSecs >= delayDouble) { startTime = TimeSpan.Zero; memoryItem.Value = startTime; ActivateOutputLink(context_, (int)NodeSlotId.Out); CustomText = String.Empty; return(info); } CustomText = string.Format("Delay ({0:0.000} seconds left)", delayDouble - totalSecs); context_.RegisterNextExecution(GetSlotById((int)NodeSlotId.In)); return(info); }
/// <summary> /// /// </summary> /// <param name="slot_"></param> /// <returns></returns> private bool ContainsConnectorFromNodeSlots(NodeSlot slot_) { foreach (ConnectorViewModel c in allConnectors) { if (c.SourceSlot.ID == slot_.ID) { return(true); } } return(false); }
/// <summary> /// /// </summary> /// <param name="node_"></param> public ProcessingContextStep RegisterNextExecution(NodeSlot slot_) { if (slot_.Node is ActionNode == false) { throw new InvalidOperationException("ProcessingContext.RegisterNextExecution() : the node is not an ActionNode"); } ProcessingContextStep step = new ProcessingContextStep(SequenceBase, CurrentFrame, slot_); CurrentProcessingContext.m_NextExecutions.Add(step); return(step); }
/// <summary> /// /// </summary> /// <returns></returns> public override ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_) { ProcessingInfo info = new ProcessingInfo(); info.State = ActionNode.LogicState.Ok; if (slot_.ID == (int)NodeSlotId.InReset) { m_Counter = 0; m_IsInitial = false; } else if (slot_.ID == (int)NodeSlotId.InEnter) { MemoryStackItem memoryItem = context_.CurrentFrame.GetValueFromID(Id); if (m_IsInitial == false) { object objN = GetValueFromSlot((int)NodeSlotId.VarInN); if (objN == null) { info.State = ActionNode.LogicState.Warning; info.ErrorMessage = "Please connect a variable node into the slot N"; LogManager.Instance.WriteLine(LogVerbosity.Warning, "{0} : DoN failed. {1}.", Title, info.ErrorMessage); } if (objN != null) { int n = (int)objN; if (memoryItem == null) { memoryItem = context_.CurrentFrame.Allocate(Id, n); } memoryItem.Value = n; } m_IsInitial = true; } if (m_Counter < (int)memoryItem.Value) { m_Counter++; ActivateOutputLink(context_, (int)NodeSlotId.Out); } } return(info); }
/// <summary> /// /// </summary> /// <returns></returns> public override ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_) { ProcessingInfo info = new ProcessingInfo(); info.State = ActionNode.LogicState.Ok; //call script with input nodes List <ScriptSlotData> list = new List <ScriptSlotData>(m_ScriptElement.InputCount); foreach (NodeSlot slot in this.SlotVariableIn) { if (slot is NodeSlotVar) { NodeSlotVar varSlot = slot as NodeSlotVar; list.Add(new ScriptSlotData(varSlot.Text, varSlot.ID, GetValueFromSlot(varSlot.ID))); } } ScriptSlotDataCollection parameters = new ScriptSlotDataCollection(list); list.Clear(); // foreach (NodeSlot slot in this.SlotVariableOut) { if (slot is NodeSlotVar) { NodeSlotVar varSlot = slot as NodeSlotVar; list.Add(new ScriptSlotData(varSlot.Text, varSlot.ID, GetValueFromSlot(varSlot.ID))); } } ScriptSlotDataCollection returnVals = new ScriptSlotDataCollection(list); list.Clear(); if (m_ScriptElement.Run(parameters, returnVals) == false) { info.ErrorMessage = "Some errors in the execution of the script"; info.State = ActionNode.LogicState.Error; return(info); } //set output slot value foreach (ScriptSlotData s in returnVals.List) { SetValueInSlot(s.ID, s.Value); } ActivateOutputLink(context_, (int)NodeSlotId.Out); return(info); }
/// <summary> /// /// </summary> /// <returns></returns> public override ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_) { ProcessingInfo info = new ProcessingInfo(); info.State = ActionNode.LogicState.Ok; //TODO //Set output variable // the nodes executed after the node CallFunctionNode are already registered // we only have to delete the subsequence context_.RemoveLastSequence(); return info; }
/// <summary> /// /// </summary> /// <returns></returns> public override ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_) { ProcessingInfo info = new ProcessingInfo(); info.State = ActionNode.LogicState.Ok; //TODO //Set output variable // the nodes executed after the node CallFunctionNode are already registered // we only have to delete the subsequence context_.RemoveLastSequence(); return(info); }
public static Port Create(NodeSlot slot, IEdgeConnectorListener connectorListener) { var port = new NodePort(Orientation.Horizontal, slot.isInputSlot ? Direction.Input : Direction.Output, slot.isInputSlot || slot.allowMultipleConnections ? Capacity.Single : Capacity.Multi, null) { m_EdgeConnector = new EdgeConnector <UnityEditor.Experimental.UIElements.GraphView.Edge>(connectorListener), }; port.AddManipulator(port.m_EdgeConnector); port.slot = slot; port.portName = slot.displayName; port.portType = slot.valueType.Type; port.visualClass = slot.valueType.Type.Name; return(port); }
/// <summary> /// /// </summary> /// <returns></returns> public override ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_) { ProcessingInfo info = new ProcessingInfo(); info.State = ActionNode.LogicState.Ok; //call script with input nodes List<ScriptSlotData> list = new List<ScriptSlotData>(m_ScriptElement.InputCount); foreach (NodeSlot slot in this.SlotVariableIn) { if (slot is NodeSlotVar) { NodeSlotVar varSlot = slot as NodeSlotVar; list.Add(new ScriptSlotData(varSlot.Text, varSlot.ID, GetValueFromSlot(varSlot.ID))); } } ScriptSlotDataCollection parameters = new ScriptSlotDataCollection(list); list.Clear(); // foreach (NodeSlot slot in this.SlotVariableOut) { if (slot is NodeSlotVar) { NodeSlotVar varSlot = slot as NodeSlotVar; list.Add(new ScriptSlotData(varSlot.Text, varSlot.ID, GetValueFromSlot(varSlot.ID))); } } ScriptSlotDataCollection returnVals = new ScriptSlotDataCollection(list); list.Clear(); if (m_ScriptElement.Run(parameters, returnVals) == false) { info.ErrorMessage = "Some errors in the execution of the script"; info.State = ActionNode.LogicState.Error; return info; } //set output slot value foreach (ScriptSlotData s in returnVals.List) { SetValueInSlot(s.ID, s.Value); } ActivateOutputLink(context_, (int)NodeSlotId.Out); return info; }
public PortInputView(NodeSlot slot) { styleSheets.Add(Resources.Load <StyleSheet>("Styles/PortInputView")); pickingMode = PickingMode.Ignore; ClearClassList(); m_Slot = slot; m_SlotType = slot.valueType; AddToClassList("type" + m_SlotType.Type.Name); m_EdgeControl = new EdgeControl { @from = new Vector2(212f - 21f, 11.5f), to = new Vector2(212f, 11.5f), edgeWidth = 2, pickingMode = PickingMode.Ignore }; Add(m_EdgeControl); m_Container = new VisualElement { name = "container" }; { m_Control = this.slot.InstantiateControl(); if (m_Control != null) { m_Container.Add(m_Control); } var slotElement = new VisualElement { name = "slot" }; { slotElement.Add(new VisualElement { name = "dot" }); } m_Container.Add(slotElement); } Add(m_Container); m_Container.visible = m_EdgeControl.visible = m_Control != null; RegisterCallback <CustomStyleResolvedEvent>(OnCustomStyleResolved); }
public void SimpleSlotDependencies() { List <DependentNode> nodes = new List <DependentNode>(); DependentNode a = new DependentNode(0, "a"), b = new DependentNode(1, "b"), c = new DependentNode(2, "c"); nodes.Add(a); nodes.Add(b); nodes.Add(c); TestHelpers.MatchSlots(b, a, 0, 0); TestHelpers.MatchSlots(b, c, 1, 0); NodeSlot resultSlot = ExecutionHelper.FindFirstNodeSlotInDependents(b, TestHelpers.ConvertToDictionary(nodes), 0); Assert.AreEqual(a.Id, resultSlot.NodeId); }
/// <summary> /// /// </summary> /// <returns></returns> public override ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_) { ProcessingInfo info = new ProcessingInfo(); info.State = ActionNode.LogicState.Ok; MemoryStackItem memoryItem = context_.CurrentFrame.GetValueFromID(Id); if (memoryItem == null) { object a = GetValueFromSlot((int)NodeSlotId.VarInStartClosed); bool state = a != null ? (bool)a : true; memoryItem = context_.CurrentFrame.Allocate(Id, state); } bool val = (bool)memoryItem.Value; if (slot_.ID == (int)NodeSlotId.InEnter) { if (val == true) { ActivateOutputLink(context_, (int)NodeSlotId.Out); } } else if (slot_.ID == (int)NodeSlotId.InOpen) { memoryItem.Value = true; } else if (slot_.ID == (int)NodeSlotId.InClose) { memoryItem.Value = false; } else if (slot_.ID == (int)NodeSlotId.InToggle) { memoryItem.Value = !val; } return(info); }
/// <summary> /// /// </summary> /// <returns></returns> public override ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_) { ProcessingInfo info = new ProcessingInfo(); info.State = ActionNode.LogicState.Ok; MemoryStackItem memoryItem = context_.CurrentFrame.GetValueFromID(Id); if (memoryItem == null) { memoryItem = context_.CurrentFrame.Allocate(Id, true); } if (slot_.ID == (int)NodeSlotId.InEnter) { bool val = (bool)memoryItem.Value; memoryItem.Value = !((bool)memoryItem.Value); SetValueInSlot((int)NodeSlotId.VarOutIsA, val); if (val == true) { ActivateOutputLink(context_, (int)NodeSlotId.OutA); } else { ActivateOutputLink(context_, (int)NodeSlotId.OutB); } } return info; }
/// <summary> /// /// </summary> /// <param name="seq_"></param> /// <param name="stack_"></param> /// <param name="slot_"></param> public ProcessingContextStep(SequenceBase seq_, MemoryStack stack_, NodeSlot slot_) { SequenceBase = seq_; MemoryStack = stack_; Slot = slot_; }
/// <summary> /// Checks if the loop has ended /// </summary> /// <param name="data"></param> /// <param name="dependencyGraph"></param> /// <returns>next set of Ids to be triggered</returns> public int[] Finished(DataStore data, Dictionary <int, DependentNode> dependencyGraph) { //check condition bool done = false; { //find the "done" result NodeSlot search = ExecutionHelper.FindFirstNodeSlotInDependencies(node, dependencyGraph, 1); if (search.NodeId == -1) { return(new int[0]); } byte[] result = data.getData(search); if (result == null) { return(new int[0]); } if (Convert.ToBoolean(result[0])) { done = true; } } //trigger dependencies and iterate loop start depth if (done) { //move the data through to the output of the node List <byte[]> transferData = new List <byte[]>(); for (int j = 2; j < node.Dependencies.Length; j++) { for (var i = 0; i < node.Dependencies.Length; i++) { NodeSlot slot = node.Dependencies[i]; int slotPos = ExecutionHelper.OtherNodeSlotDependents(dependencyGraph[slot.NodeId], node.Id); //slot 0 and 1 are loop node slots, all other data must be passed on if (slotPos == j) { transferData.Add(data.getData(node.Dependencies[i])); break; } } } data.StoreResults(transferData, NodeId); //trigger next nodes List <int> ids = new List <int>(); foreach (NodeSlot slot in node.Dependents) { if (!ids.Contains(slot.NodeId)) { ids.Add(slot.NodeId); } } return(ids.ToArray()); } //move loop end input data to the loop start output //so that it can be used in the next cycle List <byte[]> outputData = new List <byte[]>(); outputData.Add(new byte[0]); //loop start Link slot outputData.Add(BitConverter.GetBytes(++pair.Iteration)); //loop start increment slot for (int j = 2; j < node.Dependencies.Length; j++) { for (var i = 0; i < node.Dependencies.Length; i++) { NodeSlot slot = node.Dependencies[i]; int slotPos = ExecutionHelper.OtherNodeSlotDependents(dependencyGraph[slot.NodeId], node.Id); //slot 0 and 1 are loop node slots, all other data must be passed on if (slotPos == j) { outputData.Add(data.getData(node.Dependencies[i])); break; } } } data.ClearResults(pair.ContainedNodes); data.StoreResults(outputData, pair.Start.NodeId); return(pair.Start.StartDependencies(NodeId, data)); }
/// <summary> /// /// </summary> /// <returns></returns> public override ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_) { ProcessingInfo info = new ProcessingInfo(); info.State = ActionNode.LogicState.Ok; if (slot_.ID == (int)NodeSlotId.In) { int firstIndex = 0, lastIndex = -1; #region first index object objFirstIndex = GetValueFromSlot((int)NodeSlotId.VarInFirstIndex); if (objFirstIndex == null) { info.State = ActionNode.LogicState.Warning; info.ErrorMessage = "Please connect a variable node into the slot First Index"; LogManager.Instance.WriteLine(LogVerbosity.Warning, "{0} : For Loop failed. {1}.", Title, info.ErrorMessage); return(info); } if (objFirstIndex != null) { firstIndex = (int)objFirstIndex; } #endregion // first index #region last index object objLastIndex = GetValueFromSlot((int)NodeSlotId.VarInLastIndex); if (objLastIndex == null) { info.State = ActionNode.LogicState.Warning; info.ErrorMessage = "Please connect a variable node into the slot Last Index"; LogManager.Instance.WriteLine(LogVerbosity.Warning, "{0} : For Loop failed. {1}.", Title, info.ErrorMessage); return(info); } if (objLastIndex != null) { lastIndex = (int)objLastIndex; } #endregion last index MemoryStackItem memoryItem = context_.CurrentFrame.GetValueFromID(Id); if (memoryItem == null) { memoryItem = context_.CurrentFrame.Allocate(Id, new ForLoopNodeInfo { Counter = firstIndex, IsWaitingLoopBody = false }); } ForLoopNodeInfo memoryInfo = (ForLoopNodeInfo)memoryItem.Value; if (memoryInfo.IsWaitingLoopBody == false) { SetValueInSlot((int)NodeSlotId.VarOutIndex, memoryInfo.Counter); if (memoryInfo.Counter <= lastIndex) { memoryInfo.IsWaitingLoopBody = true; memoryInfo.Counter++; // register again this node in order to active itself // after the sequence activated by the loop body slot // is finished memoryInfo.Step = context_.RegisterNextExecution(GetSlotById((int)NodeSlotId.In)); memoryItem.Value = memoryInfo; ProcessingContext newContext = context_.PushNewContext(); newContext.Finished += new EventHandler(OnLoopBodyFinished); ActivateOutputLink(newContext, (int)NodeSlotId.OutLoop); } else { context_.CurrentFrame.Deallocate(Id); ActivateOutputLink(context_, (int)NodeSlotId.OutCompleted); } } } else if (slot_.ID == (int)NodeSlotId.InBreak) { MemoryStackItem memoryItem = context_.CurrentFrame.GetValueFromID(Id); ForLoopNodeInfo memoryInfo = (ForLoopNodeInfo)memoryItem.Value; context_.RemoveExecution(context_, memoryInfo.Step); context_.CurrentFrame.Deallocate(Id); ActivateOutputLink(context_, (int)NodeSlotId.OutCompleted); } return(info); }
private void FindLoopPairs(DependentNode loopEnd, ref List <int> foundEnds, int depth = 0) { LoopPair instance = new LoopPair(); instance.Id = loopIdCount++; if (loopEnd.Type == LoopEnd.TypeName) { instance.End = new LoopEnd(loopEnd, instance); instance.Depth = depth; int startNode = ExecutionHelper.FindFirstNodeSlotInDependencies(loopEnd, dependencyGraph, 0).NodeId; if (startNode == -1) { throw new MissingLinkException("No link for loop start specified"); } DependentNode loopStart = dependencyGraph[startNode]; //try to keep one instance per unique loop start node Id if (loopStarts.ContainsKey(startNode)) { instance.Start = loopStarts[startNode]; } else { instance.Start = new LoopStart(loopStart); loopStarts.Add(startNode, instance.Start); } //ensure that only the start and end nodes are linked if (loopStart.Dependents.Where((testSlot, b) => { bool incorrectType = dependencyGraph[testSlot.NodeId].Type != LoopEnd.TypeName; foreach (NodeSlot slot in dependencyGraph[testSlot.NodeId].Dependencies) { if (slot.NodeId == loopStart.Id && slot.SlotPos == 0) { if (incorrectType) { return(true); } } } return(false); }).Any()) { throw new InvalidNodeException("Loop Start Link (slot 0) cannot link to anything but a Loop End"); } //find out how many loops the "LoopStart" node is directly responsible for int loopCount; { List <int> matched = new List <int>(); loopCount = loopStart.Dependents.Where((testSlot, b) => { if (matched.Contains(testSlot.NodeId)) { return(false); } foreach (NodeSlot slot in dependencyGraph[testSlot.NodeId].Dependencies) { if (slot.NodeId == loopStart.Id && slot.SlotPos == 0) { matched.Add(testSlot.NodeId); return(true); } } return(false); }).Count(); } if (loopCount > 1) { throw new SlotLimitExceeded("Loop Start may only have one loop end, use multiple loop starts for nesting or branching"); #region //multiple nodes linked so there must be nested loops sharing this start position /*int[] ids = new int[loopCount]; * for (int i = 0, c = 0; i < loopStart.Dependents.Length; i++) * if (loopStart.Dependents[i].SlotPos == 0) * ids[c++] = loopStart.Dependents[i].NodeId; * * //check if co dependent nodes exist * List<int> dependencies = new List<int>(); * for (int a = 0; a < ids.Length; a++) * { * for (int b = 0; b < ids.Length; b++) * { * if (a == b) continue; * * bool aTob = NodeDependentOn(ids[a], ids[b]), * bToa = NodeDependentOn(ids[b], ids[a]); * * if (aTob && bToa) throw new CoDependentLoopException * ("Node " + ids[a] + " and " + ids[b] + "Are dependent on each other and can't loop!"); * * if (aTob && !dependencies.Contains(a)) dependencies.Add(ids[a]); * } * } * * //check non dependent nodes for internal loops * foreach (int id in ids) * { * if (dependencies.Contains(id)) continue; * * LoopPair subPair = new LoopPair(); * subPair.Id = loopIdCount++; * subPair.Depth = depth; * subPair.End = new LoopEnd(dependencyGraph[id], subPair); * if (loopStarts.ContainsKey(loopEnd.Dependencies[0].NodeId)) * subPair.Start = loopStarts[loopEnd.Dependencies[0].NodeId]; * else * { * instance.Start = new LoopStart(dependencyGraph[loopEnd.Dependencies[0].NodeId]); * loopStarts.Add(loopEnd.Dependencies[0].NodeId, subPair.Start); * } * * int foundEnd; * if (ContainsLoop(instance, out foundEnd)) * //contains internal loop * FindLoopPairs(dependencyGraph[foundEnd], ref foundEnds, subPair.Depth + 1); * * foundEnds.Add(subPair.End.NodeId); * subPair.Start.AddLoopPair(ref subPair); * loopPairs.Add(subPair); * } * * //go back and handle the nodes which are dependent on each other * if (dependencies.Count > 1) * { * throw new NotImplementedException(); * //todo * }*/ #endregion } else { NodeSlot startLink = ExecutionHelper.FindFirstNodeSlotInDependents(loopStart, dependencyGraph, 0); if (startLink.NodeId == -1) { throw new MissingLinkException("No link for loop start specified"); } if (startLink.NodeId != loopEnd.Id) { throw new MissingLinkException(StartEndIdMismatch); } int foundEnd; //contains internal loop? if (ContainsLoop(instance, out foundEnd)) { FindLoopPairs(dependencyGraph[foundEnd], ref foundEnds, instance.Depth + 1); } instance.ContainedNodes = FindContainingNodeIds(instance.Start.NodeId, instance.End.NodeId); int start = 0, end = 0; foreach (NodeSlot nodes in instance.ContainedNodes) { if (dependencyGraph[nodes.NodeId].Type == LoopStart.TypeName) { start += 1; } else if (dependencyGraph[nodes.NodeId].Type == LoopEnd.TypeName) { end += 1; } } if (start != end) { throw new CoDependentLoopException(); } foundEnds.Add(instance.End.NodeId); instance.Start.AddLoopPair(ref instance); loopPairs.Add(instance); } } else if (loopEnd.Type == LoopStart.TypeName) { //abort as you are in the middle of a loop rather than at the end if (instance.End == null) { return; } } }
/// <summary> /// /// </summary> /// <returns></returns> public override ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_) { ProcessingInfo info = new ProcessingInfo(); info.State = ActionNode.LogicState.Ok; MemoryStackItem memoryItem = context_.CurrentFrame.GetValueFromID(Id); if (memoryItem == null) { memoryItem = context_.CurrentFrame.Allocate(Id, false); } if (slot_.ID == (int)NodeSlotId.InReset) { memoryItem.Value = false; } else if (slot_.ID == (int)NodeSlotId.InEnter) { if ((bool)memoryItem.Value == false) { memoryItem.Value = true; ActivateOutputLink(context_, (int)NodeSlotId.Out); } } return info; }
/// <summary> /// /// </summary> /// <returns></returns> public override ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_) { ProcessingInfo info = new ProcessingInfo(); info.State = ActionNode.LogicState.Ok; if (slot_.ID == (int)NodeSlotId.InReset) { m_Counter = 0; m_IsInitial = false; } else if (slot_.ID == (int)NodeSlotId.InEnter) { MemoryStackItem memoryItem = context_.CurrentFrame.GetValueFromID(Id); if (m_IsInitial == false) { object objN = GetValueFromSlot((int)NodeSlotId.VarInN); if (objN == null) { info.State = ActionNode.LogicState.Warning; info.ErrorMessage = "Please connect a variable node into the slot N"; LogManager.Instance.WriteLine(LogVerbosity.Warning, "{0} : DoN failed. {1}.", Title, info.ErrorMessage); } if (objN != null) { int n = (int)objN; if (memoryItem == null) { memoryItem = context_.CurrentFrame.Allocate(Id, n); } memoryItem.Value = n; } m_IsInitial = true; } if (m_Counter < (int)memoryItem.Value) { m_Counter++; ActivateOutputLink(context_, (int)NodeSlotId.Out); } } return info; }
/// <summary> /// /// </summary> /// <returns></returns> public override ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_) { ProcessingInfo info = new ProcessingInfo(); info.State = ActionNode.LogicState.Ok; if (slot_.ID == (int)NodeSlotId.In) { int firstIndex = 0, lastIndex = -1; #region first index object objFirstIndex = GetValueFromSlot((int)NodeSlotId.VarInFirstIndex); if (objFirstIndex == null) { info.State = ActionNode.LogicState.Warning; info.ErrorMessage = "Please connect a variable node into the slot First Index"; LogManager.Instance.WriteLine(LogVerbosity.Warning, "{0} : For Loop failed. {1}.", Title, info.ErrorMessage); return info; } if (objFirstIndex != null) { firstIndex = (int)objFirstIndex; } #endregion // first index #region last index object objLastIndex = GetValueFromSlot((int)NodeSlotId.VarInLastIndex); if (objLastIndex == null) { info.State = ActionNode.LogicState.Warning; info.ErrorMessage = "Please connect a variable node into the slot Last Index"; LogManager.Instance.WriteLine(LogVerbosity.Warning, "{0} : For Loop failed. {1}.", Title, info.ErrorMessage); return info; } if (objLastIndex != null) { lastIndex = (int)objLastIndex; } #endregion last index MemoryStackItem memoryItem = context_.CurrentFrame.GetValueFromID(Id); if (memoryItem == null) { memoryItem = context_.CurrentFrame.Allocate(Id, new ForLoopNodeInfo { Counter = firstIndex, IsWaitingLoopBody = false }); } ForLoopNodeInfo memoryInfo = (ForLoopNodeInfo)memoryItem.Value; if (memoryInfo.IsWaitingLoopBody == false) { SetValueInSlot((int)NodeSlotId.VarOutIndex, memoryInfo.Counter); if (memoryInfo.Counter <= lastIndex) { memoryInfo.IsWaitingLoopBody = true; memoryInfo.Counter++; // register again this node in order to active itself // after the sequence activated by the loop body slot // is finished memoryInfo.Step = context_.RegisterNextExecution(GetSlotById((int)NodeSlotId.In)); memoryItem.Value = memoryInfo; ProcessingContext newContext = context_.PushNewContext(); newContext.Finished += new EventHandler(OnLoopBodyFinished); ActivateOutputLink(newContext, (int)NodeSlotId.OutLoop); } else { context_.CurrentFrame.Deallocate(Id); ActivateOutputLink(context_, (int)NodeSlotId.OutCompleted); } } } else if (slot_.ID == (int)NodeSlotId.InBreak) { MemoryStackItem memoryItem = context_.CurrentFrame.GetValueFromID(Id); ForLoopNodeInfo memoryInfo = (ForLoopNodeInfo)memoryItem.Value; context_.RemoveExecution(context_, memoryInfo.Step); context_.CurrentFrame.Deallocate(Id); ActivateOutputLink(context_, (int)NodeSlotId.OutCompleted); } return info; }
public ValueSlotControlView(ValueSlot <T> slot) { m_Slot = slot; if (slot is ValueSlot <bool> ) { var toggle = new Toggle(); toggle.value = ((IHasValue <bool>)slot).value; toggle.RegisterValueChangedCallback((e) => { m_Slot.owner.owner.owner.RegisterCompleteObjectUndo("Boolean Change"); if (m_Slot is IValueSetter <bool> ) { ((IValueSetter <bool>)m_Slot).SetValue(e.newValue); } m_Slot.owner.Dirty(ModificationScope.Node); }); Add(toggle); } #if UNITY_EDITOR else if (slot is ValueSlot <float> ) { AddControl(new FloatField(), slot); styleSheets.Add(Resources.Load <StyleSheet>("Styles/Controls/FloatControlView")); } else if (slot is ValueSlot <double> ) { AddControl(new DoubleField(), slot); } else if (slot is ValueSlot <string> ) { AddControl(new TextField(), slot); styleSheets.Add(Resources.Load <StyleSheet>("Styles/Controls/StringControlView")); } else if (slot is ValueSlot <int> ) { AddControl(new IntegerField(), slot); styleSheets.Add(Resources.Load <StyleSheet>("Styles/Controls/IntegerControlView")); } else if (slot is ValueSlot <Color> ) { AddControl(new ColorField(), slot); styleSheets.Add(Resources.Load <StyleSheet>("Styles/Controls/ColorControlView")); } else if (slot is ValueSlot <Gradient> ) { AddControl(new GradientField(), slot); styleSheets.Add(Resources.Load <StyleSheet>("Styles/Controls/GradientControlView")); } else if (slot is ValueSlot <AnimationCurve> ) { AddControl(new CurveField(), slot); styleSheets.Add(Resources.Load <StyleSheet>("Styles/Controls/CurveControlView")); } else if (slot is ValueSlot <Vector2> ) { Add(new MultiFloatSlotControlView(m_Slot.owner, new [] { "x", "y" }, () => (m_Slot as ValueSlot <Vector2>).value, v => (m_Slot as ValueSlot <Vector2>).value = v)); } else if (slot is ValueSlot <Vector3> ) { Add(new MultiFloatSlotControlView(m_Slot.owner, new[] { "x", "y", "z" }, () => (m_Slot as ValueSlot <Vector3>).value, v => (m_Slot as ValueSlot <Vector3>).value = v)); } else if (slot is ValueSlot <Vector4> ) { Add(new MultiFloatSlotControlView(m_Slot.owner, new[] { "x", "y", "z", "w" }, () => (m_Slot as ValueSlot <Vector4>).value, v => (m_Slot as ValueSlot <Vector4>).value = v)); } else if (slot is ValueSlot <Quaternion> ) { Add(new MultiFloatSlotControlView(m_Slot.owner, new[] { "x", "y", "z" }, () => (m_Slot as ValueSlot <Quaternion>).value.eulerAngles, v => (m_Slot as ValueSlot <Quaternion>).value = Quaternion.Euler(v))); } else if (slot is ValueSlot <Rect> ) { Add(new MultiFloatSlotControlView(m_Slot.owner, new[] { "x", "y", "w", "h" }, () => { var rect = (m_Slot as ValueSlot <Rect>).value; return(new Vector4(rect.x, rect.y, rect.width, rect.height)); }, v => (m_Slot as ValueSlot <Rect>).value = new Rect(v.x, v.y, v.z, v.w))); } else { var genericType = slot.GetType().GetGenericArguments()[0]; if (typeof(Object).IsAssignableFrom(genericType)) { var objField = new ObjectField() { objectType = genericType }; if (slot is IHasValue <Object> ) { objField.value = ((IHasValue <Object>)slot).value; } objField.RegisterValueChangedCallback(e => { slot.owner.owner.owner.RegisterCompleteObjectUndo(genericType.Name + " Change"); if (m_Slot is IValueSetter <Object> ) { ((IValueSetter <Object>)m_Slot).SetValue(e.newValue); } slot.owner.Dirty(ModificationScope.Node); }); Add(objField); styleSheets.Add(Resources.Load <StyleSheet>("Styles/Controls/ObjectSlotControlView")); } } #endif }
/// <summary> /// /// </summary> /// <returns></returns> public override ProcessingInfo ActivateLogic(ProcessingContext context_, NodeSlot slot_) { ProcessingInfo info = new ProcessingInfo(); info.State = ActionNode.LogicState.Ok; MemoryStackItem memoryItem = context_.CurrentFrame.GetValueFromID(Id); if (memoryItem == null) { object a = GetValueFromSlot((int)NodeSlotId.VarInStartClosed); bool state = a != null ? (bool)a : true; memoryItem = context_.CurrentFrame.Allocate(Id, state); } bool val = (bool)memoryItem.Value; if (slot_.ID == (int)NodeSlotId.InEnter) { if (val == true) { ActivateOutputLink(context_, (int)NodeSlotId.Out); } } else if (slot_.ID == (int)NodeSlotId.InOpen) { memoryItem.Value = true; } else if (slot_.ID == (int)NodeSlotId.InClose) { memoryItem.Value = false; } else if (slot_.ID == (int)NodeSlotId.InToggle) { memoryItem.Value = !val; } return info; }
public void UpdateSlot(NodeSlot newSlot) { m_Slot = newSlot; Recreate(); }
public override void CopyValuesFrom(NodeSlot foundSlot) { }