public void AddComponentThenSetThenAddDoesNotChangeValue()
        {
            m_Manager.CreateEntity();

            var value0 = new EcsTestData(1);

            m_Manager.AddComponent(m_Manager.UniversalQuery, ComponentType.ReadWrite <EcsTestData>());
            var entities = m_Manager.UniversalQuery.ToEntityArray(Allocator.Persistent);

            for (int i = 0; i < entities.Length; i++)
            {
                m_Manager.SetComponentData(entities[i], value0);
            }

            var addedQuery = m_Manager.CreateEntityQuery(typeof(EcsTestData));

            m_Manager.AddComponent(addedQuery, ComponentType.ReadWrite <EcsTestData>());
            var values = addedQuery.ToComponentDataArray <EcsTestData>(Allocator.Persistent);

            for (int i = 0; i < entities.Length; i++)
            {
                Assert.AreEqual(value0.value, values[i].value);
            }

            addedQuery.Dispose();
            entities.Dispose();
            values.Dispose();
        }
 static void SetComponentDataValueByMethod(ComponentDataFromEntity <EcsTestData> cdfe, Entity entity, int value)
 {
     cdfe[entity] = new EcsTestData()
     {
         value = 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);
            }
        }
Ejemplo n.º 4
0
        public void ComponentDataArrayCopy()
        {
            var entity = m_Manager.CreateEntity(typeof(EcsTestData));

            var entities = new NativeArray <Entity>(20000, Allocator.Persistent);

            m_Manager.Instantiate(entity, entities);

            var ecsArray = m_Manager.CreateComponentGroup(typeof(EcsTestData)).GetComponentDataArray <EcsTestData>();

            for (int i = 0; i < ecsArray.Length; i++)
            {
                ecsArray[i] = new EcsTestData(i);
            }

            var copied = new NativeArray <EcsTestData>(entities.Length - 11 + 1, Allocator.Persistent);

            ecsArray.CopyTo(copied, 11);

            for (int i = 0; i < copied.Length; i++)
            {
                if (copied[i].value != i)
                {
                    Assert.AreEqual(i + 11, copied[i].value);
                }
            }

            copied.Dispose();
            entities.Dispose();
        }
Ejemplo n.º 5
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);
                    }
                }
            }
Ejemplo n.º 6
0
        public void AddComponentQueryWithArray()
        {
            m_Manager.CreateEntity(typeof(EcsTestData2));
            m_Manager.CreateEntity();
            m_Manager.CreateEntity();
            m_Manager.CreateEntity();

            var entities = m_Manager.UniversalQuery.ToEntityArray(Allocator.TempJob);
            var data     = new NativeArray <EcsTestData>(entities.Length, Allocator.Temp);

            for (int i = 0; i != data.Length; i++)
            {
                data[i] = new EcsTestData(entities[i].Index);
            }

            m_Manager.AddComponentData(m_Manager.UniversalQuery, data);

            for (int i = 0; i != data.Length; i++)
            {
                Assert.AreEqual(entities[i].Index, data[i].value);
            }
            Assert.AreEqual(4, entities.Length);

            data.Dispose();
            entities.Dispose();
        }
