Compare commits
6 Commits
a7608bcd7e
...
0.5.2
Author | SHA1 | Date | |
---|---|---|---|
9f73c8ffad | |||
c1c354959d | |||
94428d9e18 | |||
5198ecec1f | |||
6779b88055 | |||
c5dab3a232 |
@@ -145,7 +145,7 @@ namespace Cryville.Common {
|
|||||||
/// <returns>An array containing all the subclasses of the type in the current app domain.</returns>
|
/// <returns>An array containing all the subclasses of the type in the current app domain.</returns>
|
||||||
public static Type[] GetSubclassesOf<T>() where T : class {
|
public static Type[] GetSubclassesOf<T>() where T : class {
|
||||||
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
||||||
IEnumerable<Type> r = new List<Type>();
|
IEnumerable<Type> r = Enumerable.Empty<Type>();
|
||||||
foreach (var a in assemblies)
|
foreach (var a in assemblies)
|
||||||
r = r.Concat(a.GetTypes().Where(
|
r = r.Concat(a.GetTypes().Where(
|
||||||
t => t.IsClass
|
t => t.IsClass
|
||||||
|
@@ -4,7 +4,19 @@ using UnityEngine;
|
|||||||
namespace Cryville.Common.Unity.Input {
|
namespace Cryville.Common.Unity.Input {
|
||||||
public delegate void InputEventDelegate(InputIdentifier id, InputVector vec);
|
public delegate void InputEventDelegate(InputIdentifier id, InputVector vec);
|
||||||
public abstract class InputHandler : IDisposable {
|
public abstract class InputHandler : IDisposable {
|
||||||
public event InputEventDelegate OnInput;
|
InputEventDelegate m_onInput;
|
||||||
|
public event InputEventDelegate OnInput {
|
||||||
|
add {
|
||||||
|
if (m_onInput == null) Activate();
|
||||||
|
m_onInput -= value;
|
||||||
|
m_onInput += value;
|
||||||
|
}
|
||||||
|
remove {
|
||||||
|
if (m_onInput == null) return;
|
||||||
|
m_onInput -= value;
|
||||||
|
if (m_onInput == null) Deactivate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
~InputHandler() {
|
~InputHandler() {
|
||||||
Dispose(false);
|
Dispose(false);
|
||||||
@@ -14,26 +26,15 @@ namespace Cryville.Common.Unity.Input {
|
|||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Activated { get; private set; }
|
protected abstract void Activate();
|
||||||
public void Activate() {
|
protected abstract void Deactivate();
|
||||||
if (Activated) return;
|
|
||||||
Activated = true;
|
|
||||||
ActivateImpl();
|
|
||||||
}
|
|
||||||
protected abstract void ActivateImpl();
|
|
||||||
public void Deactivate() {
|
|
||||||
if (!Activated) return;
|
|
||||||
Activated = false;
|
|
||||||
DeactivateImpl();
|
|
||||||
}
|
|
||||||
protected abstract void DeactivateImpl();
|
|
||||||
public abstract void Dispose(bool disposing);
|
public abstract void Dispose(bool disposing);
|
||||||
public abstract bool IsNullable(int type);
|
public abstract bool IsNullable(int type);
|
||||||
public abstract byte GetDimension(int type);
|
public abstract byte GetDimension(int type);
|
||||||
public abstract string GetTypeName(int type);
|
public abstract string GetTypeName(int type);
|
||||||
public abstract double GetCurrentTimestamp();
|
public abstract double GetCurrentTimestamp();
|
||||||
protected void Feed(int type, int id, InputVector vec) {
|
protected void Feed(int type, int id, InputVector vec) {
|
||||||
var del = OnInput;
|
var del = m_onInput;
|
||||||
if (del != null) del(new InputIdentifier { Source = new InputSource { Handler = this, Type = type }, Id = id }, vec);
|
if (del != null) del(new InputIdentifier { Source = new InputSource { Handler = this, Type = type }, Id = id }, vec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,28 +4,22 @@ using System.Reflection;
|
|||||||
|
|
||||||
namespace Cryville.Common.Unity.Input {
|
namespace Cryville.Common.Unity.Input {
|
||||||
public class InputManager {
|
public class InputManager {
|
||||||
static readonly List<Type> HandlerRegistries = new List<Type> {
|
static readonly HashSet<Type> HandlerRegistries = new HashSet<Type> {
|
||||||
typeof(WindowsPointerHandler),
|
typeof(WindowsPointerHandler),
|
||||||
typeof(UnityKeyHandler<UnityKeyboardReceiver>),
|
typeof(UnityKeyHandler<UnityKeyboardReceiver>),
|
||||||
typeof(UnityKeyHandler<UnityMouseButtonReceiver>),
|
typeof(UnityKeyHandler<UnityMouseButtonReceiver>),
|
||||||
typeof(UnityMouseHandler),
|
typeof(UnityMouseHandler),
|
||||||
typeof(UnityTouchHandler),
|
typeof(UnityTouchHandler),
|
||||||
};
|
};
|
||||||
readonly List<InputHandler> _handlers = new List<InputHandler>();
|
readonly HashSet<InputHandler> _handlers = new HashSet<InputHandler>();
|
||||||
readonly Dictionary<Type, InputHandler> _typemap = new Dictionary<Type, InputHandler>();
|
readonly Dictionary<Type, InputHandler> _typemap = new Dictionary<Type, InputHandler>();
|
||||||
readonly Dictionary<InputHandler, double> _timeOrigins = new Dictionary<InputHandler, double>();
|
|
||||||
readonly object _lock = new object();
|
|
||||||
readonly Dictionary<InputIdentifier, InputVector> _vectors = new Dictionary<InputIdentifier, InputVector>();
|
|
||||||
readonly List<InputEvent> _events = new List<InputEvent>();
|
|
||||||
public InputManager() {
|
public InputManager() {
|
||||||
foreach (var t in HandlerRegistries) {
|
foreach (var t in HandlerRegistries) {
|
||||||
try {
|
try {
|
||||||
if (!typeof(InputHandler).IsAssignableFrom(t)) continue;
|
if (!typeof(InputHandler).IsAssignableFrom(t)) continue;
|
||||||
var h = (InputHandler)ReflectionHelper.InvokeEmptyConstructor(t);
|
var h = (InputHandler)ReflectionHelper.InvokeEmptyConstructor(t);
|
||||||
_typemap.Add(t, h);
|
_typemap.Add(t, h);
|
||||||
h.OnInput += OnInput;
|
|
||||||
_handlers.Add(h);
|
_handlers.Add(h);
|
||||||
_timeOrigins.Add(h, 0);
|
|
||||||
Logger.Log("main", 1, "Input", "Initialized {0}", ReflectionHelper.GetSimpleName(t));
|
Logger.Log("main", 1, "Input", "Initialized {0}", ReflectionHelper.GetSimpleName(t));
|
||||||
}
|
}
|
||||||
catch (TargetInvocationException ex) {
|
catch (TargetInvocationException ex) {
|
||||||
@@ -36,49 +30,8 @@ namespace Cryville.Common.Unity.Input {
|
|||||||
public InputHandler GetHandler(string name) {
|
public InputHandler GetHandler(string name) {
|
||||||
return _typemap[Type.GetType(name)];
|
return _typemap[Type.GetType(name)];
|
||||||
}
|
}
|
||||||
public void Activate() {
|
public void EnumerateHandlers(Action<InputHandler> cb) {
|
||||||
lock (_lock) {
|
foreach (var h in _handlers) cb(h);
|
||||||
_events.Clear();
|
|
||||||
}
|
|
||||||
foreach (var h in _handlers) h.Activate();
|
|
||||||
}
|
|
||||||
public void SyncTime(double time) {
|
|
||||||
foreach (var h in _handlers) {
|
|
||||||
_timeOrigins[h] = time - h.GetCurrentTimestamp();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void Deactivate() {
|
|
||||||
foreach (var h in _handlers) h.Deactivate();
|
|
||||||
}
|
|
||||||
void OnInput(InputIdentifier id, InputVector vec) {
|
|
||||||
lock (_lock) {
|
|
||||||
double timeOrigin = _timeOrigins[id.Source.Handler];
|
|
||||||
vec.Time += timeOrigin;
|
|
||||||
InputVector vec0;
|
|
||||||
if (_vectors.TryGetValue(id, out vec0)) {
|
|
||||||
_events.Add(new InputEvent {
|
|
||||||
Id = id,
|
|
||||||
From = vec0,
|
|
||||||
To = vec,
|
|
||||||
});
|
|
||||||
if (vec.IsNull) _vectors.Remove(id);
|
|
||||||
else _vectors[id] = vec;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
_events.Add(new InputEvent {
|
|
||||||
Id = id,
|
|
||||||
From = new InputVector(vec.Time),
|
|
||||||
To = vec,
|
|
||||||
});
|
|
||||||
_vectors.Add(id, vec);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void EnumerateEvents(Action<InputEvent> cb) {
|
|
||||||
lock (_lock) {
|
|
||||||
foreach (var ev in _events) cb(ev);
|
|
||||||
_events.Clear();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
49
Assets/Cryville/Common/Unity/Input/SimpleInputConsumer.cs
Normal file
49
Assets/Cryville/Common/Unity/Input/SimpleInputConsumer.cs
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Cryville.Common.Unity.Input {
|
||||||
|
public class SimpleInputConsumer {
|
||||||
|
readonly InputManager _manager;
|
||||||
|
readonly object _lock = new object();
|
||||||
|
readonly Dictionary<InputIdentifier, InputVector> _vectors = new Dictionary<InputIdentifier, InputVector>();
|
||||||
|
readonly List<InputEvent> _events = new List<InputEvent>();
|
||||||
|
public SimpleInputConsumer(InputManager manager) { _manager = manager; }
|
||||||
|
public void Activate() {
|
||||||
|
lock (_lock) {
|
||||||
|
_events.Clear();
|
||||||
|
}
|
||||||
|
_manager.EnumerateHandlers(h => h.OnInput += OnInput);
|
||||||
|
}
|
||||||
|
public void Deactivate() {
|
||||||
|
_manager.EnumerateHandlers(h => h.OnInput -= OnInput);
|
||||||
|
}
|
||||||
|
protected void OnInput(InputIdentifier id, InputVector vec) {
|
||||||
|
lock (_lock) {
|
||||||
|
InputVector vec0;
|
||||||
|
if (_vectors.TryGetValue(id, out vec0)) {
|
||||||
|
_events.Add(new InputEvent {
|
||||||
|
Id = id,
|
||||||
|
From = vec0,
|
||||||
|
To = vec,
|
||||||
|
});
|
||||||
|
if (vec.IsNull) _vectors.Remove(id);
|
||||||
|
else _vectors[id] = vec;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
_events.Add(new InputEvent {
|
||||||
|
Id = id,
|
||||||
|
From = new InputVector(vec.Time),
|
||||||
|
To = vec,
|
||||||
|
});
|
||||||
|
_vectors.Add(id, vec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void EnumerateEvents(Action<InputEvent> cb) {
|
||||||
|
lock (_lock) {
|
||||||
|
foreach (var ev in _events) cb(ev);
|
||||||
|
_events.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8fd2d5f1c7ba0c74c9ce8775075750db
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@@ -9,19 +9,19 @@ namespace Cryville.Common.Unity.Input {
|
|||||||
|
|
||||||
public UnityKeyHandler() { }
|
public UnityKeyHandler() { }
|
||||||
|
|
||||||
protected override void ActivateImpl() {
|
protected override void Activate() {
|
||||||
receiver = new GameObject("__keyrecv__");
|
receiver = new GameObject("__keyrecv__");
|
||||||
recvcomp = receiver.AddComponent<T>();
|
recvcomp = receiver.AddComponent<T>();
|
||||||
recvcomp.SetCallback(Feed);
|
recvcomp.SetCallback(Feed);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void DeactivateImpl() {
|
protected override void Deactivate() {
|
||||||
if (receiver) GameObject.Destroy(receiver);
|
if (receiver) GameObject.Destroy(receiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Dispose(bool disposing) {
|
public override void Dispose(bool disposing) {
|
||||||
if (disposing) {
|
if (disposing) {
|
||||||
DeactivateImpl();
|
Deactivate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ namespace Cryville.Common.Unity.Input {
|
|||||||
|
|
||||||
public abstract class UnityKeyReceiver<T> : MonoBehaviour where T : UnityKeyReceiver<T> {
|
public abstract class UnityKeyReceiver<T> : MonoBehaviour where T : UnityKeyReceiver<T> {
|
||||||
protected Action<int, int, InputVector> Callback;
|
protected Action<int, int, InputVector> Callback;
|
||||||
protected readonly List<int> Keys = new List<int>();
|
protected readonly HashSet<int> Keys = new HashSet<int>();
|
||||||
public void SetCallback(Action<int, int, InputVector> h) {
|
public void SetCallback(Action<int, int, InputVector> h) {
|
||||||
Callback = h;
|
Callback = h;
|
||||||
}
|
}
|
||||||
|
@@ -12,18 +12,18 @@ namespace Cryville.Common.Unity.Input {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void ActivateImpl() {
|
protected override void Activate() {
|
||||||
receiver = new GameObject("__mouserecv__");
|
receiver = new GameObject("__mouserecv__");
|
||||||
receiver.AddComponent<UnityMouseReceiver>().SetHandler(this);
|
receiver.AddComponent<UnityMouseReceiver>().SetHandler(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void DeactivateImpl() {
|
protected override void Deactivate() {
|
||||||
if (receiver) GameObject.Destroy(receiver);
|
if (receiver) GameObject.Destroy(receiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Dispose(bool disposing) {
|
public override void Dispose(bool disposing) {
|
||||||
if (disposing) {
|
if (disposing) {
|
||||||
DeactivateImpl();
|
Deactivate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -12,18 +12,18 @@ namespace Cryville.Common.Unity.Input {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void ActivateImpl() {
|
protected override void Activate() {
|
||||||
receiver = new GameObject("__touchrecv__");
|
receiver = new GameObject("__touchrecv__");
|
||||||
receiver.AddComponent<UnityPointerReceiver>().SetHandler(this);
|
receiver.AddComponent<UnityPointerReceiver>().SetHandler(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void DeactivateImpl() {
|
protected override void Deactivate() {
|
||||||
if (receiver) GameObject.Destroy(receiver);
|
if (receiver) GameObject.Destroy(receiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Dispose(bool disposing) {
|
public override void Dispose(bool disposing) {
|
||||||
if (disposing) {
|
if (disposing) {
|
||||||
DeactivateImpl();
|
Deactivate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -61,7 +61,7 @@ namespace Cryville.Common.Unity.Input {
|
|||||||
public const int TABLET_DISABLE_PENBARRELFEEDBACK = 0x00000010;
|
public const int TABLET_DISABLE_PENBARRELFEEDBACK = 0x00000010;
|
||||||
public const int TABLET_DISABLE_FLICKS = 0x00010000;
|
public const int TABLET_DISABLE_FLICKS = 0x00010000;
|
||||||
|
|
||||||
protected override void ActivateImpl() {
|
protected override void Activate() {
|
||||||
newWndProc = WndProc;
|
newWndProc = WndProc;
|
||||||
newWndProcPtr = Marshal.GetFunctionPointerForDelegate(newWndProc);
|
newWndProcPtr = Marshal.GetFunctionPointerForDelegate(newWndProc);
|
||||||
oldWndProcPtr = SetWindowLongPtr(hMainWindow, -4, newWndProcPtr);
|
oldWndProcPtr = SetWindowLongPtr(hMainWindow, -4, newWndProcPtr);
|
||||||
@@ -77,7 +77,7 @@ namespace Cryville.Common.Unity.Input {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void DeactivateImpl() {
|
protected override void Deactivate() {
|
||||||
if (pressAndHoldAtomID != 0) {
|
if (pressAndHoldAtomID != 0) {
|
||||||
NativeMethods.RemoveProp(hMainWindow, PRESS_AND_HOLD_ATOM);
|
NativeMethods.RemoveProp(hMainWindow, PRESS_AND_HOLD_ATOM);
|
||||||
NativeMethods.GlobalDeleteAtom(pressAndHoldAtomID);
|
NativeMethods.GlobalDeleteAtom(pressAndHoldAtomID);
|
||||||
@@ -142,7 +142,7 @@ namespace Cryville.Common.Unity.Input {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override void Dispose(bool disposing) {
|
public override void Dispose(bool disposing) {
|
||||||
DeactivateImpl();
|
Deactivate();
|
||||||
if (usePointerMessage)
|
if (usePointerMessage)
|
||||||
NativeMethods.EnableMouseInPointer(false);
|
NativeMethods.EnableMouseInPointer(false);
|
||||||
Instance = null;
|
Instance = null;
|
||||||
|
@@ -485,6 +485,7 @@ namespace Cryville.Crtr {
|
|||||||
workerTimer = new diag::Stopwatch();
|
workerTimer = new diag::Stopwatch();
|
||||||
workerTimer.Start();
|
workerTimer.Start();
|
||||||
RMVPool.Prepare();
|
RMVPool.Prepare();
|
||||||
|
MotionCachePool.Prepare();
|
||||||
LoadChart(info);
|
LoadChart(info);
|
||||||
workerTimer.Stop();
|
workerTimer.Stop();
|
||||||
Logger.Log("main", 1, "Load/WorkerThread", "Worker thread done ({0}ms)", workerTimer.Elapsed.TotalMilliseconds);
|
Logger.Log("main", 1, "Load/WorkerThread", "Worker thread done ({0}ms)", workerTimer.Elapsed.TotalMilliseconds);
|
||||||
|
@@ -57,7 +57,6 @@ namespace Cryville.Crtr.Config {
|
|||||||
var proxy = new InputProxy(ruleset.Root, null);
|
var proxy = new InputProxy(ruleset.Root, null);
|
||||||
proxy.LoadFrom(_rscfg.inputs);
|
proxy.LoadFrom(_rscfg.inputs);
|
||||||
m_inputConfigPanel.proxy = proxy;
|
m_inputConfigPanel.proxy = proxy;
|
||||||
Game.InputManager.Activate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SwitchCategory(GameObject cat) {
|
public void SwitchCategory(GameObject cat) {
|
||||||
@@ -68,7 +67,6 @@ namespace Cryville.Crtr.Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void SaveAndReturnToMenu() {
|
public void SaveAndReturnToMenu() {
|
||||||
Game.InputManager.Deactivate();
|
|
||||||
m_inputConfigPanel.proxy.SaveTo(_rscfg.inputs);
|
m_inputConfigPanel.proxy.SaveTo(_rscfg.inputs);
|
||||||
m_inputConfigPanel.proxy.Dispose();
|
m_inputConfigPanel.proxy.Dispose();
|
||||||
FileInfo cfgfile = new FileInfo(
|
FileInfo cfgfile = new FileInfo(
|
||||||
|
@@ -24,6 +24,7 @@ namespace Cryville.Crtr.Config {
|
|||||||
[SerializeField]
|
[SerializeField]
|
||||||
GameObject m_prefabInputConfigEntry;
|
GameObject m_prefabInputConfigEntry;
|
||||||
|
|
||||||
|
readonly SimpleInputConsumer _consumer = new SimpleInputConsumer(Game.InputManager);
|
||||||
public InputProxy proxy;
|
public InputProxy proxy;
|
||||||
readonly Dictionary<string, InputConfigPanelEntry> _entries = new Dictionary<string, InputConfigPanelEntry>();
|
readonly Dictionary<string, InputConfigPanelEntry> _entries = new Dictionary<string, InputConfigPanelEntry>();
|
||||||
|
|
||||||
@@ -32,7 +33,7 @@ namespace Cryville.Crtr.Config {
|
|||||||
_sel = entry;
|
_sel = entry;
|
||||||
m_inputDialog.SetActive(true);
|
m_inputDialog.SetActive(true);
|
||||||
CallHelper.Purge(m_deviceList);
|
CallHelper.Purge(m_deviceList);
|
||||||
Game.InputManager.EnumerateEvents(ev => { });
|
_consumer.EnumerateEvents(ev => { });
|
||||||
_recvsrcs.Clear();
|
_recvsrcs.Clear();
|
||||||
AddSourceItem(null);
|
AddSourceItem(null);
|
||||||
}
|
}
|
||||||
@@ -46,10 +47,11 @@ namespace Cryville.Crtr.Config {
|
|||||||
Target = _sel,
|
Target = _sel,
|
||||||
Source = src,
|
Source = src,
|
||||||
});
|
});
|
||||||
m_inputDialog.SetActive(false);
|
CloseDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Start() {
|
void Start() {
|
||||||
|
_consumer.Activate();
|
||||||
foreach (var i in m_configScene.ruleset.Root.inputs) {
|
foreach (var i in m_configScene.ruleset.Root.inputs) {
|
||||||
var e = GameObject.Instantiate(m_prefabInputConfigEntry, m_entryList.transform).GetComponent<InputConfigPanelEntry>();
|
var e = GameObject.Instantiate(m_prefabInputConfigEntry, m_entryList.transform).GetComponent<InputConfigPanelEntry>();
|
||||||
_entries.Add(i.Key, e);
|
_entries.Add(i.Key, e);
|
||||||
@@ -59,6 +61,10 @@ namespace Cryville.Crtr.Config {
|
|||||||
proxy.ProxyChanged += OnProxyChanged;
|
proxy.ProxyChanged += OnProxyChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OnDestroy() {
|
||||||
|
_consumer.Deactivate();
|
||||||
|
}
|
||||||
|
|
||||||
void OnProxyChanged(object sender, ProxyChangedEventArgs e) {
|
void OnProxyChanged(object sender, ProxyChangedEventArgs e) {
|
||||||
_entries[e.Name].SetEnabled(!e.Used);
|
_entries[e.Name].SetEnabled(!e.Used);
|
||||||
_entries[e.Name].SetValue(e.Proxy == null ? "None" : e.Proxy.Value.Handler.GetTypeName(e.Proxy.Value.Type));
|
_entries[e.Name].SetValue(e.Proxy == null ? "None" : e.Proxy.Value.Handler.GetTypeName(e.Proxy.Value.Type));
|
||||||
@@ -67,7 +73,7 @@ namespace Cryville.Crtr.Config {
|
|||||||
readonly List<InputSource?> _recvsrcs = new List<InputSource?>();
|
readonly List<InputSource?> _recvsrcs = new List<InputSource?>();
|
||||||
void Update() {
|
void Update() {
|
||||||
if (m_inputDialog.activeSelf) {
|
if (m_inputDialog.activeSelf) {
|
||||||
Game.InputManager.EnumerateEvents(ev => {
|
_consumer.EnumerateEvents(ev => {
|
||||||
AddSourceItem(ev.Id.Source);
|
AddSourceItem(ev.Id.Source);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -65,16 +65,10 @@ namespace Cryville.Crtr.Event {
|
|||||||
}
|
}
|
||||||
|
|
||||||
readonly RMVPool RMVPool = new RMVPool();
|
readonly RMVPool RMVPool = new RMVPool();
|
||||||
protected Dictionary<StampedEvent, RealtimeMotionValue> PlayingMotions = new Dictionary<StampedEvent, RealtimeMotionValue>();
|
readonly MotionCachePool MCPool = new MotionCachePool();
|
||||||
protected Dictionary<Identifier, RealtimeMotionValue> Values;
|
Dictionary<StampedEvent, RealtimeMotionValue> PlayingMotions = new Dictionary<StampedEvent, RealtimeMotionValue>(4);
|
||||||
protected Dictionary<Identifier, CacheEntry> CachedValues;
|
Dictionary<Identifier, RealtimeMotionValue> Values;
|
||||||
protected class CacheEntry {
|
Dictionary<Identifier, MotionCache> CachedValues;
|
||||||
public bool Valid { get; set; }
|
|
||||||
public Vector Value { get; set; }
|
|
||||||
public CacheEntry Clone() {
|
|
||||||
return new CacheEntry { Valid = Valid, Value = Value == null ? null : Value.Clone() };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a motion value.
|
/// Gets a motion value.
|
||||||
@@ -89,9 +83,9 @@ namespace Cryville.Crtr.Event {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void InvalidateMotion(Identifier name) {
|
void InvalidateMotion(Identifier name) {
|
||||||
CacheEntry cache;
|
MotionCache cache;
|
||||||
if (!CachedValues.TryGetValue(name, out cache))
|
if (!CachedValues.TryGetValue(name, out cache))
|
||||||
CachedValues.Add(name, cache = new CacheEntry());
|
CachedValues.Add(name, cache = MCPool.Rent(name));
|
||||||
cache.Valid = false;
|
cache.Valid = false;
|
||||||
ValidateChildren();
|
ValidateChildren();
|
||||||
foreach (var c in WorkingChildren)
|
foreach (var c in WorkingChildren)
|
||||||
@@ -107,7 +101,7 @@ namespace Cryville.Crtr.Event {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Values = new Dictionary<Identifier, RealtimeMotionValue>(ChartPlayer.motionRegistry.Count);
|
Values = new Dictionary<Identifier, RealtimeMotionValue>(ChartPlayer.motionRegistry.Count);
|
||||||
CachedValues = new Dictionary<Identifier, CacheEntry>(ChartPlayer.motionRegistry.Count);
|
CachedValues = new Dictionary<Identifier, MotionCache>(ChartPlayer.motionRegistry.Count);
|
||||||
foreach (var m in ChartPlayer.motionRegistry)
|
foreach (var m in ChartPlayer.motionRegistry)
|
||||||
Values.Add(m.Key, new RealtimeMotionValue().Init(Parent == null ? m.Value.GlobalInitValue : m.Value.InitValue));
|
Values.Add(m.Key, new RealtimeMotionValue().Init(Parent == null ? m.Value.GlobalInitValue : m.Value.InitValue));
|
||||||
}
|
}
|
||||||
@@ -128,9 +122,11 @@ namespace Cryville.Crtr.Event {
|
|||||||
}
|
}
|
||||||
r.Values = mvs;
|
r.Values = mvs;
|
||||||
|
|
||||||
var cvs = new Dictionary<Identifier, CacheEntry>(ChartPlayer.motionRegistry.Count);
|
var cvs = new Dictionary<Identifier, MotionCache>(ChartPlayer.motionRegistry.Count);
|
||||||
foreach (var cv in CachedValues) {
|
foreach (var cv in CachedValues) {
|
||||||
cvs.Add(cv.Key, cv.Value.Clone());
|
var dv = r.MCPool.Rent(cv.Key);
|
||||||
|
cv.Value.CopyTo(dv);
|
||||||
|
cvs.Add(cv.Key, dv);
|
||||||
}
|
}
|
||||||
r.CachedValues = cvs;
|
r.CachedValues = cvs;
|
||||||
|
|
||||||
@@ -141,7 +137,7 @@ namespace Cryville.Crtr.Event {
|
|||||||
AddChild(child.Key, cc, r);
|
AddChild(child.Key, cc, r);
|
||||||
}
|
}
|
||||||
|
|
||||||
var pms = new Dictionary<StampedEvent, RealtimeMotionValue>(PlayingMotions.Count);
|
var pms = new Dictionary<StampedEvent, RealtimeMotionValue>(Math.Max(4, PlayingMotions.Count));
|
||||||
foreach (var m in PlayingMotions)
|
foreach (var m in PlayingMotions)
|
||||||
pms.Add(m.Key, m.Value);
|
pms.Add(m.Key, m.Value);
|
||||||
r.PlayingMotions = pms;
|
r.PlayingMotions = pms;
|
||||||
@@ -169,12 +165,11 @@ namespace Cryville.Crtr.Event {
|
|||||||
|
|
||||||
foreach (var cv in dest.CachedValues) cv.Value.Valid = false;
|
foreach (var cv in dest.CachedValues) cv.Value.Valid = false;
|
||||||
foreach (var cv in CachedValues) {
|
foreach (var cv in CachedValues) {
|
||||||
CacheEntry dv;
|
MotionCache dv;
|
||||||
if (dest.CachedValues.TryGetValue(cv.Key, out dv)) {
|
if (!dest.CachedValues.TryGetValue(cv.Key, out dv)) {
|
||||||
dv.Valid = cv.Value.Valid;
|
dest.CachedValues.Add(cv.Key, dv = dest.MCPool.Rent(cv.Key));
|
||||||
if (cv.Value.Value != null) cv.Value.Value.CopyTo(dv.Value);
|
|
||||||
}
|
}
|
||||||
else dest.CachedValues.Add(cv.Key, cv.Value.Clone());
|
cv.Value.CopyTo(dv);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ct != 1) foreach (var cev in WorkingChildren)
|
if (ct != 1) foreach (var cev in WorkingChildren)
|
||||||
@@ -198,6 +193,7 @@ namespace Cryville.Crtr.Event {
|
|||||||
foreach (var s in Children)
|
foreach (var s in Children)
|
||||||
s.Value.Dispose();
|
s.Value.Dispose();
|
||||||
RMVPool.ReturnAll();
|
RMVPool.ReturnAll();
|
||||||
|
MCPool.ReturnAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AttachHandler(ContainerHandler h) {
|
public void AttachHandler(ContainerHandler h) {
|
||||||
@@ -212,11 +208,9 @@ namespace Cryville.Crtr.Event {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Vector GetRawValue(Identifier key) {
|
public Vector GetRawValue(Identifier key) {
|
||||||
CacheEntry tr;
|
MotionCache tr;
|
||||||
if (!CachedValues.TryGetValue(key, out tr))
|
if (!CachedValues.TryGetValue(key, out tr))
|
||||||
CachedValues.Add(key, tr = new CacheEntry { });
|
CachedValues.Add(key, tr = MCPool.Rent(key));
|
||||||
if (tr.Value == null)
|
|
||||||
tr.Value = RMVPool.Rent(key).AbsoluteValue;
|
|
||||||
Vector r = tr.Value;
|
Vector r = tr.Value;
|
||||||
#if !DISABLE_CACHE
|
#if !DISABLE_CACHE
|
||||||
if (tr.Valid) return r;
|
if (tr.Valid) return r;
|
||||||
|
@@ -11,8 +11,8 @@ namespace Cryville.Crtr.Event {
|
|||||||
|
|
||||||
Dictionary<EventContainer, ContainerState> states
|
Dictionary<EventContainer, ContainerState> states
|
||||||
= new Dictionary<EventContainer, ContainerState>();
|
= new Dictionary<EventContainer, ContainerState>();
|
||||||
List<EventContainer> activeContainers
|
HashSet<EventContainer> activeContainers
|
||||||
= new List<EventContainer>();
|
= new HashSet<EventContainer>();
|
||||||
HashSet<ContainerState> workingStates
|
HashSet<ContainerState> workingStates
|
||||||
= new HashSet<ContainerState>();
|
= new HashSet<ContainerState>();
|
||||||
HashSet<ContainerState> invalidatedStates
|
HashSet<ContainerState> invalidatedStates
|
||||||
@@ -29,7 +29,7 @@ namespace Cryville.Crtr.Event {
|
|||||||
var r = (EventBus)MemberwiseClone();
|
var r = (EventBus)MemberwiseClone();
|
||||||
r.prototype = this;
|
r.prototype = this;
|
||||||
r.states = new Dictionary<EventContainer, ContainerState>();
|
r.states = new Dictionary<EventContainer, ContainerState>();
|
||||||
r.activeContainers = new List<EventContainer>();
|
r.activeContainers = new HashSet<EventContainer>();
|
||||||
r.workingStates = new HashSet<ContainerState>();
|
r.workingStates = new HashSet<ContainerState>();
|
||||||
r.invalidatedStates = new HashSet<ContainerState>();
|
r.invalidatedStates = new HashSet<ContainerState>();
|
||||||
r.tempEvents = new List<StampedEvent>();
|
r.tempEvents = new List<StampedEvent>();
|
||||||
|
55
Assets/Cryville/Crtr/Event/MotionCache.cs
Normal file
55
Assets/Cryville/Crtr/Event/MotionCache.cs
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
using Cryville.Common;
|
||||||
|
using Cryville.Common.Buffers;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Cryville.Crtr.Event {
|
||||||
|
internal class MotionCache {
|
||||||
|
public bool Valid { get; set; }
|
||||||
|
public Vector Value { get; set; }
|
||||||
|
public void CopyTo(MotionCache dest) {
|
||||||
|
dest.Valid = Valid;
|
||||||
|
Value.CopyTo(dest.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
internal class MotionCachePool {
|
||||||
|
private class Bucket : ObjectPool<MotionCache> {
|
||||||
|
readonly MotionRegistry _reg;
|
||||||
|
public Bucket(string name, int capacity) : base(capacity) {
|
||||||
|
_reg = ChartPlayer.motionRegistry[name];
|
||||||
|
}
|
||||||
|
protected override MotionCache Construct() {
|
||||||
|
var result = new MotionCache();
|
||||||
|
result.Value = (Vector)ReflectionHelper.InvokeEmptyConstructor(_reg.Type);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static Dictionary<Identifier, Bucket> _buckets;
|
||||||
|
public static void Prepare() {
|
||||||
|
_buckets = new Dictionary<Identifier, Bucket>(ChartPlayer.motionRegistry.Count);
|
||||||
|
foreach (var reg in ChartPlayer.motionRegistry)
|
||||||
|
_buckets.Add(reg.Key, new Bucket(reg.Key, 4096));
|
||||||
|
}
|
||||||
|
|
||||||
|
static readonly SimpleObjectPool<Dictionary<MotionCache, Identifier>> _dictPool
|
||||||
|
= new SimpleObjectPool<Dictionary<MotionCache, Identifier>>(1024);
|
||||||
|
Dictionary<MotionCache, Identifier> _rented;
|
||||||
|
public MotionCache Rent(Identifier name) {
|
||||||
|
var obj = _buckets[name].Rent();
|
||||||
|
obj.Valid = false;
|
||||||
|
if (_rented == null) _rented = _dictPool.Rent();
|
||||||
|
_rented.Add(obj, name);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
public void Return(MotionCache obj) {
|
||||||
|
_buckets[_rented[obj]].Return(obj);
|
||||||
|
_rented.Remove(obj);
|
||||||
|
}
|
||||||
|
public void ReturnAll() {
|
||||||
|
if (_rented == null) return;
|
||||||
|
foreach (var obj in _rented)
|
||||||
|
_buckets[obj.Value].Return(obj.Key);
|
||||||
|
_rented.Clear();
|
||||||
|
_dictPool.Return(_rented);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Cryville/Crtr/Event/MotionCache.cs.meta
Normal file
11
Assets/Cryville/Crtr/Event/MotionCache.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 5d11b50a98974254f87273c94ed20de7
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@@ -24,10 +24,9 @@ namespace Cryville.Crtr.Event {
|
|||||||
= new SimpleObjectPool<Dictionary<RealtimeMotionValue, Identifier>>(1024);
|
= new SimpleObjectPool<Dictionary<RealtimeMotionValue, Identifier>>(1024);
|
||||||
Dictionary<RealtimeMotionValue, Identifier> _rented;
|
Dictionary<RealtimeMotionValue, Identifier> _rented;
|
||||||
public RealtimeMotionValue Rent(Identifier name) {
|
public RealtimeMotionValue Rent(Identifier name) {
|
||||||
var n = name;
|
var obj = _buckets[name].Rent();
|
||||||
var obj = _buckets[n].Rent();
|
|
||||||
if (_rented == null) _rented = _dictPool.Rent();
|
if (_rented == null) _rented = _dictPool.Rent();
|
||||||
_rented.Add(obj, n);
|
_rented.Add(obj, name);
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
public void Return(RealtimeMotionValue obj) {
|
public void Return(RealtimeMotionValue obj) {
|
||||||
@@ -35,6 +34,7 @@ namespace Cryville.Crtr.Event {
|
|||||||
_rented.Remove(obj);
|
_rented.Remove(obj);
|
||||||
}
|
}
|
||||||
public void ReturnAll() {
|
public void ReturnAll() {
|
||||||
|
if (_rented == null) return;
|
||||||
foreach (var obj in _rented)
|
foreach (var obj in _rented)
|
||||||
_buckets[obj.Value].Return(obj.Key);
|
_buckets[obj.Value].Return(obj.Key);
|
||||||
_rented.Clear();
|
_rented.Clear();
|
||||||
|
@@ -65,10 +65,6 @@ namespace Cryville.Crtr {
|
|||||||
if (_use[target] > 0)
|
if (_use[target] > 0)
|
||||||
throw new InvalidOperationException("Input already assigned");
|
throw new InvalidOperationException("Input already assigned");
|
||||||
if (proxy.Source != null) {
|
if (proxy.Source != null) {
|
||||||
if (_judge != null) {
|
|
||||||
proxy.Source.Value.Handler.OnInput -= OnInput; // Prevent duplicated hooks, no exception will be thrown
|
|
||||||
proxy.Source.Value.Handler.OnInput += OnInput;
|
|
||||||
}
|
|
||||||
_tproxies.Add(target, proxy);
|
_tproxies.Add(target, proxy);
|
||||||
_sproxies.Add(proxy.Source.Value, proxy);
|
_sproxies.Add(proxy.Source.Value, proxy);
|
||||||
IncrementUseRecursive(target);
|
IncrementUseRecursive(target);
|
||||||
@@ -77,7 +73,6 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
void Remove(InputProxyEntry proxy) {
|
void Remove(InputProxyEntry proxy) {
|
||||||
var target = proxy.Target;
|
var target = proxy.Target;
|
||||||
if (_judge != null) _tproxies[target].Source.Value.Handler.OnInput -= OnInput;
|
|
||||||
_sproxies.Remove(_tproxies[target].Source.Value);
|
_sproxies.Remove(_tproxies[target].Source.Value);
|
||||||
_tproxies.Remove(target);
|
_tproxies.Remove(target);
|
||||||
DecrementUseRecursive(target);
|
DecrementUseRecursive(target);
|
||||||
@@ -142,12 +137,22 @@ namespace Cryville.Crtr {
|
|||||||
public void Activate() {
|
public void Activate() {
|
||||||
_activeCounts.Clear();
|
_activeCounts.Clear();
|
||||||
_vect.Clear(); _vecs.Clear();
|
_vect.Clear(); _vecs.Clear();
|
||||||
foreach (var src in _sproxies.Keys) {
|
foreach (var src in _sproxies) {
|
||||||
_activeCounts.Add(src, 0);
|
_activeCounts.Add(src.Key, 0);
|
||||||
src.Handler.Activate();
|
var isrc = src.Value.Source;
|
||||||
|
if (isrc != null) {
|
||||||
|
isrc.Value.Handler.OnInput += OnInput;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void Deactivate() {
|
||||||
|
foreach (var src in _sproxies) {
|
||||||
|
var isrc = src.Value.Source;
|
||||||
|
if (isrc != null) {
|
||||||
|
isrc.Value.Handler.OnInput -= OnInput;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void Deactivate() { foreach (var src in _sproxies.Keys) src.Handler.Deactivate(); }
|
|
||||||
|
|
||||||
~InputProxy() {
|
~InputProxy() {
|
||||||
Dispose(false);
|
Dispose(false);
|
||||||
|
@@ -58,7 +58,7 @@ namespace Cryville.Crtr {
|
|||||||
MatchStatic(r.Value, state, nrctx);
|
MatchStatic(r.Value, state, nrctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (SelectorNotStaticException) {
|
catch (SelectorNotAvailableException) {
|
||||||
dynelems.Add(
|
dynelems.Add(
|
||||||
new DynamicElement { Context = ctx, Selectors = r.Key, Element = r.Value }
|
new DynamicElement { Context = ctx, Selectors = r.Key, Element = r.Value }
|
||||||
);
|
);
|
||||||
|
@@ -61,8 +61,8 @@ namespace Cryville.Crtr {
|
|||||||
public abstract class SkinSelector {
|
public abstract class SkinSelector {
|
||||||
protected SkinSelector() { }
|
protected SkinSelector() { }
|
||||||
public virtual void Optimize(PdtEvaluatorBase etor) { }
|
public virtual void Optimize(PdtEvaluatorBase etor) { }
|
||||||
public virtual IEnumerable<SkinContext> MatchStatic(ContainerState h, SkinContext c) { throw new SelectorNotStaticException(); }
|
public virtual IEnumerable<SkinContext> MatchStatic(ContainerState h, SkinContext c) { throw new SelectorNotAvailableException(); }
|
||||||
public virtual SkinContext MatchDynamic(ContainerState h, SkinContext c) { throw new NotSupportedException(); }
|
public virtual SkinContext MatchDynamic(ContainerState h, SkinContext c) { throw new SelectorNotAvailableException(); }
|
||||||
public virtual bool IsUpdatable(ContainerState h) {
|
public virtual bool IsUpdatable(ContainerState h) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -121,17 +121,16 @@ namespace Cryville.Crtr {
|
|||||||
else return Enumerable.Empty<SkinContext>();
|
else return Enumerable.Empty<SkinContext>();
|
||||||
}
|
}
|
||||||
public override SkinContext MatchDynamic(ContainerState h, SkinContext c) {
|
public override SkinContext MatchDynamic(ContainerState h, SkinContext c) {
|
||||||
return Match(c, true);
|
return Match(c);
|
||||||
}
|
}
|
||||||
public SkinContext Match(SkinContext a, bool dyn = false) {
|
public SkinContext Match(SkinContext a) {
|
||||||
ChartPlayer.etor.ContextTransform = a.Transform;
|
ChartPlayer.etor.ContextTransform = a.Transform;
|
||||||
try {
|
try {
|
||||||
ChartPlayer.etor.Evaluate(_op, _exp);
|
ChartPlayer.etor.Evaluate(_op, _exp);
|
||||||
return _flag ? a : null;
|
return _flag ? a : null;
|
||||||
}
|
}
|
||||||
catch (Exception) {
|
catch (Exception ex) {
|
||||||
if (dyn) throw;
|
throw new SelectorNotAvailableException("The expression is not evaluatable under the current context", ex);
|
||||||
else throw new SelectorNotStaticException();
|
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
ChartPlayer.etor.ContextTransform = null;
|
ChartPlayer.etor.ContextTransform = null;
|
||||||
@@ -152,10 +151,10 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public class SelectorNotStaticException : Exception {
|
public class SelectorNotAvailableException : Exception {
|
||||||
public SelectorNotStaticException() : base("The selector is not static") { }
|
public SelectorNotAvailableException() : base("The selector is not available under the current context") { }
|
||||||
public SelectorNotStaticException(string message) : base(message) { }
|
public SelectorNotAvailableException(string message) : base(message) { }
|
||||||
public SelectorNotStaticException(string message, Exception innerException) : base(message, innerException) { }
|
public SelectorNotAvailableException(string message, Exception innerException) : base(message, innerException) { }
|
||||||
protected SelectorNotStaticException(SerializationInfo info, StreamingContext context) : base(info, context) { }
|
protected SelectorNotAvailableException(SerializationInfo info, StreamingContext context) : base(info, context) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -27,6 +27,7 @@ using System.Diagnostics.CodeAnalysis;
|
|||||||
[assembly: SuppressMessage("Style", "IDE0034")]
|
[assembly: SuppressMessage("Style", "IDE0034")]
|
||||||
|
|
||||||
// Simplified new not supported
|
// Simplified new not supported
|
||||||
|
[assembly: SuppressMessage("Style", "IDE0017")]
|
||||||
[assembly: SuppressMessage("Style", "IDE0090")]
|
[assembly: SuppressMessage("Style", "IDE0090")]
|
||||||
|
|
||||||
// Pattern matching not supported
|
// Pattern matching not supported
|
||||||
|
Reference in New Issue
Block a user