Exemple #1
0
        public void ArchetypeRemoveHolesTest()
        {
            EcsWorld      world     = new EcsWorld();
            IEcsArchetype archetype = world.GetArchetype <ComponentA, ComponentB>();

            IEcsEntity entity0 = world.CreateEntity(new ComponentA(), new ComponentB());
            IEcsEntity entity1 = world.CreateEntity(new ComponentA(), new ComponentB());
            IEcsEntity entity2 = world.CreateEntity(new ComponentA(), new ComponentB());
            IEcsEntity entity3 = world.CreateEntity(new ComponentA(), new ComponentB());

            entity1.RemoveComponent <ComponentA>();
            entity2.RemoveComponent <ComponentA>();
            Assert.AreEqual(2, archetype.EntitiesCount);
            Assert.AreEqual(entity0, archetype[0]);
            Assert.AreEqual(entity3, archetype[1]);

            entity0.RemoveComponent <ComponentA>();
            Assert.AreEqual(1, archetype.EntitiesCount);
            Assert.AreEqual(entity3, archetype[0]);


            entity1.AddComponent(new ComponentA());
            entity2.AddComponent(new ComponentA());
            Assert.AreEqual(3, archetype.EntitiesCount);
            Assert.AreEqual(entity3, archetype[0]);
            Assert.AreEqual(entity1, archetype[1]);
            Assert.AreEqual(entity2, archetype[2]);
        }