From 8722a9920c1f6119bf6e769cba270e63097f8e25 Mon Sep 17 00:00:00 2001
From: chai <215380520@qq.com>
Date: Thu, 23 May 2024 10:08:29 +0800
Subject: + astar project
---
.../Graphs/Grid/Jobs/JobCopyBuffers.cs | 50 ++++++++++++++++++++++
1 file changed, 50 insertions(+)
create mode 100644 Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Graphs/Grid/Jobs/JobCopyBuffers.cs
(limited to 'Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Graphs/Grid/Jobs/JobCopyBuffers.cs')
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 {
+ ///
+ /// 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 jobs in one (to avoid scheduling overhead).
+ /// See that job for more documentation.
+ ///
+ [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.Copy(input.positions, output.positions, inputSlice, outputSlice);
+ JobCopyRectangle.Copy(input.normals, output.normals, inputSlice, outputSlice);
+ JobCopyRectangle.Copy(input.connections, output.connections, inputSlice, outputSlice);
+ if (copyPenaltyAndTags) {
+ JobCopyRectangle.Copy(input.penalties, output.penalties, inputSlice, outputSlice);
+ JobCopyRectangle.Copy(input.tags, output.tags, inputSlice, outputSlice);
+ }
+ JobCopyRectangle.Copy(input.walkable, output.walkable, inputSlice, outputSlice);
+ JobCopyRectangle.Copy(input.walkableWithErosion, output.walkableWithErosion, inputSlice, outputSlice);
+ }
+ }
+}
--
cgit v1.1-26-g67d0