public void ToComponentArrayContainsAllInstances()
        {
            var go1 = new GameObject();
            var go2 = new GameObject();

            try
            {
                {
                    var entity = m_Manager.CreateEntity();
                    m_Manager.AddComponentObject(entity, go1.transform);
                }
                {
                    var entity = m_Manager.CreateEntity();
                    m_Manager.AddComponentObject(entity, go2.transform);
                }

                var query = EmptySystem.GetEntityQuery(typeof(Transform));
                var arr   = query.ToComponentArray <Transform>();
                Assert.AreEqual(2, arr.Length);
                Assert.That(arr.Any(t => ReferenceEquals(t, go1.transform)), "Output doesn't contain transform 1");
                Assert.That(arr.Any(t => ReferenceEquals(t, go2.transform)), "Output doesn't contain transform 2");
            }
            finally
            {
                Object.DestroyImmediate(go1);
                Object.DestroyImmediate(go2);
            }
        }
        void GetValue(ChangeMode mode)
        {
            EmptySystem.Update();
            var entityArray = EmptySystem.GetComponentGroup(typeof(EcsTestData)).GetEntityArray();

            if (mode == ChangeMode.ComponentDataArray)
            {
                var array = EmptySystem.GetComponentGroup(typeof(EcsTestData)).GetComponentDataArray <EcsTestData>();
                for (int i = 0; i != array.Length; i++)
                {
                    var val = array[i];
                }
            }
            else 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]);
                }
            }
            else if (mode == ChangeMode.ComponentGroupArray)
            {
                foreach (var e in EmptySystem.GetEntities <GroupRO>())
                {
                    ;
                }
            }
        }
Example #3
0
        public void CalculateChunkCount()
        {
            var archetype = m_Manager.CreateArchetype(typeof(EcsTestData), typeof(EcsTestSharedComp));
            var entityA   = m_Manager.CreateEntity(archetype);
            var entityB   = m_Manager.CreateEntity(archetype);

            m_Manager.SetSharedComponentData(entityA, new EcsTestSharedComp {
                value = 10
            });

            var query = EmptySystem.GetEntityQuery(typeof(EcsTestData), typeof(EcsTestSharedComp));

            var chunkCountBeforeFilter = query.CalculateChunkCount();

            query.SetSharedComponentFilter(new EcsTestSharedComp {
                value = 10
            });
            var chunkCountAfterSetFilter = query.CalculateChunkCount();

            var chunkCountUnfilteredAfterSetFilter = query.CalculateChunkCountWithoutFiltering();

            Assert.AreEqual(2, chunkCountBeforeFilter);
            Assert.AreEqual(1, chunkCountAfterSetFilter);
            Assert.AreEqual(2, chunkCountUnfilteredAfterSetFilter);
        }
Example #4
0
        public void GetSetSingleton()
        {
            m_Manager.CreateEntity(typeof(EcsTestData));

            EmptySystem.SetSingleton(new EcsTestData(10));
            Assert.AreEqual(10, EmptySystem.GetSingleton <EcsTestData>().value);
        }
#pragma warning restore 649

        unsafe void SetValue(int index, int value, ChangeMode mode)
        {
            EmptySystem.Update();
            var entityArray = EmptySystem.GetComponentGroup(typeof(EcsTestData)).GetEntityArray();
            var entity      = entityArray[index];

            if (mode == ChangeMode.ComponentDataArray)
            {
                var array = EmptySystem.GetComponentGroup(typeof(EcsTestData)).GetComponentDataArray <EcsTestData>();
                array[index] = new EcsTestData(value);
            }
            else if (mode == ChangeMode.SetComponentData)
            {
                m_Manager.SetComponentData(entity, new EcsTestData(value));
            }
            else if (mode == ChangeMode.SetComponentDataFromEntity)
            {
                //@TODO: Chaining correctness... Definately not implemented right now...
                var array = EmptySystem.GetComponentDataFromEntity <EcsTestData>(false);
                array[entity] = new EcsTestData(value);
            }
            else if (mode == ChangeMode.ComponentGroupArray)
            {
                *(EmptySystem.GetEntities <GroupRW>()[index].Data) = new EcsTestData(value);
            }
        }
