Beispiel #1
0
        public IEnumerator ConditionsActivateOnlyAfterBehaviors()
        {
            Step step = new Step("Step1");
            EndlessConditionMock conditionMock = new EndlessConditionMock();
            EndlessBehaviorMock  behaviorMock  = new EndlessBehaviorMock();
            Transition           transition    = new Transition();

            transition.Data.Conditions.Add(conditionMock);
            step.Data.Transitions.Data.Transitions.Add(transition);
            step.Data.Behaviors.Data.Behaviors.Add(behaviorMock);
            step.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode);

            step.LifeCycle.Activate();

            while (behaviorMock.LifeCycle.Stage != Stage.Activating)
            {
                Assert.AreEqual(Stage.Activating, step.LifeCycle.Stage);
                Assert.AreEqual(Stage.Inactive, conditionMock.LifeCycle.Stage);
                yield return(null);

                step.Update();
            }

            behaviorMock.LifeCycle.MarkToFastForwardStage(Stage.Activating);

            while (conditionMock.LifeCycle.Stage != Stage.Active)
            {
                Assert.AreEqual(Stage.Activating, step.LifeCycle.Stage);
                yield return(null);

                step.Update();
            }
        }
        public IEnumerator NonBlockingBehaviorDoesNotBlock()
        {
            // Given a chapter with a step with no conditions but a transition to the end, and a non-blocking endless behavior,
            EndlessBehaviorMock nonBlockingBehaviorMock = new EndlessBehaviorMock(false);
            ITransition         transition = new Transition();

            transition.Data.TargetStep = null;
            IStep step = new Step("NonBlockingStep");

            step.Data.Transitions.Data.Transitions.Add(transition);
            step.Data.Behaviors.Data.Behaviors.Add(nonBlockingBehaviorMock);
            IChapter chapter = new Chapter("NonBlockingChapter", step);

            chapter.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode);

            // When we activate the chapter,
            chapter.LifeCycle.Activate();

            // Then it will finish activation immediately after a few update cycles.
            while (chapter.LifeCycle.Stage != Stage.Active)
            {
                yield return(null);

                chapter.Update();
            }

            Assert.AreEqual(Stage.Active, chapter.LifeCycle.Stage);
        }
Beispiel #3
0
        public IEnumerator FastForwardActive()
        {
            // Given a step,
            IBehavior  behavior   = new EndlessBehaviorMock();
            ICondition condition  = new EndlessConditionMock();
            Transition transition = new Transition();
            IStep      step       = new Step("Step");

            transition.Data.Conditions.Add(condition);
            step.Data.Behaviors.Data.Behaviors.Add(behavior);
            step.Data.Transitions.Data.Transitions.Add(transition);
            step.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode);

            step.LifeCycle.Activate();

            // When you fast-forward it,
            step.LifeCycle.MarkToFastForward();

            // Then everything is completed.
            Assert.AreEqual(Stage.Active, step.LifeCycle.Stage);
            Assert.AreEqual(Stage.Active, behavior.LifeCycle.Stage);
            Assert.AreEqual(Stage.Active, condition.LifeCycle.Stage);

            yield break;
        }
