/// <summary>
        /// Tells the iterator to abort the current running subtree and jump to the aborter.
        /// </summary>
        /// <param name="aborter"></param>
        public void OnAbort(ConditionalAbort aborter)
        {
            BehaviourNode parent           = aborter.Parent;
            int           terminatingIndex = BehaviourNode.kInvalidOrder;

            if (parent)
            {
                terminatingIndex = parent.preOrderIndex;
            }

            // If an abort node is the root, then we need to empty the entire traversal.
            // We can achieve this by setting the terminating index to the invalid index, which is an invalid index
            // and will empty the traversal.
            while (_traversal.Count != 0 && _traversal.Peek() != terminatingIndex)
            {
                StepBackAbort();
            }

            // Only composite nodes need to worry about which of their subtrees fired an abort.
            if (parent.MaxChildCount() > 1)
            {
                parent.OnAbort(aborter);
            }

            // Any requested traversals are cancelled on abort.
            _requestedTraversals.Clear();

            Traverse(aborter);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Tells the iterator to abort the current running branch and jump to the aborter.
        /// </summary>
        /// <param name="parent">The parent that will abort is running branch.</param>
        /// <param name="abortBranchIndex">The child branch that caused the abort.</param>
        public void AbortRunningChildBranch(BehaviourNode parent, int abortBranchIndex)
        {
            // If the iterator is inactive, ignore.
            if (IsRunning && parent)
            {
                int terminatingIndex = parent.preOrderIndex;

                while (traversal.Count != 0 && traversal.Peek() != terminatingIndex)
                {
                    StepBackAbort();
                }

                // Only composite nodes need to worry about which of their subtrees fired an abort.
                if (parent.IsComposite())
                {
                    parent.OnAbort(abortBranchIndex);
                }

                // Any requested traversals are cancelled on abort.
                requestedTraversals.Clear();

                Traverse(parent.GetChildAt(abortBranchIndex));
            }
        }