diff --git a/Assets/Scripts/Framework/DDT.cs b/Assets/Scripts/Framework/DDT.cs index 1ce13fd..0ca99eb 100644 --- a/Assets/Scripts/Framework/DDT.cs +++ b/Assets/Scripts/Framework/DDT.cs @@ -3,10 +3,12 @@ using System.Collections.Generic; using Convention; using UnityEngine; using System; +using Unity.Collections; +using UnityEngine.Rendering; namespace Demo.Game { - public class DDT : ScriptableObject, IEnumerable + public class DDT : ScriptableObject { protected override bool IsSelfEnableUpdate => false; public static DDT Make() @@ -14,27 +16,31 @@ namespace Demo.Game return new GameObject().AddComponent(); } - public List Datas = new(); + public NativeArray Datas = new(128, Allocator.Persistent, NativeArrayOptions.UninitializedMemory); + public int Count { get; private set; } = 0; [Convention.RScript.Variable.Attr.Method] public void Add(float value) { - Datas.Add(value); + if (Count >= Datas.Length) + Datas.ResizeArray(Mathf.FloorToInt(Count * 1.5f)); + Datas[Count] = value; + Count++; } [Convention.RScript.Variable.Attr.Method] public void Add(int barSplitTimes, int barCount, int tickCount) { - Datas.Add((barCount + tickCount / (float)barSplitTimes) * OneBarTime); + Add((barCount + tickCount / (float)barSplitTimes) * OneBarTime); } [Convention.RScript.Variable.Attr.Method] public float At(int index) { if (index < 0) - index = Datas.Count + index; - if (index < 0 || index >= Datas.Count) - throw new IndexOutOfRangeException($"{index} is out of [0, {Datas.Count})"); + index = Count + index; + if (index < 0 || index >= Count) + throw new IndexOutOfRangeException($"{index} is out of [0, {Count})"); return Datas[index]; } @@ -45,19 +51,7 @@ namespace Demo.Game [Convention.RScript.Variable.Attr.Method] public int GetCount() { - return Datas.Count; + return Count; } - - public IEnumerator GetEnumerator() - { - return ((IEnumerable)Datas).GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return ((IEnumerable)Datas).GetEnumerator(); - } - - public int Count => Datas.Count; } } diff --git a/Assets/Scripts/Framework/Updatement.cs b/Assets/Scripts/Framework/Updatement.cs index 9faac30..24e30ba 100644 --- a/Assets/Scripts/Framework/Updatement.cs +++ b/Assets/Scripts/Framework/Updatement.cs @@ -63,9 +63,9 @@ namespace Demo.Game { Entries.Sort((x, y) => x.TimePoint.CompareTo(y.TimePoint)); CompiledEntries = new( - new NativeArray(Entries.Count, Allocator.Persistent), - new NativeArray(Entries.Count, Allocator.Persistent), - new NativeArray(Entries.Count, Allocator.Persistent), + new NativeArray(Entries.Count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory), + new NativeArray(Entries.Count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory), + new NativeArray(Entries.Count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory), Entries.Count ); int index = 0;