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
|
@@ -31,30 +31,82 @@ namespace DxMessaging.Core.Attributes
|
|
|
31
31
|
/// Optional default value overloads. Values must be compile-time constants and
|
|
32
32
|
/// will be validated by the source generator against the field type.
|
|
33
33
|
/// </summary>
|
|
34
|
+
/// <summary>
|
|
35
|
+
/// Initializes the attribute with the specified default boolean value.
|
|
36
|
+
/// </summary>
|
|
37
|
+
/// <param name="value">Default value used when the constructor parameter is omitted.</param>
|
|
34
38
|
public DxOptionalParameterAttribute(bool value) { }
|
|
35
39
|
|
|
40
|
+
/// <summary>
|
|
41
|
+
/// Initializes the attribute with the specified default character value.
|
|
42
|
+
/// </summary>
|
|
43
|
+
/// <param name="value">Default value used when the constructor parameter is omitted.</param>
|
|
36
44
|
public DxOptionalParameterAttribute(char value) { }
|
|
37
45
|
|
|
46
|
+
/// <summary>
|
|
47
|
+
/// Initializes the attribute with the specified default string value.
|
|
48
|
+
/// </summary>
|
|
49
|
+
/// <param name="value">Default value used when the constructor parameter is omitted.</param>
|
|
38
50
|
public DxOptionalParameterAttribute(string value) { }
|
|
39
51
|
|
|
52
|
+
/// <summary>
|
|
53
|
+
/// Initializes the attribute with the specified default byte value.
|
|
54
|
+
/// </summary>
|
|
55
|
+
/// <param name="value">Default value used when the constructor parameter is omitted.</param>
|
|
40
56
|
public DxOptionalParameterAttribute(byte value) { }
|
|
41
57
|
|
|
58
|
+
/// <summary>
|
|
59
|
+
/// Initializes the attribute with the specified default signed byte value.
|
|
60
|
+
/// </summary>
|
|
61
|
+
/// <param name="value">Default value used when the constructor parameter is omitted.</param>
|
|
42
62
|
public DxOptionalParameterAttribute(sbyte value) { }
|
|
43
63
|
|
|
64
|
+
/// <summary>
|
|
65
|
+
/// Initializes the attribute with the specified default short value.
|
|
66
|
+
/// </summary>
|
|
67
|
+
/// <param name="value">Default value used when the constructor parameter is omitted.</param>
|
|
44
68
|
public DxOptionalParameterAttribute(short value) { }
|
|
45
69
|
|
|
70
|
+
/// <summary>
|
|
71
|
+
/// Initializes the attribute with the specified default unsigned short value.
|
|
72
|
+
/// </summary>
|
|
73
|
+
/// <param name="value">Default value used when the constructor parameter is omitted.</param>
|
|
46
74
|
public DxOptionalParameterAttribute(ushort value) { }
|
|
47
75
|
|
|
76
|
+
/// <summary>
|
|
77
|
+
/// Initializes the attribute with the specified default integer value.
|
|
78
|
+
/// </summary>
|
|
79
|
+
/// <param name="value">Default value used when the constructor parameter is omitted.</param>
|
|
48
80
|
public DxOptionalParameterAttribute(int value) { }
|
|
49
81
|
|
|
82
|
+
/// <summary>
|
|
83
|
+
/// Initializes the attribute with the specified default unsigned integer value.
|
|
84
|
+
/// </summary>
|
|
85
|
+
/// <param name="value">Default value used when the constructor parameter is omitted.</param>
|
|
50
86
|
public DxOptionalParameterAttribute(uint value) { }
|
|
51
87
|
|
|
88
|
+
/// <summary>
|
|
89
|
+
/// Initializes the attribute with the specified default long value.
|
|
90
|
+
/// </summary>
|
|
91
|
+
/// <param name="value">Default value used when the constructor parameter is omitted.</param>
|
|
52
92
|
public DxOptionalParameterAttribute(long value) { }
|
|
53
93
|
|
|
94
|
+
/// <summary>
|
|
95
|
+
/// Initializes the attribute with the specified default unsigned long value.
|
|
96
|
+
/// </summary>
|
|
97
|
+
/// <param name="value">Default value used when the constructor parameter is omitted.</param>
|
|
54
98
|
public DxOptionalParameterAttribute(ulong value) { }
|
|
55
99
|
|
|
100
|
+
/// <summary>
|
|
101
|
+
/// Initializes the attribute with the specified default single-precision floating point value.
|
|
102
|
+
/// </summary>
|
|
103
|
+
/// <param name="value">Default value used when the constructor parameter is omitted.</param>
|
|
56
104
|
public DxOptionalParameterAttribute(float value) { }
|
|
57
105
|
|
|
106
|
+
/// <summary>
|
|
107
|
+
/// Initializes the attribute with the specified default double-precision floating point value.
|
|
108
|
+
/// </summary>
|
|
109
|
+
/// <param name="value">Default value used when the constructor parameter is omitted.</param>
|
|
58
110
|
public DxOptionalParameterAttribute(double value) { }
|
|
59
111
|
|
|
60
112
|
/// <summary>
|
|
@@ -29,6 +29,10 @@ namespace DxMessaging.Core.DataStructure
|
|
|
29
29
|
_current = default;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
/// <summary>
|
|
33
|
+
/// Advances the enumerator to the next element in chronological order.
|
|
34
|
+
/// </summary>
|
|
35
|
+
/// <returns><c>true</c> when another element is available; otherwise <c>false</c>.</returns>
|
|
32
36
|
public bool MoveNext()
|
|
33
37
|
{
|
|
34
38
|
if (++_index < _buffer.Count)
|
|
@@ -41,16 +45,25 @@ namespace DxMessaging.Core.DataStructure
|
|
|
41
45
|
return false;
|
|
42
46
|
}
|
|
43
47
|
|
|
48
|
+
/// <summary>
|
|
49
|
+
/// Gets the element at the current enumerator position.
|
|
50
|
+
/// </summary>
|
|
44
51
|
public T Current => _current;
|
|
45
52
|
|
|
46
53
|
object IEnumerator.Current => Current;
|
|
47
54
|
|
|
55
|
+
/// <summary>
|
|
56
|
+
/// Resets the enumerator to its initial position before the first element.
|
|
57
|
+
/// </summary>
|
|
48
58
|
public void Reset()
|
|
49
59
|
{
|
|
50
60
|
_index = -1;
|
|
51
61
|
_current = default;
|
|
52
62
|
}
|
|
53
63
|
|
|
64
|
+
/// <summary>
|
|
65
|
+
/// Releases resources held by the enumerator.
|
|
66
|
+
/// </summary>
|
|
54
67
|
public void Dispose() { }
|
|
55
68
|
}
|
|
56
69
|
|
|
@@ -107,6 +120,9 @@ namespace DxMessaging.Core.DataStructure
|
|
|
107
120
|
}
|
|
108
121
|
}
|
|
109
122
|
|
|
123
|
+
/// <summary>
|
|
124
|
+
/// Creates an enumerator that iterates from the oldest element to the most recently added.
|
|
125
|
+
/// </summary>
|
|
110
126
|
public CyclicBufferEnumerator GetEnumerator()
|
|
111
127
|
{
|
|
112
128
|
return new CyclicBufferEnumerator(this);
|
|
@@ -12,7 +12,7 @@ namespace DxMessaging.Core.Diagnostics
|
|
|
12
12
|
/// Captures a snapshot of a message emission for diagnostics.
|
|
13
13
|
/// </summary>
|
|
14
14
|
/// <remarks>
|
|
15
|
-
/// When diagnostics are enabled (see <see cref="MessageBus.IMessageBus.
|
|
15
|
+
/// When diagnostics are enabled (see <see cref="MessageBus.IMessageBus.GlobalDiagnosticsTargets"/>),
|
|
16
16
|
/// the bus and tokens record recent emissions in ring buffers along with a trimmed stack trace
|
|
17
17
|
/// that excludes DxMessaging internals for easier debugging.
|
|
18
18
|
///
|
|
@@ -1,21 +1,83 @@
|
|
|
1
1
|
namespace DxMessaging.Core.Diagnostics
|
|
2
2
|
{
|
|
3
|
+
/// <summary>
|
|
4
|
+
/// Categories used when recording registrations in diagnostics logs.
|
|
5
|
+
/// </summary>
|
|
3
6
|
public enum MessageRegistrationType
|
|
4
7
|
{
|
|
8
|
+
/// <summary>
|
|
9
|
+
/// No registration type was captured.
|
|
10
|
+
/// </summary>
|
|
5
11
|
None = 0,
|
|
12
|
+
|
|
13
|
+
/// <summary>
|
|
14
|
+
/// A targeted handler that listens for messages addressed to a specific <see cref="Core.InstanceId"/>.
|
|
15
|
+
/// </summary>
|
|
6
16
|
Targeted = 1,
|
|
17
|
+
|
|
18
|
+
/// <summary>
|
|
19
|
+
/// A global untargeted handler that receives all messages of a given type.
|
|
20
|
+
/// </summary>
|
|
7
21
|
Untargeted = 2,
|
|
22
|
+
|
|
23
|
+
/// <summary>
|
|
24
|
+
/// A broadcast handler that listens for messages emitted from a source <see cref="Core.InstanceId"/>.
|
|
25
|
+
/// </summary>
|
|
8
26
|
Broadcast = 3,
|
|
27
|
+
|
|
28
|
+
/// <summary>
|
|
29
|
+
/// A broadcast post-processor that runs after broadcast handlers complete.
|
|
30
|
+
/// </summary>
|
|
9
31
|
BroadcastPostProcessor = 4,
|
|
32
|
+
|
|
33
|
+
/// <summary>
|
|
34
|
+
/// A targeted post-processor that runs after targeted handlers complete.
|
|
35
|
+
/// </summary>
|
|
10
36
|
TargetedPostProcessor = 5,
|
|
37
|
+
|
|
38
|
+
/// <summary>
|
|
39
|
+
/// A targeted handler that ignores the concrete target during invocation.
|
|
40
|
+
/// </summary>
|
|
11
41
|
TargetedWithoutTargeting = 6,
|
|
42
|
+
|
|
43
|
+
/// <summary>
|
|
44
|
+
/// A post-processor for handlers registered without a concrete target.
|
|
45
|
+
/// </summary>
|
|
12
46
|
TargetedWithoutTargetingPostProcessor = 7,
|
|
47
|
+
|
|
48
|
+
/// <summary>
|
|
49
|
+
/// A broadcast handler registered without an explicit source identity.
|
|
50
|
+
/// </summary>
|
|
13
51
|
BroadcastWithoutSource = 8,
|
|
52
|
+
|
|
53
|
+
/// <summary>
|
|
54
|
+
/// A post-processor for broadcast handlers registered without an explicit source.
|
|
55
|
+
/// </summary>
|
|
14
56
|
BroadcastWithoutSourcePostProcessor = 9,
|
|
57
|
+
|
|
58
|
+
/// <summary>
|
|
59
|
+
/// A post-processor that runs after untargeted handlers complete.
|
|
60
|
+
/// </summary>
|
|
15
61
|
UntargetedPostProcessor = 10,
|
|
62
|
+
|
|
63
|
+
/// <summary>
|
|
64
|
+
/// A global catch-all registration that observes every message.
|
|
65
|
+
/// </summary>
|
|
16
66
|
GlobalAcceptAll = 11,
|
|
67
|
+
|
|
68
|
+
/// <summary>
|
|
69
|
+
/// An untargeted interceptor that can mutate or cancel global messages.
|
|
70
|
+
/// </summary>
|
|
17
71
|
UntargetedInterceptor = 12,
|
|
72
|
+
|
|
73
|
+
/// <summary>
|
|
74
|
+
/// A targeted interceptor that can mutate or cancel messages bound to a specific recipient.
|
|
75
|
+
/// </summary>
|
|
18
76
|
TargetedInterceptor = 13,
|
|
77
|
+
|
|
78
|
+
/// <summary>
|
|
79
|
+
/// A broadcast interceptor that can mutate or cancel messages emitted from a source.
|
|
80
|
+
/// </summary>
|
|
19
81
|
BroadcastInterceptor = 14,
|
|
20
82
|
}
|
|
21
83
|
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
namespace DxMessaging.Core
|
|
2
|
+
{
|
|
3
|
+
using System;
|
|
4
|
+
using Helper;
|
|
5
|
+
using MessageBus;
|
|
6
|
+
|
|
7
|
+
/// <summary>
|
|
8
|
+
/// Centralised utility for resetting DxMessaging static state when Domain Reload is disabled.
|
|
9
|
+
/// </summary>
|
|
10
|
+
public static class DxMessagingStaticState
|
|
11
|
+
{
|
|
12
|
+
private static readonly object ResetLock = new object();
|
|
13
|
+
private static readonly BaselineState Baseline;
|
|
14
|
+
|
|
15
|
+
static DxMessagingStaticState()
|
|
16
|
+
{
|
|
17
|
+
Baseline = CaptureBaseline();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/// <summary>
|
|
21
|
+
/// Resets all static variables in DxMessaging to their default values.
|
|
22
|
+
/// </summary>
|
|
23
|
+
public static void Reset()
|
|
24
|
+
{
|
|
25
|
+
lock (ResetLock)
|
|
26
|
+
{
|
|
27
|
+
MessagingDebug.enabled = Baseline.MessagingDebugEnabled;
|
|
28
|
+
MessagingDebug.LogFunction = Baseline.MessagingDebugLogFunction;
|
|
29
|
+
|
|
30
|
+
IMessageBus.GlobalDiagnosticsTargets = Baseline.GlobalDiagnosticsTargets;
|
|
31
|
+
IMessageBus.GlobalMessageBufferSize = Baseline.GlobalMessageBufferSize;
|
|
32
|
+
IMessageBus.GlobalSequentialIndex = Baseline.GlobalSequentialIndex;
|
|
33
|
+
|
|
34
|
+
MessageHelperIndexer.RestoreState(Baseline.HelperState);
|
|
35
|
+
|
|
36
|
+
MessageRegistrationHandle.SetIdSeed(Baseline.MessageRegistrationHandleSeed);
|
|
37
|
+
MessageRegistrationBuilder.SetSyntheticOwnerCounter(Baseline.SyntheticOwnerCounter);
|
|
38
|
+
|
|
39
|
+
MessageHandler.ResetStatics();
|
|
40
|
+
IMessageBus.GlobalSequentialIndex = Baseline.GlobalSequentialIndex;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private static BaselineState CaptureBaseline()
|
|
45
|
+
{
|
|
46
|
+
bool messagingDebugEnabled = MessagingDebug.enabled;
|
|
47
|
+
Action<LogLevel, string> messagingDebugLogFunction = MessagingDebug.LogFunction;
|
|
48
|
+
DiagnosticsTarget globalDiagnosticsTargets = IMessageBus.GlobalDiagnosticsTargets;
|
|
49
|
+
int globalMessageBufferSize = IMessageBus.GlobalMessageBufferSize;
|
|
50
|
+
int globalSequentialIndex = IMessageBus.GlobalSequentialIndex;
|
|
51
|
+
long messageRegistrationHandleSeed = MessageRegistrationHandle.GetCurrentIdSeed();
|
|
52
|
+
int syntheticOwnerCounter = MessageRegistrationBuilder.GetSyntheticOwnerCounter();
|
|
53
|
+
MessageHelperIndexer.MessageHelperIndexerState helperState =
|
|
54
|
+
MessageHelperIndexer.CaptureState();
|
|
55
|
+
|
|
56
|
+
return new BaselineState(
|
|
57
|
+
messagingDebugEnabled,
|
|
58
|
+
messagingDebugLogFunction,
|
|
59
|
+
globalDiagnosticsTargets,
|
|
60
|
+
globalMessageBufferSize,
|
|
61
|
+
globalSequentialIndex,
|
|
62
|
+
messageRegistrationHandleSeed,
|
|
63
|
+
syntheticOwnerCounter,
|
|
64
|
+
helperState
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private sealed class BaselineState
|
|
69
|
+
{
|
|
70
|
+
internal BaselineState(
|
|
71
|
+
bool messagingDebugEnabled,
|
|
72
|
+
Action<LogLevel, string> messagingDebugLogFunction,
|
|
73
|
+
DiagnosticsTarget globalDiagnosticsTargets,
|
|
74
|
+
int globalMessageBufferSize,
|
|
75
|
+
int globalSequentialIndex,
|
|
76
|
+
long messageRegistrationHandleSeed,
|
|
77
|
+
int syntheticOwnerCounter,
|
|
78
|
+
MessageHelperIndexer.MessageHelperIndexerState helperState
|
|
79
|
+
)
|
|
80
|
+
{
|
|
81
|
+
MessagingDebugEnabled = messagingDebugEnabled;
|
|
82
|
+
MessagingDebugLogFunction = messagingDebugLogFunction;
|
|
83
|
+
GlobalDiagnosticsTargets = globalDiagnosticsTargets;
|
|
84
|
+
GlobalMessageBufferSize = globalMessageBufferSize;
|
|
85
|
+
GlobalSequentialIndex = globalSequentialIndex;
|
|
86
|
+
MessageRegistrationHandleSeed = messageRegistrationHandleSeed;
|
|
87
|
+
SyntheticOwnerCounter = syntheticOwnerCounter;
|
|
88
|
+
HelperState = helperState;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
internal bool MessagingDebugEnabled { get; }
|
|
92
|
+
|
|
93
|
+
internal Action<LogLevel, string> MessagingDebugLogFunction { get; }
|
|
94
|
+
|
|
95
|
+
internal DiagnosticsTarget GlobalDiagnosticsTargets { get; }
|
|
96
|
+
|
|
97
|
+
internal int GlobalMessageBufferSize { get; }
|
|
98
|
+
|
|
99
|
+
internal int GlobalSequentialIndex { get; }
|
|
100
|
+
|
|
101
|
+
internal long MessageRegistrationHandleSeed { get; }
|
|
102
|
+
|
|
103
|
+
internal int SyntheticOwnerCounter { get; }
|
|
104
|
+
|
|
105
|
+
internal MessageHelperIndexer.MessageHelperIndexerState HelperState { get; }
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -5,6 +5,22 @@ namespace DxMessaging.Core.Extensions
|
|
|
5
5
|
|
|
6
6
|
internal static class IListExtensions
|
|
7
7
|
{
|
|
8
|
+
/// <summary>
|
|
9
|
+
/// Rotates the list contents in-place by the specified offset.
|
|
10
|
+
/// </summary>
|
|
11
|
+
/// <typeparam name="T">Element type held by the list.</typeparam>
|
|
12
|
+
/// <param name="list">List to rotate. Must have at least two elements to perform work.</param>
|
|
13
|
+
/// <param name="amount">
|
|
14
|
+
/// Number of positions to rotate. Positive values move elements toward the end (wrapping),
|
|
15
|
+
/// negative values move them toward the start.
|
|
16
|
+
/// </param>
|
|
17
|
+
/// <example>
|
|
18
|
+
/// <code>
|
|
19
|
+
/// var numbers = new List<int> { 1, 2, 3, 4 };
|
|
20
|
+
/// numbers.Shift(1); // numbers becomes { 4, 1, 2, 3 }
|
|
21
|
+
/// numbers.Shift(-2); // numbers becomes { 2, 3, 4, 1 }
|
|
22
|
+
/// </code>
|
|
23
|
+
/// </example>
|
|
8
24
|
public static void Shift<T>(this IList<T> list, int amount)
|
|
9
25
|
{
|
|
10
26
|
if (list is not { Count: > 1 })
|
|
@@ -26,6 +42,14 @@ namespace DxMessaging.Core.Extensions
|
|
|
26
42
|
Reverse(list, amount, count - 1);
|
|
27
43
|
}
|
|
28
44
|
|
|
45
|
+
/// <summary>
|
|
46
|
+
/// Reverses the order of elements in-place within the inclusive range.
|
|
47
|
+
/// </summary>
|
|
48
|
+
/// <typeparam name="T">Element type held by the list.</typeparam>
|
|
49
|
+
/// <param name="list">List whose segment should be reversed.</param>
|
|
50
|
+
/// <param name="start">Zero-based index of the first element in the range.</param>
|
|
51
|
+
/// <param name="end">Zero-based index of the last element in the range.</param>
|
|
52
|
+
/// <exception cref="ArgumentException">Thrown when the start or end value is outside the list bounds.</exception>
|
|
29
53
|
public static void Reverse<T>(this IList<T> list, int start, int end)
|
|
30
54
|
{
|
|
31
55
|
if (start < 0 || list.Count <= start)
|
|
@@ -13,6 +13,13 @@ namespace DxMessaging.Core.Extensions
|
|
|
13
13
|
/// </summary>
|
|
14
14
|
public static class MessageBusExtensions
|
|
15
15
|
{
|
|
16
|
+
/// <summary>
|
|
17
|
+
/// Emits an untargeted message instance through the provided message bus.
|
|
18
|
+
/// </summary>
|
|
19
|
+
/// <typeparam name="TMessage">Concrete message type implementing <see cref="IUntargetedMessage"/>.</typeparam>
|
|
20
|
+
/// <param name="messageBus">Bus that should dispatch the message.</param>
|
|
21
|
+
/// <param name="message">Message instance to send.</param>
|
|
22
|
+
/// <exception cref="ArgumentNullException">Thrown when <paramref name="messageBus"/> is null.</exception>
|
|
16
23
|
public static void EmitUntargeted<TMessage>(this IMessageBus messageBus, TMessage message)
|
|
17
24
|
where TMessage : class, IUntargetedMessage
|
|
18
25
|
{
|
|
@@ -24,6 +31,13 @@ namespace DxMessaging.Core.Extensions
|
|
|
24
31
|
message.EmitUntargeted(messageBus);
|
|
25
32
|
}
|
|
26
33
|
|
|
34
|
+
/// <summary>
|
|
35
|
+
/// Emits an untargeted struct message through the provided message bus without copying the payload.
|
|
36
|
+
/// </summary>
|
|
37
|
+
/// <typeparam name="TMessage">Concrete message type implementing <see cref="IUntargetedMessage"/>.</typeparam>
|
|
38
|
+
/// <param name="messageBus">Bus that should dispatch the message.</param>
|
|
39
|
+
/// <param name="message">Reference to the struct message to send.</param>
|
|
40
|
+
/// <exception cref="ArgumentNullException">Thrown when <paramref name="messageBus"/> is null.</exception>
|
|
27
41
|
public static void EmitUntargeted<TMessage>(
|
|
28
42
|
this IMessageBus messageBus,
|
|
29
43
|
ref TMessage message
|
|
@@ -38,6 +52,21 @@ namespace DxMessaging.Core.Extensions
|
|
|
38
52
|
message.EmitUntargeted(messageBus);
|
|
39
53
|
}
|
|
40
54
|
|
|
55
|
+
/// <summary>
|
|
56
|
+
/// Emits a targeted message to the specified recipient.
|
|
57
|
+
/// </summary>
|
|
58
|
+
/// <typeparam name="TMessage">Concrete message type implementing <see cref="ITargetedMessage"/>.</typeparam>
|
|
59
|
+
/// <param name="messageBus">Bus that should dispatch the message.</param>
|
|
60
|
+
/// <param name="target">Recipient of the message.</param>
|
|
61
|
+
/// <param name="message">Message instance to deliver.</param>
|
|
62
|
+
/// <exception cref="ArgumentNullException">Thrown when <paramref name="messageBus"/> is null.</exception>
|
|
63
|
+
/// <example>
|
|
64
|
+
/// <code>
|
|
65
|
+
/// InstanceId playerId = GetPlayerId();
|
|
66
|
+
/// var change = new HealthChanged(5);
|
|
67
|
+
/// bus.EmitTargeted(playerId, change);
|
|
68
|
+
/// </code>
|
|
69
|
+
/// </example>
|
|
41
70
|
public static void EmitTargeted<TMessage>(
|
|
42
71
|
this IMessageBus messageBus,
|
|
43
72
|
InstanceId target,
|
|
@@ -53,6 +82,14 @@ namespace DxMessaging.Core.Extensions
|
|
|
53
82
|
message.EmitTargeted(target, messageBus);
|
|
54
83
|
}
|
|
55
84
|
|
|
85
|
+
/// <summary>
|
|
86
|
+
/// Emits a targeted struct message to the specified recipient without copying the payload.
|
|
87
|
+
/// </summary>
|
|
88
|
+
/// <typeparam name="TMessage">Concrete message type implementing <see cref="ITargetedMessage"/>.</typeparam>
|
|
89
|
+
/// <param name="messageBus">Bus that should dispatch the message.</param>
|
|
90
|
+
/// <param name="target">Recipient of the message.</param>
|
|
91
|
+
/// <param name="message">Reference to the struct message to deliver.</param>
|
|
92
|
+
/// <exception cref="ArgumentNullException">Thrown when <paramref name="messageBus"/> is null.</exception>
|
|
56
93
|
public static void EmitTargeted<TMessage>(
|
|
57
94
|
this IMessageBus messageBus,
|
|
58
95
|
InstanceId target,
|
|
@@ -68,6 +105,14 @@ namespace DxMessaging.Core.Extensions
|
|
|
68
105
|
message.EmitTargeted(target, messageBus);
|
|
69
106
|
}
|
|
70
107
|
|
|
108
|
+
/// <summary>
|
|
109
|
+
/// Emits a broadcast message sourced from the specified instance.
|
|
110
|
+
/// </summary>
|
|
111
|
+
/// <typeparam name="TMessage">Concrete message type implementing <see cref="IBroadcastMessage"/>.</typeparam>
|
|
112
|
+
/// <param name="messageBus">Bus that should dispatch the message.</param>
|
|
113
|
+
/// <param name="source">Originating instance for the broadcast.</param>
|
|
114
|
+
/// <param name="message">Message instance to deliver.</param>
|
|
115
|
+
/// <exception cref="ArgumentNullException">Thrown when <paramref name="messageBus"/> is null.</exception>
|
|
71
116
|
public static void EmitBroadcast<TMessage>(
|
|
72
117
|
this IMessageBus messageBus,
|
|
73
118
|
InstanceId source,
|
|
@@ -83,6 +128,14 @@ namespace DxMessaging.Core.Extensions
|
|
|
83
128
|
message.EmitBroadcast(source, messageBus);
|
|
84
129
|
}
|
|
85
130
|
|
|
131
|
+
/// <summary>
|
|
132
|
+
/// Emits a broadcast struct message sourced from the specified instance without copying the payload.
|
|
133
|
+
/// </summary>
|
|
134
|
+
/// <typeparam name="TMessage">Concrete message type implementing <see cref="IBroadcastMessage"/>.</typeparam>
|
|
135
|
+
/// <param name="messageBus">Bus that should dispatch the message.</param>
|
|
136
|
+
/// <param name="source">Originating instance for the broadcast.</param>
|
|
137
|
+
/// <param name="message">Reference to the struct message to deliver.</param>
|
|
138
|
+
/// <exception cref="ArgumentNullException">Thrown when <paramref name="messageBus"/> is null.</exception>
|
|
86
139
|
public static void EmitBroadcast<TMessage>(
|
|
87
140
|
this IMessageBus messageBus,
|
|
88
141
|
InstanceId source,
|
|
@@ -99,6 +152,14 @@ namespace DxMessaging.Core.Extensions
|
|
|
99
152
|
}
|
|
100
153
|
|
|
101
154
|
#if UNITY_2021_3_OR_NEWER
|
|
155
|
+
/// <summary>
|
|
156
|
+
/// Emits a targeted message to the specified Unity <see cref="GameObject"/>.
|
|
157
|
+
/// </summary>
|
|
158
|
+
/// <typeparam name="TMessage">Concrete message type implementing <see cref="ITargetedMessage"/>.</typeparam>
|
|
159
|
+
/// <param name="messageBus">Bus that should dispatch the message.</param>
|
|
160
|
+
/// <param name="target">Unity object that will receive the message.</param>
|
|
161
|
+
/// <param name="message">Message instance to deliver.</param>
|
|
162
|
+
/// <exception cref="ArgumentNullException">Thrown when <paramref name="messageBus"/> is null.</exception>
|
|
102
163
|
public static void EmitGameObjectTargeted<TMessage>(
|
|
103
164
|
this IMessageBus messageBus,
|
|
104
165
|
GameObject target,
|
|
@@ -114,6 +175,14 @@ namespace DxMessaging.Core.Extensions
|
|
|
114
175
|
message.EmitGameObjectTargeted(target, messageBus);
|
|
115
176
|
}
|
|
116
177
|
|
|
178
|
+
/// <summary>
|
|
179
|
+
/// Emits a targeted struct message to the specified Unity <see cref="GameObject"/> without copying the payload.
|
|
180
|
+
/// </summary>
|
|
181
|
+
/// <typeparam name="TMessage">Concrete message type implementing <see cref="ITargetedMessage"/>.</typeparam>
|
|
182
|
+
/// <param name="messageBus">Bus that should dispatch the message.</param>
|
|
183
|
+
/// <param name="target">Unity object that will receive the message.</param>
|
|
184
|
+
/// <param name="message">Reference to the struct message to deliver.</param>
|
|
185
|
+
/// <exception cref="ArgumentNullException">Thrown when <paramref name="messageBus"/> is null.</exception>
|
|
117
186
|
public static void EmitGameObjectTargeted<TMessage>(
|
|
118
187
|
this IMessageBus messageBus,
|
|
119
188
|
GameObject target,
|
|
@@ -129,6 +198,14 @@ namespace DxMessaging.Core.Extensions
|
|
|
129
198
|
message.EmitGameObjectTargeted(target, messageBus);
|
|
130
199
|
}
|
|
131
200
|
|
|
201
|
+
/// <summary>
|
|
202
|
+
/// Emits a targeted message to the specified Unity <see cref="Component"/>.
|
|
203
|
+
/// </summary>
|
|
204
|
+
/// <typeparam name="TMessage">Concrete message type implementing <see cref="ITargetedMessage"/>.</typeparam>
|
|
205
|
+
/// <param name="messageBus">Bus that should dispatch the message.</param>
|
|
206
|
+
/// <param name="target">Unity component that will receive the message.</param>
|
|
207
|
+
/// <param name="message">Message instance to deliver.</param>
|
|
208
|
+
/// <exception cref="ArgumentNullException">Thrown when <paramref name="messageBus"/> is null.</exception>
|
|
132
209
|
public static void EmitComponentTargeted<TMessage>(
|
|
133
210
|
this IMessageBus messageBus,
|
|
134
211
|
Component target,
|
|
@@ -144,6 +221,14 @@ namespace DxMessaging.Core.Extensions
|
|
|
144
221
|
message.EmitComponentTargeted(target, messageBus);
|
|
145
222
|
}
|
|
146
223
|
|
|
224
|
+
/// <summary>
|
|
225
|
+
/// Emits a targeted struct message to the specified Unity <see cref="Component"/> without copying the payload.
|
|
226
|
+
/// </summary>
|
|
227
|
+
/// <typeparam name="TMessage">Concrete message type implementing <see cref="ITargetedMessage"/>.</typeparam>
|
|
228
|
+
/// <param name="messageBus">Bus that should dispatch the message.</param>
|
|
229
|
+
/// <param name="target">Unity component that will receive the message.</param>
|
|
230
|
+
/// <param name="message">Reference to the struct message to deliver.</param>
|
|
231
|
+
/// <exception cref="ArgumentNullException">Thrown when <paramref name="messageBus"/> is null.</exception>
|
|
147
232
|
public static void EmitComponentTargeted<TMessage>(
|
|
148
233
|
this IMessageBus messageBus,
|
|
149
234
|
Component target,
|
|
@@ -159,6 +244,14 @@ namespace DxMessaging.Core.Extensions
|
|
|
159
244
|
message.EmitComponentTargeted(target, messageBus);
|
|
160
245
|
}
|
|
161
246
|
|
|
247
|
+
/// <summary>
|
|
248
|
+
/// Emits a broadcast message from the specified Unity <see cref="GameObject"/>.
|
|
249
|
+
/// </summary>
|
|
250
|
+
/// <typeparam name="TMessage">Concrete message type implementing <see cref="IBroadcastMessage"/>.</typeparam>
|
|
251
|
+
/// <param name="messageBus">Bus that should dispatch the message.</param>
|
|
252
|
+
/// <param name="source">Unity object that is broadcasting the message.</param>
|
|
253
|
+
/// <param name="message">Message instance to deliver.</param>
|
|
254
|
+
/// <exception cref="ArgumentNullException">Thrown when <paramref name="messageBus"/> is null.</exception>
|
|
162
255
|
public static void EmitGameObjectBroadcast<TMessage>(
|
|
163
256
|
this IMessageBus messageBus,
|
|
164
257
|
GameObject source,
|
|
@@ -174,6 +267,14 @@ namespace DxMessaging.Core.Extensions
|
|
|
174
267
|
message.EmitGameObjectBroadcast(source, messageBus);
|
|
175
268
|
}
|
|
176
269
|
|
|
270
|
+
/// <summary>
|
|
271
|
+
/// Emits a broadcast struct message from the specified Unity <see cref="GameObject"/> without copying the payload.
|
|
272
|
+
/// </summary>
|
|
273
|
+
/// <typeparam name="TMessage">Concrete message type implementing <see cref="IBroadcastMessage"/>.</typeparam>
|
|
274
|
+
/// <param name="messageBus">Bus that should dispatch the message.</param>
|
|
275
|
+
/// <param name="source">Unity object that is broadcasting the message.</param>
|
|
276
|
+
/// <param name="message">Reference to the struct message to deliver.</param>
|
|
277
|
+
/// <exception cref="ArgumentNullException">Thrown when <paramref name="messageBus"/> is null.</exception>
|
|
177
278
|
public static void EmitGameObjectBroadcast<TMessage>(
|
|
178
279
|
this IMessageBus messageBus,
|
|
179
280
|
GameObject source,
|
|
@@ -189,6 +290,14 @@ namespace DxMessaging.Core.Extensions
|
|
|
189
290
|
message.EmitGameObjectBroadcast(source, messageBus);
|
|
190
291
|
}
|
|
191
292
|
|
|
293
|
+
/// <summary>
|
|
294
|
+
/// Emits a broadcast message from the specified Unity <see cref="Component"/>.
|
|
295
|
+
/// </summary>
|
|
296
|
+
/// <typeparam name="TMessage">Concrete message type implementing <see cref="IBroadcastMessage"/>.</typeparam>
|
|
297
|
+
/// <param name="messageBus">Bus that should dispatch the message.</param>
|
|
298
|
+
/// <param name="source">Unity component that is broadcasting the message.</param>
|
|
299
|
+
/// <param name="message">Message instance to deliver.</param>
|
|
300
|
+
/// <exception cref="ArgumentNullException">Thrown when <paramref name="messageBus"/> is null.</exception>
|
|
192
301
|
public static void EmitComponentBroadcast<TMessage>(
|
|
193
302
|
this IMessageBus messageBus,
|
|
194
303
|
Component source,
|
|
@@ -204,6 +313,14 @@ namespace DxMessaging.Core.Extensions
|
|
|
204
313
|
message.EmitComponentBroadcast(source, messageBus);
|
|
205
314
|
}
|
|
206
315
|
|
|
316
|
+
/// <summary>
|
|
317
|
+
/// Emits a broadcast struct message from the specified Unity <see cref="Component"/> without copying the payload.
|
|
318
|
+
/// </summary>
|
|
319
|
+
/// <typeparam name="TMessage">Concrete message type implementing <see cref="IBroadcastMessage"/>.</typeparam>
|
|
320
|
+
/// <param name="messageBus">Bus that should dispatch the message.</param>
|
|
321
|
+
/// <param name="source">Unity component that is broadcasting the message.</param>
|
|
322
|
+
/// <param name="message">Reference to the struct message to deliver.</param>
|
|
323
|
+
/// <exception cref="ArgumentNullException">Thrown when <paramref name="messageBus"/> is null.</exception>
|
|
207
324
|
public static void EmitComponentBroadcast<TMessage>(
|
|
208
325
|
this IMessageBus messageBus,
|
|
209
326
|
Component source,
|
|
@@ -220,6 +337,17 @@ namespace DxMessaging.Core.Extensions
|
|
|
220
337
|
}
|
|
221
338
|
#endif
|
|
222
339
|
|
|
340
|
+
/// <summary>
|
|
341
|
+
/// Emits a string payload using the string-message utility channel.
|
|
342
|
+
/// </summary>
|
|
343
|
+
/// <param name="messageBus">Bus that should dispatch the message.</param>
|
|
344
|
+
/// <param name="payload">Message text to broadcast globally.</param>
|
|
345
|
+
/// <exception cref="ArgumentNullException">Thrown when <paramref name="messageBus"/> is null.</exception>
|
|
346
|
+
/// <example>
|
|
347
|
+
/// <code>
|
|
348
|
+
/// bus.Emit("PlayerJoined");
|
|
349
|
+
/// </code>
|
|
350
|
+
/// </example>
|
|
223
351
|
public static void Emit(this IMessageBus messageBus, string payload)
|
|
224
352
|
{
|
|
225
353
|
if (messageBus == null)
|
|
@@ -230,6 +358,13 @@ namespace DxMessaging.Core.Extensions
|
|
|
230
358
|
payload.Emit(messageBus);
|
|
231
359
|
}
|
|
232
360
|
|
|
361
|
+
/// <summary>
|
|
362
|
+
/// Emits a string payload targeted at the specified instance.
|
|
363
|
+
/// </summary>
|
|
364
|
+
/// <param name="messageBus">Bus that should dispatch the message.</param>
|
|
365
|
+
/// <param name="target">Intended recipient of the payload.</param>
|
|
366
|
+
/// <param name="payload">Message text to deliver.</param>
|
|
367
|
+
/// <exception cref="ArgumentNullException">Thrown when <paramref name="messageBus"/> is null.</exception>
|
|
233
368
|
public static void EmitAt(this IMessageBus messageBus, InstanceId target, string payload)
|
|
234
369
|
{
|
|
235
370
|
if (messageBus == null)
|
|
@@ -240,6 +375,13 @@ namespace DxMessaging.Core.Extensions
|
|
|
240
375
|
payload.Emit(target, messageBus);
|
|
241
376
|
}
|
|
242
377
|
|
|
378
|
+
/// <summary>
|
|
379
|
+
/// Emits a string payload broadcast from the specified instance.
|
|
380
|
+
/// </summary>
|
|
381
|
+
/// <param name="messageBus">Bus that should dispatch the message.</param>
|
|
382
|
+
/// <param name="source">Origin of the payload.</param>
|
|
383
|
+
/// <param name="payload">Message text to deliver.</param>
|
|
384
|
+
/// <exception cref="ArgumentNullException">Thrown when <paramref name="messageBus"/> is null.</exception>
|
|
243
385
|
public static void EmitFrom(this IMessageBus messageBus, InstanceId source, string payload)
|
|
244
386
|
{
|
|
245
387
|
if (messageBus == null)
|