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>()) { ; } } }
public void EmptyTransformAccessArrayWorks() { var group = EmptySystem.GetComponentGroup(typeof(Transform), typeof(TransformAccessArrayTestTag)); var ta = group.GetTransformAccessArray(); Assert.AreEqual(0, ta.length); }
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()); }
public void JobProcessWithFilteredComponentGroup() { 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.GetComponentGroup(typeof(EcsTestData), typeof(EcsTestSharedComp)); group.SetFilter(new EcsTestSharedComp { value = 1 }); var processJob = new ProcessFilteredData(); processJob.ScheduleGroup(group).Complete(); Assert.AreEqual(10, m_Manager.GetComponentData <EcsTestData>(entityInGroupA).value); Assert.AreEqual(5, m_Manager.GetComponentData <EcsTestData>(entityInGroupB).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); } }
// 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 RequireSingletonWorks() { EmptySystem.RequireSingletonForUpdate<EcsTestData>(); EmptySystem.GetComponentGroup(typeof(EcsTestData2)); m_Manager.CreateEntity(typeof(EcsTestData2)); Assert.IsFalse(EmptySystem.ShouldRunSystem()); m_Manager.CreateEntity(typeof(EcsTestData)); Assert.IsTrue(EmptySystem.ShouldRunSystem()); }
public void StructuralChangeAfterSchedulingNoDependenciesJobThrows() { var archetype = m_Manager.CreateArchetype(typeof(EcsTestData)); var entity = m_Manager.CreateEntity(archetype); var group = EmptySystem.GetComponentGroup(typeof(EcsTestData)); var handle = new NoDependenciesJob().Schedule(group); Assert.Throws <InvalidOperationException>(() => m_Manager.DestroyEntity(entity)); handle.Complete(); }
public void JobProcessComponentWithEntityGroupCorrect() { ComponentType[] expectedTypes = { ComponentType.ReadOnly <EcsTestData>(), ComponentType.Create <EcsTestData2>(), ComponentType.Create <EcsTestData3>() }; new Process3Entity().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); }
void CheckFilter(NativeArray <int> indexList) { var group = EmptySystem.GetComponentGroup(typeof(EcsTestData)); group.SetFilter(indexList); var array = group.GetComponentDataArray <EcsTestData>(); for (int i = 0; i != indexList.Length; i++) { Assert.AreEqual(indexList[i], array[i].value); } }
public void ReadOnlyDynamicBufferImpl(bool readOnlyType) { var original = m_Manager.CreateEntity(typeof(EcsIntElement)); var buffer = m_Manager.GetBuffer<EcsIntElement>(original); buffer.Add(5); var group = EmptySystem.GetComponentGroup(new EntityArchetypeQuery {All = new ComponentType[] {typeof(EcsIntElement)}}); var job = new ReadOnlyJob { Int = EmptySystem.GetArchetypeChunkBufferType<EcsIntElement>(readOnlyType) }; job.Schedule(group).Complete(); }
public void GetComponentGroupWithDuplicates() { // Currently duplicates will create two seperate groups doing the same thing... ComponentType[] dup_1 = { typeof(EcsTestData2) }; ComponentType[] dup_2 = { typeof(EcsTestData2), typeof(EcsTestData2) }; var dup1_system = EmptySystem.GetComponentGroup(dup_1); var dup2_system = EmptySystem.GetComponentGroup(dup_2); Assert.AreEqual(dup1_system, EmptySystem.GetComponentGroup(dup_1)); Assert.AreEqual(dup2_system, EmptySystem.GetComponentGroup(dup_2)); Assert.AreEqual(2, EmptySystem.ComponentGroups.Length); }
public void ReadWriteDynamicBuffer() { var original = m_Manager.CreateEntity(typeof(EcsIntElement)); var buffer = m_Manager.GetBuffer<EcsIntElement>(original); buffer.Add(5); var group = EmptySystem.GetComponentGroup(new EntityArchetypeQuery {All = new ComponentType[] {typeof(EcsIntElement)}}); var job = new WriteJob { //@TODO: Throw exception when read only flag is not accurately passed to job for buffers... Int = EmptySystem.GetArchetypeChunkBufferType<EcsIntElement>() }; job.Schedule(group).Complete(); }
public void GetComponentGroupRespectsRWAccessInequality() { var query1 = new EntityArchetypeQuery { All = new [] { ComponentType.ReadOnly <EcsTestData>(), ComponentType.ReadWrite <EcsTestData2>() } }; var query2 = new EntityArchetypeQuery { All = new [] { ComponentType.ReadOnly <EcsTestData>(), ComponentType.ReadOnly <EcsTestData2>() } }; var group1 = EmptySystem.GetComponentGroup(query1); var group2 = EmptySystem.GetComponentGroup(query2); Assert.AreNotEqual(group1, group2); Assert.AreEqual(2, EmptySystem.ComponentGroups.Length); }
public void GetComponentGroup() { ComponentType[] ro_rw = { ComponentType.ReadOnly <EcsTestData>(), typeof(EcsTestData2) }; ComponentType[] rw_rw = { typeof(EcsTestData), typeof(EcsTestData2) }; ComponentType[] rw = { typeof(EcsTestData) }; var ro_rw0_system = EmptySystem.GetComponentGroup(ro_rw); var rw_rw_system = EmptySystem.GetComponentGroup(rw_rw); var rw_system = EmptySystem.GetComponentGroup(rw); Assert.AreEqual(ro_rw0_system, EmptySystem.GetComponentGroup(ro_rw)); Assert.AreEqual(rw_rw_system, EmptySystem.GetComponentGroup(rw_rw)); Assert.AreEqual(rw_system, EmptySystem.GetComponentGroup(rw)); Assert.AreEqual(3, EmptySystem.ComponentGroups.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.GetComponentGroup(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); }
public void GetComponentGroupComponentTypeArchetypeQueryEquality() { var query1 = new ComponentType[] { typeof(EcsTestData) }; var query2 = new EntityArchetypeQuery { All = new ComponentType[] { typeof(EcsTestData) } }; var query3 = new EntityArchetypeQuery { All = new [] { ComponentType.ReadWrite <EcsTestData>() } }; var group1 = EmptySystem.GetComponentGroup(query1); var group2 = EmptySystem.GetComponentGroup(query2); var group3 = EmptySystem.GetComponentGroup(query3); Assert.AreEqual(group1, group2); Assert.AreEqual(group2, group3); Assert.AreEqual(1, EmptySystem.ComponentGroups.Length); }
public void GetComponentGroupArchetypeQuery() { var query1 = new ComponentType[] { typeof(EcsTestData) }; var query2 = new EntityArchetypeQuery { All = new ComponentType[] { typeof(EcsTestData) } }; var query3 = new EntityArchetypeQuery { All = new ComponentType[] { typeof(EcsTestData), typeof(EcsTestData2) } }; var group1 = EmptySystem.GetComponentGroup(query1); var group2 = EmptySystem.GetComponentGroup(query2); var group3 = EmptySystem.GetComponentGroup(query3); Assert.AreEqual(group1, EmptySystem.GetComponentGroup(query1)); Assert.AreEqual(group2, EmptySystem.GetComponentGroup(query2)); Assert.AreEqual(group3, EmptySystem.GetComponentGroup(query3)); Assert.AreEqual(3, EmptySystem.ComponentGroups.Length); }
public void DestroyAndGetNewTransformAccessArrayUpdatesContent() { var go = new GameObject(); go.AddComponent <TransformAccessArrayTestTagComponent>(); var go2 = new GameObject(); go2.AddComponent <TransformAccessArrayTestTagComponent>(); var group = EmptySystem.GetComponentGroup(typeof(Transform), typeof(TransformAccessArrayTestTag)); var ta = group.GetTransformAccessArray(); Assert.AreEqual(2, ta.length); Object.DestroyImmediate(go); ta = group.GetTransformAccessArray(); Assert.AreEqual(1, ta.length); Object.DestroyImmediate(go2); }
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.GetComponentGroup(componentTypes); Assert.AreEqual(1, EmptySystem.ComponentGroups.Length); Assert.IsTrue(EmptySystem.ComponentGroups[0].CompareComponents(componentTypes)); Assert.AreEqual(group, EmptySystem.ComponentGroups[0]); componentTypes.Dispose(); }
public void GetComponentGroupOrderIndependent() { var query1 = new ComponentType[] { typeof(EcsTestData), typeof(EcsTestData2) }; var query2 = new ComponentType[] { typeof(EcsTestData2), typeof(EcsTestData) }; var group1 = EmptySystem.GetComponentGroup(query1); var group2 = EmptySystem.GetComponentGroup(query2); Assert.AreEqual(group1, group2); Assert.AreEqual(1, EmptySystem.ComponentGroups.Length); var query3 = new EntityArchetypeQuery { All = new ComponentType[] { typeof(EcsTestData2), typeof(EcsTestData3) } }; var query4 = new EntityArchetypeQuery { All = new ComponentType[] { typeof(EcsTestData3), typeof(EcsTestData2) } }; var group3 = EmptySystem.GetComponentGroup(query3); var group4 = EmptySystem.GetComponentGroup(query4); Assert.AreEqual(group3, group4); Assert.AreEqual(2, EmptySystem.ComponentGroups.Length); }
public void GetComponentGroupWithEntityThrows() { ComponentType[] e = { typeof(Entity), typeof(EcsTestData) }; EmptySystem.GetComponentGroup(e); Assert.Throws <ArgumentException>(() => EmptySystem.GetComponentGroup(e)); }