protected override void ExpandInternal(MyStateMachineCursor cursor, MyConcurrentHashSet<MyStringId> enquedActions, int passThrough) { foreach (var activeCursor in cursor.StateMachine.ActiveCursors) { cursor.StateMachine.DeleteCursor(activeCursor.Id); } }
protected override void ExpandInternal(MyStateMachineCursor cursor, MyConcurrentHashSet<MyStringId> enquedActions, int passThrough) { if(OutTransitions.Count == 0) return; var stateMachine = cursor.StateMachine; // Remove the current Cursor stateMachine.DeleteCursor(cursor.Id); // Spawn new cursors for the rest for (var i = 0; i < OutTransitions.Count; i++) stateMachine.CreateCursor(OutTransitions[i].TargetNode.Name); }
/// <summary> /// Creates new active cursor. /// </summary> public virtual MyStateMachineCursor CreateCursor(string nodeName) { var foundNode = FindNode(nodeName); if (foundNode != null) { var newCursor = new MyStateMachineCursor(foundNode, this); m_activeCursorsById.Add(newCursor.Id, newCursor); m_activeCursors.Add(newCursor); return newCursor; } return null; }
/// <summary> /// Creates new active cursor. /// </summary> public virtual MyStateMachineCursor CreateCursor(string nodeName) { var foundNode = FindNode(nodeName); if (foundNode != null) { var newCursor = new MyStateMachineCursor(foundNode, this); m_activeCursorsById.Add(newCursor.Id, newCursor); m_activeCursors.Add(newCursor); return(newCursor); } return(null); }
// Cache cursor data, remove cursor, let go when all incoming branch cursors reach the barrier node protected override void ExpandInternal(MyStateMachineCursor cursor, MyConcurrentHashSet<MyStringId> enquedActions, int passThrough) { var stateMachine = cursor.StateMachine; var inTransitionIndex = 0; for (; inTransitionIndex < InTransitions.Count; inTransitionIndex++) if(InTransitions[inTransitionIndex].Id == cursor.LastTransitionTakenId) break; Debug.Assert(inTransitionIndex < InTransitions.Count, "Transition not found."); Debug.Assert(!m_cursorsFromInEdgesReceived[inTransitionIndex], "More than one cursor from branch received."); m_cursorsFromInEdgesReceived[inTransitionIndex] = true; stateMachine.DeleteCursor(cursor.Id); // Check if all cursors arrived foreach (var value in m_cursorsFromInEdgesReceived) if(!value) return; if(OutTransitions.Count > 0) stateMachine.CreateCursor(OutTransitions[0].TargetNode.Name); }
/// <summary> /// Expands current node with given cursor. /// First enquedAction is taking place then any valid transition. /// Cursor is being transitioned to result of expansion. /// Override this for custom behavior. /// </summary> protected virtual void ExpandInternal(MyStateMachineCursor cursor, MyConcurrentHashSet <MyStringId> enquedActions, int passThrough) { MyStateMachineTransition nextTransition; do { // Try to find best transition across enquedActions // Does not need to be evaluated one. nextTransition = null; var transitions = cursor.Node.OutTransitions; if (enquedActions.Count > 0) { int bestPriority = int.MaxValue; for (var i = 0; i < transitions.Count; i++) { int transitionPriority = transitions[i].Priority ?? int.MaxValue; if (enquedActions.Contains(transitions[i].Name) && transitionPriority <= bestPriority && (transitions[i].Conditions.Count == 0 || transitions[i].Evaluate())) { nextTransition = transitions[i]; bestPriority = transitionPriority; } } } if (nextTransition == null) { // Try to find valid transition to next state nextTransition = cursor.Node.QueryNextTransition(); } // Transition into next state if (nextTransition != null) { cursor.FollowTransition(nextTransition); } } while (nextTransition != null && cursor.Node.PassThrough && passThrough-- > 0); }
/// <summary> /// Expands current node with given cursor. /// First enquedAction is taking place then any valid transition. /// Cursor is being transitioned to result of expansion. /// Override this for custom behavior. /// </summary> protected virtual void ExpandInternal(MyStateMachineCursor cursor, MyConcurrentHashSet<MyStringId> enquedActions, int passThrough) { MyStateMachineTransition nextTransition; do { // Try to find best transition across enquedActions // Does not need to be evaluated one. nextTransition = null; var transitions = cursor.Node.OutTransitions; if (enquedActions.Count > 0) { int bestPriority = int.MaxValue; for (var i = 0; i < transitions.Count; i++) { int transitionPriority = transitions[i].Priority ?? int.MaxValue; if (enquedActions.Contains(transitions[i].Name) && transitionPriority <= bestPriority && (transitions[i].Conditions.Count == 0 || transitions[i].Evaluate())) { nextTransition = transitions[i]; bestPriority = transitionPriority; } } } if (nextTransition == null) { // Try to find valid transition to next state nextTransition = cursor.Node.QueryNextTransition(); } // Transition into next state if (nextTransition != null) cursor.FollowTransition(nextTransition); } while (nextTransition != null && cursor.Node.PassThrough && passThrough-- > 0); }
// Should stay internal, we do not want to anything outside of StateMachines to use // Expand methods. internal void Expand(MyStateMachineCursor cursor, MyConcurrentHashSet <MyStringId> enquedActions) { ExpandInternal(cursor, enquedActions, 100); }
// Should stay internal, we do not want to anything outside of StateMachines to use // Expand methods. internal void Expand(MyStateMachineCursor cursor, MyConcurrentHashSet<MyStringId> enquedActions) { ExpandInternal(cursor, enquedActions, 100); }