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]); }
public void RemoveComponentThrowExceptionTest() { EcsWorld world = new EcsWorld(); IEcsEntity entity = world.CreateEntity(); entity.RemoveComponent <ComponentA>(); }
public void GetSetRemoveComponentTest() { EcsWorld world = new EcsWorld(); ComponentB componentB = new ComponentB(); IEcsEntity entity = world.CreateEntity(); entity.AddComponent(new ComponentA()); entity.AddComponent(componentB); entity.AddComponent(new ComponentC()); Assert.IsNotNull(entity.GetComponent <ComponentA>()); Assert.IsNotNull(entity.GetComponent <ComponentC>()); Assert.AreEqual(componentB, entity.GetComponent <ComponentB>()); Assert.IsFalse(entity.HasComponent <ComponentD>()); entity.RemoveComponent <ComponentB>(); Assert.IsFalse(entity.HasComponent <ComponentB>()); }
public void SerializeUpdateBaselineTest() { Baseline <uint> baseline = new Baseline <uint>(); byte[] data = _world.Serialize(new EcsFilter(), baseline); EcsWorld source = new EcsWorld(); source.Update(data); IEcsEntity entityAB = source[_entityAB.Id]; Assert.AreEqual(_entityAB.GetComponent <ComponentA>(), entityAB.GetComponent <ComponentA>()); Assert.AreEqual(_entityAB.GetComponent <ComponentB>(), entityAB.GetComponent <ComponentB>()); IEcsEntity entityABD = source[_entityABD.Id]; Assert.AreEqual(_entityABD.GetComponent <ComponentA>(), entityABD.GetComponent <ComponentA>()); Assert.AreEqual(_entityABD.GetComponent <ComponentB>(), entityABD.GetComponent <ComponentB>()); Assert.AreEqual(_entityABD.GetComponent <ComponentD>(), entityABD.GetComponent <ComponentD>()); IEcsEntity entityAC = source[_entityAC.Id]; Assert.AreEqual(_entityAC.GetComponent <ComponentA>(), entityAC.GetComponent <ComponentA>()); Assert.AreEqual(_entityAC.GetComponent <ComponentC>(), entityAC.GetComponent <ComponentC>()); IEcsEntity entityAD = source[_entityAD.Id]; Assert.AreEqual(_entityAD.GetComponent <ComponentA>(), entityAD.GetComponent <ComponentA>()); Assert.AreEqual(_entityAD.GetComponent <ComponentD>(), entityAD.GetComponent <ComponentD>()); IEcsEntity entityBC = source[_entityBC.Id]; Assert.AreEqual(_entityBC.GetComponent <ComponentB>(), entityBC.GetComponent <ComponentB>()); Assert.AreEqual(_entityBC.GetComponent <ComponentC>(), entityBC.GetComponent <ComponentC>()); IEcsEntity entityBD0 = source[_entityBD0.Id]; Assert.AreEqual(_entityBD0.GetComponent <ComponentB>(), entityBD0.GetComponent <ComponentB>()); Assert.AreEqual(_entityBD0.GetComponent <ComponentD>(), entityBD0.GetComponent <ComponentD>()); IEcsEntity entityBD1 = source[_entityBD1.Id]; Assert.AreEqual(_entityBD1.GetComponent <ComponentB>(), entityBD1.GetComponent <ComponentB>()); Assert.AreEqual(_entityBD1.GetComponent <ComponentD>(), entityBD1.GetComponent <ComponentD>()); data = source.Serialize(new EcsFilter(), baseline); Assert.AreEqual(0, data.Length); EcsWorld target = new EcsWorld(); // change Component entityAB.GetComponent <ComponentA>().Value = int.MaxValue; data = source.Serialize(new EcsFilter(), baseline); target.Update(data); Assert.AreEqual(1, target.EntitiesCount); Assert.AreEqual(entityAB.GetComponent <ComponentA>(), target[entityAB.Id].GetComponent <ComponentA>()); //removeComponent entityAB.RemoveComponent <ComponentA>(); data = source.Serialize(new EcsFilter(), baseline); target.Update(data); Assert.AreEqual(1, target.EntitiesCount); Assert.IsFalse(target[entityAB.Id].HasComponent <ComponentA>()); //AddComponent entityAB.AddComponent(new ComponentA()); data = source.Serialize(new EcsFilter(), baseline); target.Update(data); Assert.AreEqual(1, target.EntitiesCount); Assert.IsTrue(target[entityAB.Id].HasComponent <ComponentA>()); //remove Entity entityAB.Destroy(); data = source.Serialize(new EcsFilter(), baseline); target.Update(data); Assert.AreEqual(0, target.EntitiesCount); //create Entity entityAB = source.CreateEntity(new ComponentA { Value = 100 }, new ComponentB { Value = 200 }); data = source.Serialize(new EcsFilter(), baseline); target.Update(data); Assert.AreEqual(1, target.EntitiesCount); IEcsEntity targetEntityAB = target[entityAB.Id]; Assert.AreEqual(2, targetEntityAB.ComponentsCount); Assert.AreEqual(entityAB.GetComponent <ComponentA>(), targetEntityAB.GetComponent <ComponentA>()); Assert.AreEqual(entityAB.GetComponent <ComponentB>(), targetEntityAB.GetComponent <ComponentB>()); }