Compare commits
5 Commits
bca71982e5
...
fcc159ab6c
@@ -4,6 +4,7 @@ using Cryville.Common.Unity.Input;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using Logger = Cryville.Common.Logger;
|
||||||
|
|
||||||
namespace Cryville.Crtr {
|
namespace Cryville.Crtr {
|
||||||
public class InputProxy {
|
public class InputProxy {
|
||||||
@@ -42,6 +43,7 @@ namespace Cryville.Crtr {
|
|||||||
if (_use[proxy.Target] > 0)
|
if (_use[proxy.Target] > 0)
|
||||||
throw new InvalidOperationException("Input already assigned");
|
throw new InvalidOperationException("Input already assigned");
|
||||||
if (proxy.Source != null) {
|
if (proxy.Source != null) {
|
||||||
|
proxy.Source.Value.Handler.OnInput -= OnInput; // Prevent duplicated hooks, no exception will be thrown
|
||||||
proxy.Source.Value.Handler.OnInput += OnInput;
|
proxy.Source.Value.Handler.OnInput += OnInput;
|
||||||
_tproxies.Add(proxy.Target, proxy);
|
_tproxies.Add(proxy.Target, proxy);
|
||||||
_sproxies.Add(proxy.Source.Value, proxy);
|
_sproxies.Add(proxy.Source.Value, proxy);
|
||||||
@@ -101,25 +103,22 @@ namespace Cryville.Crtr {
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Handling
|
#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(); }
|
public void Deactivate() { foreach (var src in _sproxies.Keys) src.Handler.Deactivate(); }
|
||||||
|
|
||||||
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<InputSource, int> _activeCounts = new Dictionary<InputSource, int>(); // TODO used for force tick
|
||||||
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;
|
||||||
@@ -127,11 +126,8 @@ 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, _nullvalue));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fixed (byte* ptr = _vecbuf) {
|
fixed (byte* ptr = _vecbuf) {
|
||||||
@@ -139,35 +135,45 @@ 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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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, 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) {
|
if (fv.Type != PdtInternalType.Null || tv.Type != PdtInternalType.Null) {
|
||||||
|
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.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();
|
||||||
|
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;
|
_vecs[pid] = tv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -193,7 +199,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);
|
||||||
|
|||||||
@@ -1,11 +1,20 @@
|
|||||||
using Cryville.Common;
|
using Cryville.Common;
|
||||||
using Cryville.Common.Pdt;
|
using Cryville.Common.Pdt;
|
||||||
using Cryville.Common.Unity.Input;
|
using Cryville.Crtr.Event;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Cryville.Crtr {
|
namespace Cryville.Crtr {
|
||||||
public class Judge {
|
public class Judge {
|
||||||
readonly PdtRuleset _rs;
|
readonly PdtRuleset _rs;
|
||||||
|
readonly Dictionary<Identifier, float> ct
|
||||||
|
= new Dictionary<Identifier, float>();
|
||||||
|
readonly Dictionary<Identifier, Dictionary<float, JudgeEvent>> evs
|
||||||
|
= new Dictionary<Identifier, Dictionary<float, JudgeEvent>>();
|
||||||
|
struct JudgeEvent {
|
||||||
|
public float EndTime;
|
||||||
|
public JudgeDefinition Definition { get; set; }
|
||||||
|
public ContainerState State { get; set; }
|
||||||
|
}
|
||||||
public Judge(PdtRuleset rs) {
|
public Judge(PdtRuleset rs) {
|
||||||
_rs = rs;
|
_rs = rs;
|
||||||
foreach (var s in rs.scores) {
|
foreach (var s in rs.scores) {
|
||||||
@@ -14,10 +23,19 @@ namespace Cryville.Crtr {
|
|||||||
scores.Add(name, s.Value.init);
|
scores.Add(name, s.Value.init);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void Feed(string target) {
|
public void Prepare(float time, Identifier input, JudgeDefinition def, ContainerState container) {
|
||||||
|
Dictionary<float, JudgeEvent> list;
|
||||||
|
if (!evs.TryGetValue(input, out list)) {
|
||||||
|
ct.Add(input, 0);
|
||||||
|
evs.Add(input, list = new Dictionary<float, JudgeEvent>());
|
||||||
|
}
|
||||||
|
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>();
|
||||||
|
|||||||
@@ -95,10 +95,11 @@ namespace Cryville.Crtr {
|
|||||||
else if (ev.Unstamped == null) { }
|
else if (ev.Unstamped == null) { }
|
||||||
else if (ev.Unstamped is Chart.Judge) {
|
else if (ev.Unstamped is Chart.Judge) {
|
||||||
var tev = (Chart.Judge)ev.Unstamped;
|
var tev = (Chart.Judge)ev.Unstamped;
|
||||||
Identifier name;
|
Identifier name = default(Identifier);
|
||||||
ChartPlayer.etor.ContextEvent = tev;
|
ChartPlayer.etor.ContextEvent = tev;
|
||||||
ChartPlayer.etor.ContextState = s;
|
ChartPlayer.etor.ContextState = s;
|
||||||
ChartPlayer.etor.Evaluate(new PropOp.Identifier(v => name = new Identifier(v)), ruleset.judges[tev.Id].input);
|
ChartPlayer.etor.Evaluate(new PropOp.Identifier(v => name = new Identifier(v)), ruleset.judges[tev.Id].input);
|
||||||
|
judge.Prepare(ps.Time, name, ruleset.judges[tev.Id], cs);
|
||||||
ChartPlayer.etor.ContextState = null;
|
ChartPlayer.etor.ContextState = null;
|
||||||
ChartPlayer.etor.ContextEvent = null;
|
ChartPlayer.etor.ContextEvent = null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user