Optimize code structure for input module.

This commit is contained in:
2023-01-21 17:04:29 +08:00
parent 6779b88055
commit 5198ecec1f
11 changed files with 116 additions and 93 deletions

View File

@@ -65,10 +65,6 @@ namespace Cryville.Crtr {
if (_use[target] > 0)
throw new InvalidOperationException("Input already assigned");
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);
_sproxies.Add(proxy.Source.Value, proxy);
IncrementUseRecursive(target);
@@ -77,7 +73,6 @@ namespace Cryville.Crtr {
}
void Remove(InputProxyEntry proxy) {
var target = proxy.Target;
if (_judge != null) _tproxies[target].Source.Value.Handler.OnInput -= OnInput;
_sproxies.Remove(_tproxies[target].Source.Value);
_tproxies.Remove(target);
DecrementUseRecursive(target);
@@ -142,12 +137,22 @@ namespace Cryville.Crtr {
public void Activate() {
_activeCounts.Clear();
_vect.Clear(); _vecs.Clear();
foreach (var src in _sproxies.Keys) {
_activeCounts.Add(src, 0);
src.Handler.Activate();
foreach (var src in _sproxies) {
_activeCounts.Add(src.Key, 0);
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() {
Dispose(false);