public void CreateAndDestroy([Values(1, 100, 200)] int count) { var stream = new NativeStream(count, Allocator.Temp); Assert.IsTrue(stream.IsCreated); Assert.IsTrue(stream.ForEachCount == count); Assert.IsTrue(stream.ComputeItemCount() == 0); stream.Dispose(); Assert.IsFalse(stream.IsCreated); }
public void ItemCount([Values(1, 100, 200)] int count, [Values(1, 3, 10)] int batchSize) { var stream = new NativeStream(count, Allocator.TempJob); var fillInts = new WriteInts { Writer = stream.AsWriter() }; fillInts.Schedule(count, batchSize).Complete(); Assert.AreEqual(count * (count - 1) / 2, stream.ComputeItemCount()); stream.Dispose(); }
public static int Count(this NativeStream stream) => stream.ComputeItemCount();
public unsafe void BuildTreeAndOverlapTasks([Values(2, 10, 33, 100)] int elementCount) { const int threadCount = 8; elementCount *= 2; var tree = new Broadphase.Tree(elementCount); var points = new NativeArray <PointAndIndex>(elementCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var aabbs = new NativeArray <Aabb>(elementCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var branchCount = new NativeArray <int>(1, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); InitInputWithCopyArrays(points, aabbs, tree.BodyFilters); // Override filter data with default filters. for (int i = 0; i < tree.BodyFilters.Length; i++) { tree.BodyFilters[i] = CollisionFilter.Default; } for (int i = 0; i < tree.NodeFilters.Length; i++) { tree.NodeFilters[i] = CollisionFilter.Default; } var branchNodeOffset = new NativeArray <int>(Constants.MaxNumTreeBranches, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var shouldDoWork = new NativeArray <int>(1, Allocator.Persistent); shouldDoWork[0] = 1; int oldBranchCount = branchCount[0]; JobHandle handle = new BuildFirstNLevelsJob { Points = points, Nodes = (Node *)tree.Nodes.GetUnsafePtr(), Ranges = tree.Ranges, BranchNodeOffsets = branchNodeOffset, BranchCount = branchCount, ThreadCount = threadCount, ShouldDoWork = shouldDoWork }.Schedule(); handle = new BuildBranchesJob { Points = points, Aabbs = aabbs, BodyFilters = tree.BodyFilters, Nodes = (Node *)tree.Nodes.GetUnsafePtr(), Ranges = tree.Ranges, BranchNodeOffsets = branchNodeOffset, BranchCount = branchCount }.ScheduleUnsafeIndex0(branchCount, 1, handle); new FinalizeTreeJob { Aabbs = aabbs, LeafFilters = tree.BodyFilters, Nodes = (Node *)tree.Nodes.GetUnsafePtr(), BranchNodeOffsets = branchNodeOffset, NumNodes = tree.Nodes.Length, BranchCount = branchCount, ShouldDoWork = shouldDoWork, OldBranchCount = oldBranchCount }.Schedule(handle).Complete(); int numBranchOverlapPairs = branchCount[0] * (branchCount[0] + 1) / 2; var nodePairIndices = new NativeList <int2>(Allocator.TempJob); nodePairIndices.ResizeUninitialized(numBranchOverlapPairs); var collisionPairs = new NativeStream(numBranchOverlapPairs, Allocator.TempJob); handle = new Broadphase.DynamicVsDynamicBuildBranchNodePairsJob { Ranges = tree.Ranges, NumBranches = branchCount, NodePairIndices = nodePairIndices }.Schedule(); handle = new Broadphase.DynamicVsDynamicFindOverlappingPairsJob { DynamicTree = tree, NodePairIndices = nodePairIndices, PairWriter = collisionPairs.AsWriter() }.Schedule(nodePairIndices, numBranchOverlapPairs, handle); handle.Complete(); int numPairs = collisionPairs.ComputeItemCount(); Assert.AreEqual(elementCount / 2, numPairs); //Debug.Log($"Num colliding pairs: {numPairs}"); tree.BoundingVolumeHierarchy.CheckIntegrity(); nodePairIndices.Dispose(); tree.Dispose(); collisionPairs.Dispose(); branchCount.Dispose(); shouldDoWork.Dispose(); }