示例#1
0
            public void Execute(int chunkIndex)
            {
                var chunk                   = chunks[chunkIndex];
                var chunkCount              = chunk.Count;
                var chunkEcsTestData        = chunk.GetNativeArray(ecsTestData);
                var chunkEcsTestData2       = chunk.GetNativeArray(ecsTestData2);
                var chunkEcsSharedDataIndex = chunk.GetSharedComponentIndex(ecsTestSharedData);

                if (chunkEcsSharedDataIndex != sharedFilterIndex)
                {
                    return;
                }

                if (chunkEcsTestData.Length > 0)
                {
                    for (int i = 0; i < chunkCount; i++)
                    {
                        chunkEcsTestData[i] = new EcsTestData(chunkEcsTestData[i].value + 100);
                    }
                }
                else if (chunkEcsTestData2.Length > 0)
                {
                    for (int i = 0; i < chunkCount; i++)
                    {
                        chunkEcsTestData2[i] = new EcsTestData2(chunkEcsTestData2[i].value0 - 1000);
                    }
                }
            }
示例#2
0
        public void CreateArchetypeChunkArray_FiltersTwoChangeVersions()
        {
            var archetype1 = m_Manager.CreateArchetype(typeof(EcsTestData), typeof(EcsTestData2));
            var archetype2 = m_Manager.CreateArchetype(typeof(EcsTestData), typeof(EcsTestData2), typeof(EcsTestData3));
            var archetype3 = m_Manager.CreateArchetype(typeof(EcsTestData), typeof(EcsTestData2), typeof(EcsTestData4));

            m_ManagerDebug.SetGlobalSystemVersion(20);
            var createdChunks1 = CreateEntitiesAndReturnChunks(archetype1, 5000, e => SetData(e, 1, 4));

            m_ManagerDebug.SetGlobalSystemVersion(30);
            var createdChunks2 = CreateEntitiesAndReturnChunks(archetype2, 5000, e => SetData(e, 2, 5));

            m_ManagerDebug.SetGlobalSystemVersion(40);
            var createdChunks3 = CreateEntitiesAndReturnChunks(archetype3, 5000, e => SetData(e, 3, 6));

            var group = m_Manager.CreateEntityQuery(typeof(EcsTestData), typeof(EcsTestData2));

            group.SetChangedVersionFilter(new ComponentType[] { typeof(EcsTestData), typeof(EcsTestData2) });

            group.SetChangedFilterRequiredVersion(30);

            var testType1 = m_Manager.GetArchetypeChunkComponentType <EcsTestData>(false);
            var testType2 = m_Manager.GetArchetypeChunkComponentType <EcsTestData2>(false);

            var queriedChunks1 = group.CreateArchetypeChunkArray(Allocator.TempJob);

            foreach (var chunk in createdChunks1)
            {
                var array = chunk.GetNativeArray(testType1);
                array[0] = new EcsTestData(7);
            }

            var queriedChunks2 = group.CreateArchetypeChunkArray(Allocator.TempJob);

            foreach (var chunk in createdChunks2)
            {
                var array = chunk.GetNativeArray(testType2);
                array[0] = new EcsTestData2(7);
            }

            var queriedChunks3 = group.CreateArchetypeChunkArray(Allocator.TempJob);


            CollectionAssert.AreEquivalent(createdChunks3, queriedChunks1);
            CollectionAssert.AreEquivalent(createdChunks1.Concat(createdChunks3), queriedChunks2);

            group.Dispose();
            queriedChunks1.Dispose();
            queriedChunks2.Dispose();
            queriedChunks3.Dispose();
        }
        [StandaloneFixme] // Real problem : Atomic Safety
        public void ComponentDataArrayFromEntityThrowsIfNotExist()
        {
            var entity          = m_Manager.CreateEntity(typeof(EcsTestData));
            var destroyedEntity = m_Manager.CreateEntity(typeof(EcsTestData));

            m_Manager.DestroyEntity(destroyedEntity);

            var data = EmptySystem.GetComponentDataFromEntity <EcsTestData2>();

            Assert.Throws <System.ArgumentException>(() => { data[entity] = new EcsTestData2(); });
            Assert.Throws <System.ArgumentException>(() => { data[destroyedEntity] = new EcsTestData2(); });

            Assert.Throws <System.ArgumentException>(() => { var p = data[entity]; });
            Assert.Throws <System.ArgumentException>(() => { var p = data[destroyedEntity]; });
        }
        void ChangeGroupOrder(int version, EntityQuery group)
        {
            var entities = group.ToEntityArray(Allocator.TempJob);

            for (int i = 0; i < 50; i++)
            {
                var e = entities[i];
                if ((i & 0x01) == 0)
                {
                    var testData2 = new EcsTestData2(i);
                    m_Manager.AddComponentData(e, testData2);
                }
            }

            entities.Dispose();
        }
