Update input feeding logic.

This commit is contained in:
2022-11-12 01:00:31 +08:00
parent d10e6ea18b
commit 35040e4ebd
2 changed files with 14 additions and 21 deletions

View File

@@ -107,20 +107,11 @@ namespace Cryville.Crtr {
readonly object _lock = new object(); readonly object _lock = new object();
static readonly int _var_value = IdentifierManager.SharedInstance.Request("value"); static readonly int _var_value = IdentifierManager.SharedInstance.Request("value");
static readonly int _var_ft = IdentifierManager.SharedInstance.Request("ft");
static readonly int _var_tt = IdentifierManager.SharedInstance.Request("tt");
static readonly PropOp.Arbitrary _arbop = new PropOp.Arbitrary(); static readonly PropOp.Arbitrary _arbop = new PropOp.Arbitrary();
readonly byte[] _numbuf = new byte[sizeof(float)];
readonly byte[] _numbuf2 = new byte[sizeof(float)];
readonly byte[] _vecbuf = new byte[3 * sizeof(float) + sizeof(int)]; readonly byte[] _vecbuf = new byte[3 * sizeof(float) + sizeof(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>();
unsafe void LoadNum(float value) { static readonly byte[] _nullvalue = new byte[0];
fixed (byte* ptr = _numbuf) *(float*)ptr = value;
}
unsafe void LoadNum2(float value) {
fixed (byte* ptr = _numbuf2) *(float*)ptr = value;
}
unsafe void OnInput(InputIdentifier id, InputVector vec) { unsafe void OnInput(InputIdentifier id, InputVector vec) {
lock (_lock) { lock (_lock) {
InputProxyEntry proxy; InputProxyEntry proxy;
@@ -128,9 +119,6 @@ namespace Cryville.Crtr {
_etor.ContextCascadeInsert(); _etor.ContextCascadeInsert();
float ft, tt = (float)vec.Time; float ft, tt = (float)vec.Time;
if (!_vect.TryGetValue(id, out ft)) ft = tt; if (!_vect.TryGetValue(id, out ft)) ft = tt;
LoadNum(ft); _etor.ContextCascadeUpdate(_var_ft, new PropSrc.Arbitrary(PdtInternalType.Number, _numbuf));
LoadNum2(tt); _etor.ContextCascadeUpdate(_var_tt, new PropSrc.Arbitrary(PdtInternalType.Number, _numbuf2));
_vect[id] = tt;
if (vec.IsNull) { if (vec.IsNull) {
_etor.ContextCascadeUpdate(_var_value, new PropSrc.Arbitrary(PdtInternalType.Null, new byte[0])); _etor.ContextCascadeUpdate(_var_value, new PropSrc.Arbitrary(PdtInternalType.Null, new byte[0]));
} }
@@ -140,21 +128,22 @@ namespace Cryville.Crtr {
} }
_etor.ContextCascadeUpdate(_var_value, new PropSrc.Arbitrary(PdtInternalType.Vector, _vecbuf)); _etor.ContextCascadeUpdate(_var_value, new PropSrc.Arbitrary(PdtInternalType.Vector, _vecbuf));
} }
OnInput(id, proxy.Target); OnInput(id, proxy.Target, ft, tt);
_vect[id] = tt;
_etor.ContextCascadeDiscard(); _etor.ContextCascadeDiscard();
} }
} }
} }
static readonly int _var_fv = IdentifierManager.SharedInstance.Request("fv"); static readonly int _var_fv = IdentifierManager.SharedInstance.Request("fv");
static readonly int _var_tv = IdentifierManager.SharedInstance.Request("tv"); static readonly int _var_tv = IdentifierManager.SharedInstance.Request("tv");
unsafe void OnInput(InputIdentifier id, string target) { unsafe void OnInput(InputIdentifier id, Identifier target, float ft, float tt) {
var def = _ruleset.inputs[target]; var def = _ruleset.inputs[target];
if (def.pass != null) { if (def.pass != null) {
foreach (var p in def.pass) { foreach (var p in def.pass) {
_etor.ContextCascadeInsert(); _etor.ContextCascadeInsert();
_arbop.Name = _var_value; _arbop.Name = _var_value;
_etor.Evaluate(_arbop, p.Value); _etor.Evaluate(_arbop, p.Value);
OnInput(id, p.Key); OnInput(id, p.Key, ft, tt);
_etor.ContextCascadeDiscard(); _etor.ContextCascadeDiscard();
} }
} }
@@ -164,11 +153,12 @@ namespace Cryville.Crtr {
if (!_vecs.TryGetValue(pid, out fv)) fv = new PropSrc.Arbitrary(PdtInternalType.Null, new byte[0]); if (!_vecs.TryGetValue(pid, out fv)) fv = new PropSrc.Arbitrary(PdtInternalType.Null, new byte[0]);
if (fv.Type != PdtInternalType.Null || tv.Type != PdtInternalType.Null) { if (fv.Type != PdtInternalType.Null || tv.Type != PdtInternalType.Null) {
_etor.ContextCascadeInsert(); _etor.ContextCascadeInsert();
_etor.ContextCascadeUpdate(_var_tv, tv);
_etor.ContextCascadeUpdate(_var_fv, fv); _etor.ContextCascadeUpdate(_var_fv, fv);
_judge.Feed(target); _etor.ContextCascadeUpdate(_var_tv, tv);
_judge.Feed(target, ft, tt);
_etor.ContextCascadeDiscard(); _etor.ContextCascadeDiscard();
} }
_judge.Cleanup(target, ft, tt);
_vecs[pid] = tv; _vecs[pid] = tv;
} }
} }
@@ -194,7 +184,7 @@ namespace Cryville.Crtr {
public struct ProxiedInputIdentifier : IEquatable<ProxiedInputIdentifier> { public struct ProxiedInputIdentifier : IEquatable<ProxiedInputIdentifier> {
public InputIdentifier Source { get; set; } public InputIdentifier Source { get; set; }
public string Target { get; set; } public Identifier Target { get; set; }
public override bool Equals(object obj) { public override bool Equals(object obj) {
if (obj == null || !(obj is ProxiedInputIdentifier)) return false; if (obj == null || !(obj is ProxiedInputIdentifier)) return false;
return Equals((ProxiedInputIdentifier)obj); return Equals((ProxiedInputIdentifier)obj);

View File

@@ -31,8 +31,11 @@ namespace Cryville.Crtr {
} }
list.Add(time + def.clip[0], new JudgeEvent { EndTime = time + def.clip[1], Definition = def, State = container }); list.Add(time + def.clip[0], new JudgeEvent { EndTime = time + def.clip[1], Definition = def, State = container });
} }
public void Feed(InputEvent ev) { public void Feed(string target, float ft, float tt) {
Logger.Log("main", 0, "Judge", "Feed {0}: {1}->{2}", target, ft, tt);
}
public void Cleanup(string target, float ft, float tt) {
Logger.Log("main", 0, "Judge", "Cleanup {0}: {1}->{2}", target, ft, tt);
} }
public readonly Dictionary<int, ScoreDefinition> scoreDefs = new Dictionary<int, ScoreDefinition>(); public readonly Dictionary<int, ScoreDefinition> scoreDefs = new Dictionary<int, ScoreDefinition>();
public readonly Dictionary<int, float> scores = new Dictionary<int, float>(); public readonly Dictionary<int, float> scores = new Dictionary<int, float>();