protected static EventQueue EnqueueComponent <T>(T component = default) where T : struct, IComponentData { var(baseQueue, componentQueue, bufferQueue) = new QueueRig <T, EcsIntElement>(Allocator.Temp); componentQueue.Enqueue(component); return(baseQueue); }
protected static EventQueue EnqueueBuffer <T1, T2>(T1 component, NativeArray <T2> bufferElements) where T1 : struct, IComponentData where T2 : unmanaged, IBufferElementData { var(baseQueue, componentQueue, bufferQueue) = new QueueRig <T1, T2>(Allocator.Temp); bufferQueue.Enqueue(component, bufferElements); return(baseQueue); }
public void EnqueuesFromBurst() { var(baseQueue, componentQueue, bufferQueue) = new QueueRig <EcsTestData, EcsIntElement>(Allocator.Temp); new EnqueuesFromBurstJob { Events = componentQueue, }.Schedule().Complete(); new EnqueuesFromBurstJob { Events = componentQueue, }.Run(); Assert.AreEqual(2, baseQueue.ComponentCount()); }
public void EnqueuesToCorrectThread([Values(1, 10, 100)] int jobCount, [Values(1, 2, 10)] int numPerThread) { var threadIds = new NativeArray <int>(jobCount, Allocator.TempJob); var threadUsages = new NativeArray <int>(JobsUtility.MaxJobThreadCount, Allocator.TempJob); var(baseQueue, componentQueue, bufferQueue) = new QueueRig <EcsTestData, EcsIntElement>(Allocator.TempJob); try { var handle = IJobParallelForExtensions.Schedule(new EnqueuesToCorrectThreadJob { Events = componentQueue, ThreadIds = threadIds, ThreadUsages = threadUsages }, jobCount, numPerThread); handle.Complete(); for (int i = 0; i < jobCount; i++) { var threadId = threadIds[i]; var usageCount = threadUsages[threadId]; if (usageCount == 0) { continue; } var size = baseQueue.GetComponentsForThread(threadId).Length; var componentCountForThread = size / sizeof(EcsTestData); if (usageCount != componentCountForThread) { Debugger.Break(); } Assert.AreEqual(usageCount, componentCountForThread); } } finally { threadIds.Dispose(); threadUsages.Dispose(); baseQueue.Dispose(); } }
private EventQueue EnqueueBufferFromChunkJobDynamicBuffer() { var components = new[] { ComponentType.ReadWrite <EcsTestData2>(), ComponentType.ReadWrite <EcsIntElement>() }; var query = Manager.CreateEntityQuery(components); var arch = Manager.CreateArchetype(components); var entity = Manager.CreateEntity(arch); var testComponent = GetDefaultComponent2(); Manager.SetComponentData(entity, testComponent); var testBuffer = GetDefaultBufferData(); var buffer = Manager.GetBuffer <EcsIntElement>(entity); buffer.AddRange(testBuffer); var(baseQueue, componentQueue, bufferQueue) = new QueueRig <EcsTestData, EcsIntElement>(Allocator.Temp); var handle1 = new EnqueuesFromDynamicBufferJob { ComponentType = Manager.GetArchetypeChunkComponentType <EcsTestData2>(true), BufferType = Manager.GetArchetypeChunkBufferType <EcsIntElement>(true), Events = bufferQueue }.ScheduleSingle(query); var handle2 = new EnqueuesFromDynamicBufferJob { ComponentType = Manager.GetArchetypeChunkComponentType <EcsTestData2>(true), BufferType = Manager.GetArchetypeChunkBufferType <EcsIntElement>(true), Events = bufferQueue }.ScheduleSingle(query); EmptySystem.AddDependencies(handle1, handle2); handle1.Complete(); handle2.Complete(); return(baseQueue); }