Optimize GC for motion string parsing.

This commit is contained in:
2023-04-18 10:10:11 +08:00
parent a7be55f2b0
commit f664708165

View File

@@ -294,6 +294,10 @@ namespace Cryville.Crtr {
} }
public class Motion : ChartEvent { public class Motion : ChartEvent {
static readonly PdtFragmentInterpreter _itor = new PdtFragmentInterpreter();
static readonly PropOp _vecop = new VectorOp(v => _vecbuf = v);
static float[] _vecbuf;
#pragma warning disable IDE1006 #pragma warning disable IDE1006
[JsonRequired] [JsonRequired]
public string motion { public string motion {
@@ -301,8 +305,6 @@ namespace Cryville.Crtr {
set { LoadFromString(value); } set { LoadFromString(value); }
} }
#pragma warning restore IDE1006 #pragma warning restore IDE1006
static readonly PdtFragmentInterpreter _itor = new PdtFragmentInterpreter();
private void LoadFromString(string s) { private void LoadFromString(string s) {
if (Node != null) if (Node != null)
throw new InvalidOperationException("The motion property can only be set at initialization"); throw new InvalidOperationException("The motion property can only be set at initialization");
@@ -323,19 +325,16 @@ namespace Cryville.Crtr {
var exp = _itor.GetExp(); var exp = _itor.GetExp();
switch (c) { switch (c) {
case '@': case '@':
ChartPlayer.etor.Evaluate(new VectorOp(v => { ChartPlayer.etor.Evaluate(_vecop, exp);
Node.Time = new Vec1(v); Node.Time = new Vec1(_vecbuf);
}), exp);
break; break;
case '~': case '~':
ChartPlayer.etor.Evaluate(new VectorOp(v => { ChartPlayer.etor.Evaluate(_vecop, exp);
Node.EndTime = new Vec1(v); Node.EndTime = new Vec1(_vecbuf);
}), exp);
break; break;
case ':': case ':':
ChartPlayer.etor.Evaluate(new VectorOp(v => { ChartPlayer.etor.Evaluate(_vecop, exp);
Node.Value = Vector.Construct(ChartPlayer.motionRegistry[Name].Type, v); Node.Value = Vector.Construct(ChartPlayer.motionRegistry[Name].Type, _vecbuf);
}), exp);
break; break;
default: default:
throw new ArgumentException("Invalid motion string format"); throw new ArgumentException("Invalid motion string format");