Skip to content

Commit

Permalink
Fix CollisionLayer DistanceBetween bugs and make more jobs BurstSched…
Browse files Browse the repository at this point in the history
…ulable

DistanceBetween using CollisionLayer didn't inflate the initial AABB collider. And none of the variants accounted for negative maxDistance values. This is all fixed now.

In addition, I did a project-wide search to find more instances of IJob, IJobFor, and IJobParallelFor and switched them to their BurstSchedulable counterparts. I'm likely going to have to undo that when 1.0 drops, but whatevs. That's the least of my 1.0 concerns.
  • Loading branch information
Dreaming381 committed Sep 27, 2022
1 parent 9028ee8 commit 6d5f1cd
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private unsafe void RunPrepInJob(ref bool ran, ref NativeList<Entity> entities)
}

[BurstCompile]
private struct PrepJob : IJob
private struct PrepJob : IJobBurstSchedulable
{
[ReadOnly] public EntityOperationCommandBuffer eocb;
public NativeList<Entity> entities;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private void RunPrepInJob(BufferFromEntity<LinkedEntityGroup> linkedFE, ref bool
}

[BurstCompile]
private struct PrepJob : IJob
private struct PrepJob : IJobBurstSchedulable
{
[ReadOnly] public BufferFromEntity<LinkedEntityGroup> linkedFE;
[ReadOnly] public EntityOperationCommandBuffer eocb;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private void RunPrepInJob(BufferFromEntity<LinkedEntityGroup> linkedFE, ref bool
}

[BurstCompile]
private struct PrepJob : IJob
private struct PrepJob : IJobBurstSchedulable
{
[ReadOnly] public BufferFromEntity<LinkedEntityGroup> linkedFE;
[ReadOnly] public EntityOperationCommandBuffer eocb;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ internal EntityOperationCommandBuffer(AllocatorManager.AllocatorHandle allocator
}

[BurstCompile]
private struct DisposeJob : IJob
private struct DisposeJob : IJobBurstSchedulable
{
[NativeDisableUnsafePtrRestriction]
public State* state;
Expand Down Expand Up @@ -461,3 +461,5 @@ void CheckWriteAccess()





Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void CheckDidNotPlayback()

#region PlaybackJobs
[BurstCompile]
private struct PlaybackJob : IJob
private struct PlaybackJob : IJobBurstSchedulable
{
[ReadOnly] public EntityOperationCommandBuffer eocb;
public ExclusiveEntityTransaction eet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ void CheckBlockCountMatchesCount(int count, int blockCount)
}

[BurstCompile]
struct DisposeJob : IJob
struct DisposeJob : IJobBurstSchedulable
{
public UnsafeParallelBlockList upbl;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ internal InstantiateCommandBufferUntyped(AllocatorManager.AllocatorHandle alloca
}

[BurstCompile]
private struct DisposeJob : IJob
private struct DisposeJob : IJobBurstSchedulable
{
[NativeDisableUnsafePtrRestriction]
public State* state;
Expand Down Expand Up @@ -356,7 +356,7 @@ public ParallelWriter AsParallelWriter()

#region Implementation
[BurstCompile]
private struct InstantiateAndBuildListsJob : IJob
private struct InstantiateAndBuildListsJob : IJobBurstSchedulable
{
[ReadOnly] public InstantiateCommandBufferUntyped icb;
//public ExclusiveEntityTransaction eet;
Expand Down Expand Up @@ -486,7 +486,7 @@ void TryRun(ref bool ran)
}

[BurstCompile]
private struct WriteComponentDataJob : IJobFor
private struct WriteComponentDataJob : IJobParallelForBurstSchedulable
{
[ReadOnly] public InstantiateCommandBufferUntyped icb;
[ReadOnly] public NativeArray<ArchetypeChunk> chunks;
Expand Down Expand Up @@ -877,3 +877,9 @@ void CheckHasNotPlayedBack()









Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public JobHandle ScheduleSingle(JobHandle inputDeps = default)
layer = layer,
colors = colors,
crossColor = crossColor
}.Schedule(layer.BucketCount, inputDeps);
}.Schedule(inputDeps);
}

/// <summary>
Expand All @@ -101,7 +101,7 @@ public JobHandle ScheduleParallel(JobHandle inputDeps = default)
layer = layer,
colors = colors,
crossColor = crossColor
}.ScheduleParallel(layer.BucketCount, 1, inputDeps);
}.Schedule(layer.BucketCount, 1, inputDeps);
}
}

