public void When_Debugger_Disabled_then_Logs_not_Received()
        {
            BehaviourDebugger.DisableDebugger();
            var modelSequence = new ModelOfAction <MyAction>(null);
            var executor      = BTExecutorFactory.CreateBTExecutor(modelSequence);

            Assert.DoesNotThrow(delegate
            {
                executor.Tick();
                executor.Tick();
            });

            mockDebugger.Verify(m => m.LogTick(It.IsAny <MyAction>()), Times.Never);
        }
Ejemplo n.º 2
0
        /**
         * After spawning an ExecutionTask, <code>tick()</code> has to be called in
         * order to update it and keep track of its status.
         * <p>
         * This method is in charge of updating this ExecutionTask according to its
         * semantics. This process may include spawning none, one, or several of its
         * children depending on their termination status. It may also have to
         * terminate some of its children.
         * <p>
         * <code>tick()</code> is not an abstract method. In reality, the actual
         * ticking process is not carried out by <code>tick()</code> itself, but by
         * the abstract {@link #internalTick()} method. <b>Thus, subclasses must
         * define the abstract <code>internalSpawn()</code> method</b>.
         * <p>
         * What <code>tick()</code> does is to call <code>internalTick()</code> to
         * carry out the actual ticking process. Then, <code>tick()</code> checks
         * if, after the tick, the task has finished (that is, it checks if the
         * status returned by <code>internalTick()</code> is {@link Status#FAILURE}
         * or {@link Status#SUCCESS}). If so, <code>tick()</code> fires a TaskEvent
         * to the parent of this ExecutionTask, so the parent does whatever it has
         * to do after the termination of its child, and also requests to be removed
         * from both the lists of tickable and open nodes of the BTExecutor (because
         * this task will not be ticked again unless it is spawned again). Also, if
         * the ExecutionTask has finished, <code>tick()</code> stores the current
         * state of the task just in case it is spawned again in the future.
         * <p>
         * <b>It should be noted that when a task has been terminated (
         * {@link #terminate()}), <code>tick()</code> does nothing</b>, and it just
         * returns {@link Status#TERMINATED} (it does not even fire a TaskEvent).
         *
         * @return the status of the task after being ticked.
         */
        public Status Tick()
        {
            /* If the task cannot be ticked, throw an exception. */
            if (!_tickable)
            {
                throw new NotTickableException("The task cannot be ticked. It must be spawned first.");
            }

            /* If the task has been terminated, do nothing. */
            if (_terminated)
            {
                return(Status.Terminated);
            }

            /* Otherwise, perform the actual tick by calling "internalTick()". */
            var newStatus = AlwaysFail ? Status.Failure : InternalTick();

            /* Check if the value that is returned by "internalTick()" is valid. */
            if (!ValidInternalTickStatus(newStatus))
            {
                throw new IllegalReturnStatusException(newStatus + " cannot be returned by ExecutionTask.internalTick()");
            }

            _status = newStatus;

            BehaviourDebugger.LogTick(this);

            /*
             * If the task has finished (either successfully or in failure), a
             * TaskEvent has to be fired in order to notify its parent about the
             * termination. Before firing the event, the current state of the
             * task has to be stored into the BTExecutor, just in case it needs
             * to be restored in the future. The task also requests to be
             * removed from both the list of tickable and open nodes.
             *
             * Otherwise the task has not finished, so nothing in particular is
             * done.
             */
            if (newStatus != Status.Running)
            {
                var taskState = StoreState();
                _executor.SetTaskState(Position, taskState);
                _executor.RequestRemovalFromList(BTExecutor.BTExecutorList.Tickable, this);
                _executor.RequestRemovalFromList(BTExecutor.BTExecutorList.Open, this);

                FireTaskEvent(newStatus);
            }

            return(newStatus);
        }
 public void Setup()
 {
     mockDebugger = new Mock <IBehaviourDebugger>();
     BehaviourDebugger.SetActiveDebugger(mockDebugger.Object);
 }