Optimize GC for input proxy.

This commit is contained in:
2022-11-21 14:09:44 +08:00
parent 109b489104
commit a0174b94c6

View File

@@ -17,6 +17,7 @@ namespace Cryville.Crtr {
*(int*)(ptr + 3 * sizeof(float)) = PdtInternalType.Number; *(int*)(ptr + 3 * sizeof(float)) = PdtInternalType.Number;
} }
} }
_vecsrc = new PropSrc.Arbitrary(PdtInternalType.Vector, _vecbuf);
_etor = ChartPlayer.etor; _etor = ChartPlayer.etor;
_ruleset = ruleset; _ruleset = ruleset;
_judge = judge; _judge = judge;
@@ -168,11 +169,12 @@ namespace Cryville.Crtr {
static readonly int _var_value = IdentifierManager.SharedInstance.Request("value"); static readonly int _var_value = IdentifierManager.SharedInstance.Request("value");
static readonly PropOp.Arbitrary _arbop = new PropOp.Arbitrary(); static readonly PropOp.Arbitrary _arbop = new PropOp.Arbitrary();
readonly byte[] _vecbuf = new byte[3 * sizeof(float) + sizeof(int)]; readonly byte[] _vecbuf = new byte[3 * sizeof(float) + sizeof(int)];
readonly PropSrc.Arbitrary _vecsrc;
readonly Dictionary<InputHandler, double> _timeOrigins = new Dictionary<InputHandler, double>(); readonly Dictionary<InputHandler, double> _timeOrigins = new Dictionary<InputHandler, double>();
readonly Dictionary<InputSource, int> _activeCounts = new Dictionary<InputSource, int>(); readonly Dictionary<InputSource, int> _activeCounts = new Dictionary<InputSource, int>();
readonly Dictionary<InputIdentifier, float> _vect = new Dictionary<InputIdentifier, float>(); readonly Dictionary<InputIdentifier, float> _vect = new Dictionary<InputIdentifier, float>();
readonly Dictionary<ProxiedInputIdentifier, PropSrc.Arbitrary> _vecs = new Dictionary<ProxiedInputIdentifier, PropSrc.Arbitrary>(); readonly Dictionary<ProxiedInputIdentifier, PropSrc.Arbitrary> _vecs = new Dictionary<ProxiedInputIdentifier, PropSrc.Arbitrary>();
static readonly byte[] _nullvalue = new byte[0]; static readonly PropSrc.Arbitrary _nullsrc = new PropSrc.Arbitrary(PdtInternalType.Null, new byte[0]);
unsafe void OnInput(InputIdentifier id, InputVector vec) { unsafe void OnInput(InputIdentifier id, InputVector vec) {
lock (_lock) { lock (_lock) {
InputProxyEntry proxy; InputProxyEntry proxy;
@@ -181,14 +183,15 @@ namespace Cryville.Crtr {
float ft, tt = (float)(vec.Time - _timeOrigins[id.Source.Handler]); float ft, tt = (float)(vec.Time - _timeOrigins[id.Source.Handler]);
if (!_vect.TryGetValue(id, out ft)) ft = tt; if (!_vect.TryGetValue(id, out ft)) ft = tt;
if (vec.IsNull) { if (vec.IsNull) {
_etor.ContextCascadeUpdate(_var_value, new PropSrc.Arbitrary(PdtInternalType.Null, _nullvalue)); _etor.ContextCascadeUpdate(_var_value, _nullsrc);
OnInput(id, proxy.Target, ft, tt, true); OnInput(id, proxy.Target, ft, tt, true);
} }
else { else {
fixed (byte* ptr = _vecbuf) { fixed (byte* ptr = _vecbuf) {
*(Vector3*)ptr = vec.Vector; *(Vector3*)ptr = vec.Vector;
} }
_etor.ContextCascadeUpdate(_var_value, new PropSrc.Arbitrary(PdtInternalType.Vector, _vecbuf)); _vecsrc.Invalidate();
_etor.ContextCascadeUpdate(_var_value, _vecsrc);
OnInput(id, proxy.Target, ft, tt, false); OnInput(id, proxy.Target, ft, tt, false);
} }
_vect[id] = tt; _vect[id] = tt;
@@ -212,7 +215,7 @@ namespace Cryville.Crtr {
else { else {
var pid = new ProxiedInputIdentifier { Source = id, Target = target }; var pid = new ProxiedInputIdentifier { Source = id, Target = target };
PropSrc.Arbitrary fv, tv = _etor.ContextCascadeLookup(_var_value); PropSrc.Arbitrary fv, tv = _etor.ContextCascadeLookup(_var_value);
if (!_vecs.TryGetValue(pid, out fv)) fv = new PropSrc.Arbitrary(PdtInternalType.Null, _nullvalue); if (!_vecs.TryGetValue(pid, out fv)) fv = _nullsrc;
if (fv.Type != PdtInternalType.Null || tv.Type != PdtInternalType.Null) { if (fv.Type != PdtInternalType.Null || tv.Type != PdtInternalType.Null) {
if (fv.Type == PdtInternalType.Null) _activeCounts[id.Source]++; if (fv.Type == PdtInternalType.Null) _activeCounts[id.Source]++;
_etor.ContextCascadeInsert(); _etor.ContextCascadeInsert();