|
|
|
@@ -4,6 +4,7 @@ using Cryville.Common.Unity.Input;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using Logger = Cryville.Common.Logger;
|
|
|
|
|
|
|
|
|
|
namespace Cryville.Crtr {
|
|
|
|
|
public class InputProxy {
|
|
|
|
@@ -42,6 +43,7 @@ namespace Cryville.Crtr {
|
|
|
|
|
if (_use[proxy.Target] > 0)
|
|
|
|
|
throw new InvalidOperationException("Input already assigned");
|
|
|
|
|
if (proxy.Source != null) {
|
|
|
|
|
proxy.Source.Value.Handler.OnInput -= OnInput; // Prevent duplicated hooks, no exception will be thrown
|
|
|
|
|
proxy.Source.Value.Handler.OnInput += OnInput;
|
|
|
|
|
_tproxies.Add(proxy.Target, proxy);
|
|
|
|
|
_sproxies.Add(proxy.Source.Value, proxy);
|
|
|
|
@@ -101,25 +103,22 @@ namespace Cryville.Crtr {
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Handling
|
|
|
|
|
public void Activate() { foreach (var src in _sproxies.Keys) src.Handler.Activate(); }
|
|
|
|
|
public void Activate() {
|
|
|
|
|
_activeCounts.Clear();
|
|
|
|
|
foreach (var p in _tproxies.Values) _activeCounts.Add(p.Source.Value, 0);
|
|
|
|
|
_vect.Clear(); _vecs.Clear();
|
|
|
|
|
foreach (var src in _sproxies.Keys) src.Handler.Activate();
|
|
|
|
|
}
|
|
|
|
|
public void Deactivate() { foreach (var src in _sproxies.Keys) src.Handler.Deactivate(); }
|
|
|
|
|
|
|
|
|
|
readonly object _lock = new object();
|
|
|
|
|
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();
|
|
|
|
|
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 Dictionary<InputSource, int> _activeCounts = new Dictionary<InputSource, int>(); // TODO used for force tick
|
|
|
|
|
readonly Dictionary<InputIdentifier, float> _vect = new Dictionary<InputIdentifier, float>();
|
|
|
|
|
readonly Dictionary<ProxiedInputIdentifier, PropSrc.Arbitrary> _vecs = new Dictionary<ProxiedInputIdentifier, PropSrc.Arbitrary>();
|
|
|
|
|
unsafe void LoadNum(float value) {
|
|
|
|
|
fixed (byte* ptr = _numbuf) *(float*)ptr = value;
|
|
|
|
|
}
|
|
|
|
|
unsafe void LoadNum2(float value) {
|
|
|
|
|
fixed (byte* ptr = _numbuf2) *(float*)ptr = value;
|
|
|
|
|
}
|
|
|
|
|
static readonly byte[] _nullvalue = new byte[0];
|
|
|
|
|
unsafe void OnInput(InputIdentifier id, InputVector vec) {
|
|
|
|
|
lock (_lock) {
|
|
|
|
|
InputProxyEntry proxy;
|
|
|
|
@@ -127,11 +126,8 @@ namespace Cryville.Crtr {
|
|
|
|
|
_etor.ContextCascadeInsert();
|
|
|
|
|
float ft, tt = (float)vec.Time;
|
|
|
|
|
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) {
|
|
|
|
|
_etor.ContextCascadeUpdate(_var_value, new PropSrc.Arbitrary(PdtInternalType.Null, new byte[0]));
|
|
|
|
|
_etor.ContextCascadeUpdate(_var_value, new PropSrc.Arbitrary(PdtInternalType.Null, _nullvalue));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
fixed (byte* ptr = _vecbuf) {
|
|
|
|
@@ -139,35 +135,45 @@ namespace Cryville.Crtr {
|
|
|
|
|
}
|
|
|
|
|
_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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
static readonly int _var_fv = IdentifierManager.SharedInstance.Request("fv");
|
|
|
|
|
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];
|
|
|
|
|
if (def.pass != null) {
|
|
|
|
|
foreach (var p in def.pass) {
|
|
|
|
|
_etor.ContextCascadeInsert();
|
|
|
|
|
_arbop.Name = _var_value;
|
|
|
|
|
_etor.Evaluate(_arbop, p.Value);
|
|
|
|
|
OnInput(id, p.Key);
|
|
|
|
|
OnInput(id, p.Key, ft, tt);
|
|
|
|
|
_etor.ContextCascadeDiscard();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
var pid = new ProxiedInputIdentifier { Source = id, Target = target };
|
|
|
|
|
PropSrc.Arbitrary fv, tv = _etor.ContextCascadeLookup(_var_value);
|
|
|
|
|
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, _nullvalue);
|
|
|
|
|
if (fv.Type != PdtInternalType.Null || tv.Type != PdtInternalType.Null) {
|
|
|
|
|
_etor.ContextCascadeInsert();
|
|
|
|
|
_etor.ContextCascadeUpdate(_var_tv, tv);
|
|
|
|
|
_etor.ContextCascadeUpdate(_var_fv, fv);
|
|
|
|
|
_judge.Feed(target);
|
|
|
|
|
_etor.ContextCascadeDiscard();
|
|
|
|
|
if (fv.Type == PdtInternalType.Null) {
|
|
|
|
|
_activeCounts[id.Source]++;
|
|
|
|
|
Logger.Log("main", 0, "Input/Proxy", "active {0} # {1} (+)", id.Source, _activeCounts[id.Source]);
|
|
|
|
|
}
|
|
|
|
|
_etor.ContextCascadeInsert();
|
|
|
|
|
_etor.ContextCascadeUpdate(_var_fv, fv);
|
|
|
|
|
_etor.ContextCascadeUpdate(_var_tv, tv);
|
|
|
|
|
_judge.Feed(target, ft, tt);
|
|
|
|
|
_etor.ContextCascadeDiscard();
|
|
|
|
|
if (tv.Type == PdtInternalType.Null) {
|
|
|
|
|
_activeCounts[id.Source]--;
|
|
|
|
|
Logger.Log("main", 0, "Input/Proxy", "active {0} # {1} (-)", id.Source, _activeCounts[id.Source]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_judge.Cleanup(target, ft, tt);
|
|
|
|
|
_vecs[pid] = tv;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -193,7 +199,7 @@ namespace Cryville.Crtr {
|
|
|
|
|
|
|
|
|
|
public struct ProxiedInputIdentifier : IEquatable<ProxiedInputIdentifier> {
|
|
|
|
|
public InputIdentifier Source { get; set; }
|
|
|
|
|
public string Target { get; set; }
|
|
|
|
|
public Identifier Target { get; set; }
|
|
|
|
|
public override bool Equals(object obj) {
|
|
|
|
|
if (obj == null || !(obj is ProxiedInputIdentifier)) return false;
|
|
|
|
|
return Equals((ProxiedInputIdentifier)obj);
|
|
|
|
|