public static JobHandle ScheduleParallel(this BuildCollisionLayerConfig config, out CollisionLayer layer, Allocator allocator, JobHandle inputDeps = default) { config.ValidateSettings(); var jh = inputDeps; if (config.hasQueryData) { int count = config.query.CalculateEntityCount(); layer = new CollisionLayer(count, config.settings, allocator); var layerIndices = new NativeArray <int>(count, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var xmins = new NativeArray <float>(count, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var aos = new NativeArray <BuildCollisionLayerInternal.ColliderAoSData>(count, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); NativeArray <int> remapSrcIndices = config.hasRemapSrcIndices ? config.remapSrcIndices : new NativeArray <int>(count, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); jh = new BuildCollisionLayerInternal.Part1FromQueryJob { layer = layer, typeGroup = config.typeGroup, layerIndices = layerIndices, xmins = xmins, colliderAoS = aos }.ScheduleParallel(config.query, 1, jh); jh = new BuildCollisionLayerInternal.Part2Job { layer = layer, layerIndices = layerIndices }.Schedule(jh); jh = new BuildCollisionLayerInternal.Part3Job { layerIndices = layerIndices, unsortedSrcIndices = remapSrcIndices }.ScheduleParallel(count, 512, jh); jh = new BuildCollisionLayerInternal.Part4Job { unsortedSrcIndices = remapSrcIndices, xmins = xmins, bucketStartAndCounts = layer.bucketStartsAndCounts }.ScheduleParallel(layer.BucketCount, 1, jh); jh = new BuildCollisionLayerInternal.Part5FromQueryJob { layer = layer, colliderAoS = aos, remapSrcIndices = remapSrcIndices }.ScheduleParallel(count, 128, jh); if (!config.hasRemapSrcIndices) { jh = remapSrcIndices.Dispose(jh); } return(jh); } else if (config.hasBodiesArray) { layer = new CollisionLayer(config.bodies.Length, config.settings, allocator); int count = config.bodies.Length; var layerIndices = new NativeArray <int>(count, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var xmins = new NativeArray <float>(count, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); NativeArray <int> remapSrcIndices = config.hasRemapSrcIndices ? config.remapSrcIndices : new NativeArray <int>(count, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); NativeArray <Aabb> aabbs = config.hasAabbsArray ? config.aabbs : new NativeArray <Aabb>(count, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); if (config.hasAabbsArray) { jh = new BuildCollisionLayerInternal.Part1FromDualArraysJob { layer = layer, aabbs = aabbs, layerIndices = layerIndices, xmins = xmins }.ScheduleParallel(count, 64, jh); } else { jh = new BuildCollisionLayerInternal.Part1FromColliderBodyArrayJob { layer = layer, aabbs = aabbs, colliderBodies = config.bodies, layerIndices = layerIndices, xmins = xmins }.ScheduleParallel(count, 64, jh); } jh = new BuildCollisionLayerInternal.Part2Job { layer = layer, layerIndices = layerIndices }.Schedule(jh); jh = new BuildCollisionLayerInternal.Part3Job { layerIndices = layerIndices, unsortedSrcIndices = remapSrcIndices }.ScheduleParallel(count, 512, jh); jh = new BuildCollisionLayerInternal.Part4Job { bucketStartAndCounts = layer.bucketStartsAndCounts, unsortedSrcIndices = remapSrcIndices, xmins = xmins }.ScheduleParallel(layer.BucketCount, 1, jh); jh = new BuildCollisionLayerInternal.Part5FromArraysJob { aabbs = aabbs, bodies = config.bodies, layer = layer, remapSrcIndices = remapSrcIndices }.ScheduleParallel(count, 128, jh); if ((!config.hasAabbsArray) && (!config.hasRemapSrcIndices)) { jh = JobHandle.CombineDependencies(remapSrcIndices.Dispose(jh), aabbs.Dispose(jh)); } else if (!config.hasRemapSrcIndices) { jh = remapSrcIndices.Dispose(jh); } else if (!config.hasAabbsArray) { jh = aabbs.Dispose(jh); } return(jh); } else { throw new InvalidOperationException("Something went wrong with the BuildCollisionError configuration."); } }
public static JobHandle ScheduleSingle(this BuildCollisionLayerConfig config, out CollisionLayer layer, Allocator allocator, JobHandle inputDeps = default) { config.ValidateSettings(); var jh = inputDeps; if (config.hasQueryData) { int count = config.count; layer = new CollisionLayer(count, config.settings, allocator); var layerIndices = new NativeArray <int>(count, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var aos = new NativeArray <BuildCollisionLayerInternal.ColliderAoSData>(count, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var xmins = new NativeArray <float>(count, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); NativeArray <int> remapSrcIndices = config.hasRemapSrcIndices ? config.remapSrcIndices : new NativeArray <int>(count, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); jh = new BuildCollisionLayerInternal.Part1FromQueryJob { typeGroup = config.typeGroup, layer = layer, layerIndices = layerIndices, colliderAoS = aos, xmins = xmins }.Schedule(config.query, jh); jh = new BuildCollisionLayerInternal.Part2Job { layer = layer, layerIndices = layerIndices }.Schedule(jh); jh = new BuildCollisionLayerInternal.Part3Job { layerIndices = layerIndices, unsortedSrcIndices = remapSrcIndices }.Schedule(count, jh); jh = new BuildCollisionLayerInternal.Part4Job { bucketStartAndCounts = layer.bucketStartsAndCounts, unsortedSrcIndices = remapSrcIndices, xmins = xmins }.Schedule(layer.BucketCount, jh); jh = new BuildCollisionLayerInternal.Part5FromQueryJob { colliderAoS = aos, layer = layer, remapSrcIndices = remapSrcIndices }.Schedule(count, jh); if (!config.hasRemapSrcIndices) { jh = remapSrcIndices.Dispose(jh); } return(jh); } else if (config.hasAabbsArray && config.hasBodiesArray) { layer = new CollisionLayer(config.aabbs.Length, config.settings, allocator); if (config.hasRemapSrcIndices) { jh = new BuildCollisionLayerInternal.BuildFromDualArraysSingleWithRemapJob { layer = layer, aabbs = config.aabbs, bodies = config.bodies, remapSrcIndices = config.remapSrcIndices }.Schedule(jh); } else { jh = new BuildCollisionLayerInternal.BuildFromDualArraysSingleJob { layer = layer, aabbs = config.aabbs, bodies = config.bodies }.Schedule(jh); } return(jh); } else if (config.hasBodiesArray) { layer = new CollisionLayer(config.bodies.Length, config.settings, allocator); if (config.hasRemapSrcIndices) { jh = new BuildCollisionLayerInternal.BuildFromColliderArraySingleWithRemapJob { layer = layer, bodies = config.bodies, remapSrcIndices = config.remapSrcIndices }.Schedule(jh); } else { jh = new BuildCollisionLayerInternal.BuildFromColliderArraySingleJob { layer = layer, bodies = config.bodies }.Schedule(jh); } return(jh); } else { throw new InvalidOperationException("Something went wrong with the BuildCollisionError configuration."); } }