Exemple #1
0
        public DataBuffer(World world, ME.ECS.Collections.NativeBufferArray <Entity> arr, Unity.Collections.Allocator allocator = Unity.Collections.Allocator.Persistent)
        {
            var reg = (StructComponents <T>)world.currentState.structComponents.list.arr[WorldUtilities.GetAllComponentTypeId <T>()];

            this.arr = new NativeArrayBurst <T>(reg.components.data.arr, allocator);
            this.ops = new NativeArrayBurst <byte>(reg.components.data.arr.Length, allocator);
        }
        public static void Copy <T, TCopy>(NativeArrayBurst <T> fromArr, ref NativeArrayBurst <T> arr, TCopy copy)
            where TCopy : IArrayElementCopy <T> where T : struct
        {
            if (fromArr.IsCreated == false)
            {
                if (arr.IsCreated == true)
                {
                    NativeArrayUtils.Recycle(ref arr, copy);
                }
                arr = default;
                return;
            }

            if (arr.IsCreated == false || fromArr.Length != arr.Length)
            {
                if (arr.IsCreated == true)
                {
                    NativeArrayUtils.Recycle(ref arr, copy);
                }
                arr = new NativeArrayBurst <T>(fromArr.Length, Unity.Collections.Allocator.Persistent);
            }

            for (int i = 0; i < fromArr.Length; ++i)
            {
                copy.Copy(fromArr[i], ref arr.GetRef(i));
            }
        }
        public static void RecycleWithIndex <T, TCopy>(ref NativeArrayBurst <T> item, TCopy copy) where TCopy : IArrayElementCopyWithIndex <T> where T : struct
        {
            for (int i = 0; i < item.Length; ++i)
            {
                copy.Recycle(i, ref item.GetRef(i));
            }

            item.Dispose();
        }
        public static void Recycle <T, TCopy>(ref NativeArrayBurst <T> item, TCopy copy) where TCopy : IArrayElementCopy <T> where T : struct
        {
            for (int i = 0; i < item.Length; ++i)
            {
                copy.Recycle(item[i]);
            }

            item.Dispose();
        }
 public static unsafe void Clear <T>(NativeArrayBurst <T> arr, int index, int length) where T : struct
 {
     Unity.Collections.LowLevel.Unsafe.UnsafeUtility.MemClear((void *)((System.IntPtr)arr.GetUnsafePtr() + (int)((ulong)UnsafeUtility.SizeOf <T>() * (ulong)index)), (long)((ulong)UnsafeUtility.SizeOf <T>() * (ulong)length));
 }
 public static unsafe void Clear <T>(NativeArrayBurst <T> arr) where T : struct
 {
     Unity.Collections.LowLevel.Unsafe.UnsafeUtility.MemClear(arr.GetUnsafePtr(), UnsafeUtility.SizeOf <T>() * arr.Length);
 }