Ejemplo n.º 7
0
        public void UpdateChunkComponent()
        {
            var            arch0  = m_Manager.CreateArchetype(ComponentType.ChunkComponent <EcsTestData>(), typeof(EcsTestData2));
            ComponentGroup group0 = m_Manager.CreateComponentGroup(typeof(ChunkHeader), typeof(EcsTestData));

            var         entity0  = m_Manager.CreateEntity(arch0);
            var         chunk0   = m_Manager.GetChunk(entity0);
            EcsTestData testData = new EcsTestData {
                value = 7
            };

            var headers = group0.GetComponentDataArray <ChunkHeader>();

            Assert.AreEqual(1, headers.Length);

            m_Manager.SetChunkComponentData(chunk0, testData);

            headers = group0.GetComponentDataArray <ChunkHeader>();
            Assert.AreEqual(1, headers.Length);

            Assert.AreEqual(7, m_Manager.GetChunkComponentData <EcsTestData>(entity0).value);

            m_Manager.SetComponentData(entity0, new EcsTestData2 {
                value0 = 1, value1 = 2
            });

            var entity1 = m_Manager.CreateEntity(arch0);
            var chunk1  = m_Manager.GetChunk(entity1);

            Assert.AreEqual(7, m_Manager.GetChunkComponentData <EcsTestData>(entity0).value);
            Assert.AreEqual(7, m_Manager.GetChunkComponentData <EcsTestData>(entity1).value);

            headers = group0.GetComponentDataArray <ChunkHeader>();
            Assert.AreEqual(1, headers.Length);

            m_Manager.SetChunkComponentData(chunk1, testData);

            headers = group0.GetComponentDataArray <ChunkHeader>();
            Assert.AreEqual(1, headers.Length);

            m_Manager.SetComponentData(entity1, new EcsTestData2 {
                value0 = 2, value1 = 3
            });

            headers = group0.GetComponentDataArray <ChunkHeader>();

            Assert.AreEqual(1, headers.Length);

            m_Manager.SetChunkComponentData <EcsTestData>(chunk0, new EcsTestData {
                value = 10
            });

            Assert.AreEqual(10, m_Manager.GetChunkComponentData <EcsTestData>(entity0).value);

            headers = group0.GetComponentDataArray <ChunkHeader>();

            Assert.AreEqual(1, headers.Length);
        }
Ejemplo n.º 8
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int entityOffset)
            {
                var testDataArray = chunk.GetNativeArray(ecsTestType);

                testDataArray[0] = new EcsTestData
                {
                    value = chunkIndex
                };
            }
            public void Execute(ArchetypeChunk batch, int batchIndex, int indexOfFirstEntityInQuery)
            {
                var testDataArray = batch.GetNativeArray(EcsTestTypeHandle);

                testDataArray[0] = new EcsTestData
                {
                    value = indexOfFirstEntityInQuery
                };
            }
            public void Execute(ArchetypeChunk batch, int batchIndex)
            {
                var testDataArray = batch.GetNativeArray(EcsTestTypeHandle);

                testDataArray[0] = new EcsTestData
                {
                    value = batchIndex
                };
            }
Ejemplo n.º 11
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                NativeArray <EcsTestData> chunkData = chunk.GetNativeArray(testType);

                for (int i = 0; i < chunk.Count; ++i)
                {
                    chunkData[i] = new EcsTestData()
                    {
                        value = 100 + chunkData[i].value
                    };
                }
            }
                public void Execute(int chunkIndex)
                {
                    var chunk       = Chunks[chunkIndex];
                    var ecsTestData = chunk.GetNativeArray(EcsTestDataType);

                    for (int i = 0; i < chunk.Count; i++)
                    {
                        ecsTestData[i] = new EcsTestData {
                            value = ecsTestData[i].value + 1
                        };
                    }
                }
Ejemplo n.º 13
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int entityOffset)
            {
                var testDataArray = chunk.GetNativeArray(ecsTestType);

                for (int i = 0; i < chunk.Count; ++i)
                {
                    testDataArray[i] = new EcsTestData
                    {
                        value = entityOffset + i
                    };
                }
            }
Ejemplo n.º 14
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();
        }
