예제 #1
0
        public void JobProcessComponentGroupCorrect()
        {
            ComponentType[] expectedTypes = { ComponentType.ReadOnly <EcsTestData>(), ComponentType.ReadWrite <EcsTestData2>() };

            new Process2().Run(EmptySystem);
            var group = EmptySystem.GetEntityQuery(expectedTypes);

            Assert.AreEqual(1, EmptySystem.EntityQueries.Length);
            Assert.IsTrue(EmptySystem.EntityQueries[0].CompareComponents(expectedTypes));
            Assert.AreEqual(group, EmptySystem.EntityQueries[0]);
        }
예제 #2
0
        public void MatchesArchetypeAddedAfterMaskCreation()
        {
            var archetypeBefore = m_Manager.CreateArchetype(typeof(EcsTestData), typeof(EcsTestData2));
            var query           = EmptySystem.GetEntityQuery(typeof(EcsTestData));
            var queryMask       = m_Manager.GetEntityQueryMask(query);

            var archetypeAfter = m_Manager.CreateArchetype(typeof(EcsTestData), typeof(EcsTestData3));
            var entity         = m_Manager.CreateEntity(archetypeAfter);

            Assert.True(queryMask.Matches(entity));
        }
예제 #3
0
        public unsafe void GetEntityQueryMaskReturnsCachedMask()
        {
            var queryMatches     = EmptySystem.GetEntityQuery(typeof(EcsTestData), typeof(EcsTestData2), typeof(EcsTestSharedComp));
            var queryMaskMatches = m_Manager.GetEntityQueryMask(queryMatches);

            var queryMaskMatches2 = m_Manager.GetEntityQueryMask(queryMatches);

            Assert.True(queryMaskMatches.Mask == queryMaskMatches2.Mask &&
                        queryMaskMatches.Index == queryMaskMatches2.Index &&
                        queryMaskMatches.EntityComponentStore == queryMaskMatches2.EntityComponentStore);
        }
        public void SingleItemTransformAccessArrayWorks()
        {
            var go = new GameObject();

            go.AddComponent <TransformAccessArrayTestTagProxy>();
            var group = EmptySystem.GetEntityQuery(typeof(Transform), typeof(TransformAccessArrayTestTag));
            var ta    = group.GetTransformAccessArray();

            Assert.AreEqual(1, ta.length);

            Object.DestroyImmediate(go);
        }
예제 #5
0
        public void StructuralChangeAfterSchedulingEntityOnlyDependencyJobThrows()
        {
            var archetype = m_Manager.CreateArchetype(typeof(EcsTestData));
            var entity = m_Manager.CreateEntity(archetype);
            var group = EmptySystem.GetEntityQuery(typeof(EcsTestData));
            var handle = new EntityOnlyDependencyJob {
                entityType = m_Manager.GetArchetypeChunkEntityType()
            }.Schedule(group);

            Assert.Throws <InvalidOperationException>(() => m_Manager.DestroyEntity(entity));
            handle.Complete();
        }
예제 #6
0
        public void TestSimpleIJobChunk([Values(0, 1, 2, 3)] int mode, [Values(1, 100)] int n)
        {
            NativeArray <Entity> eArr = new NativeArray <Entity>(n, Allocator.TempJob);
            var arch = m_Manager.CreateArchetype(typeof(EcsTestData));

            m_Manager.CreateEntity(arch, eArr);

            for (int i = 0; i < n; ++i)
            {
                m_Manager.SetComponentData(eArr[i], new EcsTestData()
                {
                    value = 10 + i
                });
            }

            NativeList <int> listOfInt = new NativeList <int>(1, Allocator.TempJob);

            EntityQuery query = EmptySystem.GetEntityQuery(typeof(EcsTestData));
            var         job   = new SimpleChunk <int>
            {
                testType = m_Manager.GetArchetypeChunkComponentType <EcsTestData>(false),
                listOfT  = listOfInt
            };

            switch (mode)
            {
            case 0:
                job.Schedule(query).Complete();
                break;

            case 1:
                job.ScheduleParallel(query).Complete();
                break;

            case 2:
                job.ScheduleSingle(query).Complete();
                break;

            case 3:
                job.Run(query);
                break;
            }

            for (int i = 0; i < n; ++i)
            {
                EcsTestData data = m_Manager.GetComponentData <EcsTestData>(eArr[i]);
                Assert.AreEqual(10 + i + 100, data.value);
            }

            listOfInt.Dispose();
            eArr.Dispose();
        }