示例#5
0
        void ChangeGroupOrder(int version, ComponentGroup group)
        {
            var entityData = group.GetEntityArray();
            var entities   = new NativeArray <Entity>(50, Allocator.Temp);

            entityData.CopyTo(new NativeSlice <Entity>(entities));

            for (int i = 0; i < 50; i++)
            {
                var e = entities[i];
                if ((i & 0x01) == 0)
                {
                    var testData2 = new EcsTestData2(i);
                    m_Manager.AddComponentData(e, testData2);
                }
            }

            entities.Dispose();
        }
示例#6
0
            public void Execute(int chunkIndex)
            {
                var chunk             = chunks[chunkIndex];
                var chunkCount        = chunk.Count;
                var chunkEcsTestData  = chunk.GetNativeArray(ecsTestData);
                var chunkEcsTestData2 = chunk.GetNativeArray(ecsTestData2);

                if (chunkEcsTestData.Length > 0)
                {
                    for (int i = 0; i < chunkCount; i++)
                    {
                        chunkEcsTestData[i] = new EcsTestData(chunkEcsTestData[i].value + 100);
                    }
                }
                else if (chunkEcsTestData2.Length > 0)
                {
                    for (int i = 0; i < chunkCount; i++)
                    {
                        chunkEcsTestData2[i] = new EcsTestData2(chunkEcsTestData2[i].value0 - 1000);
                    }
                }
            }
        [StandaloneFixme] // Real problem : Atomic Safety
        public void ReadOnlyComponentDataArray()
        {
            var group = m_Manager.CreateComponentGroup(typeof(EcsTestData2), ComponentType.ReadOnly(typeof(EcsTestData)));

            var entity = m_Manager.CreateEntity(typeof(EcsTestData), typeof(EcsTestData2));

            m_Manager.SetComponentData(entity, new EcsTestData(42));

            // EcsTestData is read only
            var arr = group.GetComponentDataArray <EcsTestData>();

            Assert.AreEqual(1, arr.Length);
            Assert.AreEqual(42, arr[0].value);
            Assert.Throws <System.InvalidOperationException>(() => { arr[0] = new EcsTestData(0); });

            // EcsTestData2 can be written to
            var arr2 = group.GetComponentDataArray <EcsTestData2>();

            Assert.AreEqual(1, arr2.Length);
            arr2[0] = new EcsTestData2(55);
            Assert.AreEqual(55, arr2[0].value0);
        }
示例#8
0
        public void CreateArchetypeChunkArray_FiltersTwoSharedTwoChangeVersion()
        {
            var archetype1 = m_Manager.CreateArchetype(typeof(EcsTestData), typeof(EcsTestData2), typeof(EcsTestData3), typeof(EcsTestSharedComp), typeof(EcsTestSharedComp2));
            var archetype2 = m_Manager.CreateArchetype(typeof(EcsTestData), typeof(EcsTestData2), typeof(EcsTestSharedComp), typeof(EcsTestSharedComp2));

            // 9 chunks
            // 3 of archetype1 with 1 shared value1, 3,3 shared value2
            // 3 of archetype2 with 1 shared value1, 4,4 shared value2
            // 3 of archetype1 with 2 shared value1, 3,3 shared value2
            m_ManagerDebug.SetGlobalSystemVersion(10);
            var createdChunks1 = CreateEntitiesAndReturnChunks(archetype1, archetype1.ChunkCapacity * 3, e => SetDataAndShared(e, 1, 1, 3));
            var createdChunks2 = CreateEntitiesAndReturnChunks(archetype2, archetype2.ChunkCapacity * 3, e => SetDataAndShared(e, 2, 1, 4));
            var createdChunks3 = CreateEntitiesAndReturnChunks(archetype1, archetype1.ChunkCapacity * 3, e => SetDataAndShared(e, 3, 2, 3));

            // query matches all three
            var query = m_Manager.CreateEntityQuery(typeof(EcsTestData), typeof(EcsTestData2), typeof(EcsTestSharedComp), typeof(EcsTestSharedComp2));

            query.AddChangedVersionFilter(typeof(EcsTestData));
            query.AddChangedVersionFilter(typeof(EcsTestData2));
            query.AddSharedComponentFilter(new EcsTestSharedComp {
                value = 1
            });
            query.AddSharedComponentFilter(new EcsTestSharedComp2 {
                value0 = 3, value1 = 3
            });

            var queriedChunks1 = query.CreateArchetypeChunkArray(Allocator.TempJob);

            query.SetChangedFilterRequiredVersion(10);
            var queriedChunks2 = query.CreateArchetypeChunkArray(Allocator.TempJob);

            // bumps the version number for TestData1 for createdChunks1 and createdChunks2
            m_ManagerDebug.SetGlobalSystemVersion(20);
            for (int i = 0; i < createdChunks1.Length; ++i)
            {
                {
                    var array = createdChunks1[i].GetNativeArray(EmptySystem.GetArchetypeChunkComponentType <EcsTestData>());
                    array[0] = new EcsTestData {
                        value = 10
                    };
                }
                {
                    var array = createdChunks3[i].GetNativeArray(EmptySystem.GetArchetypeChunkComponentType <EcsTestData>());
                    array[0] = new EcsTestData {
                        value = 10
                    };
                }
            }
            var queriedChunks3 = query.CreateArchetypeChunkArray(Allocator.TempJob);

            // bumps the version number for TestData2 for createdChunks1
            query.SetChangedFilterRequiredVersion(20);
            m_ManagerDebug.SetGlobalSystemVersion(30);
            for (int i = 0; i < createdChunks1.Length; ++i)
            {
                var array = createdChunks1[i].GetNativeArray(EmptySystem.GetArchetypeChunkComponentType <EcsTestData2>());
                array[0] = new EcsTestData2 {
                    value1 = 10, value0 = 10
                };
            }
            var queriedChunks4 = query.CreateArchetypeChunkArray(Allocator.TempJob);

            CollectionAssert.AreEquivalent(createdChunks1, queriedChunks1); // query 1 = created 1
            Assert.AreEqual(0, queriedChunks2.Length);                      // query 2 is empty
            CollectionAssert.AreEquivalent(createdChunks1, queriedChunks3); // query 3 = created 1 (version # was bumped and we're filtering out created2)
            CollectionAssert.AreEquivalent(createdChunks1, queriedChunks4); // query 4 = created 1 (version # of type2 was bumped)

            query.Dispose();
            queriedChunks1.Dispose();
            queriedChunks2.Dispose();
            queriedChunks3.Dispose();
            queriedChunks4.Dispose();
        }
