#region using Unity.Collections; using Unity.Collections.LowLevel.Unsafe; using UnityEngine.Serialization; #endregion namespace nadena.dev.modular_avatar.core.armature_lock { /// /// Abstractly, an armature lock job works by taking the local transforms of the base armature and target armature, /// deciding whether to abort updates, and if not, what the transforms should be set to, and writing out the /// results. /// /// This struct handles these common inputs and outputs for different armature lock types. /// internal struct ArmatureLockJobAccessor { internal void Allocate(int nBones, int nWords) { _in_baseBone = new NativeArray(nBones, Allocator.Persistent); _in_targetBone = new NativeArray(nBones, Allocator.Persistent); _out_baseBone = new NativeArray(nBones, Allocator.Persistent); _out_targetBone = new NativeArray(nBones, Allocator.Persistent); _out_dirty_baseBone = new NativeArray(nBones, Allocator.Persistent); _out_dirty_targetBone = new NativeArray(nBones, Allocator.Persistent); _boneToJobIndex = new NativeArray(nBones, Allocator.Persistent); _abortFlag = new NativeArray(nWords, Allocator.Persistent); _didAnyWriteFlag = new NativeArray(nWords, Allocator.Persistent); } internal void Destroy() { if (_in_baseBone.IsCreated) _in_baseBone.Dispose(); _in_baseBone = default; if (_in_targetBone.IsCreated) _in_targetBone.Dispose(); _in_targetBone = default; if (_out_baseBone.IsCreated) _out_baseBone.Dispose(); _out_baseBone = default; if (_out_targetBone.IsCreated) _out_targetBone.Dispose(); _out_targetBone = default; if (_out_dirty_baseBone.IsCreated) _out_dirty_baseBone.Dispose(); _out_dirty_baseBone = default; if (_out_dirty_targetBone.IsCreated) _out_dirty_targetBone.Dispose(); _out_dirty_targetBone = default; if (_boneToJobIndex.IsCreated) _boneToJobIndex.Dispose(); _boneToJobIndex = default; if (_abortFlag.IsCreated) _abortFlag.Dispose(); _abortFlag = default; if (_didAnyWriteFlag.IsCreated) _didAnyWriteFlag.Dispose(); _didAnyWriteFlag = default; } /// /// Initial transform states /// public NativeArray _in_baseBone, _in_targetBone; /// /// Transform states to write out (if _out_dirty is set) /// public NativeArray _out_baseBone, _out_targetBone; /// /// Flags indicating whether the given bone should be written back to its transform /// public NativeArray _out_dirty_baseBone, _out_dirty_targetBone; /// /// Indexed by the job index (via _boneToJobIndex). If set to a nonzero value, none of the bones in this /// particular job (e.g. a single MergeArmature component) will be committed. /// /// Note: This array is written simultaneously from multiple threads. Jobs may set this to 1, but otherwise /// shouldn't read this value. /// [NativeDisableContainerSafetyRestriction] [NativeDisableParallelForRestriction] public NativeArray _abortFlag; /// /// Indexed by the job index (via _boneToJobIndex). Should be set to a nonzero value when any bone in the job /// has changes that need to be written out. /// /// Note: This array is written simultaneously from multiple threads. Jobs may set this to 1, but otherwise /// shouldn't read this value. /// [NativeDisableContainerSafetyRestriction] [NativeDisableParallelForRestriction] public NativeArray _didAnyWriteFlag; /// /// Maps from bone index to job index. /// [FormerlySerializedAs("_statusWordIndex")] public NativeArray _boneToJobIndex; } }