Example #6
0
        public void JobProcessWithFilteredEntityQuery()
        {
            var archetype = m_Manager.CreateArchetype(typeof(EcsTestData), typeof(EcsTestSharedComp));

            var entityInGroupA = m_Manager.CreateEntity(archetype);
            var entityInGroupB = m_Manager.CreateEntity(archetype);

            m_Manager.SetComponentData <EcsTestData>(entityInGroupA, new EcsTestData {
                value = 5
            });
            m_Manager.SetComponentData <EcsTestData>(entityInGroupB, new EcsTestData {
                value = 5
            });
            m_Manager.SetSharedComponentData <EcsTestSharedComp>(entityInGroupA, new EcsTestSharedComp {
                value = 1
            });
            m_Manager.SetSharedComponentData <EcsTestSharedComp>(entityInGroupB, new EcsTestSharedComp {
                value = 2
            });

            var group = EmptySystem.GetEntityQuery(typeof(EcsTestData), typeof(EcsTestSharedComp));

            group.SetSharedComponentFilter(new EcsTestSharedComp {
                value = 1
            });

            var processJob = new ProcessFilteredData();

            processJob.Schedule(group).Complete();

            Assert.AreEqual(10, m_Manager.GetComponentData <EcsTestData>(entityInGroupA).value);
            Assert.AreEqual(5, m_Manager.GetComponentData <EcsTestData>(entityInGroupB).value);
        }
        public void BarrierPlaybackExceptionIsolation()
        {
            var barrier = World.GetOrCreateManager <EndFrameBarrier>();

            var buf1 = barrier.CreateCommandBuffer();
            var buf2 = barrier.CreateCommandBuffer();

            var e1 = buf1.CreateEntity();

            buf1.AddComponent(e1, new EcsTestData());
            buf1.AddComponent(e1, new EcsTestData());

            var e2 = buf2.CreateEntity();

            buf2.AddComponent(e2, new EcsTestData());
            buf2.AddComponent(e2, new EcsTestData());

            // We exp both command buffers to execute, and an exception thrown afterwards
            // Essentially we want isolation of two systems that might fail independently.
            Assert.Throws <ArgumentException>(() => { barrier.Update(); });
            Assert.AreEqual(2, EmptySystem.GetComponentGroup(typeof(EcsTestData)).CalculateLength());

            // On second run, we expect all buffers to be removed...
            // So no more exceptions thrown.
            barrier.Update();

            Assert.AreEqual(2, EmptySystem.GetComponentGroup(typeof(EcsTestData)).CalculateLength());
        }
        // 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 <TransformAccessArrayTestTagComponent>();
            // Execute in edit mode is not enabled so this has to be called manually right now
            go.GetComponent <GameObjectEntity>().OnEnable();
            var group = EmptySystem.GetComponentGroup(typeof(Transform), typeof(TransformAccessArrayTestTag));
            var ta    = group.GetTransformAccessArray();

            Assert.AreEqual(1, ta.length);

            var go2 = new GameObject();

            go2.AddComponent <TransformAccessArrayTestTagComponent>();
            // Execute in edit mode is not enabled so this has to be called manually right now
            go2.GetComponent <GameObjectEntity>().OnEnable();
            Assert.AreEqual(1, ta.length);

            // Execute in edit mode is not enabled so this has to be called manually right now
            go.GetComponent <GameObjectEntity>().OnDisable();
            go2.GetComponent <GameObjectEntity>().OnDisable();
            Object.DestroyImmediate(go);
            Object.DestroyImmediate(go2);
        }
        public void EmptyTransformAccessArrayWorks()
        {
            var group = EmptySystem.GetComponentGroup(typeof(Transform), typeof(TransformAccessArrayTestTag));
            var ta    = group.GetTransformAccessArray();

            Assert.AreEqual(0, ta.length);
        }
Example #10
0
        public void GetSingletonEntityWorks()
        {
            var entity = m_Manager.CreateEntity(typeof(EcsTestData));

            var singletonEntity = EmptySystem.GetSingletonEntity <EcsTestData>();

            Assert.AreEqual(entity, singletonEntity);
        }
Example #11
0
        public void GetSetSingletonMultipleThrows()
        {
            m_Manager.CreateEntity(typeof(EcsTestData));
            m_Manager.CreateEntity(typeof(EcsTestData));

            Assert.Throws <InvalidOperationException>(() => EmptySystem.SetSingleton(new EcsTestData()));
            Assert.Throws <InvalidOperationException>(() => EmptySystem.GetSingleton <EcsTestData>());
        }
