summaryrefslogtreecommitdiff
path: root/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Graphs/Grid/Jobs/JobCopyBuffers.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2024-05-23 10:08:29 +0800
committerchai <215380520@qq.com>2024-05-23 10:08:29 +0800
commit8722a9920c1f6119bf6e769cba270e63097f8e25 (patch)
tree2eaf9865de7fb1404546de4a4296553d8f68cc3b /Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Graphs/Grid/Jobs/JobCopyBuffers.cs
parent3ba4020b69e5971bb0df7ee08b31d10ea4d01937 (diff)
+ astar project
Diffstat (limited to 'Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Graphs/Grid/Jobs/JobCopyBuffers.cs')
-rw-r--r--Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Graphs/Grid/Jobs/JobCopyBuffers.cs50
1 files changed, 50 insertions, 0 deletions
diff --git a/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Graphs/Grid/Jobs/JobCopyBuffers.cs b/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Graphs/Grid/Jobs/JobCopyBuffers.cs
new file mode 100644
index 0000000..690448f
--- /dev/null
+++ b/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Graphs/Grid/Jobs/JobCopyBuffers.cs
@@ -0,0 +1,50 @@
+using UnityEngine;
+using Unity.Burst;
+using Unity.Collections;
+using Unity.Jobs;
+using Unity.Mathematics;
+using Pathfinding.Jobs;
+using UnityEngine.Assertions;
+
+namespace Pathfinding.Graphs.Grid.Jobs {
+ /// <summary>
+ /// Copies 3D arrays with grid data from one shape to another.
+ ///
+ /// Only the data for the nodes that exist in both buffers will be copied.
+ ///
+ /// This essentially is several <see cref="JobCopyRectangle"/> jobs in one (to avoid scheduling overhead).
+ /// See that job for more documentation.
+ /// </summary>
+ [BurstCompile]
+ public struct JobCopyBuffers : IJob {
+ [ReadOnly]
+ [DisableUninitializedReadCheck]
+ public GridGraphNodeData input;
+
+ [WriteOnly]
+ public GridGraphNodeData output;
+ public IntBounds bounds;
+
+ public bool copyPenaltyAndTags;
+
+ public void Execute () {
+#if ENABLE_UNITY_COLLECTIONS_CHECKS
+ if (!input.bounds.Contains(bounds)) throw new System.ArgumentException("Bounds are outside the source buffer");
+ if (!output.bounds.Contains(bounds)) throw new System.ArgumentException("Bounds are outside the destination buffer");
+#endif
+ var inputSlice = new Slice3D(input.bounds, bounds);
+ var outputSlice = new Slice3D(output.bounds, bounds);
+ // Note: Having a single job that copies all of the buffers avoids a lot of scheduling overhead.
+ // We do miss out on parallelization, however for this job it is not that significant.
+ JobCopyRectangle<Vector3>.Copy(input.positions, output.positions, inputSlice, outputSlice);
+ JobCopyRectangle<float4>.Copy(input.normals, output.normals, inputSlice, outputSlice);
+ JobCopyRectangle<ulong>.Copy(input.connections, output.connections, inputSlice, outputSlice);
+ if (copyPenaltyAndTags) {
+ JobCopyRectangle<uint>.Copy(input.penalties, output.penalties, inputSlice, outputSlice);
+ JobCopyRectangle<int>.Copy(input.tags, output.tags, inputSlice, outputSlice);
+ }
+ JobCopyRectangle<bool>.Copy(input.walkable, output.walkable, inputSlice, outputSlice);
+ JobCopyRectangle<bool>.Copy(input.walkableWithErosion, output.walkableWithErosion, inputSlice, outputSlice);
+ }
+ }
+}