예제 #7
0
        public void SingleJobUsingSameReadOnlyDynamicBuffer()
        {
            SetupDynamicBufferJobTestEnvironment();

            var query = EmptySystem.GetEntityQuery(typeof(EcsIntElement));

            var job = new BufferSafetyJob_TwoReadOnly
            {
                BuffersFromEntity = EmptySystem.GetBufferFromEntity <EcsIntElement>(true)
            };

            job.Run(query);
        }
예제 #8
0
        public void GetEntityQuery_WithDuplicates()
        {
            // Currently duplicates will create two seperate groups doing the same thing...
            ComponentType[] dup_1 = { typeof(EcsTestData2) };
            ComponentType[] dup_2 = { typeof(EcsTestData2), typeof(EcsTestData3) };

            var dup1_system = EmptySystem.GetEntityQuery(dup_1);
            var dup2_system = EmptySystem.GetEntityQuery(dup_2);

            Assert.AreEqual(dup1_system, EmptySystem.GetEntityQuery(dup_1));
            Assert.AreEqual(dup2_system, EmptySystem.GetEntityQuery(dup_2));

            Assert.AreEqual(2, EmptySystem.EntityQueries.Length);
        }
예제 #9
0
        public void GetEntityQuery_RespectsRWAccessInequality()
        {
            var query1 = new EntityQueryDesc {
                All = new [] { ComponentType.ReadOnly <EcsTestData>(), ComponentType.ReadWrite <EcsTestData2>() }
            };
            var query2 = new EntityQueryDesc {
                All = new [] { ComponentType.ReadOnly <EcsTestData>(), ComponentType.ReadOnly <EcsTestData2>() }
            };

            var group1 = EmptySystem.GetEntityQuery(query1);
            var group2 = EmptySystem.GetEntityQuery(query2);

            Assert.AreNotEqual(group1, group2);
            Assert.AreEqual(2, EmptySystem.EntityQueries.Length);
        }
예제 #10
0
        public void GetEntityQuery()
        {
            ComponentType[] ro_rw = { ComponentType.ReadOnly <EcsTestData>(), typeof(EcsTestData2) };
            ComponentType[] rw_rw = { typeof(EcsTestData), typeof(EcsTestData2) };
            ComponentType[] rw    = { typeof(EcsTestData) };

            var ro_rw0_system = EmptySystem.GetEntityQuery(ro_rw);
            var rw_rw_system  = EmptySystem.GetEntityQuery(rw_rw);
            var rw_system     = EmptySystem.GetEntityQuery(rw);

            Assert.AreEqual(ro_rw0_system, EmptySystem.GetEntityQuery(ro_rw));
            Assert.AreEqual(rw_rw_system, EmptySystem.GetEntityQuery(rw_rw));
            Assert.AreEqual(rw_system, EmptySystem.GetEntityQuery(rw));

            Assert.AreEqual(3, EmptySystem.EntityQueries.Length);
        }
예제 #11
0
        public void SingleJobUsingSameReadOnlyAndReadWriteDynamicBufferThrows()
        {
            SetupDynamicBufferJobTestEnvironment();

            var query = EmptySystem.GetEntityQuery(typeof(EcsIntElement));

            var job = new BufferSafetyJob_OneRead_OneWrite
            {
                BuffersFromEntity = EmptySystem.GetBufferFromEntity <EcsIntElement>(false)
            };

            Assert.Throws <InvalidOperationException>(() =>
            {
                job.Run(query);
            });
        }
