public override NODE_STATE TreeExecute() { if (this.children.Count == 0 || this.updateIndex < 0 || this.updateIndex >= this.children.Count) { this.currentState = btFunctionNode.NODE_STATE.FAILED; return(this.currentState); } bool completeCycle = false; while (true) { for ( ; this.updateIndex < this.children.Count; ++this.updateIndex) { NODE_STATE childState = this.children[this.updateIndex].TreeExecute(); switch (childState) { case NODE_STATE.SUCCEEDED: { continue; } case NODE_STATE.FAILED: { if (this as btFunctionRootNode != null) { continue; } this.currentState = btFunctionNode.NODE_STATE.FAILED; return(this.currentState); } case NODE_STATE.RUNNING: { this.currentState = btFunctionNode.NODE_STATE.RUNNING; return(this.currentState); } default: { Debug.LogError("Uncaught BTSTATE: " + childState); break; } } } if (completeCycle == true) { this.currentState = btFunctionNode.NODE_STATE.FAILED; return(this.currentState); } this.updateIndex = 0; completeCycle = true; } }
protected override NODE_STATE Execute(Tick tick) { for (int i = 0; i < children.Count; i++) { NODE_STATE status = children[i].Update(tick); if (status != NODE_STATE.SUCCESS) { return(status); } } return(NODE_STATE.SUCCESS); }
public virtual NODE_STATE Update(Tick tick) { if (!tick.GetBlackboard().NodeOpened(this)) { Open(tick); } NODE_STATE status = Execute(tick); if (status != NODE_STATE.RUNNING) { Close(tick); } return(status); }
protected override NODE_STATE Execute(Tick tick) { if (children != null && children.Count == 1) { NODE_STATE childState = children[0].Update(tick); if (childState == NODE_STATE.FAILURE) { return(NODE_STATE.SUCCESS); } return(NODE_STATE.RUNNING); } else { return(NODE_STATE.ERROR); } }
// Function almost identical to TypeTopologicalVisit(..) private void NSTopologicalVisit(IRNamespace node, List <IRNamespace> topologicalOrder, Dictionary <IRNamespace, NODE_STATE> nodeState, List <IRNamespace> visitedNodes) { // Each type is represented as a NODE. // NODE STATES: // - ALIVE: Node needs to be processed. // - UNDEAD: Currently processing this node. // - DEAD: This node has been succesfully visited. NODE_STATE state = nodeState[node]; if (state == NODE_STATE.DEAD) { return; } visitedNodes.Add(node); if (state == NODE_STATE.UNDEAD) { // Create a list of all nodes within our circle. var circleEntryIDx = visitedNodes.IndexOf(node); // Do not switch into 0-based indexing, because we want a list beginning and ending // with the same node! var circleLength = visitedNodes.Count() - circleEntryIDx; var circle = visitedNodes.GetRange(circleEntryIDx, circleLength); throw new CircularException <IRNamespace>(circle); } // Node is ALIVE and will be processed. nodeState[node] = NODE_STATE.UNDEAD; // Find all dependancies of the current namespace. var dependancies = _NSDependancies[node]; // Visit each namespace dependancy. foreach (var dep in dependancies) { // Send a copy of visited nodes to not litter the list of circular dependant nodes // when we reach an undead node. NSTopologicalVisit(dep, topologicalOrder, nodeState, visitedNodes.ToList()); } // Node is recursively visited. nodeState[node] = NODE_STATE.DEAD; topologicalOrder.Add(node); }
public override NODE_STATE TreeExecute() { if (this.children.Count == 0 || this.updateIndex < 0 || this.updateIndex >= this.children.Count) { this.currentState = btFunctionNode.NODE_STATE.FAILED; return(this.currentState); } for ( ; loopCount < this.variable; ++loopCount) { for ( ; this.updateIndex < this.children.Count; ++this.updateIndex) { NODE_STATE childState = this.children[this.updateIndex].TreeExecute(); switch (childState) { case NODE_STATE.SUCCEEDED: { continue; } case NODE_STATE.FAILED: { this.currentState = btFunctionNode.NODE_STATE.FAILED; return(this.currentState); } case NODE_STATE.RUNNING: { this.currentState = btFunctionNode.NODE_STATE.RUNNING; return(this.currentState); } default: { Debug.LogError("Uncaught BTSTATE: " + childState); break; } } } } this.currentState = btFunctionNode.NODE_STATE.FAILED; return(this.currentState); }
protected override NODE_STATE Execute(Tick tick) { int childIndex = tick.GetBlackboard().GetRunningChildIndex(this); for (int i = childIndex; i < children.Count; i++) { NODE_STATE status = children[i].Update(tick); if (status != NODE_STATE.SUCCESS) { if (status == NODE_STATE.RUNNING) { tick.GetBlackboard().AddRunningChild(this, i); } return(status); } } return(NODE_STATE.SUCCESS); }
public virtual void Reset() { this.currentState = NODE_STATE.NONE; }
private void TypeTopologicalVisit(IRTypeNode node, List <IRTypeNode> topologicalOrder, Dictionary <IRTypeNode, NODE_STATE> nodeState, List <IRTypeNode> visitedNodes) { // Each type is represented as a NODE. // NODE STATES: // - ALIVE: Node needs to be processed. // - UNDEAD: Currently processing this node. // - DEAD: This node has been succesfully visited. IRTypeNode targetNode = node; // If the node is a private type, we take it's parent that's public, recursively. while (targetNode.IsPrivate == true) { if (targetNode.Parent is IRNamespace) { throw new Exception("Type cannot be private child of namespace!"); } targetNode = targetNode.Parent as IRTypeNode; } NODE_STATE state = nodeState[targetNode]; if (state == NODE_STATE.DEAD) { // This node has been processed, return to avoid running forever. return; } // Visit this node. visitedNodes.Add(targetNode); // An undead state means we hit a circular dependancy! if (state == NODE_STATE.UNDEAD) { // References from Parent node to child (nested) node are allowed. // Also self references! // eg; PARENT -> CHILD (=PARENT) .. // The last item is always 'targetNode'. If the last but one item is also 'targetNode' // we know it's one of the above allowed operations. var oneButLastIdx = visitedNodes.Count() - 2; if (visitedNodes[oneButLastIdx] == targetNode) { return; } // Create a list of all nodes within our circle. var circleEntryIDx = visitedNodes.IndexOf(targetNode); // Do not switch into 0-based indexing, because we want a list beginning and ending // with the same node! var circleLength = visitedNodes.Count() - circleEntryIDx; var circle = visitedNodes.GetRange(circleEntryIDx, circleLength); // If each type belongs to the SAME namespace, there is no circular dependancy! if (AllTypesInSameNamespace(circle)) { return; } throw new CircularException <IRTypeNode>(circle); } // Node is ALIVE and will be processed. nodeState[targetNode] = NODE_STATE.UNDEAD; var dependancies = _TypeDependancies[targetNode]; // Visit all dependancies of this node. foreach (var dep in dependancies) { // Send in a copy of visited nodes so it doesn't litter the list // with non circular types. TypeTopologicalVisit(dep, topologicalOrder, nodeState, visitedNodes.ToList()); } // Node is recursiely visited. nodeState[targetNode] = NODE_STATE.DEAD; topologicalOrder.Add(targetNode); }