public unsafe JobHandle GetEntityQueryMatchDiffAsync(EntityQuery query, NativeList <Entity> newEntities, NativeList <Entity> missingEntities) { using (k_GetEntityQueryMatchDiffAsync.Auto()) { newEntities.Clear(); missingEntities.Clear(); var queryMask = m_World.EntityManager.GetEntityQueryMask(query); var chunks = query.CreateArchetypeChunkArrayAsync(Allocator.TempJob, out var chunksJobHandle); k_GetEntityQueryMatchDiffAsyncAllocateBuffers.Begin(); m_GatheredChanges.Clear(); m_GatheredChanges.Resize(chunks.Length, NativeArrayOptions.ClearMemory); m_AllocatedShadowChunksForTheFrame.Clear(); m_AllocatedShadowChunksForTheFrame.ResizeUninitialized(chunks.Length); m_RemovedChunkEntities.Clear(); k_GetEntityQueryMatchDiffAsyncAllocateBuffers.End(); k_GetEntityQueryMatchDiffAsyncScheduling.Begin(); var gatherEntityChangesJob = new GatherEntityChangesJob { QueryMask = queryMask, Chunks = chunks, ShadowChunksBySequenceNumber = m_ShadowChunks, GatheredChanges = (ChangesCollector *)m_GatheredChanges.GetUnsafeList()->Ptr }.Schedule(chunks.Length, 1, chunksJobHandle); var allocateNewShadowChunksJobHandle = new AllocateNewShadowChunksJob { QueryMask = queryMask, Chunks = chunks, ShadowChunksBySequenceNumber = m_ShadowChunks, AllocatedShadowChunks = (ShadowChunk *)m_AllocatedShadowChunksForTheFrame.GetUnsafeList()->Ptr }.Schedule(chunks.Length, 1, chunksJobHandle); var copyJobHandle = new CopyEntityDataJob { QueryMask = queryMask, Chunks = chunks, // deallocate on job completion ShadowChunksBySequenceNumber = m_ShadowChunks, AllocatedShadowChunks = m_AllocatedShadowChunksForTheFrame, RemovedChunkEntities = m_RemovedChunkEntities }.Schedule(JobHandle.CombineDependencies(gatherEntityChangesJob, allocateNewShadowChunksJobHandle)); var concatResults = new ConcatResultsJob { GatheredChanges = m_GatheredChanges, // deallocate on job completion RemovedChunkEntities = m_RemovedChunkEntities, AddedEntities = newEntities, RemovedEntities = missingEntities }.Schedule(copyJobHandle); k_GetEntityQueryMatchDiffAsyncScheduling.End(); return(concatResults); } }
public unsafe JobHandle GetEntityQueryMatchDiffAsync(EntityQuery query, NativeList <Entity> newEntities, NativeList <Entity> missingEntities) { newEntities.Clear(); missingEntities.Clear(); var queryMask = m_World.EntityManager.GetEntityQueryMask(query); var chunks = query.CreateArchetypeChunkArrayAsync(Allocator.TempJob, out var chunksJobHandle); var gatheredChanges = new NativeArray <ChangesCollector>(chunks.Length, Allocator.TempJob); var allocatedShadowChunksForTheFrame = new NativeArray <ShadowChunk>(chunks.Length, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var removedChunkEntities = new NativeList <Entity>(Allocator.TempJob); var gatherEntityChangesJob = new GatherEntityChangesJob { QueryMask = queryMask, Chunks = chunks, ShadowChunksBySequenceNumber = m_ShadowChunks, GatheredChanges = (ChangesCollector *)NativeArrayUnsafeUtility.GetUnsafeBufferPointerWithoutChecks(gatheredChanges) }.Schedule(chunks.Length, 1, chunksJobHandle); var allocateNewShadowChunksJobHandle = new AllocateNewShadowChunksJob { QueryMask = queryMask, Chunks = chunks, ShadowChunksBySequenceNumber = m_ShadowChunks, AllocatedShadowChunks = (ShadowChunk *)NativeArrayUnsafeUtility.GetUnsafeBufferPointerWithoutChecks(allocatedShadowChunksForTheFrame) }.Schedule(chunks.Length, 1, chunksJobHandle); var copyJobHandle = new CopyEntityDataJob { QueryMask = queryMask, Chunks = chunks, // deallocate on job completion ShadowChunksBySequenceNumber = m_ShadowChunks, AllocatedShadowChunks = allocatedShadowChunksForTheFrame, // deallocate on job completion RemovedChunkEntities = removedChunkEntities }.Schedule(JobHandle.CombineDependencies(gatherEntityChangesJob, allocateNewShadowChunksJobHandle)); var concatResults = new ConcatResultsJob { GatheredChanges = gatheredChanges, // deallocate on job completion RemovedChunkEntities = removedChunkEntities.AsDeferredJobArray(), AddedEntities = newEntities, RemovedEntities = missingEntities }.Schedule(copyJobHandle); return(removedChunkEntities.Dispose(concatResults)); }