Example #12
0
 public void HasSingletonThrowsMultiple()
 {
     Assert.IsFalse(EmptySystem.HasSingleton <EcsTestData>());
     m_Manager.CreateEntity(typeof(EcsTestData));
     Assert.IsTrue(EmptySystem.HasSingleton <EcsTestData>());
     m_Manager.CreateEntity(typeof(EcsTestData));
     Assert.IsFalse(EmptySystem.HasSingleton <EcsTestData>());
 }
        public void ComponentGroupArraySubtractive()
        {
            m_Manager.CreateEntity(typeof(EcsTestData), typeof(EcsTestData2));
            m_Manager.CreateEntity(typeof(EcsTestData));

            var entities = EmptySystem.GetEntities <TestEntitySub2>();

            Assert.AreEqual(1, entities.Length);
        }
Example #14
0
        public void JobExcludedComponentExplicitQuery()
        {
            var group = EmptySystem.GetEntityQuery(ComponentType.Exclude <EcsTestData>());

            var handle = new JobHandle();

            Assert.Throws <InvalidOperationException>(() => handle = new Process1().Schedule(group));
            handle.Complete();
        }
Example #15
0
        public void GetSetSingletonMultipleComponents()
        {
            var entity = m_Manager.CreateEntity(typeof(EcsTestData3), typeof(EcsTestData), typeof(EcsTestData2));

            m_Manager.SetComponentData(entity, new EcsTestData(10));
            Assert.AreEqual(10, EmptySystem.GetSingleton <EcsTestData>().value);

            EmptySystem.SetSingleton(new EcsTestData2(100));
            Assert.AreEqual(100, m_Manager.GetComponentData <EcsTestData2>(entity).value0);
        }
Example #16
0
        public void HasSingleton_ReturnsTrueWithEntityWithOnlyComponent()
        {
            Assert.IsFalse(EmptySystem.HasSingleton <EcsTestData>());

            m_Manager.CreateEntity(typeof(EcsTestData));
            Assert.IsTrue(EmptySystem.HasSingleton <EcsTestData>());

            m_Manager.CreateEntity(typeof(EcsTestData));
            Assert.IsFalse(EmptySystem.HasSingleton <EcsTestData>());
        }
Example #17
0
        public void RequireSingletonWorks()
        {
            EmptySystem.RequireSingletonForUpdate <EcsTestData>();
            EmptySystem.GetEntityQuery(typeof(EcsTestData2));

            m_Manager.CreateEntity(typeof(EcsTestData2));
            Assert.IsFalse(EmptySystem.ShouldRunSystem());
            m_Manager.CreateEntity(typeof(EcsTestData));
            Assert.IsTrue(EmptySystem.ShouldRunSystem());
        }
        public void TryGetSingleton()
        {
            m_Manager.CreateEntity(typeof(EcsTestData));

            EmptySystem.SetSingleton(new EcsTestData(10));
            var hasSingleTon = EmptySystem.TryGetSingleton <EcsTestData>(out var ecsTestData);

            Assert.IsTrue(hasSingleTon);
            Assert.AreEqual(10, ecsTestData.value);
        }
Example #19
0
        public void GetEntityQueryMaskThrowsOnFilter()
        {
            var queryMatches = EmptySystem.GetEntityQuery(typeof(EcsTestData), typeof(EcsTestData2), typeof(EcsTestSharedComp));

            queryMatches.SetSharedComponentFilter(new EcsTestSharedComp(42));

            Assert.That(() => m_Manager.GetEntityQueryMask(queryMatches),
                        Throws.Exception.With.Message.Matches("GetEntityQueryMask can only be called on an EntityQuery without a filter applied to it."
                                                              + "  You can call EntityQuery.ResetFilter to remove the filters from an EntityQuery."));
        }
Example #20
0
        public void StructuralChangeAfterSchedulingNoDependenciesJobThrows()
        {
            var archetype = m_Manager.CreateArchetype(typeof(EcsTestData));
            var entity    = m_Manager.CreateEntity(archetype);
            var group     = EmptySystem.GetEntityQuery(typeof(EcsTestData));
            var handle    = new NoDependenciesJob().Schedule(group);

            Assert.Throws <InvalidOperationException>(() => m_Manager.DestroyEntity(entity));
            handle.Complete();
        }
