com.wallstop-studios.dxmessaging 2.1.1 → 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 +72 -0
- package/.lychee.toml +4 -2
- package/AGENTS.md +13 -12
- package/Docs/Comparisons.md +5 -5
- package/Docs/Install.md +2 -1
- package/Docs/InterceptorsAndOrdering.md +1 -1
- package/Docs/Performance.md +15 -13
- package/Docs/QuickReference.md +1 -1
- package/Docs/Reference.md +5 -5
- package/Editor/Analyzers/Microsoft.CodeAnalysis.CSharp.dll +0 -0
- package/Editor/Analyzers/Microsoft.CodeAnalysis.CSharp.dll.meta +13 -2
- package/Editor/Analyzers/Microsoft.CodeAnalysis.dll +0 -0
- package/Editor/Analyzers/Microsoft.CodeAnalysis.dll.meta +11 -0
- package/Editor/Analyzers/System.Collections.Immutable.dll +0 -0
- package/Editor/Analyzers/System.Collections.Immutable.dll.meta +11 -0
- package/Editor/Analyzers/System.Reflection.Metadata.dll +0 -0
- package/Editor/Analyzers/System.Reflection.Metadata.dll.meta +13 -2
- package/Editor/Analyzers/System.Runtime.CompilerServices.Unsafe.dll +0 -0
- package/Editor/Analyzers/System.Runtime.CompilerServices.Unsafe.dll.meta +11 -0
- package/Editor/Analyzers/WallstopStudios.DxMessaging.SourceGenerators.dll +0 -0
- package/Editor/Analyzers/WallstopStudios.DxMessaging.SourceGenerators.dll.meta +3 -2
- package/Editor/AssemblyInfo.cs +3 -0
- package/Editor/AssemblyInfo.cs.meta +3 -0
- package/Editor/CustomEditors/MessagingComponentEditor.cs +24 -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/Editor/SetupCscRsp.cs +133 -53
- package/Editor/Testing/MessagingComponentEditorHarness.cs +218 -0
- package/Editor/Testing/MessagingComponentEditorHarness.cs.meta +3 -0
- package/Editor/Testing.meta +3 -0
- package/README.md +10 -4
- package/Runtime/AssemblyInfo.cs +1 -0
- package/Runtime/Core/Attributes/DxOptionalParameterAttribute.cs +52 -0
- package/Runtime/Core/DataStructure/CyclicBuffer.cs +16 -0
- package/Runtime/Core/Diagnostics/MessageEmissionData.cs +27 -12
- 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 +144 -2
- package/Runtime/Core/Extensions/MessageExtensions.cs +2 -2
- package/Runtime/Core/Helper/MessageCache.cs +16 -0
- package/Runtime/Core/Helper/MessageHelperIndexer.cs +77 -0
- package/Runtime/Core/InstanceId.cs +91 -3
- 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 +96 -25
- package/Runtime/Core/MessageBus/MessageRegistrationBuilder.cs +46 -2
- package/Runtime/Core/MessageBus/MessagingRegistration.cs +63 -5
- package/Runtime/Core/MessageBus/RegistrationLog.cs +10 -0
- package/Runtime/Core/MessageHandler.cs +141 -8
- package/Runtime/Core/MessageRegistrationHandle.cs +59 -0
- package/Runtime/Core/MessageRegistrationToken.cs +20 -4
- package/Runtime/Core/Messages/ReflexiveMessage.cs +38 -0
- package/Runtime/Core/MessagingDebug.cs +16 -1
- package/Runtime/Unity/CurrentGlobalMessageBusProvider.cs +6 -0
- package/Runtime/Unity/DxMessagingRuntimeInitializer.cs +19 -0
- package/Runtime/Unity/DxMessagingRuntimeInitializer.cs.meta +11 -0
- package/Runtime/Unity/InitialGlobalMessageBusProvider.cs +6 -0
- package/Runtime/Unity/Integrations/Reflex/ReflexRegistrationInstaller.cs +19 -0
- package/Runtime/Unity/Integrations/VContainer/VContainerRegistrationExtensions.cs +10 -0
- package/Runtime/Unity/Integrations/Zenject/ZenjectRegistrationInstaller.cs +14 -0
- package/Runtime/Unity/MessageAwareComponent.cs +2 -0
- package/Runtime/Unity/MessageBusProviderHandle.cs +4 -0
- package/Runtime/Unity/MessagingComponent.cs +109 -0
- package/Runtime/Unity/MessagingComponentInstaller.cs +2 -0
- package/Runtime/Unity/ScriptableMessageBusProvider.cs +2 -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/Directory.Build.props +9 -0
- package/{Tests/Runtime/WallstopStudios.DxMessaging.Tests.Runtime.csproj.meta → SourceGenerators/Directory.Build.props.meta} +1 -1
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxAutoConstructorGenerator.cs +23 -24
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxMessageIdGenerator.cs +91 -27
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.csproj +24 -4
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.Tests/DocsSnippetCompilationTests.cs +193 -0
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.Tests/DocsSnippetCompilationTests.cs.meta +11 -0
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.Tests/DxAutoConstructorGeneratorDiagnosticsTests.cs +69 -0
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.Tests/DxAutoConstructorGeneratorDiagnosticsTests.cs.meta +11 -0
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.Tests/DxMessageIdGeneratorDiagnosticsTests.cs +66 -0
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.Tests/DxMessageIdGeneratorDiagnosticsTests.cs.meta +11 -0
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.Tests/GeneratorTestUtilities.cs +155 -0
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.Tests/GeneratorTestUtilities.cs.meta +11 -0
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.Tests/WallstopStudios.DxMessaging.SourceGenerators.Tests.csproj +20 -0
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.Tests/WallstopStudios.DxMessaging.SourceGenerators.Tests.csproj.meta +7 -0
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.Tests.meta +8 -0
- package/Tests/Editor/MessagingComponentEditorHarnessTests.cs +243 -0
- package/Tests/Editor/MessagingComponentEditorHarnessTests.cs.meta +3 -0
- package/Tests/Editor/MessagingComponentSerializationTests.cs +129 -0
- package/Tests/Editor/MessagingComponentSerializationTests.cs.meta +3 -0
- package/Tests/Editor/WallstopStudios.DxMessaging.Tests.Editor.asmdef +19 -0
- package/Tests/Editor/WallstopStudios.DxMessaging.Tests.Editor.asmdef.meta +3 -0
- package/Tests/Editor.meta +3 -0
- package/Tests/Runtime/Benchmarks/BenchmarkSession.cs +3 -0
- package/Tests/Runtime/Benchmarks/BenchmarkTestBase.cs +3 -0
- package/Tests/Runtime/Benchmarks/ComparisonPerformanceTests.cs +3 -0
- package/Tests/Runtime/Benchmarks/PerformanceTests.cs +137 -0
- package/Tests/Runtime/Core/AlternateBusTests.cs +3 -0
- package/Tests/Runtime/Core/BroadcastTests.cs +3 -0
- package/Tests/Runtime/Core/CyclicBufferTests.cs +3 -0
- package/Tests/Runtime/Core/DefaultBusFallbackTests.cs +5 -2
- package/Tests/Runtime/Core/DiagnosticsTests.cs +6 -3
- package/Tests/Runtime/Core/DxMessagingStaticStateTests.cs +69 -0
- package/Tests/Runtime/Core/DxMessagingStaticStateTests.cs.meta +11 -0
- package/Tests/Runtime/Core/EdgeCaseTests.cs +3 -0
- package/Tests/Runtime/Core/EnablementTests.cs +3 -0
- package/Tests/Runtime/Core/Extensions/MessageExtensionsProviderTests.cs +2 -2
- package/Tests/Runtime/Core/GenericMessageTests.cs +3 -0
- package/Tests/Runtime/Core/GlobalAcceptAllTests.cs +3 -0
- package/Tests/Runtime/Core/InterceptorCancellationTests.cs +3 -0
- package/Tests/Runtime/Core/LifecycleTests.cs +3 -0
- package/Tests/Runtime/Core/MessageEmissionDataTests.cs +70 -0
- package/Tests/Runtime/Core/MessageEmissionDataTests.cs.meta +11 -0
- package/Tests/Runtime/Core/MessagingComponentLifecycleTests.cs +3 -0
- package/Tests/Runtime/Core/MessagingTestBase.cs +3 -0
- package/Tests/Runtime/Core/MutationDedupeTests.cs +3 -0
- package/Tests/Runtime/Core/MutationDestructionTests.cs +3 -0
- package/Tests/Runtime/Core/MutationDuringEmissionTests.cs +3 -0
- package/Tests/Runtime/Core/MutationGlobalAddTests.cs +3 -0
- package/Tests/Runtime/Core/MutationInterceptorTests.cs +3 -0
- package/Tests/Runtime/Core/MutationPostProcessorAcrossHandlersTests.cs +3 -0
- package/Tests/Runtime/Core/MutationPostProcessorMoreTests.cs +3 -0
- package/Tests/Runtime/Core/MutationPriorityTests.cs +3 -0
- package/Tests/Runtime/Core/NominalTests.cs +3 -0
- package/Tests/Runtime/Core/OrderingTests.cs +3 -0
- package/Tests/Runtime/Core/OverDeregistrationTests.cs +3 -0
- package/Tests/Runtime/Core/PostProcessorTests.cs +3 -0
- package/Tests/Runtime/Core/ReflexiveErrorTests.cs +3 -0
- package/Tests/Runtime/Core/ReflexiveMessageWarningTests.cs +4 -1
- package/Tests/Runtime/Core/ReflexiveTests.cs +3 -0
- package/Tests/Runtime/Core/RegistrationTests.cs +3 -0
- package/Tests/Runtime/Core/StringShorthandTests.cs +3 -0
- package/Tests/Runtime/Core/TargetedTests.cs +3 -0
- package/Tests/Runtime/Core/TypedShorthandTests.cs +3 -0
- package/Tests/Runtime/Core/UntargetedEquivalenceTests.cs +3 -0
- package/Tests/Runtime/Core/UntargetedPrefreezeTests.cs +14 -78
- package/Tests/Runtime/Core/UntargetedTests.cs +3 -0
- package/Tests/Runtime/Integrations/Reflex/ReflexIntegrationTests.cs +4 -1
- package/Tests/Runtime/Integrations/VContainer/VContainerIntegrationTests.cs +3 -0
- package/Tests/Runtime/Integrations/Zenject/ZenjectIntegrationTests.cs +3 -0
- package/Tests/Runtime/Scripts/Components/GenericMessageAwareComponent.cs +3 -0
- package/Tests/Runtime/Scripts/Components/ManualListenerComponent.cs +3 -0
- package/Tests/Runtime/Scripts/Components/ReflexiveReceiverComponent.cs +3 -0
- package/Tests/Runtime/TestUtilities/UnityFixtureBase.cs +3 -0
- package/Tests/Runtime/Unity/MessageBusProviderAssetTests.cs +3 -0
- package/Tests/Runtime/Unity/MessageBusProviderHandleTests.cs +87 -3
- package/Tests/Runtime/Unity/MessagingComponentInstallerSceneTests.cs +109 -0
- package/Tests/Runtime/Unity/MessagingComponentInstallerSceneTests.cs.meta +11 -0
- package/Tests/Runtime/Unity/MessagingComponentProviderIntegrationTests.cs +159 -17
- package/package.json +1 -1
- package/Tests/Runtime/WallstopStudios.DxMessaging.Tests.Runtime.csproj +0 -7
|
@@ -345,12 +345,14 @@ namespace DxMessaging.Core
|
|
|
345
345
|
)
|
|
346
346
|
where TMessage : IMessage;
|
|
347
347
|
|
|
348
|
+
private static readonly object GlobalResetLock = new object();
|
|
349
|
+
|
|
348
350
|
/// <summary>
|
|
349
351
|
/// Global message bus used when no explicit bus is provided.
|
|
350
352
|
/// </summary>
|
|
351
353
|
private static IMessageBus _globalMessageBus;
|
|
352
354
|
|
|
353
|
-
private static
|
|
355
|
+
private static MessageBus.MessageBus _defaultGlobalMessageBus = new MessageBus.MessageBus();
|
|
354
356
|
|
|
355
357
|
/// <summary>
|
|
356
358
|
/// Gets the process-wide <see cref="IMessageBus"/> used when no explicit bus is supplied.
|
|
@@ -363,16 +365,17 @@ namespace DxMessaging.Core
|
|
|
363
365
|
public static IMessageBus MessageBus => _globalMessageBus;
|
|
364
366
|
|
|
365
367
|
/// <summary>
|
|
366
|
-
/// Gets the
|
|
368
|
+
/// Gets the baseline global <see cref="IMessageBus"/> instance used when no custom bus is configured.
|
|
367
369
|
/// </summary>
|
|
368
370
|
/// <remarks>
|
|
369
|
-
///
|
|
371
|
+
/// The instance is recreated when <see cref="DxMessagingStaticState.Reset"/> runs so that domain-reload-disabled
|
|
372
|
+
/// environments can obtain a clean slate.
|
|
370
373
|
/// </remarks>
|
|
371
374
|
public static IMessageBus InitialGlobalMessageBus => _defaultGlobalMessageBus;
|
|
372
375
|
|
|
373
376
|
static MessageHandler()
|
|
374
377
|
{
|
|
375
|
-
|
|
378
|
+
ResetStatics();
|
|
376
379
|
}
|
|
377
380
|
|
|
378
381
|
/// <summary>
|
|
@@ -417,11 +420,14 @@ namespace DxMessaging.Core
|
|
|
417
420
|
/// Restores the global <see cref="MessageBus.MessageBus"/> to the built-in default instance.
|
|
418
421
|
/// </summary>
|
|
419
422
|
/// <remarks>
|
|
420
|
-
/// The default instance is
|
|
423
|
+
/// The default instance is recreated by <see cref="ResetStatics"/> when the static state reset utility runs.
|
|
421
424
|
/// </remarks>
|
|
422
425
|
public static void ResetGlobalMessageBus()
|
|
423
426
|
{
|
|
424
|
-
|
|
427
|
+
lock (GlobalResetLock)
|
|
428
|
+
{
|
|
429
|
+
_globalMessageBus = _defaultGlobalMessageBus;
|
|
430
|
+
}
|
|
425
431
|
}
|
|
426
432
|
|
|
427
433
|
/// <summary>
|
|
@@ -434,6 +440,21 @@ namespace DxMessaging.Core
|
|
|
434
440
|
return new GlobalMessageBusScope(messageBus);
|
|
435
441
|
}
|
|
436
442
|
|
|
443
|
+
/// <summary>
|
|
444
|
+
/// Recreates the built-in global <see cref="MessageBus.MessageBus"/> and assigns it as the active global bus.
|
|
445
|
+
/// </summary>
|
|
446
|
+
/// <remarks>
|
|
447
|
+
/// Invoked by <see cref="DxMessagingStaticState.Reset"/> to provide a clean slate when domain reloads are disabled.
|
|
448
|
+
/// </remarks>
|
|
449
|
+
internal static void ResetStatics()
|
|
450
|
+
{
|
|
451
|
+
lock (GlobalResetLock)
|
|
452
|
+
{
|
|
453
|
+
_defaultGlobalMessageBus.ResetState();
|
|
454
|
+
_globalMessageBus = _defaultGlobalMessageBus;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
|
|
437
458
|
/// <summary>
|
|
438
459
|
/// Represents a disposable override scope for the global message bus.
|
|
439
460
|
/// </summary>
|
|
@@ -462,6 +483,9 @@ namespace DxMessaging.Core
|
|
|
462
483
|
}
|
|
463
484
|
}
|
|
464
485
|
|
|
486
|
+
/// <summary>
|
|
487
|
+
/// Restores the previously active global message bus when the scope ends.
|
|
488
|
+
/// </summary>
|
|
465
489
|
public void Dispose()
|
|
466
490
|
{
|
|
467
491
|
if (_disposed)
|
|
@@ -502,7 +526,7 @@ namespace DxMessaging.Core
|
|
|
502
526
|
/// <note>
|
|
503
527
|
/// Ideally, this would be something like a Dictionary[T, Handler[T]], but that can't be done with C#s type system.
|
|
504
528
|
/// </note>
|
|
505
|
-
|
|
529
|
+
internal readonly List<MessageCache<object>> _handlersByTypeByMessageBus;
|
|
506
530
|
private IMessageBus _defaultMessageBus;
|
|
507
531
|
|
|
508
532
|
/// <summary>
|
|
@@ -514,6 +538,14 @@ namespace DxMessaging.Core
|
|
|
514
538
|
/// </remarks>
|
|
515
539
|
public IMessageBus DefaultMessageBus => _defaultMessageBus ?? MessageBus;
|
|
516
540
|
|
|
541
|
+
/// <summary>
|
|
542
|
+
/// Initializes a message handler bound to the specified owner and optional default bus.
|
|
543
|
+
/// </summary>
|
|
544
|
+
/// <param name="owner">Identity of the object that owns this handler.</param>
|
|
545
|
+
/// <param name="defaultMessageBus">
|
|
546
|
+
/// Preferred bus to use when registrations do not specify one. Falls back to
|
|
547
|
+
/// <see cref="MessageBus"/> if omitted.
|
|
548
|
+
/// </param>
|
|
517
549
|
public MessageHandler(InstanceId owner, IMessageBus defaultMessageBus = null)
|
|
518
550
|
{
|
|
519
551
|
this.owner = owner;
|
|
@@ -1832,11 +1864,21 @@ namespace DxMessaging.Core
|
|
|
1832
1864
|
return messageBus.RegisterTargetedInterceptor(interceptor, priority);
|
|
1833
1865
|
}
|
|
1834
1866
|
|
|
1867
|
+
/// <summary>
|
|
1868
|
+
/// Checks equality against another object.
|
|
1869
|
+
/// </summary>
|
|
1870
|
+
/// <param name="obj">Object to compare.</param>
|
|
1871
|
+
/// <returns><c>true</c> when <paramref name="obj"/> is a <see cref="MessageHandler"/> with the same owner.</returns>
|
|
1835
1872
|
public override bool Equals(object obj)
|
|
1836
1873
|
{
|
|
1837
1874
|
return Equals(obj as MessageHandler);
|
|
1838
1875
|
}
|
|
1839
1876
|
|
|
1877
|
+
/// <summary>
|
|
1878
|
+
/// Checks equality against another handler instance.
|
|
1879
|
+
/// </summary>
|
|
1880
|
+
/// <param name="other">Handler to compare.</param>
|
|
1881
|
+
/// <returns><c>true</c> when both handlers share the same <see cref="owner"/>.</returns>
|
|
1840
1882
|
public bool Equals(MessageHandler other)
|
|
1841
1883
|
{
|
|
1842
1884
|
if (other == null)
|
|
@@ -1852,11 +1894,20 @@ namespace DxMessaging.Core
|
|
|
1852
1894
|
return owner.Equals(other.owner);
|
|
1853
1895
|
}
|
|
1854
1896
|
|
|
1897
|
+
/// <summary>
|
|
1898
|
+
/// Produces a hash code based on the owning instance.
|
|
1899
|
+
/// </summary>
|
|
1900
|
+
/// <returns>Hash code derived from <see cref="owner"/>.</returns>
|
|
1855
1901
|
public override int GetHashCode()
|
|
1856
1902
|
{
|
|
1857
1903
|
return owner.GetHashCode();
|
|
1858
1904
|
}
|
|
1859
1905
|
|
|
1906
|
+
/// <summary>
|
|
1907
|
+
/// Compares this handler with another handler for ordering.
|
|
1908
|
+
/// </summary>
|
|
1909
|
+
/// <param name="other">Handler to compare.</param>
|
|
1910
|
+
/// <returns>Relative ordering based on <see cref="owner"/>.</returns>
|
|
1860
1911
|
public int CompareTo(MessageHandler other)
|
|
1861
1912
|
{
|
|
1862
1913
|
if (other == null)
|
|
@@ -1867,11 +1918,22 @@ namespace DxMessaging.Core
|
|
|
1867
1918
|
return owner.CompareTo(other.owner);
|
|
1868
1919
|
}
|
|
1869
1920
|
|
|
1921
|
+
/// <summary>
|
|
1922
|
+
/// Compares this handler with an arbitrary object.
|
|
1923
|
+
/// </summary>
|
|
1924
|
+
/// <param name="obj">Object to compare.</param>
|
|
1925
|
+
/// <returns>
|
|
1926
|
+
/// Relative ordering when <paramref name="obj"/> is a <see cref="MessageHandler"/>; otherwise <c>-1</c>.
|
|
1927
|
+
/// </returns>
|
|
1870
1928
|
public int CompareTo(object obj)
|
|
1871
1929
|
{
|
|
1872
1930
|
return CompareTo(obj as MessageHandler);
|
|
1873
1931
|
}
|
|
1874
1932
|
|
|
1933
|
+
/// <summary>
|
|
1934
|
+
/// Returns a human-readable representation containing the owner identifier.
|
|
1935
|
+
/// </summary>
|
|
1936
|
+
/// <returns>String describing the handler.</returns>
|
|
1875
1937
|
public override string ToString()
|
|
1876
1938
|
{
|
|
1877
1939
|
return new { OwnerId = owner }.ToString();
|
|
@@ -1934,10 +1996,42 @@ namespace DxMessaging.Core
|
|
|
1934
1996
|
return false;
|
|
1935
1997
|
}
|
|
1936
1998
|
|
|
1999
|
+
internal int GetUntargetedPostProcessingPrefreezeCount<T>(
|
|
2000
|
+
IMessageBus messageBus,
|
|
2001
|
+
int priority
|
|
2002
|
+
)
|
|
2003
|
+
where T : IMessage
|
|
2004
|
+
{
|
|
2005
|
+
if (
|
|
2006
|
+
!GetHandlerForType(messageBus, out TypedHandler<T> handler)
|
|
2007
|
+
|| handler._untargetedPostProcessingFastHandlers == null
|
|
2008
|
+
)
|
|
2009
|
+
{
|
|
2010
|
+
return 0;
|
|
2011
|
+
}
|
|
2012
|
+
|
|
2013
|
+
if (
|
|
2014
|
+
handler._untargetedPostProcessingFastHandlers.TryGetValue(
|
|
2015
|
+
priority,
|
|
2016
|
+
out HandlerActionCache<FastHandler<T>> cache
|
|
2017
|
+
)
|
|
2018
|
+
)
|
|
2019
|
+
{
|
|
2020
|
+
return cache.prefreezeInvocationCount;
|
|
2021
|
+
}
|
|
2022
|
+
|
|
2023
|
+
return 0;
|
|
2024
|
+
}
|
|
2025
|
+
|
|
1937
2026
|
private sealed class HandlerActionCache<T>
|
|
1938
2027
|
{
|
|
1939
2028
|
internal readonly struct Entry
|
|
1940
2029
|
{
|
|
2030
|
+
/// <summary>
|
|
2031
|
+
/// Initializes an entry used to track handler invocation counts.
|
|
2032
|
+
/// </summary>
|
|
2033
|
+
/// <param name="handler">Handler delegate being tracked.</param>
|
|
2034
|
+
/// <param name="count">Number of times the handler has been cached.</param>
|
|
1941
2035
|
public Entry(T handler, int count)
|
|
1942
2036
|
{
|
|
1943
2037
|
this.handler = handler;
|
|
@@ -2318,6 +2412,12 @@ namespace DxMessaging.Core
|
|
|
2318
2412
|
}
|
|
2319
2413
|
}
|
|
2320
2414
|
|
|
2415
|
+
/// <summary>
|
|
2416
|
+
/// Runs untargeted post-processing handlers for the supplied message.
|
|
2417
|
+
/// </summary>
|
|
2418
|
+
/// <param name="message">Message being processed.</param>
|
|
2419
|
+
/// <param name="priority">Priority bucket currently executing.</param>
|
|
2420
|
+
/// <param name="emissionId">Emission identifier used to cache handler stacks.</param>
|
|
2321
2421
|
public void HandleUntargetedPostProcessing(ref T message, int priority, long emissionId)
|
|
2322
2422
|
{
|
|
2323
2423
|
RunFastHandlers(
|
|
@@ -2329,6 +2429,13 @@ namespace DxMessaging.Core
|
|
|
2329
2429
|
RunHandlers(_untargetedPostProcessingHandlers, ref message, priority, emissionId);
|
|
2330
2430
|
}
|
|
2331
2431
|
|
|
2432
|
+
/// <summary>
|
|
2433
|
+
/// Runs targeted post-processing handlers for the supplied message and recipient.
|
|
2434
|
+
/// </summary>
|
|
2435
|
+
/// <param name="target">Recipient of the message.</param>
|
|
2436
|
+
/// <param name="message">Message being processed.</param>
|
|
2437
|
+
/// <param name="priority">Priority bucket currently executing.</param>
|
|
2438
|
+
/// <param name="emissionId">Emission identifier used to cache handler stacks.</param>
|
|
2332
2439
|
public void HandleTargetedPostProcessing(
|
|
2333
2440
|
ref InstanceId target,
|
|
2334
2441
|
ref T message,
|
|
@@ -2352,6 +2459,13 @@ namespace DxMessaging.Core
|
|
|
2352
2459
|
);
|
|
2353
2460
|
}
|
|
2354
2461
|
|
|
2462
|
+
/// <summary>
|
|
2463
|
+
/// Runs targeted post-processing handlers that do not require a <see cref="InstanceId"/> target binding.
|
|
2464
|
+
/// </summary>
|
|
2465
|
+
/// <param name="target">Recipient of the message.</param>
|
|
2466
|
+
/// <param name="message">Message being processed.</param>
|
|
2467
|
+
/// <param name="priority">Priority bucket currently executing.</param>
|
|
2468
|
+
/// <param name="emissionId">Emission identifier used to cache handler stacks.</param>
|
|
2355
2469
|
public void HandleTargetedWithoutTargetingPostProcessing(
|
|
2356
2470
|
ref InstanceId target,
|
|
2357
2471
|
ref T message,
|
|
@@ -2375,6 +2489,13 @@ namespace DxMessaging.Core
|
|
|
2375
2489
|
);
|
|
2376
2490
|
}
|
|
2377
2491
|
|
|
2492
|
+
/// <summary>
|
|
2493
|
+
/// Runs broadcast post-processing handlers that expect a concrete source identifier.
|
|
2494
|
+
/// </summary>
|
|
2495
|
+
/// <param name="source">Origin of the message.</param>
|
|
2496
|
+
/// <param name="message">Message being processed.</param>
|
|
2497
|
+
/// <param name="priority">Priority bucket currently executing.</param>
|
|
2498
|
+
/// <param name="emissionId">Emission identifier used to cache handler stacks.</param>
|
|
2378
2499
|
public void HandleSourcedBroadcastPostProcessing(
|
|
2379
2500
|
ref InstanceId source,
|
|
2380
2501
|
ref T message,
|
|
@@ -2398,6 +2519,13 @@ namespace DxMessaging.Core
|
|
|
2398
2519
|
);
|
|
2399
2520
|
}
|
|
2400
2521
|
|
|
2522
|
+
/// <summary>
|
|
2523
|
+
/// Runs broadcast post-processing handlers that do not rely on a specific source identifier.
|
|
2524
|
+
/// </summary>
|
|
2525
|
+
/// <param name="source">Origin of the message.</param>
|
|
2526
|
+
/// <param name="message">Message being processed.</param>
|
|
2527
|
+
/// <param name="priority">Priority bucket currently executing.</param>
|
|
2528
|
+
/// <param name="emissionId">Emission identifier used to cache handler stacks.</param>
|
|
2401
2529
|
public void HandleBroadcastWithoutSourcePostProcessing(
|
|
2402
2530
|
ref InstanceId source,
|
|
2403
2531
|
ref T message,
|
|
@@ -3673,7 +3801,12 @@ namespace DxMessaging.Core
|
|
|
3673
3801
|
{
|
|
3674
3802
|
List<TU> list = actionCache.cache;
|
|
3675
3803
|
list.Clear();
|
|
3676
|
-
foreach (
|
|
3804
|
+
foreach (
|
|
3805
|
+
KeyValuePair<
|
|
3806
|
+
TU,
|
|
3807
|
+
HandlerActionCache<TU>.Entry
|
|
3808
|
+
> kvp in actionCache.entries
|
|
3809
|
+
)
|
|
3677
3810
|
{
|
|
3678
3811
|
list.Add(kvp.Value.handler);
|
|
3679
3812
|
}
|
|
@@ -19,6 +19,21 @@ namespace DxMessaging.Core
|
|
|
19
19
|
private readonly long _id;
|
|
20
20
|
private readonly int _hashCode;
|
|
21
21
|
|
|
22
|
+
internal static long GetCurrentIdSeed()
|
|
23
|
+
{
|
|
24
|
+
return Interlocked.Read(ref StaticIdCount);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
internal static void SetIdSeed(long value)
|
|
28
|
+
{
|
|
29
|
+
_ = Interlocked.Exchange(ref StaticIdCount, value);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
internal static void ResetIdSeed()
|
|
33
|
+
{
|
|
34
|
+
SetIdSeed(0);
|
|
35
|
+
}
|
|
36
|
+
|
|
22
37
|
/// <summary>
|
|
23
38
|
/// Creates a new unique handle.
|
|
24
39
|
/// </summary>
|
|
@@ -49,6 +64,12 @@ namespace DxMessaging.Core
|
|
|
49
64
|
return !left.Equals(right);
|
|
50
65
|
}
|
|
51
66
|
|
|
67
|
+
/// <summary>
|
|
68
|
+
/// Determines whether the left handle sorts after the right handle.
|
|
69
|
+
/// </summary>
|
|
70
|
+
/// <param name="left">Left-hand handle.</param>
|
|
71
|
+
/// <param name="right">Right-hand handle.</param>
|
|
72
|
+
/// <returns><c>true</c> when <paramref name="left"/> sorts after <paramref name="right"/>.</returns>
|
|
52
73
|
public static bool operator >(
|
|
53
74
|
MessageRegistrationHandle left,
|
|
54
75
|
MessageRegistrationHandle right
|
|
@@ -57,6 +78,12 @@ namespace DxMessaging.Core
|
|
|
57
78
|
return left.CompareTo(right) > 0;
|
|
58
79
|
}
|
|
59
80
|
|
|
81
|
+
/// <summary>
|
|
82
|
+
/// Determines whether the left handle sorts before the right handle.
|
|
83
|
+
/// </summary>
|
|
84
|
+
/// <param name="left">Left-hand handle.</param>
|
|
85
|
+
/// <param name="right">Right-hand handle.</param>
|
|
86
|
+
/// <returns><c>true</c> when <paramref name="left"/> sorts before <paramref name="right"/>.</returns>
|
|
60
87
|
public static bool operator <(
|
|
61
88
|
MessageRegistrationHandle left,
|
|
62
89
|
MessageRegistrationHandle right
|
|
@@ -81,11 +108,23 @@ namespace DxMessaging.Core
|
|
|
81
108
|
return left.CompareTo(right) >= 0;
|
|
82
109
|
}
|
|
83
110
|
|
|
111
|
+
/// <summary>
|
|
112
|
+
/// Compares this handle with another handle for ordering.
|
|
113
|
+
/// </summary>
|
|
114
|
+
/// <param name="other">Other handle to compare with.</param>
|
|
115
|
+
/// <returns>Relative ordering as defined by <see cref="IComparable{T}.CompareTo(T)"/>.</returns>
|
|
84
116
|
public int CompareTo(MessageRegistrationHandle other)
|
|
85
117
|
{
|
|
86
118
|
return _id.CompareTo(other._id);
|
|
87
119
|
}
|
|
88
120
|
|
|
121
|
+
/// <summary>
|
|
122
|
+
/// Compares this handle with an arbitrary object.
|
|
123
|
+
/// </summary>
|
|
124
|
+
/// <param name="obj">Object to compare with.</param>
|
|
125
|
+
/// <returns>
|
|
126
|
+
/// Relative ordering when <paramref name="obj"/> is a <see cref="MessageRegistrationHandle"/>; otherwise <c>-1</c>.
|
|
127
|
+
/// </returns>
|
|
89
128
|
public int CompareTo(object obj)
|
|
90
129
|
{
|
|
91
130
|
if (obj is MessageRegistrationHandle handle)
|
|
@@ -96,21 +135,41 @@ namespace DxMessaging.Core
|
|
|
96
135
|
return -1;
|
|
97
136
|
}
|
|
98
137
|
|
|
138
|
+
/// <summary>
|
|
139
|
+
/// Checks equality against another object.
|
|
140
|
+
/// </summary>
|
|
141
|
+
/// <param name="other">Object to compare.</param>
|
|
142
|
+
/// <returns>
|
|
143
|
+
/// <c>true</c> when <paramref name="other"/> is a <see cref="MessageRegistrationHandle"/> representing the same registration.
|
|
144
|
+
/// </returns>
|
|
99
145
|
public override bool Equals(object other)
|
|
100
146
|
{
|
|
101
147
|
return other is MessageRegistrationHandle handle && Equals(handle);
|
|
102
148
|
}
|
|
103
149
|
|
|
150
|
+
/// <summary>
|
|
151
|
+
/// Checks equality against another handle.
|
|
152
|
+
/// </summary>
|
|
153
|
+
/// <param name="other">Handle to compare.</param>
|
|
154
|
+
/// <returns><c>true</c> when both handles represent the same registration.</returns>
|
|
104
155
|
public bool Equals(MessageRegistrationHandle other)
|
|
105
156
|
{
|
|
106
157
|
return _id == other._id;
|
|
107
158
|
}
|
|
108
159
|
|
|
160
|
+
/// <summary>
|
|
161
|
+
/// Produces a hash code suitable for dictionary or set lookups.
|
|
162
|
+
/// </summary>
|
|
163
|
+
/// <returns>Hash code derived from the internal identifier.</returns>
|
|
109
164
|
public override int GetHashCode()
|
|
110
165
|
{
|
|
111
166
|
return _hashCode;
|
|
112
167
|
}
|
|
113
168
|
|
|
169
|
+
/// <summary>
|
|
170
|
+
/// Returns a string representation of the handle, including the underlying identifier.
|
|
171
|
+
/// </summary>
|
|
172
|
+
/// <returns>Human-readable representation of the handle.</returns>
|
|
114
173
|
public override string ToString()
|
|
115
174
|
{
|
|
116
175
|
return new { Id = _id }.ToString();
|
|
@@ -39,7 +39,7 @@ namespace DxMessaging.Core
|
|
|
39
39
|
/// }
|
|
40
40
|
/// </code>
|
|
41
41
|
/// </example>
|
|
42
|
-
public sealed class MessageRegistrationToken
|
|
42
|
+
public sealed class MessageRegistrationToken : IDisposable
|
|
43
43
|
{
|
|
44
44
|
/// <summary>
|
|
45
45
|
/// Whether the token is currently enabled (registrations are active).
|
|
@@ -71,7 +71,7 @@ namespace DxMessaging.Core
|
|
|
71
71
|
|
|
72
72
|
private IMessageBus _messageBus;
|
|
73
73
|
private bool _enabled;
|
|
74
|
-
private bool _diagnosticMode = IMessageBus.
|
|
74
|
+
private bool _diagnosticMode = IMessageBus.ShouldEnableDiagnostics();
|
|
75
75
|
|
|
76
76
|
private MessageRegistrationToken(MessageHandler messageHandler, IMessageBus messageBus)
|
|
77
77
|
{
|
|
@@ -166,7 +166,7 @@ namespace DxMessaging.Core
|
|
|
166
166
|
);
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
-
#if
|
|
169
|
+
#if UNITY_2021_3_OR_NEWER
|
|
170
170
|
/// <summary>
|
|
171
171
|
/// Stages a registration to accept targeted messages of type <typeparamref name="T"/> directed at the given GameObject.
|
|
172
172
|
/// </summary>
|
|
@@ -1024,7 +1024,7 @@ namespace DxMessaging.Core
|
|
|
1024
1024
|
);
|
|
1025
1025
|
}
|
|
1026
1026
|
|
|
1027
|
-
#if
|
|
1027
|
+
#if UNITY_2021_3_OR_NEWER
|
|
1028
1028
|
/// <summary>
|
|
1029
1029
|
/// Stages a registration to accept broadcast messages of type <typeparamref name="T"/> from a given source.
|
|
1030
1030
|
/// </summary>
|
|
@@ -1995,6 +1995,11 @@ namespace DxMessaging.Core
|
|
|
1995
1995
|
private readonly MessageRegistrationHandle _handle;
|
|
1996
1996
|
private bool _valid;
|
|
1997
1997
|
|
|
1998
|
+
/// <summary>
|
|
1999
|
+
/// Creates a disposable wrapper that removes a registration when disposed.
|
|
2000
|
+
/// </summary>
|
|
2001
|
+
/// <param name="token">Token that owns the registration.</param>
|
|
2002
|
+
/// <param name="handle">Handle to remove when disposed.</param>
|
|
1998
2003
|
public RegistrationDisposable(
|
|
1999
2004
|
MessageRegistrationToken token,
|
|
2000
2005
|
MessageRegistrationHandle handle
|
|
@@ -2005,6 +2010,9 @@ namespace DxMessaging.Core
|
|
|
2005
2010
|
_valid = true;
|
|
2006
2011
|
}
|
|
2007
2012
|
|
|
2013
|
+
/// <summary>
|
|
2014
|
+
/// Removes the wrapped registration the first time it is invoked.
|
|
2015
|
+
/// </summary>
|
|
2008
2016
|
public void Dispose()
|
|
2009
2017
|
{
|
|
2010
2018
|
// Best-effort idempotence; AsDisposable instances are short-lived and immutable
|
|
@@ -2035,5 +2043,13 @@ namespace DxMessaging.Core
|
|
|
2035
2043
|
|
|
2036
2044
|
return new MessageRegistrationToken(messageHandler, messageBus);
|
|
2037
2045
|
}
|
|
2046
|
+
|
|
2047
|
+
/// <summary>
|
|
2048
|
+
/// Removes all staged registrations and releases references to the handler.
|
|
2049
|
+
/// </summary>
|
|
2050
|
+
public void Dispose()
|
|
2051
|
+
{
|
|
2052
|
+
UnregisterAll();
|
|
2053
|
+
}
|
|
2038
2054
|
}
|
|
2039
2055
|
}
|
|
@@ -17,10 +17,29 @@ namespace DxMessaging.Core.Messages
|
|
|
17
17
|
public enum ReflexiveSendMode
|
|
18
18
|
{
|
|
19
19
|
[Obsolete("Please use a valid Send Mode")]
|
|
20
|
+
/// <summary>
|
|
21
|
+
/// Legacy sentinel indicating no traversal; not supported.
|
|
22
|
+
/// </summary>
|
|
20
23
|
None = 0,
|
|
24
|
+
|
|
25
|
+
/// <summary>
|
|
26
|
+
/// Invoke matching methods only on the immediate GameObject.
|
|
27
|
+
/// </summary>
|
|
21
28
|
Flat = 1 << 0,
|
|
29
|
+
|
|
30
|
+
/// <summary>
|
|
31
|
+
/// Traverse into child GameObjects when invoking methods.
|
|
32
|
+
/// </summary>
|
|
22
33
|
Downwards = 1 << 1,
|
|
34
|
+
|
|
35
|
+
/// <summary>
|
|
36
|
+
/// Traverse up the parent chain when invoking methods.
|
|
37
|
+
/// </summary>
|
|
23
38
|
Upwards = 1 << 2,
|
|
39
|
+
|
|
40
|
+
/// <summary>
|
|
41
|
+
/// Skip disabled components during traversal.
|
|
42
|
+
/// </summary>
|
|
24
43
|
OnlyIncludeActive = 1 << 3,
|
|
25
44
|
}
|
|
26
45
|
|
|
@@ -34,6 +53,11 @@ namespace DxMessaging.Core.Messages
|
|
|
34
53
|
|
|
35
54
|
private readonly int _hashCode;
|
|
36
55
|
|
|
56
|
+
/// <summary>
|
|
57
|
+
/// Creates a lookup key for a reflected method signature.
|
|
58
|
+
/// </summary>
|
|
59
|
+
/// <param name="methodName">Name of the method.</param>
|
|
60
|
+
/// <param name="parameterTypes">Ordered parameter list expected by the method.</param>
|
|
37
61
|
public MethodSignatureKey(string methodName, Type[] parameterTypes)
|
|
38
62
|
: this()
|
|
39
63
|
{
|
|
@@ -54,16 +78,30 @@ namespace DxMessaging.Core.Messages
|
|
|
54
78
|
return hashCode;
|
|
55
79
|
}
|
|
56
80
|
|
|
81
|
+
/// <summary>
|
|
82
|
+
/// Gets a stable hash code for the method signature.
|
|
83
|
+
/// </summary>
|
|
84
|
+
/// <returns>Hash code derived from the name and parameter types.</returns>
|
|
57
85
|
public override int GetHashCode()
|
|
58
86
|
{
|
|
59
87
|
return _hashCode;
|
|
60
88
|
}
|
|
61
89
|
|
|
90
|
+
/// <summary>
|
|
91
|
+
/// Checks equality against an arbitrary object.
|
|
92
|
+
/// </summary>
|
|
93
|
+
/// <param name="obj">Object to compare.</param>
|
|
94
|
+
/// <returns><c>true</c> when <paramref name="obj"/> represents the same signature.</returns>
|
|
62
95
|
public override bool Equals(object obj)
|
|
63
96
|
{
|
|
64
97
|
return obj is MethodSignatureKey other && Equals(other);
|
|
65
98
|
}
|
|
66
99
|
|
|
100
|
+
/// <summary>
|
|
101
|
+
/// Checks equality against another method signature key.
|
|
102
|
+
/// </summary>
|
|
103
|
+
/// <param name="other">Signature key to compare with.</param>
|
|
104
|
+
/// <returns><c>true</c> when both keys describe the same method.</returns>
|
|
67
105
|
public bool Equals(MethodSignatureKey other)
|
|
68
106
|
{
|
|
69
107
|
if (
|
|
@@ -3,13 +3,28 @@ namespace DxMessaging.Core
|
|
|
3
3
|
using System;
|
|
4
4
|
|
|
5
5
|
/// <summary>
|
|
6
|
-
/// Severity of the log message
|
|
6
|
+
/// Severity of the log message.
|
|
7
7
|
/// </summary>
|
|
8
8
|
public enum LogLevel
|
|
9
9
|
{
|
|
10
|
+
/// <summary>
|
|
11
|
+
/// Verbose diagnostic information useful while developing or debugging.
|
|
12
|
+
/// </summary>
|
|
10
13
|
Debug = 0,
|
|
14
|
+
|
|
15
|
+
/// <summary>
|
|
16
|
+
/// Informational messages that describe normal operation.
|
|
17
|
+
/// </summary>
|
|
11
18
|
Info = 1,
|
|
19
|
+
|
|
20
|
+
/// <summary>
|
|
21
|
+
/// Non-fatal issues that should be investigated.
|
|
22
|
+
/// </summary>
|
|
12
23
|
Warn = 2,
|
|
24
|
+
|
|
25
|
+
/// <summary>
|
|
26
|
+
/// Errors indicating messaging failed or data may be lost.
|
|
27
|
+
/// </summary>
|
|
13
28
|
Error = 3,
|
|
14
29
|
}
|
|
15
30
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
#if UNITY_2021_3_OR_NEWER
|
|
1
2
|
namespace DxMessaging.Unity
|
|
2
3
|
{
|
|
3
4
|
using DxMessaging.Core;
|
|
@@ -23,9 +24,14 @@ namespace DxMessaging.Unity
|
|
|
23
24
|
)]
|
|
24
25
|
public sealed class CurrentGlobalMessageBusProvider : ScriptableMessageBusProvider
|
|
25
26
|
{
|
|
27
|
+
/// <summary>
|
|
28
|
+
/// Resolves the message bus currently set as the global bus via <see cref="MessageHandler.SetGlobalMessageBus(IMessageBus)"/>.
|
|
29
|
+
/// </summary>
|
|
30
|
+
/// <returns>The active global <see cref="IMessageBus"/> instance.</returns>
|
|
26
31
|
public override IMessageBus Resolve()
|
|
27
32
|
{
|
|
28
33
|
return MessageHandler.MessageBus;
|
|
29
34
|
}
|
|
30
35
|
}
|
|
31
36
|
}
|
|
37
|
+
#endif
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#if UNITY_2021_3_OR_NEWER
|
|
2
|
+
namespace DxMessaging.Unity
|
|
3
|
+
{
|
|
4
|
+
using Core;
|
|
5
|
+
using UnityEngine;
|
|
6
|
+
|
|
7
|
+
/// <summary>
|
|
8
|
+
/// Unity-specific hook that resets DxMessaging static state when domain reloads are skipped.
|
|
9
|
+
/// </summary>
|
|
10
|
+
internal static class DxMessagingRuntimeInitializer
|
|
11
|
+
{
|
|
12
|
+
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
|
13
|
+
private static void ResetStatics()
|
|
14
|
+
{
|
|
15
|
+
DxMessagingStaticState.Reset();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
#endif
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
#if UNITY_2021_3_OR_NEWER
|
|
1
2
|
namespace DxMessaging.Unity
|
|
2
3
|
{
|
|
3
4
|
using DxMessaging.Core;
|
|
@@ -30,9 +31,14 @@ namespace DxMessaging.Unity
|
|
|
30
31
|
)]
|
|
31
32
|
public sealed class InitialGlobalMessageBusProvider : ScriptableMessageBusProvider
|
|
32
33
|
{
|
|
34
|
+
/// <summary>
|
|
35
|
+
/// Resolves the message bus captured during static initialization before any runtime overrides occur.
|
|
36
|
+
/// </summary>
|
|
37
|
+
/// <returns>The initial global <see cref="IMessageBus"/> instance.</returns>
|
|
33
38
|
public override IMessageBus Resolve()
|
|
34
39
|
{
|
|
35
40
|
return MessageHandler.InitialGlobalMessageBus;
|
|
36
41
|
}
|
|
37
42
|
}
|
|
38
43
|
}
|
|
44
|
+
#endif
|