Ejemplo n.º 15
0
        public void LockedEntityFixedGrid2DSortMainThread()
        {
            var archetype     = m_Manager.CreateArchetype(typeof(EcsTestData), typeof(EcsTestData2));
            var chunkCapacity = archetype.ChunkCapacity;
            var width         = 100;
            var height        = 100;
            var entityCount   = width * height;
            var chunkCount    = (entityCount + (chunkCapacity - 1)) / chunkCapacity;
            var chunks        = new NativeArray <ArchetypeChunk>(chunkCount, Allocator.Persistent);

            m_Manager.CreateChunk(archetype, chunks, entityCount);
            m_Manager.LockChunk(chunks);

            var grid            = new ChunksFixedGrid2D(chunks, width, height);
            var ecsTestDataType = m_Manager.GetArchetypeChunkComponentType <EcsTestData>(false);
            var ecsTestDataGrid = new ComponentFixedGrid2D <EcsTestData>(ecsTestDataType, grid);

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    ecsTestDataGrid[x, y] = new EcsTestData(y);
                }
            }

            Assert.AreEqual(width, height);

            // Transpose emulates whatever kind of sorting you might do...
            for (int y = 0; y < width; y++)
            {
                for (int x = y + 1; x < width; x++)
                {
                    var leftChunkInstanceIndex = grid.ChunkinstanceIndex(x, y);
                    var leftChunk = grid.Chunks[grid.ChunkIndex(x, y)];
                    var rightChunkInstanceIndex = grid.ChunkinstanceIndex(y, x);
                    var rightChunk = grid.Chunks[grid.ChunkIndex(y, x)];

                    m_Manager.SwapComponents(leftChunk, leftChunkInstanceIndex, rightChunk, rightChunkInstanceIndex);
                }
            }

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    Assert.AreEqual(x, ecsTestDataGrid[x, y].value);
                }
            }

            chunks.Dispose();
            ecsTestDataGrid.Dispose();
        }
Ejemplo n.º 16
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();
        }
 public void GetComponentSetComponentThroughComponentDataFromEntity_SetsValue()
 {
     Entities
     .WithoutBurst()
     .ForEach((Entity entity, in EcsTestDataEntity tde) =>
     {
         var cdfeWrite     = GetComponentDataFromEntity <EcsTestData>(false);
         cdfeWrite[entity] = new EcsTestData()
         {
             value = GetComponentDataFromEntity <EcsTestData>(true)[tde.value1].value
         };
     }).Schedule();
     Dependency.Complete();
 }
Ejemplo n.º 18
0
        public void UpdateChunkComponent()
        {
            var         arch0  = m_Manager.CreateArchetype(ComponentType.ChunkComponent <EcsTestData>(), typeof(EcsTestData2));
            EntityQuery group0 = m_Manager.CreateEntityQuery(typeof(ChunkHeader), typeof(EcsTestData));

            var         entity0  = m_Manager.CreateEntity(arch0);
            var         chunk0   = m_Manager.GetChunk(entity0);
            EcsTestData testData = new EcsTestData {
                value = 7
            };

            Assert.AreEqual(1, group0.CalculateLength());

            m_Manager.SetChunkComponentData(chunk0, testData);

            Assert.AreEqual(1, group0.CalculateLength());

            Assert.AreEqual(7, m_Manager.GetChunkComponentData <EcsTestData>(entity0).value);

            m_Manager.SetComponentData(entity0, new EcsTestData2 {
                value0 = 1, value1 = 2
            });

            var entity1 = m_Manager.CreateEntity(arch0);
            var chunk1  = m_Manager.GetChunk(entity1);

            Assert.AreEqual(7, m_Manager.GetChunkComponentData <EcsTestData>(entity0).value);
            Assert.AreEqual(7, m_Manager.GetChunkComponentData <EcsTestData>(entity1).value);

            Assert.AreEqual(1, group0.CalculateLength());

            m_Manager.SetChunkComponentData(chunk1, testData);

            Assert.AreEqual(1, group0.CalculateLength());

            m_Manager.SetComponentData(entity1, new EcsTestData2 {
                value0 = 2, value1 = 3
            });

            Assert.AreEqual(1, group0.CalculateLength());

            m_Manager.SetChunkComponentData <EcsTestData>(chunk0, new EcsTestData {
                value = 10
            });

            Assert.AreEqual(10, m_Manager.GetChunkComponentData <EcsTestData>(entity0).value);

            Assert.AreEqual(1, group0.CalculateLength());
        }
