public void AreLayoutCompatibleSharedComponent() { var a = m_Manager.CreateArchetype(); var b = m_Manager.CreateArchetype(typeof(EcsTestSharedComp)); Assert.IsTrue(ChunkDataUtility.AreLayoutCompatible(a.Archetype, b.Archetype)); Assert.IsTrue(ChunkDataUtility.AreLayoutCompatible(b.Archetype, a.Archetype)); }
public void AreLayoutCompatibleSharedComponentWithMaximumChunkCapacity() { var a = m_Manager.CreateArchetype(); var b = m_Manager.CreateArchetype(typeof(SharedComponentWithMaximumChunkCapacity1)); Assert.IsFalse(ChunkDataUtility.AreLayoutCompatible(a.Archetype, b.Archetype)); Assert.IsFalse(ChunkDataUtility.AreLayoutCompatible(b.Archetype, a.Archetype)); }
public void AreLayoutCompatibleDifferentComponentCount() { var a = m_Manager.CreateArchetype(); var b = m_Manager.CreateArchetype(typeof(EcsTestData)); Assert.IsFalse(ChunkDataUtility.AreLayoutCompatible(a.Archetype, b.Archetype)); Assert.IsFalse(ChunkDataUtility.AreLayoutCompatible(b.Archetype, a.Archetype)); }
public void SIZ_TagComponentDoesNotChangeCapacity() { var entity0 = m_Manager.CreateEntity(typeof(EcsTestData)); var entity1 = m_Manager.CreateEntity(typeof(EcsTestData), typeof(EcsTestTag)); unsafe { // a system ran, the version should match the global var chunk0 = m_Manager.EntityComponentStore->GetChunk(entity0); var chunk1 = m_Manager.EntityComponentStore->GetChunk(entity1); var archetype0 = chunk0->Archetype; var archetype1 = chunk1->Archetype; ChunkDataUtility.GetIndexInTypeArray(chunk0->Archetype, TypeManager.GetTypeIndex <EcsTestData2>()); Assert.True(ChunkDataUtility.AreLayoutCompatible(archetype0, archetype1)); } }
public void AddSharedComponentToMultipleEntitiesIncompatibleChunkLayouts() { // The goal of this test is to verify that the moved IComponentData keeps the same values from // before the addition of the shared component. var archetype = m_Manager.CreateArchetype(typeof(EcsTestData)); var archetypeWithShared = m_Manager.CreateArchetype(typeof(EcsTestData), typeof(EcsTestSharedCompWithMaxChunkCapacity)); unsafe { Assert.IsFalse(ChunkDataUtility.AreLayoutCompatible(archetype.Archetype, archetypeWithShared.Archetype)); } var query = m_Manager.CreateEntityQuery(typeof(EcsTestData)); const int numEntities = 5000; using (var entities = new NativeArray <Entity>(numEntities, Allocator.Persistent)) { m_Manager.CreateEntity(archetype, entities); for (int i = 0; i < entities.Length; ++i) { m_Manager.SetComponentData(entities[i], new EcsTestData(i)); } foreach (var e in entities) { Assert.IsFalse(m_Manager.HasComponent <EcsTestSharedCompWithMaxChunkCapacity>(e)); } m_Manager.AddSharedComponentData(query, new EcsTestSharedCompWithMaxChunkCapacity(17)); var chunk = m_Manager.GetChunk(entities[0]); int maxChunkCapacity = TypeManager.GetTypeInfo <EcsTestSharedCompWithMaxChunkCapacity>().MaximumChunkCapacity; int expectedChunkCount = (numEntities + maxChunkCapacity - 1) / maxChunkCapacity; Assert.AreEqual(expectedChunkCount, chunk.Archetype.ChunkCount); // Ensure that the moved components have the correct values. for (int i = 0; i < entities.Length; ++i) { Assert.IsTrue(m_Manager.HasComponent <EcsTestSharedCompWithMaxChunkCapacity>(entities[i])); Assert.AreEqual(17, m_Manager.GetSharedComponentData <EcsTestSharedCompWithMaxChunkCapacity>(entities[i]).Value); Assert.AreEqual(i, m_Manager.GetComponentData <EcsTestData>(entities[i]).value); } } }
public void AddSharedComponentIncompatibleChunkLayouts() { var archetype = m_Manager.CreateArchetype(typeof(EcsTestData)); var archetypeWithShared = m_Manager.CreateArchetype(typeof(EcsTestData), typeof(EcsTestSharedCompWithMaxChunkCapacity)); unsafe { Assert.IsFalse(ChunkDataUtility.AreLayoutCompatible(archetype.Archetype, archetypeWithShared.Archetype)); } var query = m_Manager.CreateEntityQuery(typeof(EcsTestData)); Entity e = m_Manager.CreateEntity(archetype); Assert.IsFalse(m_Manager.HasComponent <EcsTestSharedCompWithMaxChunkCapacity>(e)); m_Manager.AddSharedComponentData(query, new EcsTestSharedCompWithMaxChunkCapacity(17)); Assert.IsTrue(m_Manager.HasComponent <EcsTestSharedCompWithMaxChunkCapacity>(e)); Assert.AreEqual(17, m_Manager.GetSharedComponentData <EcsTestSharedCompWithMaxChunkCapacity>(e).Value); }
public void AddSharedComponentViaAddComponentWithIncompatibleChunkLayouts() { var archetype = m_Manager.CreateArchetype(typeof(EcsTestData)); var archetypeWithShared = m_Manager.CreateArchetype(typeof(EcsTestData), typeof(EcsTestSharedCompWithMaxChunkCapacity)); unsafe { Assert.IsFalse(ChunkDataUtility.AreLayoutCompatible(archetype.Archetype, archetypeWithShared.Archetype)); } using (var entities = new NativeArray <Entity>(1, Allocator.TempJob)) { m_Manager.CreateEntity(archetype, entities); Assert.IsFalse(m_Manager.HasComponent <EcsTestSharedCompWithMaxChunkCapacity>(entities[0])); m_Manager.AddComponent(entities, typeof(EcsTestSharedCompWithMaxChunkCapacity)); Assert.IsTrue(m_Manager.HasComponent <EcsTestSharedCompWithMaxChunkCapacity>(entities[0])); Assert.AreEqual(0, m_Manager.GetSharedComponentData <EcsTestSharedCompWithMaxChunkCapacity>(entities[0]).Value); } }
public void AreLayoutCompatibleSameArchetype() { var a = m_Manager.CreateArchetype(); Assert.IsTrue(ChunkDataUtility.AreLayoutCompatible(a.Archetype, a.Archetype)); }