예제 #12
0
        private void MakeExtraQueries(int size)
        {
            var TagTypes = new Type[]
            {
                typeof(TestTag0),
                typeof(TestTag1),
                typeof(TestTag2),
                typeof(TestTag3),
                typeof(TestTag4),
                typeof(TestTag5),
                typeof(TestTag6),
                typeof(TestTag7),
                typeof(TestTag8),
                typeof(TestTag9),
                typeof(TestTag10),
                typeof(TestTag11),
                typeof(TestTag12),
                typeof(TestTag13),
                typeof(TestTag14),
                typeof(TestTag15),
                typeof(TestTag16),
                typeof(TestTag17)
            };

            for (int i = 0; i < size; i++)
            {
                var typeCount = CollectionHelper.Log2Ceil(i);
                var typeList  = new List <ComponentType>();
                for (int typeIndex = 0; typeIndex < typeCount; typeIndex++)
                {
                    if ((i & (1 << typeIndex)) != 0)
                    {
                        typeList.Add(TagTypes[typeIndex]);
                    }
                }

                typeList.Add(typeof(TestDefaultData));

                var types     = typeList.ToArray();
                var archetype = m_Manager.CreateArchetype(types);

                m_Manager.CreateEntity(archetype);
                var query = EmptySystem.GetEntityQuery(types);
                m_Manager.GetEntityQueryMask(query);
            }
        }
        public void ReadOnlyDynamicBufferImpl(bool readOnlyType)
        {
            var original = m_Manager.CreateEntity(typeof(EcsIntStateElement));
            var buffer   = m_Manager.GetBuffer <EcsIntStateElement>(original);

            buffer.Add(5);

            var group = EmptySystem.GetEntityQuery(new EntityQueryDesc {
                All = new ComponentType[] { typeof(EcsIntStateElement) }
            });
            var job = new ReadOnlyJob
            {
                Int = EmptySystem.GetArchetypeChunkBufferType <EcsIntStateElement>(readOnlyType)
            };

            job.Schedule(group).Complete();
        }
예제 #14
0
        public void Matches()
        {
            var archetypeMatches     = m_Manager.CreateArchetype(typeof(EcsTestData), typeof(EcsTestData2), typeof(EcsTestSharedComp));
            var archetypeDoesntMatch = m_Manager.CreateArchetype(typeof(EcsTestData), typeof(EcsTestData3), typeof(EcsTestSharedComp));

            var entity = m_Manager.CreateEntity(archetypeMatches);
            var entityOnlyNeededToPopulateArchetype = m_Manager.CreateEntity(archetypeDoesntMatch);

            var queryMatches     = EmptySystem.GetEntityQuery(typeof(EcsTestData), typeof(EcsTestData2), typeof(EcsTestSharedComp));
            var queryDoesntMatch = EmptySystem.GetEntityQuery(typeof(EcsTestData), typeof(EcsTestData3), typeof(EcsTestSharedComp));

            var queryMaskMatches = m_Manager.GetEntityQueryMask(queryMatches);

            var queryMaskDoesntMatch = m_Manager.GetEntityQueryMask(queryDoesntMatch);

            Assert.True(queryMaskMatches.Matches(entity));
            Assert.False(queryMaskDoesntMatch.Matches(entity));
        }
        [StandaloneFixme]     // IJob
        public void ReadWriteDynamicBuffer()
        {
            var original = m_Manager.CreateEntity(typeof(EcsIntStateElement));
            var buffer   = m_Manager.GetBuffer <EcsIntStateElement>(original);

            buffer.Add(5);

            var group = EmptySystem.GetEntityQuery(new EntityQueryDesc {
                All = new ComponentType[] { typeof(EcsIntStateElement) }
            });
            var job = new WriteJob
            {
                //@TODO: Throw exception when read only flag is not accurately passed to job for buffers...
                Int = EmptySystem.GetArchetypeChunkBufferType <EcsIntStateElement>()
            };

            job.Schedule(group).Complete();
        }
예제 #16
0
        public void TwoJobsUsingDynamicBuffersDontCauseSafetySystemFalsePositiveErrors()
        {
            SetupDynamicBufferJobTestEnvironment();

            var query = EmptySystem.GetEntityQuery(typeof(EcsIntElement));

            var jobA       = new BufferSafetyJobA();
            var jobAHandle = jobA.Schedule(query, default(JobHandle));

            var jobB = new BufferSafetyJobB
            {
                Entities          = query.ToEntityArray(Allocator.TempJob),
                BuffersFromEntity = EmptySystem.GetBufferFromEntity <EcsIntElement>(true)
            };
            var jobBHandle = jobB.Schedule(jobB.Entities.Length, 1, jobAHandle);

            jobBHandle.Complete();
        }
