com.wallstop-studios.dxmessaging 2.1.2 → 2.1.3
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/.github/workflows/dotnet-tests.yml +1 -1
- package/AGENTS.md +12 -12
- package/Docs/Comparisons.md +5 -5
- package/Docs/InterceptorsAndOrdering.md +1 -1
- package/Docs/Performance.md +13 -13
- package/Docs/QuickReference.md +1 -1
- package/Docs/Reference.md +5 -5
- package/Editor/Analyzers/WallstopStudios.DxMessaging.SourceGenerators.dll +0 -0
- package/Editor/CustomEditors/MessagingComponentEditor.cs +3 -0
- package/Editor/DxMessagingEditorInitializer.cs +58 -1
- package/Editor/DxMessagingMenu.cs +38 -0
- package/Editor/DxMessagingMenu.cs.meta +11 -0
- package/Editor/DxMessagingSceneBuildProcessor.cs +81 -0
- package/Editor/DxMessagingSceneBuildProcessor.cs.meta +11 -0
- package/Editor/Settings/DxMessagingSettings.cs +37 -6
- package/Editor/Settings/DxMessagingSettingsProvider.cs +45 -7
- package/README.md +1 -1
- package/Runtime/Core/Attributes/DxOptionalParameterAttribute.cs +52 -0
- package/Runtime/Core/DataStructure/CyclicBuffer.cs +16 -0
- package/Runtime/Core/Diagnostics/MessageEmissionData.cs +1 -1
- package/Runtime/Core/Diagnostics/MessageRegistrationType.cs +62 -0
- package/Runtime/Core/DxMessagingStaticState.cs +108 -0
- package/Runtime/Core/DxMessagingStaticState.cs.meta +11 -0
- package/Runtime/Core/Extensions/IListExtensions.cs +24 -0
- package/Runtime/Core/Extensions/MessageBusExtensions.cs +142 -0
- package/Runtime/Core/Helper/MessageCache.cs +16 -0
- package/Runtime/Core/Helper/MessageHelperIndexer.cs +77 -0
- package/Runtime/Core/InstanceId.cs +86 -0
- package/Runtime/Core/MessageBus/DiagnosticsTarget.cs +31 -0
- package/Runtime/Core/MessageBus/DiagnosticsTarget.cs.meta +11 -0
- package/Runtime/Core/MessageBus/IMessageBus.cs +44 -16
- package/Runtime/Core/MessageBus/MessageBus.cs +92 -21
- package/Runtime/Core/MessageBus/MessageRegistrationBuilder.cs +44 -0
- package/Runtime/Core/MessageBus/MessagingRegistration.cs +60 -2
- package/Runtime/Core/MessageBus/RegistrationLog.cs +10 -0
- package/Runtime/Core/MessageHandler.cs +107 -6
- package/Runtime/Core/MessageRegistrationHandle.cs +59 -0
- package/Runtime/Core/MessageRegistrationToken.cs +18 -2
- package/Runtime/Core/Messages/ReflexiveMessage.cs +38 -0
- package/Runtime/Core/MessagingDebug.cs +16 -1
- package/Runtime/Unity/CurrentGlobalMessageBusProvider.cs +4 -0
- package/Runtime/Unity/DxMessagingRuntimeInitializer.cs +19 -0
- package/Runtime/Unity/DxMessagingRuntimeInitializer.cs.meta +11 -0
- package/Runtime/Unity/InitialGlobalMessageBusProvider.cs +4 -0
- package/Runtime/Unity/Integrations/Reflex/ReflexRegistrationInstaller.cs +17 -0
- package/Runtime/Unity/Integrations/VContainer/VContainerRegistrationExtensions.cs +8 -0
- package/Runtime/Unity/Integrations/Zenject/ZenjectRegistrationInstaller.cs +12 -0
- package/Runtime/Unity/MessagingComponent.cs +93 -0
- package/Samples~/DI/README.md +13 -13
- package/Samples~/Mini Combat/README.md +15 -15
- package/Samples~/Mini Combat/Walkthrough.md +12 -12
- package/Samples~/UI Buttons + Inspector/README.md +4 -4
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxAutoConstructorGenerator.cs +4 -0
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxMessageIdGenerator.cs +4 -0
- package/Tests/Runtime/Core/DiagnosticsTests.cs +3 -3
- package/Tests/Runtime/Core/DxMessagingStaticStateTests.cs +69 -0
- package/Tests/Runtime/Core/DxMessagingStaticStateTests.cs.meta +11 -0
- package/package.json +1 -1
- package/Tests/Runtime/WallstopStudios.DxMessaging.Tests.Runtime.csproj +0 -20
- package/Tests/Runtime/WallstopStudios.DxMessaging.Tests.Runtime.csproj.meta +0 -7
|
@@ -33,6 +33,10 @@ namespace DxMessaging.Core.Helper
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
36
|
+
/// <summary>
|
|
37
|
+
/// Advances the enumerator to the next cached value.
|
|
38
|
+
/// </summary>
|
|
39
|
+
/// <returns><c>true</c> if another non-null value exists; otherwise <c>false</c>.</returns>
|
|
36
40
|
public bool MoveNext()
|
|
37
41
|
{
|
|
38
42
|
List<TValue> values = _cache._values;
|
|
@@ -55,12 +59,18 @@ namespace DxMessaging.Core.Helper
|
|
|
55
59
|
object IEnumerator.Current => Current;
|
|
56
60
|
|
|
57
61
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
62
|
+
/// <summary>
|
|
63
|
+
/// Resets the enumerator to the position before the first element.
|
|
64
|
+
/// </summary>
|
|
58
65
|
public void Reset()
|
|
59
66
|
{
|
|
60
67
|
_index = -1;
|
|
61
68
|
_current = default;
|
|
62
69
|
}
|
|
63
70
|
|
|
71
|
+
/// <summary>
|
|
72
|
+
/// Releases resources held by the enumerator.
|
|
73
|
+
/// </summary>
|
|
64
74
|
public void Dispose() { }
|
|
65
75
|
}
|
|
66
76
|
|
|
@@ -179,6 +189,12 @@ namespace DxMessaging.Core.Helper
|
|
|
179
189
|
return GetEnumerator();
|
|
180
190
|
}
|
|
181
191
|
|
|
192
|
+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
193
|
+
internal void Clear()
|
|
194
|
+
{
|
|
195
|
+
_values.Clear();
|
|
196
|
+
}
|
|
197
|
+
|
|
182
198
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
183
199
|
private void FillToIndex(int index)
|
|
184
200
|
{
|
|
@@ -1,8 +1,80 @@
|
|
|
1
1
|
namespace DxMessaging.Core.Helper
|
|
2
2
|
{
|
|
3
|
+
using System;
|
|
4
|
+
using System.Collections.Generic;
|
|
5
|
+
|
|
3
6
|
public static class MessageHelperIndexer
|
|
4
7
|
{
|
|
8
|
+
internal readonly struct MessageHelperIndexerState
|
|
9
|
+
{
|
|
10
|
+
internal readonly int _totalMessages;
|
|
11
|
+
|
|
12
|
+
internal readonly Dictionary<Type, int> _sequentialIds;
|
|
13
|
+
|
|
14
|
+
internal MessageHelperIndexerState(
|
|
15
|
+
int totalMessages,
|
|
16
|
+
Dictionary<Type, int> sequentialIds
|
|
17
|
+
)
|
|
18
|
+
{
|
|
19
|
+
_totalMessages = totalMessages;
|
|
20
|
+
_sequentialIds = sequentialIds;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
private static readonly object ResetLock = new();
|
|
25
|
+
private static readonly HashSet<Type> RegisteredTypes = new();
|
|
26
|
+
private static readonly Dictionary<Type, Func<int, int>> StateManipulationByType = new();
|
|
27
|
+
|
|
5
28
|
internal static int TotalMessages = 0;
|
|
29
|
+
|
|
30
|
+
internal static void RegisterType(Type messageType, Func<int, int> idProducer)
|
|
31
|
+
{
|
|
32
|
+
if (messageType == null)
|
|
33
|
+
{
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
lock (ResetLock)
|
|
38
|
+
{
|
|
39
|
+
if (!RegisteredTypes.Add(messageType))
|
|
40
|
+
{
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
StateManipulationByType[messageType] = idProducer;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
internal static MessageHelperIndexerState CaptureState()
|
|
49
|
+
{
|
|
50
|
+
lock (ResetLock)
|
|
51
|
+
{
|
|
52
|
+
Dictionary<Type, int> snapshot = new(RegisteredTypes.Count);
|
|
53
|
+
return new MessageHelperIndexerState(TotalMessages, snapshot);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
internal static void RestoreState(MessageHelperIndexerState state)
|
|
58
|
+
{
|
|
59
|
+
lock (ResetLock)
|
|
60
|
+
{
|
|
61
|
+
TotalMessages = state._totalMessages;
|
|
62
|
+
foreach (KeyValuePair<Type, Func<int, int>> entry in StateManipulationByType)
|
|
63
|
+
{
|
|
64
|
+
Type type = entry.Key;
|
|
65
|
+
Func<int, int> manipulationAction = entry.Value;
|
|
66
|
+
if (
|
|
67
|
+
state._sequentialIds == null
|
|
68
|
+
|| !state._sequentialIds.TryGetValue(type, out int value)
|
|
69
|
+
)
|
|
70
|
+
{
|
|
71
|
+
value = -1;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
manipulationAction(value);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
6
78
|
}
|
|
7
79
|
|
|
8
80
|
public static class MessageHelperIndexer<TMessage>
|
|
@@ -10,5 +82,10 @@ namespace DxMessaging.Core.Helper
|
|
|
10
82
|
{
|
|
11
83
|
// ReSharper disable once StaticMemberInGenericType
|
|
12
84
|
internal static int SequentialId = -1;
|
|
85
|
+
|
|
86
|
+
static MessageHelperIndexer()
|
|
87
|
+
{
|
|
88
|
+
MessageHelperIndexer.RegisterType(typeof(TMessage), value => SequentialId = value);
|
|
89
|
+
}
|
|
13
90
|
}
|
|
14
91
|
}
|
|
@@ -35,6 +35,10 @@ namespace DxMessaging.Core
|
|
|
35
35
|
public readonly UnityEngine.Object Object;
|
|
36
36
|
#endif
|
|
37
37
|
|
|
38
|
+
/// <summary>
|
|
39
|
+
/// Creates an identifier that wraps the provided Unity instance ID.
|
|
40
|
+
/// </summary>
|
|
41
|
+
/// <param name="id">Unity instance ID to wrap.</param>
|
|
38
42
|
public InstanceId(int id)
|
|
39
43
|
{
|
|
40
44
|
_id = id;
|
|
@@ -51,12 +55,22 @@ namespace DxMessaging.Core
|
|
|
51
55
|
}
|
|
52
56
|
|
|
53
57
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
58
|
+
/// <summary>
|
|
59
|
+
/// Converts a <see cref="UnityEngine.GameObject"/> reference into an <see cref="InstanceId"/>.
|
|
60
|
+
/// </summary>
|
|
61
|
+
/// <param name="gameObject">GameObject to wrap.</param>
|
|
62
|
+
/// <returns>Instance identifier representing <paramref name="gameObject"/>.</returns>
|
|
54
63
|
public static implicit operator InstanceId(UnityEngine.GameObject gameObject)
|
|
55
64
|
{
|
|
56
65
|
return new InstanceId(gameObject);
|
|
57
66
|
}
|
|
58
67
|
|
|
59
68
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
69
|
+
/// <summary>
|
|
70
|
+
/// Converts a <see cref="UnityEngine.Component"/> reference into an <see cref="InstanceId"/>.
|
|
71
|
+
/// </summary>
|
|
72
|
+
/// <param name="component">Component to wrap.</param>
|
|
73
|
+
/// <returns>Instance identifier representing <paramref name="component"/>.</returns>
|
|
60
74
|
public static implicit operator InstanceId(UnityEngine.Component component)
|
|
61
75
|
{
|
|
62
76
|
return new InstanceId(component);
|
|
@@ -64,23 +78,43 @@ namespace DxMessaging.Core
|
|
|
64
78
|
#endif
|
|
65
79
|
|
|
66
80
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
81
|
+
/// <summary>
|
|
82
|
+
/// Checks for equality with another <see cref="InstanceId"/>.
|
|
83
|
+
/// </summary>
|
|
84
|
+
/// <param name="other">Other instance identifier.</param>
|
|
85
|
+
/// <returns><c>true</c> when both identifiers refer to the same Unity instance.</returns>
|
|
67
86
|
public bool Equals(InstanceId other)
|
|
68
87
|
{
|
|
69
88
|
return _id == other._id;
|
|
70
89
|
}
|
|
71
90
|
|
|
72
91
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
92
|
+
/// <summary>
|
|
93
|
+
/// Checks for equality with an arbitrary object.
|
|
94
|
+
/// </summary>
|
|
95
|
+
/// <param name="other">Object to compare.</param>
|
|
96
|
+
/// <returns>
|
|
97
|
+
/// <c>true</c> when <paramref name="other"/> is an <see cref="InstanceId"/> representing the same Unity instance.
|
|
98
|
+
/// </returns>
|
|
73
99
|
public override bool Equals(object other)
|
|
74
100
|
{
|
|
75
101
|
return other is InstanceId id && Equals(id);
|
|
76
102
|
}
|
|
77
103
|
|
|
78
104
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
105
|
+
/// <summary>
|
|
106
|
+
/// Gets a hash code suitable for dictionary or set lookups.
|
|
107
|
+
/// </summary>
|
|
108
|
+
/// <returns>Hash code derived from the underlying Unity instance ID.</returns>
|
|
79
109
|
public override int GetHashCode()
|
|
80
110
|
{
|
|
81
111
|
return _id;
|
|
82
112
|
}
|
|
83
113
|
|
|
114
|
+
/// <summary>
|
|
115
|
+
/// Returns a string representation that includes the Unity instance ID and, when available, the object name.
|
|
116
|
+
/// </summary>
|
|
117
|
+
/// <returns>Human-readable description of the identifier.</returns>
|
|
84
118
|
public override string ToString()
|
|
85
119
|
{
|
|
86
120
|
#if UNITY_2021_3_OR_NEWER
|
|
@@ -93,48 +127,100 @@ namespace DxMessaging.Core
|
|
|
93
127
|
}
|
|
94
128
|
|
|
95
129
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
130
|
+
/// <summary>
|
|
131
|
+
/// Determines whether two identifiers refer to the same Unity instance.
|
|
132
|
+
/// </summary>
|
|
133
|
+
/// <param name="lhs">Left-hand identifier.</param>
|
|
134
|
+
/// <param name="rhs">Right-hand identifier.</param>
|
|
135
|
+
/// <returns><c>true</c> when both identifiers represent the same value.</returns>
|
|
96
136
|
public static bool operator ==(InstanceId lhs, InstanceId rhs)
|
|
97
137
|
{
|
|
98
138
|
return lhs._id == rhs._id;
|
|
99
139
|
}
|
|
100
140
|
|
|
101
141
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
142
|
+
/// <summary>
|
|
143
|
+
/// Determines whether two identifiers refer to different Unity instances.
|
|
144
|
+
/// </summary>
|
|
145
|
+
/// <param name="lhs">Left-hand identifier.</param>
|
|
146
|
+
/// <param name="rhs">Right-hand identifier.</param>
|
|
147
|
+
/// <returns><c>true</c> when the identifiers represent different values.</returns>
|
|
102
148
|
public static bool operator !=(InstanceId lhs, InstanceId rhs)
|
|
103
149
|
{
|
|
104
150
|
return lhs._id != rhs._id;
|
|
105
151
|
}
|
|
106
152
|
|
|
107
153
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
154
|
+
/// <summary>
|
|
155
|
+
/// Compares two identifiers for ascending ordering.
|
|
156
|
+
/// </summary>
|
|
157
|
+
/// <param name="lhs">Left-hand identifier.</param>
|
|
158
|
+
/// <param name="rhs">Right-hand identifier.</param>
|
|
159
|
+
/// <returns><c>true</c> when <paramref name="lhs"/> precedes <paramref name="rhs"/>.</returns>
|
|
108
160
|
public static bool operator <(InstanceId lhs, InstanceId rhs)
|
|
109
161
|
{
|
|
110
162
|
return lhs._id.CompareTo(rhs._id) < 0;
|
|
111
163
|
}
|
|
112
164
|
|
|
113
165
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
166
|
+
/// <summary>
|
|
167
|
+
/// Compares two identifiers for ascending ordering with equality.
|
|
168
|
+
/// </summary>
|
|
169
|
+
/// <param name="lhs">Left-hand identifier.</param>
|
|
170
|
+
/// <param name="rhs">Right-hand identifier.</param>
|
|
171
|
+
/// <returns>
|
|
172
|
+
/// <c>true</c> when <paramref name="lhs"/> precedes <paramref name="rhs"/> or both identifiers are equal.
|
|
173
|
+
/// </returns>
|
|
114
174
|
public static bool operator <=(InstanceId lhs, InstanceId rhs)
|
|
115
175
|
{
|
|
116
176
|
return lhs._id.CompareTo(rhs._id) <= 0;
|
|
117
177
|
}
|
|
118
178
|
|
|
119
179
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
180
|
+
/// <summary>
|
|
181
|
+
/// Compares two identifiers for descending ordering.
|
|
182
|
+
/// </summary>
|
|
183
|
+
/// <param name="lhs">Left-hand identifier.</param>
|
|
184
|
+
/// <param name="rhs">Right-hand identifier.</param>
|
|
185
|
+
/// <returns><c>true</c> when <paramref name="lhs"/> follows <paramref name="rhs"/>.</returns>
|
|
120
186
|
public static bool operator >(InstanceId lhs, InstanceId rhs)
|
|
121
187
|
{
|
|
122
188
|
return lhs._id.CompareTo(rhs._id) > 0;
|
|
123
189
|
}
|
|
124
190
|
|
|
125
191
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
192
|
+
/// <summary>
|
|
193
|
+
/// Compares two identifiers for descending ordering with equality.
|
|
194
|
+
/// </summary>
|
|
195
|
+
/// <param name="lhs">Left-hand identifier.</param>
|
|
196
|
+
/// <param name="rhs">Right-hand identifier.</param>
|
|
197
|
+
/// <returns>
|
|
198
|
+
/// <c>true</c> when <paramref name="lhs"/> follows <paramref name="rhs"/> or both identifiers are equal.
|
|
199
|
+
/// </returns>
|
|
126
200
|
public static bool operator >=(InstanceId lhs, InstanceId rhs)
|
|
127
201
|
{
|
|
128
202
|
return lhs._id.CompareTo(rhs._id) >= 0;
|
|
129
203
|
}
|
|
130
204
|
|
|
131
205
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
206
|
+
/// <summary>
|
|
207
|
+
/// Compares this identifier with another identifier for ordering.
|
|
208
|
+
/// </summary>
|
|
209
|
+
/// <param name="other">Identifier to compare with.</param>
|
|
210
|
+
/// <returns>Relative ordering as defined by <see cref="IComparable{T}.CompareTo(T)"/>.</returns>
|
|
132
211
|
public int CompareTo(InstanceId other)
|
|
133
212
|
{
|
|
134
213
|
return _id.CompareTo(other._id);
|
|
135
214
|
}
|
|
136
215
|
|
|
137
216
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
217
|
+
/// <summary>
|
|
218
|
+
/// Compares this identifier with an arbitrary object for ordering.
|
|
219
|
+
/// </summary>
|
|
220
|
+
/// <param name="rhs">Object to compare with.</param>
|
|
221
|
+
/// <returns>
|
|
222
|
+
/// Relative ordering when <paramref name="rhs"/> is an <see cref="InstanceId"/>; otherwise <c>-1</c>.
|
|
223
|
+
/// </returns>
|
|
138
224
|
public int CompareTo(object rhs)
|
|
139
225
|
{
|
|
140
226
|
if (rhs is InstanceId other)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
namespace DxMessaging.Core.MessageBus
|
|
2
|
+
{
|
|
3
|
+
using System;
|
|
4
|
+
|
|
5
|
+
/// <summary>
|
|
6
|
+
/// Flags describing which execution targets should enable diagnostics by default.
|
|
7
|
+
/// </summary>
|
|
8
|
+
[Flags]
|
|
9
|
+
public enum DiagnosticsTarget
|
|
10
|
+
{
|
|
11
|
+
/// <summary>
|
|
12
|
+
/// Diagnostics are disabled.
|
|
13
|
+
/// </summary>
|
|
14
|
+
Off = 0,
|
|
15
|
+
|
|
16
|
+
/// <summary>
|
|
17
|
+
/// Diagnostics should run while in the Unity editor.
|
|
18
|
+
/// </summary>
|
|
19
|
+
Editor = 1,
|
|
20
|
+
|
|
21
|
+
/// <summary>
|
|
22
|
+
/// Diagnostics should run while in player/runtime builds.
|
|
23
|
+
/// </summary>
|
|
24
|
+
Runtime = 2,
|
|
25
|
+
|
|
26
|
+
/// <summary>
|
|
27
|
+
/// Diagnostics should run in both editor and runtime environments.
|
|
28
|
+
/// </summary>
|
|
29
|
+
All = Editor | Runtime,
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -3,7 +3,11 @@ namespace DxMessaging.Core.MessageBus
|
|
|
3
3
|
using System;
|
|
4
4
|
using System.Threading;
|
|
5
5
|
using Core;
|
|
6
|
+
using Extensions;
|
|
6
7
|
using Messages;
|
|
8
|
+
#if UNITY_2021_3_OR_NEWER
|
|
9
|
+
using UnityEngine;
|
|
10
|
+
#endif
|
|
7
11
|
|
|
8
12
|
/// <summary>
|
|
9
13
|
/// Contract for a general-purpose message bus handling registration and dispatch.
|
|
@@ -41,31 +45,59 @@ namespace DxMessaging.Core.MessageBus
|
|
|
41
45
|
/// <summary>
|
|
42
46
|
/// Default diagnostics mode for newly created buses and tokens.
|
|
43
47
|
/// </summary>
|
|
44
|
-
|
|
48
|
+
static DiagnosticsTarget GlobalDiagnosticsTargets { get; set; } = DiagnosticsTarget.Off;
|
|
49
|
+
|
|
50
|
+
[Obsolete("Use GlobalDiagnosticsTargets instead.")]
|
|
51
|
+
static bool GlobalDiagnosticsMode
|
|
52
|
+
{
|
|
53
|
+
get => GlobalDiagnosticsTargets != DiagnosticsTarget.Off;
|
|
54
|
+
set => GlobalDiagnosticsTargets = value ? DiagnosticsTarget.All : DiagnosticsTarget.Off;
|
|
55
|
+
}
|
|
45
56
|
|
|
46
57
|
long EmissionId { get; }
|
|
47
58
|
|
|
48
59
|
/// <summary>
|
|
49
60
|
/// Default ring buffer size for emission history when diagnostics are enabled.
|
|
50
61
|
/// </summary>
|
|
51
|
-
|
|
62
|
+
static int GlobalMessageBufferSize { get; set; }
|
|
52
63
|
|
|
53
64
|
internal static int GlobalSequentialIndex = -1;
|
|
54
65
|
|
|
55
66
|
protected static int GenerateNewGlobalSequentialIndex() =>
|
|
56
67
|
Interlocked.Increment(ref GlobalSequentialIndex);
|
|
57
68
|
|
|
69
|
+
internal static bool ShouldEnableDiagnostics()
|
|
70
|
+
{
|
|
71
|
+
DiagnosticsTarget targets = GlobalDiagnosticsTargets;
|
|
72
|
+
if (targets == DiagnosticsTarget.Off)
|
|
73
|
+
{
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
#if UNITY_2021_3_OR_NEWER
|
|
78
|
+
if (Application.isEditor)
|
|
79
|
+
{
|
|
80
|
+
return targets.HasFlagNoAlloc(DiagnosticsTarget.Editor)
|
|
81
|
+
|| targets.HasFlagNoAlloc(DiagnosticsTarget.Runtime);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return targets.HasFlagNoAlloc(DiagnosticsTarget.Editor);
|
|
85
|
+
#else
|
|
86
|
+
return targets.HasFlagNoAlloc(DiagnosticsTarget.Runtime);
|
|
87
|
+
#endif
|
|
88
|
+
}
|
|
89
|
+
|
|
58
90
|
/// <summary>
|
|
59
91
|
/// Whether diagnostics are recorded for this bus instance.
|
|
60
92
|
/// </summary>
|
|
61
|
-
|
|
93
|
+
bool DiagnosticsMode { get; }
|
|
62
94
|
|
|
63
|
-
|
|
64
|
-
|
|
95
|
+
int RegisteredGlobalSequentialIndex { get; }
|
|
96
|
+
int RegisteredBroadcast { get; }
|
|
65
97
|
|
|
66
|
-
|
|
98
|
+
int RegisteredTargeted { get; }
|
|
67
99
|
|
|
68
|
-
|
|
100
|
+
int RegisteredUntargeted { get; }
|
|
69
101
|
|
|
70
102
|
/// <summary>
|
|
71
103
|
/// Interceptor delegate for untargeted messages to transform or cancel them.
|
|
@@ -73,7 +105,7 @@ namespace DxMessaging.Core.MessageBus
|
|
|
73
105
|
/// <typeparam name="TMessage">Specific type of message.</typeparam>
|
|
74
106
|
/// <param name="message">Message to consider.</param>
|
|
75
107
|
/// <returns>True if the message should be processed, false if it should be skipped.</returns>
|
|
76
|
-
|
|
108
|
+
delegate bool UntargetedInterceptor<TMessage>(ref TMessage message)
|
|
77
109
|
where TMessage : IUntargetedMessage;
|
|
78
110
|
|
|
79
111
|
/// <summary>
|
|
@@ -83,10 +115,7 @@ namespace DxMessaging.Core.MessageBus
|
|
|
83
115
|
/// <param name="target">Target of the message.</param>
|
|
84
116
|
/// <param name="message">Message to consider.</param>
|
|
85
117
|
/// <returns>True if the message should be processed, false if it should be skipped.</returns>
|
|
86
|
-
|
|
87
|
-
ref InstanceId target,
|
|
88
|
-
ref TMessage message
|
|
89
|
-
)
|
|
118
|
+
delegate bool TargetedInterceptor<TMessage>(ref InstanceId target, ref TMessage message)
|
|
90
119
|
where TMessage : ITargetedMessage;
|
|
91
120
|
|
|
92
121
|
/// <summary>
|
|
@@ -96,10 +125,7 @@ namespace DxMessaging.Core.MessageBus
|
|
|
96
125
|
/// <param name="source">Source of the message.</param>
|
|
97
126
|
/// <param name="message">Message to consider.</param>
|
|
98
127
|
/// <returns>True if the message should be processed, false if it should be skipped.</returns>
|
|
99
|
-
|
|
100
|
-
ref InstanceId source,
|
|
101
|
-
ref TMessage message
|
|
102
|
-
)
|
|
128
|
+
delegate bool BroadcastInterceptor<TMessage>(ref InstanceId source, ref TMessage message)
|
|
103
129
|
where TMessage : IBroadcastMessage;
|
|
104
130
|
|
|
105
131
|
/// <summary>
|
|
@@ -149,6 +175,7 @@ namespace DxMessaging.Core.MessageBus
|
|
|
149
175
|
/// <typeparam name="T">Type of the BroadcastMessage to register.</typeparam>
|
|
150
176
|
/// <param name="source">InstanceId of the source for BroadcastMessages to listen to.</param>
|
|
151
177
|
/// <param name="messageHandler">MessageHandler to register to accept BroadcastMessages.</param>
|
|
178
|
+
/// <param name="priority"></param>
|
|
152
179
|
/// <returns>The deregistration action. Should be invoked when the handler no longer wants to receive messages.</returns>
|
|
153
180
|
Action RegisterSourcedBroadcast<T>(
|
|
154
181
|
InstanceId source,
|
|
@@ -163,6 +190,7 @@ namespace DxMessaging.Core.MessageBus
|
|
|
163
190
|
/// </summary>
|
|
164
191
|
/// <typeparam name="T">Type of the BroadcastMessage to register.</typeparam>
|
|
165
192
|
/// <param name="messageHandler">MessageHandler to register to accept BroadcastMessages.</param>
|
|
193
|
+
/// <param name="priority"></param>
|
|
166
194
|
/// <returns>The deregistration action. Should be invoked when the handler no longer wants to receive messages.</returns>
|
|
167
195
|
Action RegisterSourcedBroadcastWithoutSource<T>(
|
|
168
196
|
MessageHandler messageHandler,
|