-
Notifications
You must be signed in to change notification settings - Fork 30
/
QuadTreeJobs.cs
54 lines (47 loc) · 1.07 KB
/
QuadTreeJobs.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using Unity.Burst;
using Unity.Collections;
using Unity.Jobs;
namespace NativeQuadTree
{
/// <summary>
/// Examples on jobs for the NativeQuadTree
/// </summary>
public static class QuadTreeJobs
{
/// <summary>
/// Bulk insert many items into the tree
/// </summary>
[BurstCompile]
public struct AddBulkJob<T> : IJob where T : unmanaged
{
[ReadOnly]
public NativeArray<QuadElement<T>> Elements;
public NativeQuadTree<T> QuadTree;
public void Execute()
{
QuadTree.ClearAndBulkInsert(Elements);
}
}
/// <summary>
/// Example on how to do a range query, it's better to write your own and do many queries in a batch
/// </summary>
[BurstCompile]
public struct RangeQueryJob<T> : IJob where T : unmanaged
{
[ReadOnly]
public AABB2D Bounds;
[ReadOnly]
public NativeQuadTree<T> QuadTree;
public NativeList<QuadElement<T>> Results;
public void Execute()
{
for (int i = 0; i < 1000; i++)
{
QuadTree.RangeQuery(Bounds, Results);
Results.Clear();
}
QuadTree.RangeQuery(Bounds, Results);
}
}
}
}