Expand Down Expand Up @@ -281,10 +281,10 @@ public JobHandle ScheduleSingle(JobHandle inputDeps = default)
missColor = missColor,
drawMisses = drawMisses
};
jh = job.Schedule(layerA.Count, jh);
jh = job.Schedule(jh);
job.hitArray = hitArrayB;
job.layer = layerB;
jh = job.Schedule(layerB.Count, jh);
jh = job.Schedule(jh);
jh = hitArrayA.Dispose(jh);
return hitArrayB.Dispose(jh);
}
Expand All @@ -300,7 +300,7 @@ public JobHandle ScheduleSingle(JobHandle inputDeps = default)
hitColor = hitColor,
missColor = missColor,
drawMisses = drawMisses
}.Schedule(layerA.Count, jh);
}.Schedule(jh);
return hitArray.Dispose(jh);
}
}
Expand All @@ -326,10 +326,10 @@ public JobHandle ScheduleParallel(JobHandle inputDeps = default)
missColor = missColor,
drawMisses = drawMisses
};
jh = job.ScheduleParallel(layerA.Count, 64, jh);
jh = job.Schedule(layerA.Count, 64, jh);
job.hitArray = hitArrayB;
job.layer = layerB;
jh = job.ScheduleParallel(layerB.Count, 64, jh);
jh = job.Schedule(layerB.Count, 64, jh);
jh = hitArrayA.Dispose(jh);
return hitArrayB.Dispose(jh);
}
Expand All @@ -345,7 +345,7 @@ public JobHandle ScheduleParallel(JobHandle inputDeps = default)
hitColor = hitColor,
missColor = missColor,
drawMisses = drawMisses
}.ScheduleParallel(layerA.Count, 64, jh);
}.Schedule(layerA.Count, 64, jh);
return hitArray.Dispose(jh);
}
}
Expand Down Expand Up @@ -385,12 +385,18 @@ public static void DrawAabb(Aabb aabb, Color color)

