com.wallstop-studios.dxmessaging 3.0.1 → 3.1.0
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/CHANGELOG.md +211 -2
- package/Editor/Analyzers/DxMessagingConsoleHarvester.cs +69 -62
- package/Editor/Analyzers/Microsoft.CodeAnalysis.CSharp.dll.meta +3 -3
- package/Editor/Analyzers/Microsoft.CodeAnalysis.dll.meta +3 -3
- package/Editor/Analyzers/System.Collections.Immutable.dll.meta +3 -3
- package/Editor/Analyzers/System.Reflection.Metadata.dll.meta +3 -3
- package/Editor/Analyzers/System.Runtime.CompilerServices.Unsafe.dll.meta +3 -3
- package/Editor/Analyzers/WallstopStudios.DxMessaging.Analyzer.dll +0 -0
- package/Editor/Analyzers/WallstopStudios.DxMessaging.Analyzer.dll.meta +15 -2
- package/Editor/Analyzers/WallstopStudios.DxMessaging.SourceGenerators.dll +0 -0
- package/Editor/Analyzers/WallstopStudios.DxMessaging.SourceGenerators.dll.meta +2 -2
- package/Editor/AssemblyInfo.cs.meta +9 -1
- package/Editor/CustomEditors/MessageAwareComponentInspectorOverlay.cs +24 -15
- package/Editor/CustomEditors/MessagingComponentEditor.cs.meta +9 -1
- package/Editor/DxMessagingEditorIdle.cs +62 -0
- package/{Runtime/Core/Internal/TypedDispatchLinkIndex.cs.meta → Editor/DxMessagingEditorIdle.cs.meta} +1 -1
- package/Editor/DxMessagingEditorInitializer.cs +112 -15
- package/Editor/DxMessagingEditorInitializer.cs.meta +9 -1
- package/Editor/DxMessagingEditorLog.cs +32 -0
- package/Editor/DxMessagingEditorLog.cs.meta +11 -0
- package/Editor/Settings/DxMessagingBaseCallIgnoreSync.cs +135 -12
- package/Editor/Settings/DxMessagingSettings.cs +92 -31
- package/Editor/Settings/DxMessagingSettings.cs.meta +9 -1
- package/Editor/Settings/DxMessagingSettingsProvider.cs.meta +9 -1
- package/Editor/SetupCscRsp.cs +339 -173
- package/Editor/SetupCscRsp.cs.meta +9 -1
- package/Editor/Testing/MessagingComponentEditorHarness.cs +1 -1
- package/Editor/Testing/MessagingComponentEditorHarness.cs.meta +9 -1
- package/README.md +17 -18
- package/Runtime/AssemblyInfo.cs.meta +9 -1
- package/Runtime/Core/Attributes/DxAutoConstructorAttribute.cs.meta +9 -1
- package/Runtime/Core/Attributes/DxBroadcastMessageAttribute.cs.meta +9 -1
- package/Runtime/Core/Attributes/DxOptionalParameterAttribute.cs +2 -4
- package/Runtime/Core/Attributes/DxOptionalParameterAttribute.cs.meta +9 -1
- package/Runtime/Core/Attributes/DxTargetedMessageAttribute.cs.meta +9 -1
- package/Runtime/Core/Attributes/DxUntargetedMessageAttribute.cs.meta +9 -1
- package/Runtime/Core/Attributes/Il2CppSetOptionAttribute.cs +56 -0
- package/Runtime/Core/Attributes/Il2CppSetOptionAttribute.cs.meta +11 -0
- package/Runtime/Core/DataStructure/CyclicBuffer.cs +44 -26
- package/Runtime/Core/DataStructure/CyclicBuffer.cs.meta +9 -1
- package/Runtime/Core/Diagnostics/MessageEmissionData.cs.meta +9 -1
- package/Runtime/Core/Diagnostics/MessageRegistrationData.cs.meta +9 -1
- package/Runtime/Core/Diagnostics/MessageRegistrationType.cs.meta +9 -1
- package/Runtime/Core/Extensions/EnumExtensions.cs +6 -5
- package/Runtime/Core/Extensions/EnumExtensions.cs.meta +9 -1
- package/Runtime/Core/Extensions/IListExtensions.cs.meta +9 -1
- package/Runtime/Core/Extensions/MessageExtensions.cs +0 -60
- package/Runtime/Core/Helper/MessageCache.cs.meta +9 -1
- package/Runtime/Core/Helper/MessageHelperIndexer.cs.meta +9 -1
- package/Runtime/Core/InstanceId.cs +25 -1
- package/Runtime/Core/Internal/DxUnsafe.cs +60 -0
- package/Runtime/Core/Internal/DxUnsafe.cs.meta +11 -0
- package/Runtime/Core/Internal/FlatDispatch.cs +198 -0
- package/Runtime/Core/Internal/FlatDispatch.cs.meta +11 -0
- package/Runtime/Core/Internal/TypedSlots.cs +5 -21
- package/Runtime/Core/MessageBus/IMessageBus.cs +12 -12
- package/Runtime/Core/MessageBus/IMessageRegistrationBuilder.cs +1 -0
- package/Runtime/Core/MessageBus/Internal/BusSlots.cs +7 -6
- package/Runtime/Core/MessageBus/MessageBus.cs +2313 -2936
- package/Runtime/Core/MessageBus/MessageRegistrationBuilder.cs +187 -14
- package/Runtime/Core/MessageHandler.cs +1023 -1143
- package/Runtime/Core/MessageRegistrationToken.cs +425 -47
- package/Runtime/Core/Messages/GlobalStringMessage.cs.meta +9 -1
- package/Runtime/Core/Messages/ReflexiveMessage.cs.meta +9 -1
- package/Runtime/Core/Messages/StringMessage.cs.meta +9 -1
- package/Runtime/Unity/Integrations/Reflex/AssemblyInfo.cs.meta +9 -1
- package/Runtime/Unity/Integrations/VContainer/AssemblyInfo.cs.meta +9 -1
- package/Runtime/Unity/Integrations/Zenject/AssemblyInfo.cs.meta +9 -1
- package/Runtime/Unity/MessageAwareComponent.cs +46 -1
- package/Runtime/Unity/MessagingComponent.cs +43 -10
- package/Runtime/WallstopStudios.DxMessaging.asmdef +1 -1
- package/Samples~/DI/README.md +7 -7
- package/SourceGenerators/Directory.Build.props +50 -3
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxAutoConstructorGenerator.cs +96 -63
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxMessageIdGenerator.cs +745 -87
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxMessageIdGenerator.cs.meta +9 -1
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.csproj +39 -46
- package/SourceGenerators/global.json +7 -0
- package/SourceGenerators/global.json.meta +7 -0
- package/package.json +27 -40
- package/Runtime/Core/Internal/TypedDispatchLinkIndex.cs +0 -51
|
@@ -50,10 +50,34 @@ namespace DxMessaging.Core
|
|
|
50
50
|
#if UNITY_2021_3_OR_NEWER
|
|
51
51
|
private InstanceId(UnityEngine.Object unityObject)
|
|
52
52
|
{
|
|
53
|
-
_id = unityObject
|
|
53
|
+
_id = StableId(unityObject);
|
|
54
54
|
Object = unityObject;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
/// <summary>
|
|
58
|
+
/// Returns the stable per-object integer identity used as the dispatch key.
|
|
59
|
+
/// Unity 6 is migrating object identity to the 64-bit <c>EntityId</c>:
|
|
60
|
+
/// <c>GetInstanceID()</c> is deprecated and becomes a compile error in Unity 6.5,
|
|
61
|
+
/// and successive raw accessors (the <c>EntityId</c>-to-<c>int</c> cast, then
|
|
62
|
+
/// <c>GetRawData()</c>) have each been deprecated in turn. On Unity 6.4+ this reads
|
|
63
|
+
/// the non-deprecated <c>EntityId.ToULong(...)</c> and keeps its low 32 bits --
|
|
64
|
+
/// exactly the integer the legacy <c>GetInstanceID()</c> returned (verified on 6.4
|
|
65
|
+
/// across GameObject/Component/ScriptableObject). Older Unity keeps
|
|
66
|
+
/// <c>GetInstanceID()</c> (valid, warning-only there, never the 6.5 error). The
|
|
67
|
+
/// 32-bit dispatch key is identical either way; only the (non-deprecated) source
|
|
68
|
+
/// differs. The gate is the host-verified 6.4 rather than 6.2 because the exact
|
|
69
|
+
/// accessor that is non-deprecated has shifted across Unity 6 minors.
|
|
70
|
+
/// </summary>
|
|
71
|
+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
72
|
+
internal static int StableId(UnityEngine.Object unityObject)
|
|
73
|
+
{
|
|
74
|
+
#if UNITY_6000_4_OR_NEWER
|
|
75
|
+
return unchecked((int)UnityEngine.EntityId.ToULong(unityObject.GetEntityId()));
|
|
76
|
+
#else
|
|
77
|
+
return unityObject.GetInstanceID();
|
|
78
|
+
#endif
|
|
79
|
+
}
|
|
80
|
+
|
|
57
81
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
58
82
|
/// <summary>
|
|
59
83
|
/// Converts a <see cref="UnityEngine.GameObject"/> reference into an <see cref="InstanceId"/>.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
namespace DxMessaging.Core.Internal
|
|
2
|
+
{
|
|
3
|
+
using System.Runtime.CompilerServices;
|
|
4
|
+
// Qualified with global:: because this assembly also declares a DxMessaging.Unity
|
|
5
|
+
// namespace; an unqualified "using Unity.Collections..." would bind to
|
|
6
|
+
// DxMessaging.Unity.Collections and fail to resolve.
|
|
7
|
+
using global::Unity.Collections.LowLevel.Unsafe;
|
|
8
|
+
|
|
9
|
+
/// <summary>
|
|
10
|
+
/// Reinterpret-cast helpers used by the hot dispatch path. Each method wraps a Unity
|
|
11
|
+
/// <see cref="UnsafeUtility"/> intrinsic, which resolves in both the Editor and every
|
|
12
|
+
/// player build (Mono and IL2CPP, including the .NET Standard 2.0 profile) without an
|
|
13
|
+
/// external precompiled assembly.
|
|
14
|
+
/// </summary>
|
|
15
|
+
/// <remarks>
|
|
16
|
+
/// These are drop-in replacements for the corresponding
|
|
17
|
+
/// <c>System.Runtime.CompilerServices.Unsafe</c> members. That type is supplied by the
|
|
18
|
+
/// Editor but is absent from player builds, so referencing it compiled in the Editor yet
|
|
19
|
+
/// failed standalone IL2CPP compilation. <see cref="UnsafeUtility"/> ships inside
|
|
20
|
+
/// <c>UnityEngine.CoreModule</c> on every supported platform, so routing through it keeps
|
|
21
|
+
/// the zero-allocation reinterpret behavior while removing the unresolved dependency.
|
|
22
|
+
/// The wrapped intrinsics are pure IL (no internal-call transition), so this indirection
|
|
23
|
+
/// is free once inlined.
|
|
24
|
+
/// </remarks>
|
|
25
|
+
internal static class DxUnsafe
|
|
26
|
+
{
|
|
27
|
+
/// <summary>
|
|
28
|
+
/// Reinterprets a managed reference to <typeparamref name="TFrom"/> as a reference to
|
|
29
|
+
/// <typeparamref name="TTo"/> in place, without copying or boxing. Callers guarantee the
|
|
30
|
+
/// reinterpretation is valid for the concrete runtime layout.
|
|
31
|
+
/// </summary>
|
|
32
|
+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
33
|
+
internal static ref TTo As<TFrom, TTo>(ref TFrom source)
|
|
34
|
+
{
|
|
35
|
+
return ref UnsafeUtility.As<TFrom, TTo>(ref source);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/// <summary>
|
|
39
|
+
/// Reinterprets a reference-typed instance as <typeparamref name="TTo"/> without a type
|
|
40
|
+
/// check. Callers guarantee the runtime type, mirroring the prior unchecked
|
|
41
|
+
/// <c>Unsafe.As<T>(object)</c> usage.
|
|
42
|
+
/// </summary>
|
|
43
|
+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
44
|
+
internal static TTo As<TTo>(object value)
|
|
45
|
+
where TTo : class
|
|
46
|
+
{
|
|
47
|
+
return UnsafeUtility.As<object, TTo>(ref value);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/// <summary>
|
|
51
|
+
/// Returns the size in bytes of <typeparamref name="T"/>.
|
|
52
|
+
/// </summary>
|
|
53
|
+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
54
|
+
internal static int SizeOf<T>()
|
|
55
|
+
where T : struct
|
|
56
|
+
{
|
|
57
|
+
return UnsafeUtility.SizeOf<T>();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
namespace DxMessaging.Core.Internal
|
|
2
|
+
{
|
|
3
|
+
using System;
|
|
4
|
+
using System.Buffers;
|
|
5
|
+
using System.Collections.Generic;
|
|
6
|
+
using DxMessaging.Core;
|
|
7
|
+
|
|
8
|
+
/// <summary>
|
|
9
|
+
/// One fully-resolved dispatch entry for slots whose delegates do NOT
|
|
10
|
+
/// receive the routing context (untargeted handle/post, and the
|
|
11
|
+
/// context-keyed Default-variant targeted/broadcast slots, where the
|
|
12
|
+
/// target/source is the routing key rather than a delegate parameter):
|
|
13
|
+
/// the owning <see cref="MessageHandler"/> (for the single live
|
|
14
|
+
/// <c>active</c> check) plus the final invocable delegate, resolved at
|
|
15
|
+
/// snapshot-build time. Steady-state dispatch over an array of these is
|
|
16
|
+
/// a single field read, one branch, and a direct delegate invocation per
|
|
17
|
+
/// entry - no dispatch link, no generation guard, no per-priority
|
|
18
|
+
/// dictionary lookup, and no type test.
|
|
19
|
+
/// </summary>
|
|
20
|
+
/// <typeparam name="TMessage">Concrete message type of the dispatch slot.</typeparam>
|
|
21
|
+
internal readonly struct FlatDispatchEntry<TMessage>
|
|
22
|
+
where TMessage : IMessage
|
|
23
|
+
{
|
|
24
|
+
public FlatDispatchEntry(
|
|
25
|
+
MessageHandler handler,
|
|
26
|
+
MessageHandler.FastHandler<TMessage> invoker
|
|
27
|
+
)
|
|
28
|
+
{
|
|
29
|
+
this.handler = handler;
|
|
30
|
+
this.invoker = invoker;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public readonly MessageHandler handler;
|
|
34
|
+
public readonly MessageHandler.FastHandler<TMessage> invoker;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/// <summary>
|
|
38
|
+
/// One fully-resolved dispatch entry for the WithoutContext
|
|
39
|
+
/// targeted/broadcast slots, whose delegates DO receive the routing
|
|
40
|
+
/// context (target/source <see cref="InstanceId"/>) as a parameter.
|
|
41
|
+
/// Mirrors <see cref="FlatDispatchEntry{TMessage}"/> with the
|
|
42
|
+
/// context-carrying delegate shape.
|
|
43
|
+
/// </summary>
|
|
44
|
+
/// <typeparam name="TMessage">Concrete message type of the dispatch slot.</typeparam>
|
|
45
|
+
internal readonly struct ContextFlatDispatchEntry<TMessage>
|
|
46
|
+
where TMessage : IMessage
|
|
47
|
+
{
|
|
48
|
+
public ContextFlatDispatchEntry(
|
|
49
|
+
MessageHandler handler,
|
|
50
|
+
MessageHandler.FastHandlerWithContext<TMessage> invoker
|
|
51
|
+
)
|
|
52
|
+
{
|
|
53
|
+
this.handler = handler;
|
|
54
|
+
this.invoker = invoker;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public readonly MessageHandler handler;
|
|
58
|
+
public readonly MessageHandler.FastHandlerWithContext<TMessage> invoker;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/// <summary>
|
|
62
|
+
/// Non-generic erasure base so the non-generic
|
|
63
|
+
/// <c>MessageBus.DispatchSnapshot</c> can carry and release a typed flat
|
|
64
|
+
/// entry array without knowing the closed message type (or the entry
|
|
65
|
+
/// shape). The snapshot's pooled-release path calls <see cref="Release"/>
|
|
66
|
+
/// exactly once per snapshot teardown; the typed holder returns its array
|
|
67
|
+
/// to the per-closed-generic pool.
|
|
68
|
+
/// </summary>
|
|
69
|
+
internal abstract class FlatDispatchArray
|
|
70
|
+
{
|
|
71
|
+
internal abstract void Release();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/// <summary>
|
|
75
|
+
/// Shared pooled-holder implementation for flat dispatch arrays: a pooled
|
|
76
|
+
/// entry array (rented from <see cref="ArrayPool{T}"/>) plus a small
|
|
77
|
+
/// per-closed-generic holder stack so registration-churn rebuilds
|
|
78
|
+
/// allocate nothing in steady state. Concrete holders
|
|
79
|
+
/// (<see cref="FlatDispatch{TMessage}"/>,
|
|
80
|
+
/// <see cref="ContextFlatDispatch{TMessage}"/>) only pick the entry
|
|
81
|
+
/// shape; all lifecycle logic lives here so the pool/lock/cap/released
|
|
82
|
+
/// pattern exists exactly once.
|
|
83
|
+
/// </summary>
|
|
84
|
+
/// <remarks>
|
|
85
|
+
/// Lifecycle mirrors the snapshot that owns the holder: the array is
|
|
86
|
+
/// frozen for the duration of any emission that acquired it (mutations
|
|
87
|
+
/// mark the owning DispatchState dirty and are observed by the NEXT
|
|
88
|
+
/// emission's rebuild), and it is released back to the pool only through
|
|
89
|
+
/// <c>DispatchSnapshot.Release()</c>. The <c>_released</c> flag guards
|
|
90
|
+
/// the holder against double-release (which would seat the same holder
|
|
91
|
+
/// in the pool twice and corrupt later rents): DEBUG builds assert,
|
|
92
|
+
/// release builds no-op the second call.
|
|
93
|
+
/// </remarks>
|
|
94
|
+
/// <typeparam name="TEntry">Resolved entry struct stored in the array.</typeparam>
|
|
95
|
+
/// <typeparam name="THolder">Concrete holder type (CRTP, for typed pooling).</typeparam>
|
|
96
|
+
internal abstract class PooledFlatDispatch<TEntry, THolder> : FlatDispatchArray
|
|
97
|
+
where THolder : PooledFlatDispatch<TEntry, THolder>, new()
|
|
98
|
+
{
|
|
99
|
+
private static readonly ArrayPool<TEntry> EntryPool = ArrayPool<TEntry>.Shared;
|
|
100
|
+
|
|
101
|
+
// Cold-path pool (rebuild/teardown only); the lock is uncontended in
|
|
102
|
+
// practice but keeps the holder pool safe if multiple buses are ever
|
|
103
|
+
// driven from different threads.
|
|
104
|
+
private static readonly Stack<THolder> HolderPool = new();
|
|
105
|
+
private static readonly object HolderPoolLock = new();
|
|
106
|
+
private const int MaxRetainedHolders = 64;
|
|
107
|
+
|
|
108
|
+
internal TEntry[] entries = Array.Empty<TEntry>();
|
|
109
|
+
internal int count;
|
|
110
|
+
|
|
111
|
+
// True while the holder is parked in (or eligible for) the pool;
|
|
112
|
+
// false while it is owned by a live DispatchSnapshot. Guards the
|
|
113
|
+
// rent/release lifecycle against double-release and rent-of-live.
|
|
114
|
+
private bool _released = true;
|
|
115
|
+
|
|
116
|
+
internal static THolder Rent(int capacity)
|
|
117
|
+
{
|
|
118
|
+
THolder holder = null;
|
|
119
|
+
lock (HolderPoolLock)
|
|
120
|
+
{
|
|
121
|
+
if (0 < HolderPool.Count)
|
|
122
|
+
{
|
|
123
|
+
holder = HolderPool.Pop();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
holder ??= new THolder();
|
|
128
|
+
System.Diagnostics.Debug.Assert(
|
|
129
|
+
holder._released,
|
|
130
|
+
"PooledFlatDispatch.Rent returned a holder that is still owned by a live "
|
|
131
|
+
+ "snapshot; a Release() was skipped or the pool was corrupted."
|
|
132
|
+
);
|
|
133
|
+
holder._released = false;
|
|
134
|
+
holder.entries = 0 < capacity ? EntryPool.Rent(capacity) : Array.Empty<TEntry>();
|
|
135
|
+
holder.count = 0;
|
|
136
|
+
return holder;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
internal sealed override void Release()
|
|
140
|
+
{
|
|
141
|
+
if (_released)
|
|
142
|
+
{
|
|
143
|
+
System.Diagnostics.Debug.Assert(
|
|
144
|
+
false,
|
|
145
|
+
"PooledFlatDispatch.Release called twice on the same holder; the owning "
|
|
146
|
+
+ "DispatchSnapshot must release its flat array exactly once."
|
|
147
|
+
);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
_released = true;
|
|
152
|
+
TEntry[] localEntries = entries;
|
|
153
|
+
int localCount = count;
|
|
154
|
+
entries = Array.Empty<TEntry>();
|
|
155
|
+
count = 0;
|
|
156
|
+
if (0 < localEntries.Length)
|
|
157
|
+
{
|
|
158
|
+
Array.Clear(localEntries, 0, localCount);
|
|
159
|
+
EntryPool.Return(localEntries);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
lock (HolderPoolLock)
|
|
163
|
+
{
|
|
164
|
+
if (HolderPool.Count < MaxRetainedHolders)
|
|
165
|
+
{
|
|
166
|
+
HolderPool.Push((THolder)this);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/// <summary>
|
|
173
|
+
/// Pooled flat array of resolved entries for one
|
|
174
|
+
/// (bus, message-type[, context], phase) dispatch snapshot whose
|
|
175
|
+
/// delegates take only the message: untargeted handle/post and the
|
|
176
|
+
/// context-keyed (Default variant) targeted/broadcast handle/post slots.
|
|
177
|
+
/// Built at snapshot-build time by walking the bus priority buckets
|
|
178
|
+
/// ascending, then each bucket's MessageHandlers in bus insertion order,
|
|
179
|
+
/// then each handler's fast entries followed by its default entries
|
|
180
|
+
/// (both in first-registration order), so a plain forward iteration
|
|
181
|
+
/// reproduces the documented dispatch order exactly.
|
|
182
|
+
/// </summary>
|
|
183
|
+
/// <typeparam name="TMessage">Concrete message type of the dispatch slot.</typeparam>
|
|
184
|
+
internal sealed class FlatDispatch<TMessage>
|
|
185
|
+
: PooledFlatDispatch<FlatDispatchEntry<TMessage>, FlatDispatch<TMessage>>
|
|
186
|
+
where TMessage : IMessage { }
|
|
187
|
+
|
|
188
|
+
/// <summary>
|
|
189
|
+
/// Pooled flat array of resolved entries for one (bus, message-type,
|
|
190
|
+
/// phase) dispatch snapshot of a WithoutContext targeted/broadcast slot,
|
|
191
|
+
/// whose delegates receive the routing <see cref="InstanceId"/> alongside
|
|
192
|
+
/// the message. Build order matches <see cref="FlatDispatch{TMessage}"/>.
|
|
193
|
+
/// </summary>
|
|
194
|
+
/// <typeparam name="TMessage">Concrete message type of the dispatch slot.</typeparam>
|
|
195
|
+
internal sealed class ContextFlatDispatch<TMessage>
|
|
196
|
+
: PooledFlatDispatch<ContextFlatDispatchEntry<TMessage>, ContextFlatDispatch<TMessage>>
|
|
197
|
+
where TMessage : IMessage { }
|
|
198
|
+
}
|
|
@@ -28,10 +28,9 @@ namespace DxMessaging.Core.Internal
|
|
|
28
28
|
/// surface picks up no new members from the interface retrofit.
|
|
29
29
|
/// </para>
|
|
30
30
|
/// <para>
|
|
31
|
-
/// Deliberately a thin, marker-style surface: only the
|
|
31
|
+
/// Deliberately a thin, marker-style surface: only the five members that
|
|
32
32
|
/// staged dispatch (<see cref="Version"/>, <see cref="LastSeenVersion"/>,
|
|
33
|
-
/// <see cref="LastSeenEmissionId"
|
|
34
|
-
/// <see cref="PrefreezeInvocationCount"/>) and eviction
|
|
33
|
+
/// <see cref="LastSeenEmissionId"/>) and eviction
|
|
35
34
|
/// (<see cref="IsEmpty"/>, <see cref="Reset"/>) require. The
|
|
36
35
|
/// <c>entries</c> dictionary and <c>cache</c> list are NOT exposed
|
|
37
36
|
/// because their generic shape is the very thing this interface erases;
|
|
@@ -67,15 +66,6 @@ namespace DxMessaging.Core.Internal
|
|
|
67
66
|
/// </summary>
|
|
68
67
|
long LastSeenEmissionId { get; set; }
|
|
69
68
|
|
|
70
|
-
/// <summary>
|
|
71
|
-
/// Number of invocations observed during the prefreeze window for
|
|
72
|
-
/// the most recent dispatch. Mirrors
|
|
73
|
-
/// <c>HandlerActionCache<TDelegate>.prefreezeInvocationCount</c>.
|
|
74
|
-
/// Read-only on this surface; the cache's own dispatchers maintain
|
|
75
|
-
/// the value.
|
|
76
|
-
/// </summary>
|
|
77
|
-
int PrefreezeInvocationCount { get; }
|
|
78
|
-
|
|
79
69
|
/// <summary>
|
|
80
70
|
/// True iff the cache currently retains zero entries. Cheap (single
|
|
81
71
|
/// integer compare against <c>entries.Count</c>); used by the
|
|
@@ -87,7 +77,7 @@ namespace DxMessaging.Core.Internal
|
|
|
87
77
|
/// <summary>
|
|
88
78
|
/// Eviction-driven full clear. Empties the entries dictionary and
|
|
89
79
|
/// the flat cache list, resets <see cref="LastSeenVersion"/> /
|
|
90
|
-
/// <see cref="LastSeenEmissionId"
|
|
80
|
+
/// <see cref="LastSeenEmissionId"/>,
|
|
91
81
|
/// and bumps <see cref="Version"/> as the LAST step so any captured
|
|
92
82
|
/// dispatch closure that observed the prior version detects
|
|
93
83
|
/// invalidation. Idempotent.
|
|
@@ -109,8 +99,8 @@ namespace DxMessaging.Core.Internal
|
|
|
109
99
|
int MessageTypeIndex { get; }
|
|
110
100
|
|
|
111
101
|
/// <summary>
|
|
112
|
-
/// True when the last sweep found no live typed slots
|
|
113
|
-
///
|
|
102
|
+
/// True when the last sweep found no live typed slots worth
|
|
103
|
+
/// retaining and the owning <c>MessageCache</c> entry can be
|
|
114
104
|
/// removed.
|
|
115
105
|
/// </summary>
|
|
116
106
|
bool MarkedForOuterRemoval { get; }
|
|
@@ -169,12 +159,6 @@ namespace DxMessaging.Core.Internal
|
|
|
169
159
|
/// <c>_slots[<see cref="TypedSlotIndex.Length"/>]</c> array the
|
|
170
160
|
/// storage owner.
|
|
171
161
|
/// </para>
|
|
172
|
-
/// <para>
|
|
173
|
-
/// <see cref="TypedHandler{T}"/> owns a
|
|
174
|
-
/// <c>_dispatchLinks[<see cref="TypedDispatchLinkIndex.Length"/>]</c>
|
|
175
|
-
/// array as a plain <c>object[]</c> field. It is not a slot type; the
|
|
176
|
-
/// legacy named dispatch-link fields were removed.
|
|
177
|
-
/// </para>
|
|
178
162
|
/// </remarks>
|
|
179
163
|
/// <typeparam name="T">
|
|
180
164
|
/// The strongly-typed message contract this slot's parent
|
|
@@ -109,23 +109,23 @@ namespace DxMessaging.Core.MessageBus
|
|
|
109
109
|
|
|
110
110
|
internal static bool ShouldEnableDiagnostics()
|
|
111
111
|
{
|
|
112
|
-
|
|
112
|
+
#if UNITY_2021_3_OR_NEWER
|
|
113
|
+
return ShouldEnableDiagnostics(GlobalDiagnosticsTargets, Application.isEditor);
|
|
114
|
+
#else
|
|
115
|
+
return ShouldEnableDiagnostics(GlobalDiagnosticsTargets, isEditor: false);
|
|
116
|
+
#endif
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
internal static bool ShouldEnableDiagnostics(DiagnosticsTarget targets, bool isEditor)
|
|
120
|
+
{
|
|
113
121
|
if (targets == DiagnosticsTarget.Off)
|
|
114
122
|
{
|
|
115
123
|
return false;
|
|
116
124
|
}
|
|
117
125
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
return targets.HasFlagNoAlloc(DiagnosticsTarget.Editor)
|
|
122
|
-
|| targets.HasFlagNoAlloc(DiagnosticsTarget.Runtime);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return targets.HasFlagNoAlloc(DiagnosticsTarget.Editor);
|
|
126
|
-
#else
|
|
127
|
-
return targets.HasFlagNoAlloc(DiagnosticsTarget.Runtime);
|
|
128
|
-
#endif
|
|
126
|
+
return isEditor
|
|
127
|
+
? targets.HasFlagNoAlloc(DiagnosticsTarget.Editor)
|
|
128
|
+
: targets.HasFlagNoAlloc(DiagnosticsTarget.Runtime);
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
/// <summary>
|
|
@@ -13,6 +13,7 @@ namespace DxMessaging.Core.MessageBus
|
|
|
13
13
|
/// <param name="options">Build configuration describing ownership, message bus preference, and lifecycle hooks.</param>
|
|
14
14
|
/// <returns>Lease that exposes the constructed <see cref="MessageRegistrationToken"/>.</returns>
|
|
15
15
|
/// <exception cref="ArgumentNullException"><paramref name="options"/> is <see langword="null"/>.</exception>
|
|
16
|
+
/// <exception cref="MessageRegistrationBuildException">ActivateOnBuild activation failed and automatic cleanup remains retryable.</exception>
|
|
16
17
|
MessageRegistrationLease Build(MessageRegistrationBuildOptions options);
|
|
17
18
|
}
|
|
18
19
|
}
|
|
@@ -4,6 +4,7 @@ namespace DxMessaging.Core.MessageBus.Internal
|
|
|
4
4
|
using System.Diagnostics;
|
|
5
5
|
using System.Runtime.CompilerServices;
|
|
6
6
|
using DxMessaging.Core;
|
|
7
|
+
using DxMessaging.Core.Internal;
|
|
7
8
|
using DxMessaging.Core.Pooling;
|
|
8
9
|
|
|
9
10
|
/// <summary>
|
|
@@ -277,7 +278,7 @@ namespace DxMessaging.Core.MessageBus.Internal
|
|
|
277
278
|
/// <c>Dictionary<InstanceId, object></c> -- generic-erased to share a
|
|
278
279
|
/// single pool across every message-type instantiation. Each value is a
|
|
279
280
|
/// <see cref="BusSinkSlot"/>, accessed via
|
|
280
|
-
/// <see cref="
|
|
281
|
+
/// <see cref="DxUnsafe.As{T}(object)"/>; the class is sealed and only inserted
|
|
281
282
|
/// from this type's own methods, so the cast cannot encounter a foreign
|
|
282
283
|
/// runtime type. <c>DEBUG</c> builds verify the invariant at every
|
|
283
284
|
/// cast site.
|
|
@@ -378,7 +379,7 @@ namespace DxMessaging.Core.MessageBus.Internal
|
|
|
378
379
|
return false;
|
|
379
380
|
}
|
|
380
381
|
DebugAssertSlot(boxed);
|
|
381
|
-
slot =
|
|
382
|
+
slot = DxUnsafe.As<BusSinkSlot>(boxed);
|
|
382
383
|
return true;
|
|
383
384
|
}
|
|
384
385
|
|
|
@@ -403,7 +404,7 @@ namespace DxMessaging.Core.MessageBus.Internal
|
|
|
403
404
|
if (map.TryGetValue(context, out object boxed))
|
|
404
405
|
{
|
|
405
406
|
DebugAssertSlot(boxed);
|
|
406
|
-
return
|
|
407
|
+
return DxUnsafe.As<BusSinkSlot>(boxed);
|
|
407
408
|
}
|
|
408
409
|
BusSinkSlot slot = new BusSinkSlot();
|
|
409
410
|
map[context] = slot;
|
|
@@ -463,7 +464,7 @@ namespace DxMessaging.Core.MessageBus.Internal
|
|
|
463
464
|
continue;
|
|
464
465
|
}
|
|
465
466
|
DebugAssertSlot(boxed);
|
|
466
|
-
|
|
467
|
+
DxUnsafe.As<BusSinkSlot>(boxed).Clear();
|
|
467
468
|
}
|
|
468
469
|
map.Clear();
|
|
469
470
|
}
|
|
@@ -494,7 +495,7 @@ namespace DxMessaging.Core.MessageBus.Internal
|
|
|
494
495
|
continue;
|
|
495
496
|
}
|
|
496
497
|
DebugAssertSlot(boxed);
|
|
497
|
-
|
|
498
|
+
DxUnsafe.As<BusSinkSlot>(boxed).Reset();
|
|
498
499
|
}
|
|
499
500
|
// Pool's onRecycled callback clears the dictionary before re-use.
|
|
500
501
|
DxPools.InstanceIdDicts.Return(map);
|
|
@@ -513,7 +514,7 @@ namespace DxMessaging.Core.MessageBus.Internal
|
|
|
513
514
|
Debug.Assert(
|
|
514
515
|
boxed is BusSinkSlot,
|
|
515
516
|
"BusContextSlot.byContext must only contain BusSinkSlot values; "
|
|
516
|
-
+ "
|
|
517
|
+
+ "DxUnsafe.As<BusSinkSlot> would otherwise produce undefined behavior."
|
|
517
518
|
);
|
|
518
519
|
}
|
|
519
520
|
}
|