示例#9
0
        public void Instantiate_HasGetComponent_VisibleFromInsideForEach()
        {
            m_Manager.AddComponentData(m_Manager.CreateEntity(), new EcsTestData(5));

            MutableEntities.ForEach((Entity e, ref EcsTestData testData) =>
            {
                Assert.AreEqual(5, testData.value);
                Assert.IsFalse(m_Manager.HasComponent <EcsTestData2>(e));
                Entity newe1 = m_Manager.Instantiate(e);
                m_Manager.AddComponentData(e, new EcsTestData2()
                {
                    value0 = 1, value1 = 3
                });
                {
                    EcsTestData2 ed2 = m_Manager.GetComponentData <EcsTestData2>(e);
                    Assert.AreEqual(3, ed2.value1);
                    Assert.AreEqual(1, ed2.value0);
                }

                Entity deferred = m_Manager.CreateEntity();
                m_Manager.AddComponentData(deferred, testData);
                {
                    var ed = m_Manager.GetComponentData <EcsTestData>(deferred);
                    Assert.AreEqual(testData.value, ed.value);
                }
                Entity newe2 = m_Manager.Instantiate(e);

                Assert.IsFalse(m_Manager.HasComponent <EcsTestData2>(newe1));
                {
                    EcsTestData ed = m_Manager.GetComponentData <EcsTestData>(newe1);
                    Assert.AreEqual(5, ed.value);
                }
                Assert.IsTrue(m_Manager.HasComponent <EcsTestData2>(e));
                {
                    EcsTestData2 ed2 = m_Manager.GetComponentData <EcsTestData2>(newe2);
                    Assert.AreEqual(3, ed2.value1);
                    Assert.AreEqual(1, ed2.value0);
                }
                Assert.IsTrue(m_Manager.HasComponent <EcsTestData>(newe1));
                m_Manager.RemoveComponent <EcsTestData>(newe1);
                Assert.IsFalse(m_Manager.HasComponent <EcsTestData>(newe1));
            });

            using (var allEntities = m_Manager.GetAllEntities())
                Assert.AreEqual(4, allEntities.Length);

            using (var group = new ExtractTestDataFromEntityManager <EcsTestData>(m_Manager))
            {
                Assert.AreEqual(3, group.Values.Length);
                Assert.AreEqual(5, group.Values[0].value); // e
                Assert.AreEqual(5, group.Values[1].value); // deferred
                Assert.AreEqual(5, group.Values[2].value); // newe2
            }

            using (var group = new ExtractTestDataFromEntityManager <EcsTestData2>(m_Manager))
            {
                Assert.AreEqual(2, group.Values.Length); // (e && newe2)
                Assert.AreEqual(3, group.Values[0].value1);
                Assert.AreEqual(1, group.Values[0].value0);
                Assert.AreEqual(3, group.Values[1].value1);
                Assert.AreEqual(1, group.Values[1].value0);
            }
        }
 public void Execute(int index)
 {
     data[index]  = new EcsTestData(100);
     data2[index] = new EcsTestData2(102);
     data3[index] = new EcsTestData3(103);
 }