com.wallstop-studios.dxmessaging 2.0.0-rc26.9 → 2.0.0-rc27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -10
- package/Runtime/AssemblyInfo.cs +7 -0
- package/Runtime/AssemblyInfo.cs.meta +3 -0
- package/Runtime/Core/DataStructure/CyclicBuffer.cs +16 -23
- package/Runtime/Core/MessageBus/MessageBus.cs +27 -16
- package/Runtime/Core/MessageHandler.cs +130 -62
- package/Runtime/Core/MessageRegistrationToken.cs +0 -2
- package/Runtime/Unity/MessageAwareComponent.cs +19 -21
- package/Tests/Runtime/Benchmarks/PerformanceTests.cs +288 -34
- package/Tests/Runtime/Core/AlternateBusTests.cs +82 -0
- package/Tests/Runtime/Core/AlternateBusTests.cs.meta +11 -0
- package/Tests/Runtime/Core/BroadcastTests.cs +2 -4
- package/Tests/Runtime/Core/DiagnosticsTests.cs +118 -0
- package/Tests/Runtime/Core/DiagnosticsTests.cs.meta +11 -0
- package/Tests/Runtime/Core/EdgeCaseTests.cs +565 -0
- package/Tests/Runtime/Core/EdgeCaseTests.cs.meta +11 -0
- package/Tests/Runtime/Core/LifecycleTests.cs +72 -0
- package/Tests/Runtime/Core/LifecycleTests.cs.meta +11 -0
- package/Tests/Runtime/Core/MessagingTestBase.cs +17 -0
- package/Tests/Runtime/Core/ReflexiveTests.cs +171 -0
- package/Tests/Runtime/Core/ReflexiveTests.cs.meta +11 -0
- package/Tests/Runtime/Scripts/Components/ManualListenerComponent.cs +22 -0
- package/Tests/Runtime/Scripts/Components/ManualListenerComponent.cs.meta +11 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -40,16 +40,16 @@ For UntargetedMessages, DxMessaging is significantly faster (roughly 2x) than Un
|
|
|
40
40
|
## Windows
|
|
41
41
|
|
|
42
42
|
| Message Tech | Operations / Second | Allocations? |
|
|
43
|
-
| ------------ | ------------------- | ------------ |
|
|
44
|
-
| Unity | 2,
|
|
45
|
-
| DxMessaging (GameObject) - Normal | 2,
|
|
46
|
-
| DxMessaging (Component) - Normal | 2,
|
|
47
|
-
| DxMessaging (GameObject) - No-Copy | 2,
|
|
48
|
-
| DxMessaging (Component) - No-Copy | 2,
|
|
49
|
-
| DxMessaging (Untargeted) - No-Copy | 4,
|
|
50
|
-
| Reflexive (One Argument) |
|
|
51
|
-
| Reflexive (Two Arguments) |
|
|
52
|
-
| Reflexive (Three Arguments) |
|
|
43
|
+
| ------------ | ------------------- | ------------ |
|
|
44
|
+
| Unity | 2,496,800 | Yes |
|
|
45
|
+
| DxMessaging (GameObject) - Normal | 2,574,400 | No |
|
|
46
|
+
| DxMessaging (Component) - Normal | 2,539,800 | No |
|
|
47
|
+
| DxMessaging (GameObject) - No-Copy | 2,745,000 | No |
|
|
48
|
+
| DxMessaging (Component) - No-Copy | 2,747,000 | No |
|
|
49
|
+
| DxMessaging (Untargeted) - No-Copy | 4,138,600 | No |
|
|
50
|
+
| Reflexive (One Argument) | 1,954,600 | No |
|
|
51
|
+
| Reflexive (Two Arguments) | 928,800 | No |
|
|
52
|
+
| Reflexive (Three Arguments) | 916,400 | No |
|
|
53
53
|
|
|
54
54
|
## Linux
|
|
55
55
|
|
|
@@ -51,7 +51,7 @@ namespace DxMessaging.Core.DataStructure
|
|
|
51
51
|
public int Count { get; private set; }
|
|
52
52
|
|
|
53
53
|
private readonly List<T> _buffer;
|
|
54
|
-
private readonly List<T> _cache
|
|
54
|
+
private readonly List<T> _cache;
|
|
55
55
|
private int _position;
|
|
56
56
|
|
|
57
57
|
public T this[int index]
|
|
@@ -79,6 +79,7 @@ namespace DxMessaging.Core.DataStructure
|
|
|
79
79
|
_position = 0;
|
|
80
80
|
Count = 0;
|
|
81
81
|
_buffer = new List<T>();
|
|
82
|
+
_cache = new List<T>();
|
|
82
83
|
if (initialContents != null)
|
|
83
84
|
{
|
|
84
85
|
foreach (T item in initialContents)
|
|
@@ -158,49 +159,41 @@ namespace DxMessaging.Core.DataStructure
|
|
|
158
159
|
return false;
|
|
159
160
|
}
|
|
160
161
|
|
|
161
|
-
|
|
162
|
-
_buffer.Clear();
|
|
163
|
-
_buffer.AddRange(_cache);
|
|
164
|
-
Count = _cache.Count;
|
|
165
|
-
_position = Count < Capacity ? Count : 0;
|
|
162
|
+
RebuildFromCache();
|
|
166
163
|
return true;
|
|
167
164
|
}
|
|
168
165
|
|
|
169
|
-
public int RemoveAll(
|
|
166
|
+
public int RemoveAll(Predicate<T> predicate)
|
|
170
167
|
{
|
|
171
168
|
if (Count == 0)
|
|
172
169
|
{
|
|
173
170
|
return 0;
|
|
174
171
|
}
|
|
175
172
|
|
|
176
|
-
|
|
177
|
-
int removedCount = 0;
|
|
178
|
-
|
|
173
|
+
_cache.Clear();
|
|
179
174
|
for (int i = 0; i < Count; ++i)
|
|
180
175
|
{
|
|
181
|
-
|
|
182
|
-
T item = _buffer[readIdx];
|
|
183
|
-
if (predicate(item))
|
|
184
|
-
{
|
|
185
|
-
removedCount++;
|
|
186
|
-
}
|
|
187
|
-
else
|
|
188
|
-
{
|
|
189
|
-
_buffer[write++] = item;
|
|
190
|
-
}
|
|
176
|
+
_cache.Add(_buffer[AdjustedIndexFor(i)]);
|
|
191
177
|
}
|
|
192
178
|
|
|
179
|
+
int removedCount = _cache.RemoveAll(predicate);
|
|
193
180
|
if (removedCount == 0)
|
|
194
181
|
{
|
|
195
182
|
return 0;
|
|
196
183
|
}
|
|
197
184
|
|
|
198
|
-
|
|
199
|
-
Count -= removedCount;
|
|
200
|
-
_position = Count < Capacity ? Count : 0;
|
|
185
|
+
RebuildFromCache();
|
|
201
186
|
return removedCount;
|
|
202
187
|
}
|
|
203
188
|
|
|
189
|
+
private void RebuildFromCache()
|
|
190
|
+
{
|
|
191
|
+
_buffer.Clear();
|
|
192
|
+
_buffer.AddRange(_cache);
|
|
193
|
+
Count = _cache.Count;
|
|
194
|
+
_position = Count < Capacity ? Count : 0;
|
|
195
|
+
}
|
|
196
|
+
|
|
204
197
|
public void Clear()
|
|
205
198
|
{
|
|
206
199
|
Count = 0;
|
|
@@ -736,8 +736,6 @@ namespace DxMessaging.Core.MessageBus
|
|
|
736
736
|
}
|
|
737
737
|
|
|
738
738
|
bool foundAnyHandlers = false;
|
|
739
|
-
Dictionary<InstanceId, HandlerCache<int, HandlerCache>> targetedHandlers;
|
|
740
|
-
HandlerCache<int, HandlerCache> sortedHandlers;
|
|
741
739
|
|
|
742
740
|
if (typeof(TMessage) == typeof(ReflexiveMessage))
|
|
743
741
|
{
|
|
@@ -931,8 +929,13 @@ namespace DxMessaging.Core.MessageBus
|
|
|
931
929
|
}
|
|
932
930
|
|
|
933
931
|
if (
|
|
934
|
-
_targetedSinks.TryGetValue<TMessage>(
|
|
935
|
-
|
|
932
|
+
_targetedSinks.TryGetValue<TMessage>(
|
|
933
|
+
out Dictionary<InstanceId, HandlerCache<int, HandlerCache>> targetedHandlers
|
|
934
|
+
)
|
|
935
|
+
&& targetedHandlers.TryGetValue(
|
|
936
|
+
target,
|
|
937
|
+
out HandlerCache<int, HandlerCache> sortedHandlers
|
|
938
|
+
)
|
|
936
939
|
&& 0 < sortedHandlers.handlers.Count
|
|
937
940
|
)
|
|
938
941
|
{
|
|
@@ -2415,14 +2418,17 @@ namespace DxMessaging.Core.MessageBus
|
|
|
2415
2418
|
foreach (KeyValuePair<int, List<object>> entry in interceptorStack)
|
|
2416
2419
|
{
|
|
2417
2420
|
interceptorObjects.Clear();
|
|
2418
|
-
|
|
2421
|
+
List<object> interceptors = entry.Value;
|
|
2422
|
+
int count = interceptors.Count;
|
|
2423
|
+
|
|
2424
|
+
for (int i = 0; i < count; ++i)
|
|
2419
2425
|
{
|
|
2420
|
-
interceptorObjects.Add(
|
|
2426
|
+
interceptorObjects.Add(interceptors[i]);
|
|
2421
2427
|
}
|
|
2422
2428
|
|
|
2423
|
-
|
|
2429
|
+
for (int i = 0; i < interceptorObjects.Count; ++i)
|
|
2424
2430
|
{
|
|
2425
|
-
if (
|
|
2431
|
+
if (interceptorObjects[i] is not UntargetedInterceptor<T> typedTransformer)
|
|
2426
2432
|
{
|
|
2427
2433
|
continue;
|
|
2428
2434
|
}
|
|
@@ -2460,14 +2466,16 @@ namespace DxMessaging.Core.MessageBus
|
|
|
2460
2466
|
foreach (KeyValuePair<int, List<object>> entry in interceptorStack)
|
|
2461
2467
|
{
|
|
2462
2468
|
interceptorObjects.Clear();
|
|
2463
|
-
|
|
2469
|
+
List<object> interceptors = entry.Value;
|
|
2470
|
+
int count = interceptors.Count;
|
|
2471
|
+
for (int i = 0; i < count; ++i)
|
|
2464
2472
|
{
|
|
2465
|
-
interceptorObjects.Add(
|
|
2473
|
+
interceptorObjects.Add(interceptors[i]);
|
|
2466
2474
|
}
|
|
2467
2475
|
|
|
2468
|
-
|
|
2476
|
+
for (int i = 0; i < interceptorObjects.Count; ++i)
|
|
2469
2477
|
{
|
|
2470
|
-
if (
|
|
2478
|
+
if (interceptorObjects[i] is not TargetedInterceptor<T> typedTransformer)
|
|
2471
2479
|
{
|
|
2472
2480
|
continue;
|
|
2473
2481
|
}
|
|
@@ -2505,14 +2513,17 @@ namespace DxMessaging.Core.MessageBus
|
|
|
2505
2513
|
foreach (KeyValuePair<int, List<object>> entry in interceptorStack)
|
|
2506
2514
|
{
|
|
2507
2515
|
interceptorObjects.Clear();
|
|
2508
|
-
|
|
2516
|
+
List<object> interceptors = entry.Value;
|
|
2517
|
+
int count = interceptors.Count;
|
|
2518
|
+
|
|
2519
|
+
for (int i = 0; i < count; ++i)
|
|
2509
2520
|
{
|
|
2510
|
-
interceptorObjects.Add(
|
|
2521
|
+
interceptorObjects.Add(interceptors[i]);
|
|
2511
2522
|
}
|
|
2512
2523
|
|
|
2513
|
-
|
|
2524
|
+
for (int i = 0; i < interceptorObjects.Count; ++i)
|
|
2514
2525
|
{
|
|
2515
|
-
if (
|
|
2526
|
+
if (interceptorObjects[i] is not BroadcastInterceptor<T> typedTransformer)
|
|
2516
2527
|
{
|
|
2517
2528
|
continue;
|
|
2518
2529
|
}
|
|
@@ -1317,8 +1317,19 @@ namespace DxMessaging.Core
|
|
|
1317
1317
|
|
|
1318
1318
|
private sealed class HandlerActionCache<T>
|
|
1319
1319
|
{
|
|
1320
|
-
|
|
1321
|
-
|
|
1320
|
+
internal readonly struct Entry
|
|
1321
|
+
{
|
|
1322
|
+
public Entry(T handler, int count)
|
|
1323
|
+
{
|
|
1324
|
+
this.handler = handler;
|
|
1325
|
+
this.count = count;
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1328
|
+
public readonly T handler;
|
|
1329
|
+
public readonly int count;
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
public readonly Dictionary<T, Entry> entries = new();
|
|
1322
1333
|
public readonly List<T> cache = new();
|
|
1323
1334
|
public long version;
|
|
1324
1335
|
public long lastSeenVersion = -1;
|
|
@@ -1522,7 +1533,7 @@ namespace DxMessaging.Core
|
|
|
1522
1533
|
public void HandleGlobalUntargeted(ref IUntargetedMessage message)
|
|
1523
1534
|
{
|
|
1524
1535
|
RunFastHandlers(_globalUntargetedFastHandlers, ref message);
|
|
1525
|
-
if (_globalUntargetedHandlers?.
|
|
1536
|
+
if (_globalUntargetedHandlers?.entries is not { Count: > 0 })
|
|
1526
1537
|
{
|
|
1527
1538
|
return;
|
|
1528
1539
|
}
|
|
@@ -1545,7 +1556,7 @@ namespace DxMessaging.Core
|
|
|
1545
1556
|
{
|
|
1546
1557
|
RunFastHandlers(ref target, _globalTargetedFastHandlers, ref message);
|
|
1547
1558
|
|
|
1548
|
-
if (_globalTargetedHandlers?.
|
|
1559
|
+
if (_globalTargetedHandlers?.entries is not { Count: > 0 })
|
|
1549
1560
|
{
|
|
1550
1561
|
return;
|
|
1551
1562
|
}
|
|
@@ -1568,7 +1579,7 @@ namespace DxMessaging.Core
|
|
|
1568
1579
|
{
|
|
1569
1580
|
RunFastHandlers(ref source, _globalBroadcastFastHandlers, ref message);
|
|
1570
1581
|
|
|
1571
|
-
if (_globalBroadcastHandlers?.
|
|
1582
|
+
if (_globalBroadcastHandlers?.entries is not { Count: > 0 })
|
|
1572
1583
|
{
|
|
1573
1584
|
return;
|
|
1574
1585
|
}
|
|
@@ -2433,7 +2444,7 @@ namespace DxMessaging.Core
|
|
|
2433
2444
|
where TMessage : IMessage
|
|
2434
2445
|
where TU : IMessage
|
|
2435
2446
|
{
|
|
2436
|
-
if (cache?.
|
|
2447
|
+
if (cache?.entries is not { Count: > 0 })
|
|
2437
2448
|
{
|
|
2438
2449
|
return;
|
|
2439
2450
|
}
|
|
@@ -2494,7 +2505,7 @@ namespace DxMessaging.Core
|
|
|
2494
2505
|
where TMessage : IMessage
|
|
2495
2506
|
where TU : IMessage
|
|
2496
2507
|
{
|
|
2497
|
-
if (cache?.
|
|
2508
|
+
if (cache?.entries is not { Count: > 0 })
|
|
2498
2509
|
{
|
|
2499
2510
|
return;
|
|
2500
2511
|
}
|
|
@@ -2789,10 +2800,15 @@ namespace DxMessaging.Core
|
|
|
2789
2800
|
|
|
2790
2801
|
List<TU> cache = actionCache.cache;
|
|
2791
2802
|
cache.Clear();
|
|
2792
|
-
|
|
2803
|
+
|
|
2804
|
+
if (actionCache.entries.Count > 0)
|
|
2793
2805
|
{
|
|
2794
|
-
|
|
2806
|
+
foreach (HandlerActionCache<TU>.Entry entry in actionCache.entries.Values)
|
|
2807
|
+
{
|
|
2808
|
+
cache.Add(entry.handler);
|
|
2809
|
+
}
|
|
2795
2810
|
}
|
|
2811
|
+
|
|
2796
2812
|
actionCache.lastSeenVersion = actionCache.version;
|
|
2797
2813
|
return cache;
|
|
2798
2814
|
}
|
|
@@ -2829,63 +2845,78 @@ namespace DxMessaging.Core
|
|
|
2829
2845
|
sortedHandlers[priority] = cache;
|
|
2830
2846
|
}
|
|
2831
2847
|
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2848
|
+
if (
|
|
2849
|
+
!cache.entries.TryGetValue(
|
|
2850
|
+
originalHandler,
|
|
2851
|
+
out HandlerActionCache<TU>.Entry entry
|
|
2852
|
+
)
|
|
2853
|
+
)
|
|
2835
2854
|
{
|
|
2836
|
-
|
|
2855
|
+
entry = new HandlerActionCache<TU>.Entry(augmentedHandler, 0);
|
|
2837
2856
|
}
|
|
2838
|
-
|
|
2857
|
+
|
|
2858
|
+
entry =
|
|
2859
|
+
entry.count == 0
|
|
2860
|
+
? new HandlerActionCache<TU>.Entry(augmentedHandler, 1)
|
|
2861
|
+
: new HandlerActionCache<TU>.Entry(entry.handler, entry.count + 1);
|
|
2862
|
+
|
|
2863
|
+
cache.entries[originalHandler] = entry;
|
|
2864
|
+
cache.version++;
|
|
2839
2865
|
|
|
2840
2866
|
Dictionary<
|
|
2841
2867
|
InstanceId,
|
|
2842
2868
|
Dictionary<int, HandlerActionCache<TU>>
|
|
2843
2869
|
> localHandlersByContext = handlersByContext;
|
|
2844
2870
|
|
|
2845
|
-
cache.version++;
|
|
2846
2871
|
return () =>
|
|
2847
2872
|
{
|
|
2848
|
-
cache.version++;
|
|
2849
2873
|
if (!localHandlersByContext.TryGetValue(context, out sortedHandlers))
|
|
2850
2874
|
{
|
|
2851
2875
|
return;
|
|
2852
2876
|
}
|
|
2853
2877
|
|
|
2854
|
-
if (
|
|
2878
|
+
if (
|
|
2879
|
+
!sortedHandlers.TryGetValue(priority, out HandlerActionCache<TU> localCache)
|
|
2880
|
+
)
|
|
2855
2881
|
{
|
|
2856
2882
|
return;
|
|
2857
2883
|
}
|
|
2858
2884
|
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2885
|
+
if (
|
|
2886
|
+
!localCache.entries.TryGetValue(
|
|
2887
|
+
originalHandler,
|
|
2888
|
+
out HandlerActionCache<TU>.Entry localEntry
|
|
2889
|
+
)
|
|
2890
|
+
)
|
|
2862
2891
|
{
|
|
2863
2892
|
return;
|
|
2864
2893
|
}
|
|
2865
2894
|
|
|
2866
|
-
|
|
2895
|
+
localCache.version++;
|
|
2896
|
+
|
|
2867
2897
|
deregistration?.Invoke();
|
|
2868
2898
|
|
|
2869
|
-
if (count <= 1)
|
|
2899
|
+
if (localEntry.count <= 1)
|
|
2870
2900
|
{
|
|
2871
|
-
_ =
|
|
2872
|
-
|
|
2873
|
-
if (0 < handlers.Count)
|
|
2874
|
-
{
|
|
2875
|
-
return;
|
|
2876
|
-
}
|
|
2877
|
-
|
|
2878
|
-
_ = sortedHandlers.Remove(priority);
|
|
2879
|
-
if (0 < sortedHandlers.Count)
|
|
2901
|
+
_ = localCache.entries.Remove(originalHandler);
|
|
2902
|
+
if (localCache.entries.Count == 0)
|
|
2880
2903
|
{
|
|
2881
|
-
|
|
2904
|
+
_ = sortedHandlers.Remove(priority);
|
|
2905
|
+
if (sortedHandlers.Count == 0)
|
|
2906
|
+
{
|
|
2907
|
+
localHandlersByContext.Remove(context);
|
|
2908
|
+
}
|
|
2882
2909
|
}
|
|
2883
2910
|
|
|
2884
|
-
localHandlersByContext.Remove(context);
|
|
2885
2911
|
return;
|
|
2886
2912
|
}
|
|
2887
2913
|
|
|
2888
|
-
|
|
2914
|
+
localEntry = new HandlerActionCache<TU>.Entry(
|
|
2915
|
+
localEntry.handler,
|
|
2916
|
+
localEntry.count - 1
|
|
2917
|
+
);
|
|
2918
|
+
|
|
2919
|
+
localCache.entries[originalHandler] = localEntry;
|
|
2889
2920
|
};
|
|
2890
2921
|
}
|
|
2891
2922
|
|
|
@@ -2897,37 +2928,54 @@ namespace DxMessaging.Core
|
|
|
2897
2928
|
)
|
|
2898
2929
|
{
|
|
2899
2930
|
cache ??= new HandlerActionCache<TU>();
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2931
|
+
|
|
2932
|
+
if (
|
|
2933
|
+
!cache.entries.TryGetValue(
|
|
2934
|
+
originalHandler,
|
|
2935
|
+
out HandlerActionCache<TU>.Entry entry
|
|
2936
|
+
)
|
|
2937
|
+
)
|
|
2903
2938
|
{
|
|
2904
|
-
|
|
2939
|
+
entry = new HandlerActionCache<TU>.Entry(augmentedHandler, 0);
|
|
2905
2940
|
}
|
|
2906
2941
|
|
|
2907
|
-
|
|
2942
|
+
entry =
|
|
2943
|
+
entry.count == 0
|
|
2944
|
+
? new HandlerActionCache<TU>.Entry(augmentedHandler, 1)
|
|
2945
|
+
: new HandlerActionCache<TU>.Entry(entry.handler, entry.count + 1);
|
|
2908
2946
|
|
|
2909
|
-
|
|
2947
|
+
cache.entries[originalHandler] = entry;
|
|
2948
|
+
cache.version++;
|
|
2910
2949
|
|
|
2911
2950
|
HandlerActionCache<TU> localCache = cache;
|
|
2912
|
-
|
|
2951
|
+
|
|
2913
2952
|
return () =>
|
|
2914
2953
|
{
|
|
2915
|
-
|
|
2916
|
-
|
|
2954
|
+
if (
|
|
2955
|
+
!localCache.entries.TryGetValue(
|
|
2956
|
+
originalHandler,
|
|
2957
|
+
out HandlerActionCache<TU>.Entry localEntry
|
|
2958
|
+
)
|
|
2959
|
+
)
|
|
2917
2960
|
{
|
|
2918
2961
|
return;
|
|
2919
2962
|
}
|
|
2920
2963
|
|
|
2921
|
-
|
|
2964
|
+
localCache.version++;
|
|
2965
|
+
|
|
2922
2966
|
deregistration?.Invoke();
|
|
2923
|
-
|
|
2967
|
+
|
|
2968
|
+
if (localEntry.count <= 1)
|
|
2924
2969
|
{
|
|
2925
|
-
_ =
|
|
2926
|
-
_ = localCache.originalToAugmented.Remove(originalHandler);
|
|
2970
|
+
_ = localCache.entries.Remove(originalHandler);
|
|
2927
2971
|
return;
|
|
2928
2972
|
}
|
|
2929
2973
|
|
|
2930
|
-
|
|
2974
|
+
localEntry = new HandlerActionCache<TU>.Entry(
|
|
2975
|
+
localEntry.handler,
|
|
2976
|
+
localEntry.count - 1
|
|
2977
|
+
);
|
|
2978
|
+
localCache.entries[originalHandler] = localEntry;
|
|
2931
2979
|
};
|
|
2932
2980
|
}
|
|
2933
2981
|
|
|
@@ -2947,44 +2995,64 @@ namespace DxMessaging.Core
|
|
|
2947
2995
|
handlers[priority] = cache;
|
|
2948
2996
|
}
|
|
2949
2997
|
|
|
2950
|
-
|
|
2951
|
-
|
|
2998
|
+
if (
|
|
2999
|
+
!cache.entries.TryGetValue(
|
|
3000
|
+
originalHandler,
|
|
3001
|
+
out HandlerActionCache<TU>.Entry entry
|
|
3002
|
+
)
|
|
3003
|
+
)
|
|
2952
3004
|
{
|
|
2953
|
-
|
|
3005
|
+
entry = new HandlerActionCache<TU>.Entry(augmentedHandler, 0);
|
|
2954
3006
|
}
|
|
2955
3007
|
|
|
2956
|
-
|
|
3008
|
+
entry =
|
|
3009
|
+
entry.count == 0
|
|
3010
|
+
? new HandlerActionCache<TU>.Entry(augmentedHandler, 1)
|
|
3011
|
+
: new HandlerActionCache<TU>.Entry(entry.handler, entry.count + 1);
|
|
2957
3012
|
|
|
2958
|
-
|
|
3013
|
+
cache.entries[originalHandler] = entry;
|
|
2959
3014
|
cache.version++;
|
|
2960
3015
|
|
|
3016
|
+
Dictionary<int, HandlerActionCache<TU>> localHandlers = handlers;
|
|
3017
|
+
|
|
2961
3018
|
return () =>
|
|
2962
3019
|
{
|
|
2963
|
-
|
|
2964
|
-
if (!localHandlers.TryGetValue(priority, out cache))
|
|
3020
|
+
if (!localHandlers.TryGetValue(priority, out HandlerActionCache<TU> localCache))
|
|
2965
3021
|
{
|
|
2966
3022
|
return;
|
|
2967
3023
|
}
|
|
2968
3024
|
|
|
2969
|
-
if (
|
|
3025
|
+
if (
|
|
3026
|
+
!localCache.entries.TryGetValue(
|
|
3027
|
+
originalHandler,
|
|
3028
|
+
out HandlerActionCache<TU>.Entry localEntry
|
|
3029
|
+
)
|
|
3030
|
+
)
|
|
2970
3031
|
{
|
|
2971
3032
|
return;
|
|
2972
3033
|
}
|
|
2973
3034
|
|
|
2974
|
-
|
|
3035
|
+
localCache.version++;
|
|
3036
|
+
|
|
2975
3037
|
deregistration?.Invoke();
|
|
2976
|
-
|
|
3038
|
+
|
|
3039
|
+
if (localEntry.count <= 1)
|
|
2977
3040
|
{
|
|
2978
|
-
_ =
|
|
2979
|
-
|
|
2980
|
-
if (cache.handlers.Count == 0)
|
|
3041
|
+
_ = localCache.entries.Remove(originalHandler);
|
|
3042
|
+
if (localCache.entries.Count == 0)
|
|
2981
3043
|
{
|
|
2982
3044
|
_ = localHandlers.Remove(priority);
|
|
2983
3045
|
}
|
|
3046
|
+
|
|
2984
3047
|
return;
|
|
2985
3048
|
}
|
|
2986
3049
|
|
|
2987
|
-
|
|
3050
|
+
localEntry = new HandlerActionCache<TU>.Entry(
|
|
3051
|
+
localEntry.handler,
|
|
3052
|
+
localEntry.count - 1
|
|
3053
|
+
);
|
|
3054
|
+
|
|
3055
|
+
localCache.entries[originalHandler] = localEntry;
|
|
2988
3056
|
};
|
|
2989
3057
|
}
|
|
2990
3058
|
}
|
|
@@ -16,6 +16,11 @@ namespace DxMessaging.Unity
|
|
|
16
16
|
/// </summary>
|
|
17
17
|
protected virtual bool MessageRegistrationTiedToEnableStatus => true;
|
|
18
18
|
|
|
19
|
+
/// <summary>
|
|
20
|
+
/// If true, will register/unregister handles for StringMessages.
|
|
21
|
+
/// </summary>
|
|
22
|
+
protected virtual bool RegisterForStringMessages => true;
|
|
23
|
+
|
|
19
24
|
protected bool _isQuitting;
|
|
20
25
|
|
|
21
26
|
protected MessagingComponent _messagingComponent;
|
|
@@ -29,17 +34,20 @@ namespace DxMessaging.Unity
|
|
|
29
34
|
|
|
30
35
|
protected virtual void RegisterMessageHandlers()
|
|
31
36
|
{
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
if (RegisterForStringMessages)
|
|
38
|
+
{
|
|
39
|
+
_ = _messageRegistrationToken.RegisterGameObjectTargeted<StringMessage>(
|
|
40
|
+
gameObject,
|
|
41
|
+
HandleStringGameObjectMessage
|
|
42
|
+
);
|
|
43
|
+
_ = _messageRegistrationToken.RegisterComponentTargeted<StringMessage>(
|
|
44
|
+
this,
|
|
45
|
+
HandleStringComponentMessage
|
|
46
|
+
);
|
|
47
|
+
_ = _messageRegistrationToken.RegisterUntargeted<GlobalStringMessage>(
|
|
48
|
+
HandleGlobalStringMessage
|
|
49
|
+
);
|
|
50
|
+
}
|
|
43
51
|
}
|
|
44
52
|
|
|
45
53
|
protected virtual void OnEnable()
|
|
@@ -52,11 +60,6 @@ namespace DxMessaging.Unity
|
|
|
52
60
|
|
|
53
61
|
protected virtual void OnDisable()
|
|
54
62
|
{
|
|
55
|
-
if (_isQuitting)
|
|
56
|
-
{
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
63
|
if (MessageRegistrationTiedToEnableStatus)
|
|
61
64
|
{
|
|
62
65
|
_messageRegistrationToken?.Disable();
|
|
@@ -65,11 +68,6 @@ namespace DxMessaging.Unity
|
|
|
65
68
|
|
|
66
69
|
protected virtual void OnDestroy()
|
|
67
70
|
{
|
|
68
|
-
if (_isQuitting)
|
|
69
|
-
{
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
71
|
_messageRegistrationToken?.Disable();
|
|
74
72
|
_messageRegistrationToken = null;
|
|
75
73
|
}
|