Ejemplo n.º 19
0
        public void LockedEntityFixedGrid2DSort()
        {
            var archetype     = m_Manager.CreateArchetype(typeof(EcsTestData), typeof(EcsTestData2));
            var chunkCapacity = archetype.ChunkCapacity;
            var width         = 100;
            var height        = 100;
            var entityCount   = width * height;
            var chunkCount    = (entityCount + (chunkCapacity - 1)) / chunkCapacity;
            var chunks        = new NativeArray <ArchetypeChunk>(chunkCount, Allocator.Persistent);

            m_Manager.CreateChunk(archetype, chunks, entityCount);
            m_Manager.LockChunk(chunks);

            var grid            = new ChunksFixedGrid2D(chunks, width, height);
            var ecsTestDataType = m_Manager.GetArchetypeChunkComponentType <EcsTestData>(false);
            var ecsTestDataGrid = new ComponentFixedGrid2D <EcsTestData>(ecsTestDataType, grid);

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    ecsTestDataGrid[x, y] = new EcsTestData(y);
                }
            }

            // Transpose emulates whatever kind of sorting you might do...
            var job = new ChunksFixedGrid2DTranspose
            {
                entities  = m_Manager.BeginExclusiveEntityTransaction(),
                fixedGrid = grid
            };

            m_Manager.ExclusiveEntityTransactionDependency = job.Schedule(m_Manager.ExclusiveEntityTransactionDependency);
            m_Manager.EndExclusiveEntityTransaction();

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    Assert.AreEqual(x, ecsTestDataGrid[x, y].value);
                }
            }

            chunks.Dispose();
            ecsTestDataGrid.Dispose();
        }
Ejemplo n.º 20
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();
        }
            public void GetComponentDataFromEntityInEntitiesForEachWithNestedCaptures_ComponentAccessWorks()
            {
                var outerCapture = 2;
                {
                    var innerCapture = 10;
                    Entities
                    .ForEach((Entity entity, in EcsTestDataEntity tde) =>
                    {
                        if (HasComponent <EcsTestDataEntity>(entity))
                        {
                            outerCapture = 10;
                        }

                        var cdfeRead      = GetComponentDataFromEntity <EcsTestData>(true);
                        var val           = cdfeRead[tde.value1].value;
                        var cdfeWrite     = GetComponentDataFromEntity <EcsTestData>(false);
                        cdfeWrite[entity] = new EcsTestData(val * innerCapture * outerCapture);
                    }).Run();
                }
            }
            public void SetComponentThroughGetComponentDataFromEntity_SetsValue(Entity entity, ScheduleType scheduleType)
            {
                switch (scheduleType)
                {
                case ScheduleType.Run:
                    Entities.ForEach((ref EcsTestDataEntity tde) =>
                    {
                        var cdfe     = GetComponentDataFromEntity <EcsTestData>(false);
                        cdfe[entity] = new EcsTestData()
                        {
                            value = 2
                        };
                    }).Run();
                    break;

                case ScheduleType.Schedule:
                    Entities.ForEach((ref EcsTestDataEntity tde) =>
                    {
                        var cdfe     = GetComponentDataFromEntity <EcsTestData>(false);
                        cdfe[entity] = new EcsTestData()
                        {
                            value = 2
                        };
                    }).Schedule();
                    break;

                case ScheduleType.ScheduleParallel:
                    Entities.ForEach((ref EcsTestDataEntity tde) =>
                    {
                        var cdfe     = GetComponentDataFromEntity <EcsTestData>(false);
                        cdfe[entity] = new EcsTestData()
                        {
                            value = 2
                        };
                    }).ScheduleParallel();
                    break;
                }

                Dependency.Complete();
            }
        public void GroupCopyFromNativeArray()
        {
            var archetype = m_Manager.CreateArchetype(typeof(EcsTestData));
            var entities  = new NativeArray <Entity>(10, Allocator.Persistent);

            m_Manager.CreateEntity(archetype, entities);

            var dataToCopyA = new NativeArray <EcsTestData>(10, Allocator.Persistent);
            var dataToCopyB = new NativeArray <EcsTestData>(5, Allocator.Persistent);

            for (int i = 0; i < dataToCopyA.Length; ++i)
            {
                dataToCopyA[i] = new EcsTestData {
                    value = 2
                };
            }

            for (int i = 0; i < dataToCopyB.Length; ++i)
            {
                dataToCopyA[i] = new EcsTestData {
                    value = 3
                };
            }

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

            group.CopyFromComponentDataArray(dataToCopyA);

            for (int i = 0; i < dataToCopyA.Length; ++i)
            {
                Assert.AreEqual(m_Manager.GetComponentData <EcsTestData>(entities[i]).value, dataToCopyA[i].value);
            }

            Assert.Throws <ArgumentException>(() => { group.CopyFromComponentDataArray(dataToCopyB); });

            group.Dispose();
            entities.Dispose();
            dataToCopyA.Dispose();
            dataToCopyB.Dispose();
        }