Beispiel #4
0
        public IEnumerator ActivateOnlyAfterOnePass()
        {
            // Given a behaviors sequence,
            EndlessBehaviorMock endlessBehaviorMock = new EndlessBehaviorMock();
            BehaviorSequence    sequence            = new BehaviorSequence(true, new List <IBehavior> {
                endlessBehaviorMock
            });

            // When we activate it,
            sequence.LifeCycle.Activate();

            yield return(null);

            sequence.Update();

            // Then it is activated only after one pass.
            endlessBehaviorMock.LifeCycle.MarkToFastForward();

            yield return(null);

            sequence.Update();

            yield return(null);

            sequence.Update();

            Assert.AreEqual(Stage.Active, sequence.LifeCycle.Stage);

            // Cleanup.
            sequence.LifeCycle.Deactivate();
        }
        public IEnumerator NonBlockingBehaviorLoop()
        {
            // Given a chapter with a step with a loop transition, and a non-blocking endless behavior,
            EndlessBehaviorMock nonBlockingBehaviorMock = new EndlessBehaviorMock(false);
            ITransition         transition = new Transition();
            IStep step = new Step("NonBlockingStep");

            transition.Data.TargetStep = step;
            step.Data.Transitions.Data.Transitions.Add(transition);
            step.Data.Behaviors.Data.Behaviors.Add(nonBlockingBehaviorMock);
            IChapter chapter = new Chapter("NonBlockingChapter", step);

            chapter.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode);

            // When we activate the chapter,
            chapter.LifeCycle.Activate();

            // Then it will loop without any problems.
            int loops = 3;

            while (loops > 0)
            {
                while (step.LifeCycle.Stage != Stage.Activating)
                {
                    yield return(null);

                    chapter.Update();
                }

                while (step.LifeCycle.Stage != Stage.Active)
                {
                    yield return(null);

                    chapter.Update();
                }

                while (step.LifeCycle.Stage != Stage.Deactivating)
                {
                    yield return(null);

                    chapter.Update();
                }

                while (step.LifeCycle.Stage != Stage.Inactive)
                {
                    yield return(null);

                    chapter.Update();
                }

                Assert.AreEqual(Stage.Activating, chapter.LifeCycle.Stage);
                loops--;
            }

            Assert.AreEqual(Stage.Inactive, step.LifeCycle.Stage);
        }
        public IEnumerator BlockingBehaviorDoesBlock()
        {
            // Given a chapter with a step with no conditions but a transition to the end, and a blocking endless behavior,
            EndlessBehaviorMock blockingBehaviorMock = new EndlessBehaviorMock(true);
            ITransition         transition           = new Transition();

            transition.Data.TargetStep = null;
            IStep step = new Step("BlockingStep");

            step.Data.Transitions.Data.Transitions.Add(transition);
            step.Data.Behaviors.Data.Behaviors.Add(blockingBehaviorMock);
            IChapter chapter = new Chapter("BlockingChapter", step);

            chapter.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode);

            // When we activate the chapter,
            chapter.LifeCycle.Activate();

            while (blockingBehaviorMock.LifeCycle.Stage != Stage.Activating)
            {
                yield return(null);

                chapter.Update();
            }

            // When endless behavior stays activating even after a few frames,
            int waitingFrames = 10;

            while (waitingFrames > 0)
            {
                yield return(null);

                chapter.Update();
                Assert.AreEqual(Stage.Activating, blockingBehaviorMock.LifeCycle.Stage);
                Assert.AreEqual(Stage.Activating, chapter.LifeCycle.Stage);
                waitingFrames--;
            }

            // Then the chapter will not be activated until the behavior finishes.
            blockingBehaviorMock.LifeCycle.MarkToFastForward();

            Assert.AreEqual(Stage.Activating, chapter.LifeCycle.Stage);

            while (chapter.LifeCycle.Stage != Stage.Active)
            {
                yield return(null);

                chapter.Update();
            }

            Assert.AreEqual(Stage.Active, chapter.LifeCycle.Stage);
        }
        public IEnumerator FastForwardInactiveNonBlockingBehavior()
        {
            // Given a non-blocking behavior,
            EndlessBehaviorMock behaviorMock = new EndlessBehaviorMock(false);

            behaviorMock.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode);

            // When we mark it to fast-forward,
            behaviorMock.LifeCycle.MarkToFastForward();

            // Then it doesn't autocomplete because it hasn't been activated yet.
            Assert.AreEqual(Stage.Inactive, behaviorMock.LifeCycle.Stage);

            yield break;
        }
        public IEnumerator BlockingBehaviorActivating()
        {
            // Given a blocking behavior,
            EndlessBehaviorMock behaviorMock = new EndlessBehaviorMock(true);

            behaviorMock.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode);

            // When we activate it,
            behaviorMock.LifeCycle.Activate();

            // Then it is immediately activating.
            Assert.AreEqual(Stage.Activating, behaviorMock.LifeCycle.Stage);

            yield break;
        }
        public IEnumerator NonBlockingBehaviorActivating()
        {
            // Given a non-blocking behavior,
            EndlessBehaviorMock behaviorMock = new EndlessBehaviorMock(false);

            behaviorMock.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode);

            // When we activate it,
            behaviorMock.LifeCycle.Activate();

            // Then behavior starts its activation.
            Assert.AreEqual(Stage.Activating, behaviorMock.LifeCycle.Stage);

            yield break;
        }
        public IEnumerator FastForwardInactiveNonBlockingBehaviorAndActivateIt()
        {
            // Given a non-blocking behavior,
            EndlessBehaviorMock behaviorMock = new EndlessBehaviorMock(false);

            behaviorMock.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode);

            // When we mark it to fast-forward and activate it,
            behaviorMock.LifeCycle.MarkToFastForward();
            behaviorMock.LifeCycle.Activate();

            // Then the behavior should be activated immediately.
            Assert.AreEqual(Stage.Active, behaviorMock.LifeCycle.Stage);

            yield break;
        }