Example #21
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));
        }
Example #22
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);
        }
Example #23
0
		public void BufferFromEntityWorks()
		{
			var entityInt = m_Manager.CreateEntity(typeof(EcsIntElement));
            m_Manager.GetBuffer<EcsIntElement>(entityInt).CopyFrom(new EcsIntElement[] { 1, 2, 3 });

			var intLookup = EmptySystem.GetBufferFromEntity<EcsIntElement>();
			Assert.IsTrue(intLookup.Exists(entityInt));
			Assert.IsFalse(intLookup.Exists(new Entity()));

			Assert.AreEqual(2, intLookup[entityInt][1].Value);
		}
Example #24
0
        public void JobProcessComponentWithEntityGroupCorrect()
        {
            ComponentType[] expectedTypes = { ComponentType.ReadOnly <EcsTestData>(), ComponentType.ReadWrite <EcsTestData2>(), ComponentType.ReadWrite <EcsTestData3>() };

            new Process3Entity().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]);
        }
        public void JobProcessComponentGroupCorrect()
        {
            ComponentType[] expectedTypes = { ComponentType.ReadOnly <EcsTestData>(), ComponentType.Create <EcsTestData2>() };

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

            Assert.AreEqual(1, EmptySystem.ComponentGroups.Length);
            Assert.IsTrue(EmptySystem.ComponentGroups[0].CompareComponents(expectedTypes));
            Assert.AreEqual(group, EmptySystem.ComponentGroups[0]);
        }
        public void SingleItemTransformAccessArrayWorks()
        {
            var go = new GameObject();

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

            Assert.AreEqual(1, ta.length);

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

            Assert.Throws <InvalidOperationException>(() => m_Manager.DestroyEntity(entity));
            handle.Complete();
        }
Example #28
0
        public void GetSetSingleton_ManagedComponents()
        {
            m_Manager.CreateEntity(typeof(EcsTestManagedComponent));

            const string kTestVal = "SomeString";

            EmptySystem.SetSingleton(new EcsTestManagedComponent()
            {
                value = kTestVal
            });
            Assert.AreEqual(kTestVal, EmptySystem.GetSingleton <EcsTestManagedComponent>().value);
        }
        public void IJobEntityBatch_WithNoBatching_HasCorrectIndices(
            [Values(ScheduleMode.Parallel, ScheduleMode.Single, ScheduleMode.Run, ScheduleMode.RunWithoutJobs)] ScheduleMode scheduleMode)
        {
            var archetypeA = m_Manager.CreateArchetype(typeof(EcsTestData), typeof(EcsTestSharedComp));

            using (var query = m_Manager.CreateEntityQuery(typeof(EcsTestData), typeof(EcsTestSharedComp)))
                using (var entities = m_Manager.CreateEntity(archetypeA, 100, Allocator.TempJob))
                {
                    var val = 0;
                    foreach (var entity in entities)
                    {
                        m_Manager.SetComponentData(entity, new EcsTestData()
                        {
                            value = val
                        });
                        m_Manager.SetSharedComponentData(entity, new EcsTestSharedComp()
                        {
                            value = val
                        });
                        val++;
                    }

                    var job = new CheckBatchIndices {
                        EcsTestDataTypeHandle = EmptySystem.GetComponentTypeHandle <EcsTestData>()
                    };
                    var jobWithIndex = new CheckBatchAndFirstEntityIndices {
                        EcsTestDataTypeHandle = EmptySystem.GetComponentTypeHandle <EcsTestData>()
                    };

                    switch (scheduleMode)
                    {
                    case ScheduleMode.Parallel:
                        job.ScheduleParallel(query).Complete();
                        jobWithIndex.ScheduleParallel(query).Complete();
                        break;

                    case ScheduleMode.Single:
                        job.Schedule(query).Complete();
                        jobWithIndex.Schedule(query).Complete();
                        break;

                    case ScheduleMode.Run:
                        job.Run(query);
                        jobWithIndex.Run(query);
                        break;

                    case ScheduleMode.RunWithoutJobs:
                        JobEntityBatchExtensions.RunWithoutJobs(ref job, query);
                        JobEntityBatchIndexExtensions.RunWithoutJobs(ref jobWithIndex, query);
                        break;
                    }
                }
        }
Example #30
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();
        }