#region DrawLayerUtils
[BurstCompile]
private struct DebugDrawLayerJob : IJobFor
private struct DebugDrawLayerJob : IJobBurstSchedulable, IJobParallelForBurstSchedulable
{
[ReadOnly] public CollisionLayer layer;
public FixedList512Bytes<Color> colors;
public Color crossColor;

public void Execute()
{
for (int i = 0; i < layer.BucketCount; i++)
Execute(i);
}

public void Execute(int index)
{
if (index < layer.BucketCount - 1)
Expand Down Expand Up @@ -442,14 +448,20 @@ public void Execute(in FindPairsResult result)
}

[BurstCompile]
private struct DebugFindPairsDrawJob : IJobFor
private struct DebugFindPairsDrawJob : IJobBurstSchedulable, IJobParallelForBurstSchedulable
{
[ReadOnly] public CollisionLayer layer;
[ReadOnly] public NativeBitArray hitArray;
public Color hitColor;
public Color missColor;
public bool drawMisses;

public void Execute()
{
for (int i = 0; i < layer.Count; i++)
Execute(i);
}

public void Execute(int i)
{
float3 min = new float3(layer.xmins[i], layer.yzminmaxs[i].xy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ internal static JobHandle LogFindPairsStats(CollisionLayer layerA,
}

[BurstCompile]
struct LogBucketCountsForLayerJob : IJob
struct LogBucketCountsForLayerJob : IJobBurstSchedulable
{
[ReadOnly] public CollisionLayer layer;
public FixedString128Bytes layerName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal static class FindObjectsInternal
{
#region Jobs
[BurstCompile]
public struct Single : IJob
public struct Single : IJobBurstSchedulable
{
[ReadOnly] public CollisionLayer layer;
public T processor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal static class FindPairsInternal
{
#region Jobs
[BurstCompile]
public struct LayerSelfSingle : IJob
public struct LayerSelfSingle : IJobBurstSchedulable
{
[ReadOnly] public CollisionLayer layer;
public T processor;
Expand All @@ -28,7 +28,7 @@ public void Execute()
}

[BurstCompile]
public struct LayerSelfPart1 : IJobParallelFor
public struct LayerSelfPart1 : IJobParallelForBurstSchedulable
{
[ReadOnly] public CollisionLayer layer;
public T processor;
Expand All @@ -41,7 +41,7 @@ public void Execute(int index)
}

[BurstCompile]
public struct LayerSelfPart2 : IJob
public struct LayerSelfPart2 : IJobBurstSchedulable
{
[ReadOnly] public CollisionLayer layer;
public T processor;
Expand All @@ -58,7 +58,7 @@ public void Execute()
}

[BurstCompile]
public struct LayerSelfParallelUnsafe : IJobFor
public struct LayerSelfParallelUnsafe : IJobParallelForBurstSchedulable
{
[ReadOnly] public CollisionLayer layer;
public T processor;
Expand Down Expand Up @@ -105,7 +105,7 @@ public static void RunImmediate(CollisionLayer layer, T processor)
#if ENABLE_UNITY_COLLECTIONS_CHECKS
// Scheudle for 2 iterations
[BurstCompile]
public struct LayerSelfPart2_WithSafety : IJobFor
public struct LayerSelfPart2_WithSafety : IJobParallelForBurstSchedulable
{
[ReadOnly] public CollisionLayer layer;
public T processor;
Expand Down Expand Up @@ -156,7 +156,7 @@ internal static class FindPairsInternal

// Schedule for (2 * layer.BucketCount - 1) iterations
[BurstCompile]
public struct LayerSelfPart1 : IJobParallelFor, IFindPairsProcessor
public struct LayerSelfPart1 : IJobParallelForBurstSchedulable, IFindPairsProcessor
{
[ReadOnly] public CollisionLayer layer;
public T processor;
Expand Down Expand Up @@ -188,7 +188,7 @@ public void Execute(in FindPairsResult result)
}

[BurstCompile]
public struct LayerSelfPart2 : IJob
public struct LayerSelfPart2 : IJobBurstSchedulable
{
[ReadOnly] public CollisionLayer layer;
public T processor;
Expand Down Expand Up @@ -220,7 +220,7 @@ public void Execute()

// Schedule for 2 iterations
[BurstCompile]
public struct LayerSelfPart2_WithSafety : IJobFor
public struct LayerSelfPart2_WithSafety : IJobParallelForBurstSchedulable
{
[ReadOnly] public CollisionLayer layer;
public T processor;
Expand Down Expand Up @@ -277,7 +277,7 @@ internal static class FindPairsInternal
{
#region Jobs
[BurstCompile]
public struct LayerLayerSingle : IJob
public struct LayerLayerSingle : IJobBurstSchedulable
{
[ReadOnly] public CollisionLayer layerA;
[ReadOnly] public CollisionLayer layerB;
Expand All @@ -290,7 +290,7 @@ public void Execute()
}

[BurstCompile]
public struct LayerLayerPart1 : IJobParallelFor
public struct LayerLayerPart1 : IJobParallelForBurstSchedulable
{
[ReadOnly] public CollisionLayer layerA;
[ReadOnly] public CollisionLayer layerB;
Expand All @@ -306,7 +306,7 @@ public void Execute(int index)

// Schedule for 2 iterations
[BurstCompile]
public struct LayerLayerPart2 : IJobParallelFor
public struct LayerLayerPart2 : IJobParallelForBurstSchedulable
{
[ReadOnly] public CollisionLayer layerA;
[ReadOnly] public CollisionLayer layerB;
Expand Down Expand Up @@ -337,7 +337,7 @@ public void Execute(int index)

// Schedule for (3 * layer.BucketCount - 2) iterations
[BurstCompile]
public struct LayerLayerParallelUnsafe : IJobFor
public struct LayerLayerParallelUnsafe : IJobParallelForBurstSchedulable
{
[ReadOnly] public CollisionLayer layerA;
[ReadOnly] public CollisionLayer layerB;
Expand Down Expand Up @@ -404,7 +404,7 @@ public static void RunImmediate(CollisionLayer layerA, CollisionLayer layerB, T

// Schedule for 3 iterations
[BurstCompile]
public struct LayerLayerPart2_WithSafety : IJobParallelFor
public struct LayerLayerPart2_WithSafety : IJobParallelForBurstSchedulable
{
[ReadOnly] public CollisionLayer layerA;
[ReadOnly] public CollisionLayer layerB;
Expand Down Expand Up @@ -479,7 +479,7 @@ internal static class FindPairsInternal

// Schedule for (3 * layer.BucketCount - 2) iterations
[BurstCompile]
public struct LayerLayerPart1 : IJobParallelFor, IFindPairsProcessor
public struct LayerLayerPart1 : IJobParallelForBurstSchedulable, IFindPairsProcessor
{
[ReadOnly] public CollisionLayer layerA;
[ReadOnly] public CollisionLayer layerB;
Expand Down Expand Up @@ -524,7 +524,7 @@ public void Execute(in FindPairsResult result)

// Schedule for 2 iterations
[BurstCompile]
public struct LayerLayerPart2 : IJobParallelFor
public struct LayerLayerPart2 : IJobParallelForBurstSchedulable
{
[ReadOnly] public CollisionLayer layerA;
[ReadOnly] public CollisionLayer layerB;
Expand Down Expand Up @@ -673,7 +673,7 @@ public void Execute()
}

[BurstCompile]
public struct LayerSelfPart1 : IJobParallelFor
public struct LayerSelfPart1 : IJobParallelForBurstSchedulable
{
[ReadOnly] public CollisionLayer layer;
public T processor;
Expand Down Expand Up @@ -833,7 +833,7 @@ public void Execute()
}

[BurstCompile]
public struct LayerLayerPart1 : IJobParallelFor
public struct LayerLayerPart1 : IJobParallelForBurstSchedulable
{
[ReadOnly] public CollisionLayer layerA;
[ReadOnly] public CollisionLayer layerB;
Expand All @@ -853,7 +853,7 @@ public void Execute(int index)
}

[BurstCompile]
public struct LayerLayerPart2 : IJobParallelFor
public struct LayerLayerPart2 : IJobParallelForBurstSchedulable
{
[ReadOnly] public CollisionLayer layerA;
[ReadOnly] public CollisionLayer layerB;
Expand Down
Loading

0 comments on commit 6d5f1cd

Please sign in to comment.