예제 #17
0
        public void GetEntityQuery_ComponentTypeArchetypeQueryEquality()
        {
            var query1 = new ComponentType[] { typeof(EcsTestData) };
            var query2 = new EntityQueryDesc {
                All = new ComponentType[] { typeof(EcsTestData) }
            };
            var query3 = new EntityQueryDesc {
                All = new [] { ComponentType.ReadWrite <EcsTestData>() }
            };

            var group1 = EmptySystem.GetEntityQuery(query1);
            var group2 = EmptySystem.GetEntityQuery(query2);
            var group3 = EmptySystem.GetEntityQuery(query3);

            Assert.AreEqual(group1, group2);
            Assert.AreEqual(group2, group3);
            Assert.AreEqual(1, EmptySystem.EntityQueries.Length);
        }
        // The atomic safety handle of TransformAccessArrays are not invalidated when injection changes, the array represents the transforms when you got it
        public void AddAndUseOldTransformAccessArrayDoesNotUpdateContent()
        {
            var go = new GameObject();

            go.AddComponent <TransformAccessArrayTestTagProxy>();
            var group = EmptySystem.GetEntityQuery(typeof(Transform), typeof(TransformAccessArrayTestTag));
            var ta    = group.GetTransformAccessArray();

            Assert.AreEqual(1, ta.length);

            var go2 = new GameObject();

            go2.AddComponent <TransformAccessArrayTestTagProxy>();
            Assert.AreEqual(1, ta.length);

            Object.DestroyImmediate(go);
            Object.DestroyImmediate(go2);
        }
예제 #19
0
#pragma warning restore 649

        // Running SetValue should change the chunk version for the data it's writing to.
        unsafe void SetValue(int index, int value, ChangeMode mode)
        {
            EmptySystem.Update();
            var entityArray = EmptySystem.GetEntityQuery(typeof(EcsTestData)).ToEntityArray(Allocator.TempJob);
            var entity      = entityArray[index];

            if (mode == ChangeMode.SetComponentData)
            {
                m_Manager.SetComponentData(entity, new EcsTestData(value));
            }
            else if (mode == ChangeMode.SetComponentDataFromEntity)
            {
                //@TODO: Chaining correctness... Definitely not implemented right now...
                var array = EmptySystem.GetComponentDataFromEntity <EcsTestData>(false);
                array[entity] = new EcsTestData(value);
            }

            entityArray.Dispose();
        }
예제 #20
0
        public void GetEntityQuery_ArchetypeQuery()
        {
            var query1 = new ComponentType[] { typeof(EcsTestData) };
            var query2 = new EntityQueryDesc {
                All = new ComponentType[] { typeof(EcsTestData) }
            };
            var query3 = new EntityQueryDesc {
                All = new ComponentType[] { typeof(EcsTestData), typeof(EcsTestData2) }
            };

            var group1 = EmptySystem.GetEntityQuery(query1);
            var group2 = EmptySystem.GetEntityQuery(query2);
            var group3 = EmptySystem.GetEntityQuery(query3);

            Assert.AreEqual(group1, EmptySystem.GetEntityQuery(query1));
            Assert.AreEqual(group2, EmptySystem.GetEntityQuery(query2));
            Assert.AreEqual(group3, EmptySystem.GetEntityQuery(query3));

            Assert.AreEqual(2, EmptySystem.EntityQueries.Length);
        }
        public void ReadWriteDynamicBuffer()
        {
            // Create multiple chunks so we ensure we are doing parallel for writing to buffers
            for (int i = 0; i != 10; i++)
            {
                var original = m_Manager.CreateEntity(typeof(EcsIntElement));
                m_Manager.AddSharedComponentData(original, new SharedData1(i));
                var buffer = m_Manager.GetBuffer <EcsIntElement>(original);
                buffer.Add(5);
            }

            var group = EmptySystem.GetEntityQuery(new EntityQueryDesc {
                All = new ComponentType[] { typeof(EcsIntElement) }
            });
            var job = new WriteJob
            {
                Int = EmptySystem.GetBufferTypeHandle <EcsIntElement>()
            };

            job.Schedule(group).Complete();
        }