Ejemplo n.º 24
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);
                    }
                }
            }
Ejemplo n.º 25
0
        [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);
        }
Ejemplo n.º 26
0
        public void RemoveComponent_ModifiedEntity_VisibleFromInsideForEach()
        {
            m_Manager.AddComponentData(m_Manager.CreateEntity(), new EcsTestData(5));
            MutableEntities.ForEach((Entity e, ref EcsTestData testData) =>
            {
                Assert.IsTrue(m_Manager.HasComponent <EcsTestData>(e));
                m_Manager.RemoveComponent <EcsTestData>(e);
                Assert.IsFalse(m_Manager.HasComponent <EcsTestData>(e));
                m_Manager.AddComponentData(e, new EcsTestData(123));
                Assert.IsTrue(m_Manager.HasComponent <EcsTestData>(e));
                {
                    EcsTestData d = m_Manager.GetComponentData <EcsTestData>(e);
                    Assert.AreEqual(123, d.value);
                    testData.value = 123;
                }

                m_Manager.AddSharedComponentData(e, new EcsTestSharedComp(22));
                Assert.IsTrue(m_Manager.HasComponent <EcsTestSharedComp>(e));
                m_Manager.RemoveComponent <EcsTestSharedComp>(e);
                Assert.IsFalse(m_Manager.HasComponent <EcsTestSharedComp>(e));

                Entity c = m_Manager.CreateEntity();
                m_Manager.AddComponentData(c, new EcsTestData(-22));
                Assert.IsTrue(m_Manager.HasComponent <EcsTestData>(c));
                m_Manager.RemoveComponent <EcsTestData>(c);
                Assert.IsFalse(m_Manager.HasComponent <EcsTestData>(c));
                m_Manager.AddComponentData(c, new EcsTestData(-123));

                m_Manager.RemoveComponent <EcsTestData>(c);
            });

            using (var group = m_Manager.CreateEntityQuery(typeof(EcsTestData)))
                using (var arr = group.ToComponentDataArray <EcsTestData>(Allocator.TempJob))
                {
                    Assert.AreEqual(1, arr.Length); // (e)
                    Assert.AreEqual(123, arr[0].value);
                }
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 28
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();
        }
Ejemplo n.º 29
0
        public void RunSimpleIJobChunk()
        {
            didDispose = 0;
            const int            N    = 10 * 1000;
            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();

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

#if NET_DOTS
            Assert.AreEqual(1, didDispose);
#endif

            eArr.Dispose();
        }
Ejemplo n.º 30
0
        public void LockedEntityFixedGrid2DAccess()
        {
            var archetype     = m_Manager.CreateArchetype(typeof(EcsTestData), typeof(EcsTestData2));
            var chunkCapacity = archetype.ChunkCapacity;
            var width         = 100;
            var height        = 100;
            var entityCount   = width * height;
            var chunkCount    = (entityCount + (chunkCapacity - 1)) / chunkCapacity;
            var chunks        = new NativeArray <ArchetypeChunk>(chunkCount, Allocator.Persistent);

            m_Manager.CreateChunk(archetype, chunks, entityCount);
            m_Manager.LockChunk(chunks);

            var grid            = new ChunksFixedGrid2D(chunks, width, height);
            var ecsTestDataType = m_Manager.GetArchetypeChunkComponentType <EcsTestData>(false);
            var ecsTestDataGrid = new ComponentFixedGrid2D <EcsTestData>(ecsTestDataType, grid);

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    ecsTestDataGrid[x, y] = new EcsTestData(x);
                }
            }

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    Assert.AreEqual(x, ecsTestDataGrid[x, y].value);
                }
            }

            ecsTestDataGrid.Dispose();
            chunks.Dispose();
        }