| | 1 | | // Copyright (c) 2020-2024 dotBunny Inc. |
| | 2 | | // dotBunny licenses this file to you under the BSL-1.0 license. |
| | 3 | | // See the LICENSE file in the project root for more information. |
| | 4 | |
|
| | 5 | | using Unity.Burst; |
| | 6 | | using Unity.Collections; |
| | 7 | | using Unity.Jobs; |
| | 8 | |
|
| | 9 | | namespace GDX.Jobs.ParallelFor |
| | 10 | | { |
| | 11 | | /// <summary> |
| | 12 | | /// Swaps a <see cref="NativeArray{T}" /> typed as <see cref="int" /> with a another |
| | 13 | | /// in parallel. |
| | 14 | | /// </summary> |
| | 15 | | /// <remarks> |
| | 16 | | /// <para> |
| | 17 | | /// The <see cref="IntegerBufferSwapJob" /> relies on the <see cref="IJobParallelFor" /> which |
| | 18 | | /// requires UnityEngine.CoreModule.dll. |
| | 19 | | /// </para> |
| | 20 | | /// </remarks> |
| | 21 | | [BurstCompile] |
| | 22 | | public struct IntegerBufferSwapJob : IJobParallelFor |
| | 23 | | { |
| | 24 | | /// <summary> |
| | 25 | | /// The left-hand side <see cref="NativeArray{T}" /> typed as <see cref="int" />. |
| | 26 | | /// </summary> |
| | 27 | | public NativeArray<int> A; |
| | 28 | |
|
| | 29 | | /// <summary> |
| | 30 | | /// The right-hand side <see cref="NativeArray{T}" /> typed as <see cref="int" />. |
| | 31 | | /// </summary> |
| | 32 | | public NativeArray<int> B; |
| | 33 | |
|
| | 34 | | /// <summary> |
| | 35 | | /// Executable work for the provided index. |
| | 36 | | /// </summary> |
| | 37 | | /// <param name="index">The index of the Parallel for loop at which to perform work.</param> |
| | 38 | | public void Execute(int index) |
| 0 | 39 | | { |
| 0 | 40 | | (A[index], B[index]) = (B[index], A[index]); |
| 0 | 41 | | } |
| | 42 | | } |
| | 43 | | } |