Add active counting for input sources for force tick.

This commit is contained in:
2022-11-12 01:02:00 +08:00
parent 35040e4ebd
commit f7454eb514

View File

@@ -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 {
@@ -102,13 +103,19 @@ 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 PropOp.Arbitrary _arbop = new PropOp.Arbitrary();
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>();
static readonly byte[] _nullvalue = new byte[0];
@@ -152,11 +159,19 @@ namespace Cryville.Crtr {
PropSrc.Arbitrary fv, tv = _etor.ContextCascadeLookup(_var_value);
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) {
_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;