예제 #1
0
        public void CharacterTest1()
        {
            var game = new CharacterTest();

            game.Script.AddTask(async() =>
            {
                game.ScreenShotAutomationEnabled = false;

                await game.Script.NextFrame();
                await game.Script.NextFrame();

                var character  = game.SceneSystem.SceneInstance.Scene.Entities.First(ent => ent.Name == "Character");
                var controller = character.Get <CharacterComponent>();
                var simulation = controller.Simulation;

                //let the controller land
                var twoSeconds = 120;
                while (twoSeconds-- > 0)
                {
                    await game.Script.NextFrame();
                }

                Assert.IsTrue(controller.IsGrounded);

                controller.Jump();

                await game.Script.NextFrame();

                Assert.IsFalse(controller.IsGrounded);

                //let the controller land
                twoSeconds = 120;
                while (twoSeconds-- > 0)
                {
                    await game.Script.NextFrame();
                }

                Assert.IsTrue(controller.IsGrounded);

                var currentPos = character.Transform.Position;

                controller.SetVelocity(Vector3.UnitX * 3);

                await game.Script.NextFrame();

                Assert.AreNotEqual(currentPos, character.Transform.Position);
                var target = currentPos + Vector3.UnitX * 3 * simulation.FixedTimeStep;
                Assert.AreEqual(character.Transform.Position.X, target.X, float.Epsilon);
                Assert.AreEqual(character.Transform.Position.Y, target.Y, float.Epsilon);
                Assert.AreEqual(character.Transform.Position.Z, target.Z, float.Epsilon);

                currentPos = character.Transform.Position;

                await game.Script.NextFrame();

                Assert.AreNotEqual(currentPos, character.Transform.Position);
                target = currentPos + Vector3.UnitX * 3 * simulation.FixedTimeStep;
                Assert.AreEqual(character.Transform.Position.X, target.X, float.Epsilon);
                Assert.AreEqual(character.Transform.Position.Y, target.Y, float.Epsilon);
                Assert.AreEqual(character.Transform.Position.Z, target.Z, float.Epsilon);

                controller.SetVelocity(Vector3.Zero);

                await game.Script.NextFrame();

                currentPos = character.Transform.Position;

                await game.Script.NextFrame();

                Assert.AreEqual(currentPos, character.Transform.Position);

                var collider = game.SceneSystem.SceneInstance.Scene.Entities.First(ent => ent.Name == "Collider").Get <StaticColliderComponent>();

                game.Script.AddTask(async() =>
                {
                    var fourSeconds = 240;
                    while (fourSeconds-- > 0)
                    {
                        await game.Script.NextFrame();
                    }
                    Assert.Fail("Character controller never collided with test collider.");
                });

                controller.SetVelocity(Vector3.UnitX * 2.5f);

                await collider.NewCollision();

                game.Exit();
            });
            RunGameTest(game);
        }
예제 #2
0
 /// <summary>
 /// This is useful if you want to run all the tests on your own machine and compare images
 /// </summary>
 public static void Main()
 {
     using (var game = new ColliderShapesTest()) { game.ColliderShapesTest1(); }
     using (var game = new CharacterTest()) { game.CharacterTest1(); }
     using (var game = new SkinnedTest()) { game.SkinnedTest1(); }
 }
예제 #3
0
        public void CharacterTest1()
        {
            var game = new CharacterTest();
            game.Script.AddTask(async () =>
            {
                game.ScreenShotAutomationEnabled = false;

                await game.Script.NextFrame();
                await game.Script.NextFrame();

                var character = game.SceneSystem.SceneInstance.Scene.Entities.First(ent => ent.Name == "Character");
                var controller = character.Get<CharacterComponent>();
                var simulation = controller.Simulation;

                //let the controller land
                var twoSeconds = 120;
                while (twoSeconds-- > 0)
                {
                    await game.Script.NextFrame();
                }

                Assert.IsTrue(controller.IsGrounded);

                controller.Jump();

                await game.Script.NextFrame();

                Assert.IsFalse(controller.IsGrounded);

                //let the controller land
                twoSeconds = 120;
                while (twoSeconds-- > 0)
                {
                    await game.Script.NextFrame();
                }

                Assert.IsTrue(controller.IsGrounded);

                var currentPos = character.Transform.Position;

                controller.SetVelocity(Vector3.UnitX * 3);

                await game.Script.NextFrame();

                Assert.AreNotEqual(currentPos, character.Transform.Position);
                var target = currentPos + Vector3.UnitX*3*simulation.FixedTimeStep;
                Assert.AreEqual(character.Transform.Position.X, target.X, float.Epsilon);
                Assert.AreEqual(character.Transform.Position.Y, target.Y, float.Epsilon);
                Assert.AreEqual(character.Transform.Position.Z, target.Z, float.Epsilon);

                currentPos = character.Transform.Position;

                await game.Script.NextFrame();

                Assert.AreNotEqual(currentPos, character.Transform.Position);
                target = currentPos + Vector3.UnitX * 3 * simulation.FixedTimeStep;
                Assert.AreEqual(character.Transform.Position.X, target.X, float.Epsilon);
                Assert.AreEqual(character.Transform.Position.Y, target.Y, float.Epsilon);
                Assert.AreEqual(character.Transform.Position.Z, target.Z, float.Epsilon);

                controller.SetVelocity(Vector3.Zero);

                await game.Script.NextFrame();

                currentPos = character.Transform.Position;

                await game.Script.NextFrame();

                Assert.AreEqual(currentPos, character.Transform.Position);

                var collider = game.SceneSystem.SceneInstance.Scene.Entities.First(ent => ent.Name == "Collider").Get<StaticColliderComponent>();

                game.Script.AddTask(async () =>
                {
                    var fourSeconds = 240;
                    while (fourSeconds-- > 0)
                    {
                        await game.Script.NextFrame();
                    }
                    Assert.Fail("Character controller never collided with test collider.");
                });

                controller.SetVelocity(Vector3.UnitX * 2.5f);

                await collider.NewCollision();

                game.Exit();
            });
            RunGameTest(game);
        }
예제 #4
0
파일: GameTest.cs 프로젝트: vol16bit/xenko
 /// <summary>
 /// This is useful if you want to run all the tests on your own machine and compare images
 /// </summary>
 public static void Main()
 {
     using (var game = new ColliderShapesTest()) { game.ColliderShapesTest1(); }
     using (var game = new CharacterTest()) { game.CharacterTest1(); }
     using (var game = new SkinnedTest()) { game.SkinnedTest1(); }
 }