运行时缓存优化
This commit is contained in:
@@ -3,10 +3,12 @@ using System.Collections.Generic;
|
|||||||
using Convention;
|
using Convention;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System;
|
using System;
|
||||||
|
using Unity.Collections;
|
||||||
|
using UnityEngine.Rendering;
|
||||||
|
|
||||||
namespace Demo.Game
|
namespace Demo.Game
|
||||||
{
|
{
|
||||||
public class DDT : ScriptableObject, IEnumerable<float>
|
public class DDT : ScriptableObject
|
||||||
{
|
{
|
||||||
protected override bool IsSelfEnableUpdate => false;
|
protected override bool IsSelfEnableUpdate => false;
|
||||||
public static DDT Make()
|
public static DDT Make()
|
||||||
@@ -14,27 +16,31 @@ namespace Demo.Game
|
|||||||
return new GameObject().AddComponent<DDT>();
|
return new GameObject().AddComponent<DDT>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<float> Datas = new();
|
public NativeArray<float> Datas = new(128, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
|
||||||
|
public int Count { get; private set; } = 0;
|
||||||
|
|
||||||
[Convention.RScript.Variable.Attr.Method]
|
[Convention.RScript.Variable.Attr.Method]
|
||||||
public void Add(float value)
|
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]
|
[Convention.RScript.Variable.Attr.Method]
|
||||||
public void Add(int barSplitTimes, int barCount, int tickCount)
|
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]
|
[Convention.RScript.Variable.Attr.Method]
|
||||||
public float At(int index)
|
public float At(int index)
|
||||||
{
|
{
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
index = Datas.Count + index;
|
index = Count + index;
|
||||||
if (index < 0 || index >= Datas.Count)
|
if (index < 0 || index >= Count)
|
||||||
throw new IndexOutOfRangeException($"{index} is out of [0, {Datas.Count})");
|
throw new IndexOutOfRangeException($"{index} is out of [0, {Count})");
|
||||||
return Datas[index];
|
return Datas[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,19 +51,7 @@ namespace Demo.Game
|
|||||||
[Convention.RScript.Variable.Attr.Method]
|
[Convention.RScript.Variable.Attr.Method]
|
||||||
public int GetCount()
|
public int GetCount()
|
||||||
{
|
{
|
||||||
return Datas.Count;
|
return Count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerator<float> GetEnumerator()
|
|
||||||
{
|
|
||||||
return ((IEnumerable<float>)Datas).GetEnumerator();
|
|
||||||
}
|
|
||||||
|
|
||||||
IEnumerator IEnumerable.GetEnumerator()
|
|
||||||
{
|
|
||||||
return ((IEnumerable)Datas).GetEnumerator();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int Count => Datas.Count;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,9 +63,9 @@ namespace Demo.Game
|
|||||||
{
|
{
|
||||||
Entries.Sort((x, y) => x.TimePoint.CompareTo(y.TimePoint));
|
Entries.Sort((x, y) => x.TimePoint.CompareTo(y.TimePoint));
|
||||||
CompiledEntries = new(
|
CompiledEntries = new(
|
||||||
new NativeArray<float>(Entries.Count, Allocator.Persistent),
|
new NativeArray<float>(Entries.Count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory),
|
||||||
new NativeArray<DataType>(Entries.Count, Allocator.Persistent),
|
new NativeArray<DataType>(Entries.Count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory),
|
||||||
new NativeArray<MathExtension.EaseCurveType>(Entries.Count, Allocator.Persistent),
|
new NativeArray<MathExtension.EaseCurveType>(Entries.Count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory),
|
||||||
Entries.Count
|
Entries.Count
|
||||||
);
|
);
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user