Beispiel #11
0
        public IEnumerator FastForwardNextStage()
        {
            // Given an entity,
            IEntity entity = new EndlessBehaviorMock();

            entity.LifeCycle.Activate();

            Assert.AreEqual(Stage.Activating, entity.LifeCycle.Stage);

            // When you fast-forward its next stage,
            entity.LifeCycle.MarkToFastForwardStage(Stage.Active);

            // Then the current stage is not fast-forwarded.
            Assert.AreEqual(Stage.Activating, entity.LifeCycle.Stage);

            yield break;
        }
Beispiel #12
0
        public IEnumerator UnskipChild()
        {
            // Given an activating repeating behavior sequence of one not optional and one skipped optional behavior,
            OptionalEndlessBehaviorMock optional    = new OptionalEndlessBehaviorMock();
            EndlessBehaviorMock         notOptional = new EndlessBehaviorMock();
            BehaviorSequence            sequence    = new BehaviorSequence(true, new List <IBehavior>
            {
                notOptional,
                optional,
            });

            sequence.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode);

            sequence.LifeCycle.Activate();

            yield return(null);

            sequence.Update();

            notOptional.LifeCycle.MarkToFastForwardStage(Stage.Activating);
            notOptional.LifeCycle.MarkToFastForwardStage(Stage.Deactivating);

            sequence.Configure(new Mode("Test", new WhitelistTypeRule <IOptional>().Add <OptionalEndlessBehaviorMock>()));

            yield return(null);

            sequence.Update();

            //When you re-enable it,
            sequence.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode);

            notOptional.LifeCycle.MarkToFastForwardStage(Stage.Activating);
            notOptional.LifeCycle.MarkToFastForwardStage(Stage.Deactivating);

            while (optional.LifeCycle.Stage != Stage.Activating)
            {
                yield return(null);

                sequence.Update();
            }

            // Then it is not skipped when it's its turn.
            Assert.AreEqual(Stage.Activating, optional.LifeCycle.Stage);
        }
Beispiel #13
0
        public IEnumerator SkipChildNotWhenItIsExecuted()
        {
            // Given an activating behavior sequence of one not optional and one optional behavior,
            OptionalEndlessBehaviorMock optional    = new OptionalEndlessBehaviorMock();
            EndlessBehaviorMock         notOptional = new EndlessBehaviorMock();
            BehaviorSequence            sequence    = new BehaviorSequence(false, new List <IBehavior>
            {
                notOptional,
                optional,
            });

            sequence.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode);
            sequence.LifeCycle.Activate();

            yield return(null);

            sequence.Update();

            // When the optional behavior is marked to be skipped before it was its turn,
            sequence.Configure(new Mode("Test", new WhitelistTypeRule <IOptional>().Add <OptionalEndlessBehaviorMock>()));

            notOptional.LifeCycle.MarkToFastForwardStage(Stage.Activating);
            notOptional.LifeCycle.MarkToFastForwardStage(Stage.Deactivating);

            while (notOptional.LifeCycle.Stage != Stage.Inactive)
            {
                yield return(null);

                sequence.Update();
            }

            while (sequence.LifeCycle.Stage != Stage.Active)
            {
                Assert.AreEqual(Stage.Inactive, optional.LifeCycle.Stage);
                yield return(null);

                sequence.Update();
            }

            // Then it is skipped.
            Assert.AreEqual(Stage.Active, sequence.LifeCycle.Stage);

            yield break;
        }
        public IEnumerator NonBlockingBehaviorActivated()
        {
            // Given a non-blocking behavior,
            EndlessBehaviorMock behaviorMock = new EndlessBehaviorMock(false);

            behaviorMock.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode);

            // When we activate and finish activation,
            behaviorMock.LifeCycle.Activate();

            behaviorMock.LifeCycle.MarkToFastForward();

            yield return(null);

            behaviorMock.Update();

            yield return(null);

            behaviorMock.Update();

            // Then it is activated.
            Assert.AreEqual(Stage.Active, behaviorMock.LifeCycle.Stage);
        }
Beispiel #15
0
        public IEnumerator FastForwardInactive()
        {
            // Given a step,
            IBehavior  behavior   = new EndlessBehaviorMock();
            ICondition condition  = new EndlessConditionMock();
            Transition transition = new Transition();
            IStep      step       = new Step("Step");

            transition.Data.Conditions.Add(condition);
            step.Data.Behaviors.Data.Behaviors.Add(behavior);
            step.Data.Transitions.Data.Transitions.Add(transition);
            step.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode);

            // When you fast-forward it,
            step.LifeCycle.MarkToFastForward();

            // Then it doesn't change it's activation state, as well as its contents.
            Assert.AreEqual(Stage.Inactive, step.LifeCycle.Stage);
            Assert.AreEqual(Stage.Inactive, behavior.LifeCycle.Stage);
            Assert.AreEqual(Stage.Inactive, condition.LifeCycle.Stage);

            yield break;
        }