Example #1
0
        public void TestThatSystemsAreExecutedInProperOrder()
        {
            var log = new List <string>();
            // @formatter:off
            var world = new WorldBuilder()
                        .AddFeature("Feature 1")
                        .Systems()
                        .Setup(((contexts, bus) => log.Add("F1-S1")))
                        .Update(((contexts, bus) => log.Add("F1-U1")))
                        .Cleanup(((contexts, bus) => log.Add("F1-C1")))
                        .End()
                        .End()
                        .AddFeature("Feature 2")
                        .Systems()
                        .Setup(((contexts, bus) => log.Add("F2-S1")))
                        .Update(((contexts, bus) => log.Add("F2-U1")))
                        .Cleanup(((contexts, bus) => log.Add("F2-C1")))
                        .Cleanup(((contexts, bus) => log.Add("F2-C2")))
                        .End()
                        .End()
                        .AddFeature("Feature 3")
                        .Systems()
                        .Setup(((contexts, bus) => log.Add("F3-S1")))
                        .Update(((contexts, bus) => log.Add("F3-U1")))
                        .Cleanup(((contexts, bus) => log.Add("F3-C1")))
                        .End()
                        .End()
                        .Build();

            // @formatter:on

            world.Setup();
            world.Update();
            world.Cleanup();

            CollectionAssert.AreEqual(new[] {
                "F1-S1", "F2-S1", "F3-S1",
                "F1-U1", "F2-U1", "F3-U1",
                "F3-C1", "F2-C1", "F2-C2", "F1-C1"
            }, log);
        }
Example #2
0
        public static void Main(string[] args)
        {
            // @formatter:off
            var world = new WorldBuilder()
                        .AddFeature("Benchmark")
                        .Contexts()
                        .Add <Simulation>(c => c.SetInitialCapacity(EntitiesCount))
                        .End()
                        .Components <Simulation>()
                        .Add <Position>()
                        .Add <Velocity>()
                        .End()
                        .Systems()
                        .Update((contexts, bus) => MoveSystem.Update(contexts))
                        .End()
                        .End()
                        .Build();
            // @formatter:on

            var simulation = world.Contexts.Get <Simulation>();

            for (var i = 0; i < EntitiesCount; i++)
            {
                simulation.CreateEntity()
                .Add(new Position(new Vector3(1, 2, 0), 0))
                .Add(new Velocity(new Vector3(2, 2, 1), 0.01f));
            }

            // Warm up
            world.Update();

            Measure("Entity", () =>
            {
                for (var i = 0; i < RepeatCount; i++)
                {
                    world.Update();
                    world.Cleanup();
                }
            });
        }
Example #3
0
        public void NotificationsTests()
        {
            // @formatter:off
            var world = new WorldBuilder()
                        .AddCoreFeature()
                        .AddFeature("TestNotifications")
                        .DependsOn()
                        .Feature(CoreFeature.Name)
                        .End()
                        .Components <Game>()
                        .Add <EmptyTestComponent>()
                        .End()
                        .ComponentNotifications <Game>()
                        .AddAllNotifications <EmptyTestComponent>()
                        .End()
                        .End()
                        .Build();
            // @formatter:on

            var log = new List <string>();

            world.Setup();

            var context = world.Contexts.Get <Game>();
            var entity  = context.CreateEntity();

            entity.AddComponentListener(new EmptyTestComponentNotificationsListener(log));
            entity.Add(new EmptyTestComponent());
            entity.Replace(new EmptyTestComponent());
            entity.Remove <EmptyTestComponent>();

            world.Update();
            world.Cleanup();
            world.Clear();

            CollectionAssert.AreEqual(new[] { "Added", "Removed", "Replaced" }, log);
        }