예제 #22
0
        public void ReadOnlyDynamicBufferImpl(bool readOnlyType)
        {
            // Create multiple chunks so we ensure we are doing parallel for reading from buffers
            for (int i = 0; i != 10; i++)
            {
                var original = m_Manager.CreateEntity(typeof(EcsIntElement));
                m_Manager.AddSharedComponentData(original, new SharedData1(i));
                var buffer = m_Manager.GetBuffer <EcsIntElement>(original);
                buffer.Add(5);
            }

            var group = EmptySystem.GetEntityQuery(new EntityQueryDesc {
                All = new ComponentType[] { typeof(EcsIntElement) }
            });
            var job = new ReadOnlyJob
            {
                Int = EmptySystem.GetArchetypeChunkBufferType <EcsIntElement>(readOnlyType)
            };

            job.Schedule(group).Complete();
        }
예제 #23
0
        public void TwoJobsUsingReadOnlyDynamicBuffersCanRunInParallel_BufferFromEntity()
        {
            SetupDynamicBufferJobTestEnvironment();

            var query = EmptySystem.GetEntityQuery(typeof(EcsIntElement));

            var jobA = new BufferSafetyJobC {
                EntityTypeHandle = m_Manager.GetEntityTypeHandle(), BufferFromEntityRO = m_Manager.GetBufferFromEntity <EcsIntElement>(true), MyArray = new NativeArray <int>(1, Allocator.TempJob)
            };
            var jobAHandle = jobA.Schedule(query, default(JobHandle));

            var jobB = new BufferSafetyJobB
            {
                Entities          = query.ToEntityArray(Allocator.TempJob),
                BuffersFromEntity = EmptySystem.GetBufferFromEntity <EcsIntElement>(true)
            };
            var jobBHandle = jobB.Schedule(jobB.Entities.Length, 1, default(JobHandle));

            jobAHandle.Complete();
            jobBHandle.Complete();
        }
예제 #24
0
        public void CopyFromComponentDataArrayWithUnrelatedQueryThrows()
        {
            var query = EmptySystem.GetEntityQuery(typeof(EcsTestData));

            JobHandle jobHandle;

            Assert.Throws <InvalidOperationException>(() =>
            {
                using (var array = new NativeArray <EcsTestData2>(0, Allocator.Persistent))
                {
                    query.CopyFromComponentDataArray <EcsTestData2>(array);
                }
            });
            Assert.Throws <InvalidOperationException>(() =>
            {
                using (var array = new NativeArray <EcsTestData2>(0, Allocator.Persistent))
                {
                    query.CopyFromComponentDataArrayAsync <EcsTestData2>(array, out jobHandle);
                }
            });
        }
예제 #25
0
        public void ToComponentDataArrayWithUnrelatedQueryThrows()
        {
            var query = EmptySystem.GetEntityQuery(typeof(EcsTestData));

            JobHandle jobHandle;

            Assert.Throws <InvalidOperationException>(() =>
            {
                query.ToComponentDataArrayAsync <EcsTestData2>(Allocator.Persistent, out jobHandle);
            });
            Assert.Throws <InvalidOperationException>(() =>
            {
                query.ToComponentDataArray <EcsTestData2>(Allocator.Persistent);
            });
#if !UNITY_DISABLE_MANAGED_COMPONENTS
            Assert.Throws <InvalidOperationException>(() =>
            {
                query.ToComponentDataArray <EcsTestManagedComponent>();
            });
#endif
        }
예제 #26
0
        // Running GetValue should not trigger any changes to chunk version.
        void GetValue(ChangeMode mode)
        {
            EmptySystem.Update();
            var entityArray = EmptySystem.GetEntityQuery(typeof(EcsTestData)).ToEntityArray(Allocator.TempJob);

            if (mode == ChangeMode.SetComponentData)
            {
                for (int i = 0; i != entityArray.Length; i++)
                {
                    m_Manager.GetComponentData <EcsTestData>(entityArray[i]);
                }
            }
            else if (mode == ChangeMode.SetComponentDataFromEntity)
            {
                for (int i = 0; i != entityArray.Length; i++)
                {
                    m_Manager.GetComponentData <EcsTestData>(entityArray[i]);
                }
            }
            entityArray.Dispose();
        }
예제 #27
0
        public void RunSimpleIJobChunk()
        {
            didDispose = 0;
            const int            N    = 10000 * NMULT;
            NativeArray <Entity> eArr = new NativeArray <Entity>(N, Allocator.TempJob);
            var arch = m_Manager.CreateArchetype(typeof(EcsTestData));

            m_Manager.CreateEntity(arch, eArr);

            for (int i = 0; i < N; ++i)
            {
                m_Manager.SetComponentData(eArr[i], new EcsTestData()
                {
                    value = 10 + i
                });
            }

            EntityQuery query = EmptySystem.GetEntityQuery(typeof(EcsTestData));
            var         job   = new SimpleChunk {
                testType = m_Manager.GetArchetypeChunkComponentType <EcsTestData>(false)
            };

            job.Schedule(query).Complete();

#if !UNITY_DOTSPLAYER
            // TODO: Understand / fix why the editor tests don't run quite the same code path.
            job.mDisposable.Dispose();
#endif

            for (int i = 0; i < N; ++i)
            {
                EcsTestData data = m_Manager.GetComponentData <EcsTestData>(eArr[i]);
                Assert.AreEqual(data.value, 10 + i + 100);
            }

            Assert.AreEqual(1, didDispose);
            eArr.Dispose();
        }
예제 #28
0
        public void JobProcessComponentGroupCorrectNativeArrayOfComponentTypes()
        {
            ComponentType[] initialTypes = { typeof(EcsTestData), typeof(EcsTestData2) };

            var archetype = m_Manager.CreateArchetype(initialTypes);
            var entity    = m_Manager.CreateEntity(archetype);

            new Process2().Run(EmptySystem);
            var componentTypes = m_Manager.GetComponentTypes(entity);

            Assert.IsTrue(componentTypes[0] == initialTypes[0]);
            Assert.IsTrue(componentTypes[1] == initialTypes[1]);

            componentTypes[0] = ComponentType.ReadOnly(componentTypes[0].TypeIndex);

            var group = EmptySystem.GetEntityQuery(componentTypes);

            Assert.AreEqual(1, EmptySystem.EntityQueries.Length);
            Assert.IsTrue(EmptySystem.EntityQueries[0].CompareComponents(componentTypes));
            Assert.AreEqual(group, EmptySystem.EntityQueries[0]);

            componentTypes.Dispose();
        }
예제 #29
0
        public void RunSimpleIJobChunk()
        {
            const int            N    = 10000 * NMULT;
            NativeArray <Entity> eArr = new NativeArray <Entity>(N, Allocator.TempJob);
            var arch = m_Manager.CreateArchetype(typeof(EcsTestData));

            m_Manager.CreateEntity(arch, eArr);

            for (int i = 0; i < N; ++i)
            {
                m_Manager.SetComponentData(eArr[i], new EcsTestData()
                {
                    value = 10 + i
                });
            }

            NativeList <int> listOfInt = new NativeList <int>(1, Allocator.TempJob);

            EntityQuery query = EmptySystem.GetEntityQuery(typeof(EcsTestData));
            var         job   = new SimpleChunk <int>
            {
                testType = m_Manager.GetArchetypeChunkComponentType <EcsTestData>(false),
                listOfT  = listOfInt
            };

            job.Run(query);

            for (int i = 0; i < N; ++i)
            {
                EcsTestData data = m_Manager.GetComponentData <EcsTestData>(eArr[i]);
                Assert.AreEqual(10 + i + 100, data.value);
            }

            listOfInt.Dispose();
            eArr.Dispose();
        }
예제 #30
0
        public void GetEntityQuery_OrderIndependent()
        {
            var query1 = new ComponentType[] { typeof(EcsTestData), typeof(EcsTestData2) };
            var query2 = new ComponentType[] { typeof(EcsTestData2), typeof(EcsTestData) };

            var group1 = EmptySystem.GetEntityQuery(query1);
            var group2 = EmptySystem.GetEntityQuery(query2);

            Assert.AreEqual(group1, group2);
            Assert.AreEqual(1, EmptySystem.EntityQueries.Length);

            var query3 = new EntityQueryDesc {
                All = new ComponentType[] { typeof(EcsTestData2), typeof(EcsTestData3) }
            };
            var query4 = new EntityQueryDesc {
                All = new ComponentType[] { typeof(EcsTestData3), typeof(EcsTestData2) }
            };

            var group3 = EmptySystem.GetEntityQuery(query3);
            var group4 = EmptySystem.GetEntityQuery(query4);

            Assert.AreEqual(group3, group4);
            Assert.AreEqual(2, EmptySystem.EntityQueries.Length);
        }