com.wallstop-studios.dxmessaging 2.0.0-rc11 → 2.0.0-rc12
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/Editor/SetupCscRsp.cs +29 -13
- package/README.md +4 -3
- package/Runtime/Core/Attributes/DxAutoMessageTypeAttribute.cs +2 -4
- package/Runtime/Core/Attributes/DxBroadcastMessageAttribute.cs +2 -5
- package/Runtime/Core/Attributes/DxTargetedMessageAttribute.cs +2 -5
- package/Runtime/Core/Attributes/DxUntargetedMessageAttribute.cs +2 -5
- package/Runtime/Core/Extensions/MessageExtensions.cs +83 -16
- package/Runtime/Core/MessageBus/MessagingRegistration.cs +9 -4
- package/Runtime/Core/Messages/IBroadcastMessage.cs +2 -2
- package/Runtime/Core/Messages/ITargetedMessage.cs +2 -1
- package/Runtime/Core/Messages/IUntargetedMessage.cs +2 -1
- package/Runtime/Core/MessagingDebug.cs +0 -1
- package/Runtime/Unity/MessageAwareComponent.cs +1 -1
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxAutoMessageTypeGenerator.cs +36 -19
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxBroadcastMessageGenerator.cs +37 -20
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxTargetedMessageGenerator.cs +37 -20
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxUntargetedMessageGenerator.cs +38 -22
- package/Tests/Runtime/Core/GlobalAcceptAllTests.cs +32 -11
- package/Tests/Runtime/Core/MessagingTestBase.cs +36 -15
- package/Tests/Runtime/Core/NominalTests.cs +320 -98
- package/Tests/Runtime/Core/PostProcessorTests.cs +468 -81
- package/Tests/Runtime/Core/RegistrationTests.cs +390 -119
- package/Tests/Runtime/Scripts/Components/SimpleMessageAwareComponent.cs +62 -16
- package/Tests/Runtime/Scripts/Messages/ComplexTargetedMessage.cs +1 -1
- package/Tests/Runtime/Scripts/Messages/SimpleBroadcastMessage.cs +1 -1
- package/Tests/Runtime/Scripts/Messages/SimpleTargetedMessage.cs +1 -1
- package/Tests/Runtime/Scripts/Messages/SimpleUntargetedMessage.cs +1 -1
- package/Tests/Runtime/WallstopStudios.DxMessaging.Tests.Runtime.asmdef +22 -22
- package/package.json +2 -2
package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxTargetedMessageGenerator.cs
CHANGED
|
@@ -23,36 +23,49 @@ public sealed class DxTargetedMessageGenerator : ISourceGenerator
|
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
INamedTypeSymbol attributeSymbol = context.Compilation.GetTypeByMetadataName(
|
|
26
|
+
INamedTypeSymbol attributeSymbol = context.Compilation.GetTypeByMetadataName(
|
|
27
|
+
"DxMessaging.Core.Attributes.DxTargetedMessageAttribute"
|
|
28
|
+
);
|
|
27
29
|
|
|
28
30
|
foreach (TypeDeclarationSyntax classDeclaration in receiver.CandidateClasses)
|
|
29
31
|
{
|
|
30
32
|
SemanticModel model = context.Compilation.GetSemanticModel(classDeclaration.SyntaxTree);
|
|
31
33
|
ISymbol classSymbol = ModelExtensions.GetDeclaredSymbol(model, classDeclaration);
|
|
32
34
|
|
|
33
|
-
if (
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
if (
|
|
36
|
+
classSymbol
|
|
37
|
+
.GetAttributes()
|
|
38
|
+
.Any(attributeData =>
|
|
39
|
+
attributeData.AttributeClass.Equals(
|
|
40
|
+
attributeSymbol,
|
|
41
|
+
SymbolEqualityComparer.Default
|
|
42
|
+
)
|
|
43
|
+
)
|
|
44
|
+
)
|
|
36
45
|
{
|
|
37
46
|
string namespaceName = classSymbol.ContainingNamespace.ToDisplayString();
|
|
38
47
|
string className = classSymbol.Name;
|
|
39
|
-
string typeKind =
|
|
48
|
+
string typeKind =
|
|
49
|
+
classDeclaration.Kind() == SyntaxKind.ClassDeclaration ? "class" : "struct";
|
|
40
50
|
|
|
41
51
|
string source = $$"""
|
|
42
52
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
public partial {{typeKind}} {{className}} : ITargetedMessage
|
|
48
|
-
{
|
|
49
|
-
public System.Type MessageType => typeof({{className}});
|
|
50
|
-
}
|
|
51
|
-
}
|
|
53
|
+
namespace {{namespaceName}}
|
|
54
|
+
{
|
|
55
|
+
using DxMessaging.Core.Messages;
|
|
52
56
|
|
|
53
|
-
|
|
57
|
+
public partial {{typeKind}} {{className}} : ITargetedMessage
|
|
58
|
+
{
|
|
59
|
+
public System.Type MessageType => typeof({{className}});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
""";
|
|
54
64
|
|
|
55
|
-
context.AddSource(
|
|
65
|
+
context.AddSource(
|
|
66
|
+
$"{className}_DxTargetedMessage.g.cs",
|
|
67
|
+
SourceText.From(source, Encoding.UTF8)
|
|
68
|
+
);
|
|
56
69
|
}
|
|
57
70
|
}
|
|
58
71
|
}
|
|
@@ -65,13 +78,17 @@ public sealed class DxTargetedMessageGenerator : ISourceGenerator
|
|
|
65
78
|
{
|
|
66
79
|
if (syntaxNode is TypeDeclarationSyntax typeDeclarationSyntax)
|
|
67
80
|
{
|
|
68
|
-
if (
|
|
69
|
-
|
|
70
|
-
|
|
81
|
+
if (
|
|
82
|
+
typeDeclarationSyntax.AttributeLists.Count > 0
|
|
83
|
+
&& (
|
|
84
|
+
typeDeclarationSyntax.Kind() == SyntaxKind.ClassDeclaration
|
|
85
|
+
|| typeDeclarationSyntax.Kind() == SyntaxKind.StructDeclaration
|
|
86
|
+
)
|
|
87
|
+
)
|
|
71
88
|
{
|
|
72
89
|
CandidateClasses.Add(typeDeclarationSyntax);
|
|
73
90
|
}
|
|
74
91
|
}
|
|
75
92
|
}
|
|
76
93
|
}
|
|
77
|
-
}
|
|
94
|
+
}
|
|
@@ -11,7 +11,7 @@ using Microsoft.CodeAnalysis.Text;
|
|
|
11
11
|
[Generator]
|
|
12
12
|
public sealed class DxUntargetedMessageGenerator : ISourceGenerator
|
|
13
13
|
{
|
|
14
|
-
|
|
14
|
+
public void Initialize(GeneratorInitializationContext context)
|
|
15
15
|
{
|
|
16
16
|
context.RegisterForSyntaxNotifications(() => new SyntaxReceiver());
|
|
17
17
|
}
|
|
@@ -23,36 +23,49 @@ public sealed class DxUntargetedMessageGenerator : ISourceGenerator
|
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
INamedTypeSymbol attributeSymbol = context.Compilation.GetTypeByMetadataName(
|
|
26
|
+
INamedTypeSymbol attributeSymbol = context.Compilation.GetTypeByMetadataName(
|
|
27
|
+
"DxMessaging.Core.Attributes.DxUntargetedMessageAttribute"
|
|
28
|
+
);
|
|
27
29
|
|
|
28
30
|
foreach (TypeDeclarationSyntax classDeclaration in receiver.CandidateClasses)
|
|
29
31
|
{
|
|
30
32
|
SemanticModel model = context.Compilation.GetSemanticModel(classDeclaration.SyntaxTree);
|
|
31
33
|
ISymbol classSymbol = ModelExtensions.GetDeclaredSymbol(model, classDeclaration);
|
|
32
34
|
|
|
33
|
-
if (
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
if (
|
|
36
|
+
classSymbol
|
|
37
|
+
.GetAttributes()
|
|
38
|
+
.Any(attributeData =>
|
|
39
|
+
attributeData.AttributeClass.Equals(
|
|
40
|
+
attributeSymbol,
|
|
41
|
+
SymbolEqualityComparer.Default
|
|
42
|
+
)
|
|
43
|
+
)
|
|
44
|
+
)
|
|
36
45
|
{
|
|
37
46
|
string namespaceName = classSymbol.ContainingNamespace.ToDisplayString();
|
|
38
47
|
string className = classSymbol.Name;
|
|
39
|
-
string typeKind =
|
|
48
|
+
string typeKind =
|
|
49
|
+
classDeclaration.Kind() == SyntaxKind.ClassDeclaration ? "class" : "struct";
|
|
40
50
|
|
|
41
51
|
string source = $$"""
|
|
42
52
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
public partial {{typeKind}} {{className}} : IUntargetedMessage
|
|
48
|
-
{
|
|
49
|
-
public System.Type MessageType => typeof({{className}});
|
|
50
|
-
}
|
|
51
|
-
}
|
|
53
|
+
namespace {{namespaceName}}
|
|
54
|
+
{
|
|
55
|
+
using DxMessaging.Core.Messages;
|
|
52
56
|
|
|
53
|
-
|
|
57
|
+
public partial {{typeKind}} {{className}} : IUntargetedMessage
|
|
58
|
+
{
|
|
59
|
+
public System.Type MessageType => typeof({{className}});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
""";
|
|
54
64
|
|
|
55
|
-
context.AddSource(
|
|
65
|
+
context.AddSource(
|
|
66
|
+
$"{className}_DxUntargetedMessage.g.cs",
|
|
67
|
+
SourceText.From(source, Encoding.UTF8)
|
|
68
|
+
);
|
|
56
69
|
}
|
|
57
70
|
}
|
|
58
71
|
}
|
|
@@ -65,14 +78,17 @@ public sealed class DxUntargetedMessageGenerator : ISourceGenerator
|
|
|
65
78
|
{
|
|
66
79
|
if (syntaxNode is TypeDeclarationSyntax typeDeclarationSyntax)
|
|
67
80
|
{
|
|
68
|
-
if (
|
|
69
|
-
|
|
70
|
-
|
|
81
|
+
if (
|
|
82
|
+
typeDeclarationSyntax.AttributeLists.Count > 0
|
|
83
|
+
&& (
|
|
84
|
+
typeDeclarationSyntax.Kind() == SyntaxKind.ClassDeclaration
|
|
85
|
+
|| typeDeclarationSyntax.Kind() == SyntaxKind.StructDeclaration
|
|
86
|
+
)
|
|
87
|
+
)
|
|
71
88
|
{
|
|
72
89
|
CandidateClasses.Add(typeDeclarationSyntax);
|
|
73
90
|
}
|
|
74
91
|
}
|
|
75
92
|
}
|
|
76
93
|
}
|
|
77
|
-
|
|
78
|
-
}
|
|
94
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
namespace DxMessaging.Tests.Runtime.Core
|
|
2
2
|
{
|
|
3
|
-
using DxMessaging.Core;
|
|
4
|
-
using Scripts.Components;
|
|
5
3
|
using System;
|
|
6
4
|
using System.Collections;
|
|
5
|
+
using DxMessaging.Core;
|
|
7
6
|
using DxMessaging.Core.Extensions;
|
|
8
7
|
using DxMessaging.Core.Messages;
|
|
9
8
|
using NUnit.Framework;
|
|
9
|
+
using Scripts.Components;
|
|
10
10
|
using Scripts.Messages;
|
|
11
11
|
using UnityEngine;
|
|
12
12
|
using UnityEngine.TestTools;
|
|
@@ -54,13 +54,19 @@
|
|
|
54
54
|
SimpleTargetedMessage targetedMessage = new();
|
|
55
55
|
SimpleBroadcastMessage broadcastMessage = new();
|
|
56
56
|
RunGlobalAcceptAllTest(
|
|
57
|
-
token =>
|
|
57
|
+
token =>
|
|
58
|
+
token.RegisterGlobalAcceptAll(
|
|
59
|
+
HandleUntargeted,
|
|
60
|
+
HandleTargeted,
|
|
61
|
+
HandleBroadcast
|
|
62
|
+
),
|
|
58
63
|
i =>
|
|
59
64
|
{
|
|
60
65
|
Assert.AreEqual(i, untargetedCount);
|
|
61
66
|
untargetedMessage.EmitUntargeted();
|
|
62
67
|
Assert.AreEqual(i + 1, untargetedCount);
|
|
63
|
-
},
|
|
68
|
+
},
|
|
69
|
+
i =>
|
|
64
70
|
{
|
|
65
71
|
Assert.AreEqual(i, targetedCount);
|
|
66
72
|
if (_random.Next() % 2 == 0)
|
|
@@ -73,7 +79,8 @@
|
|
|
73
79
|
}
|
|
74
80
|
|
|
75
81
|
Assert.AreEqual(i + 1, targetedCount);
|
|
76
|
-
},
|
|
82
|
+
},
|
|
83
|
+
i =>
|
|
77
84
|
{
|
|
78
85
|
Assert.AreEqual(i, broadcastCount);
|
|
79
86
|
if (_random.Next() % 2 == 0)
|
|
@@ -86,7 +93,8 @@
|
|
|
86
93
|
}
|
|
87
94
|
|
|
88
95
|
Assert.AreEqual(i + 1, broadcastCount);
|
|
89
|
-
}
|
|
96
|
+
}
|
|
97
|
+
);
|
|
90
98
|
yield break;
|
|
91
99
|
}
|
|
92
100
|
|
|
@@ -116,13 +124,19 @@
|
|
|
116
124
|
SimpleTargetedMessage targetedMessage = new();
|
|
117
125
|
SimpleBroadcastMessage broadcastMessage = new();
|
|
118
126
|
RunGlobalAcceptAllTest(
|
|
119
|
-
token =>
|
|
127
|
+
token =>
|
|
128
|
+
token.RegisterGlobalAcceptAll(
|
|
129
|
+
HandleUntargeted,
|
|
130
|
+
HandleTargeted,
|
|
131
|
+
HandleBroadcast
|
|
132
|
+
),
|
|
120
133
|
i =>
|
|
121
134
|
{
|
|
122
135
|
Assert.AreEqual(i, untargetedCount);
|
|
123
136
|
untargetedMessage.EmitUntargeted();
|
|
124
137
|
Assert.AreEqual(i + 1, untargetedCount);
|
|
125
|
-
},
|
|
138
|
+
},
|
|
139
|
+
i =>
|
|
126
140
|
{
|
|
127
141
|
Assert.AreEqual(i, targetedCount);
|
|
128
142
|
if (_random.Next() % 2 == 0)
|
|
@@ -135,7 +149,8 @@
|
|
|
135
149
|
}
|
|
136
150
|
|
|
137
151
|
Assert.AreEqual(i + 1, targetedCount);
|
|
138
|
-
},
|
|
152
|
+
},
|
|
153
|
+
i =>
|
|
139
154
|
{
|
|
140
155
|
Assert.AreEqual(i, broadcastCount);
|
|
141
156
|
if (_random.Next() % 2 == 0)
|
|
@@ -148,11 +163,17 @@
|
|
|
148
163
|
}
|
|
149
164
|
|
|
150
165
|
Assert.AreEqual(i + 1, broadcastCount);
|
|
151
|
-
}
|
|
166
|
+
}
|
|
167
|
+
);
|
|
152
168
|
yield break;
|
|
153
169
|
}
|
|
154
170
|
|
|
155
|
-
private void RunGlobalAcceptAllTest(
|
|
171
|
+
private void RunGlobalAcceptAllTest(
|
|
172
|
+
Action<MessageRegistrationToken> register,
|
|
173
|
+
Action<int> untargeted,
|
|
174
|
+
Action<int> targeted,
|
|
175
|
+
Action<int> broadcast
|
|
176
|
+
)
|
|
156
177
|
{
|
|
157
178
|
EmptyMessageAwareComponent component = _test.GetComponent<EmptyMessageAwareComponent>();
|
|
158
179
|
MessageRegistrationToken token = GetToken(component);
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
namespace DxMessaging.Tests.Runtime.Core
|
|
2
2
|
{
|
|
3
|
-
using
|
|
4
|
-
using DxMessaging.Core;
|
|
5
|
-
using NUnit.Framework;
|
|
6
|
-
using System.Collections.Generic;
|
|
7
|
-
using UnityEngine;
|
|
8
|
-
using Unity;
|
|
3
|
+
using System;
|
|
9
4
|
using System.Collections;
|
|
5
|
+
using System.Collections.Generic;
|
|
10
6
|
using System.Diagnostics;
|
|
11
7
|
using System.Linq;
|
|
12
8
|
using System.Reflection;
|
|
13
|
-
using
|
|
9
|
+
using DxMessaging.Core;
|
|
10
|
+
using DxMessaging.Core.MessageBus;
|
|
11
|
+
using NUnit.Framework;
|
|
12
|
+
using Unity;
|
|
13
|
+
using UnityEngine;
|
|
14
14
|
using UnityEngine.TestTools;
|
|
15
15
|
using Debug = UnityEngine.Debug;
|
|
16
16
|
using Object = UnityEngine.Object;
|
|
@@ -69,7 +69,14 @@
|
|
|
69
69
|
return WaitUntilMessageHandlerIsFresh();
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
protected void Run(
|
|
72
|
+
protected void Run(
|
|
73
|
+
Func<IEnumerable<MessageRegistrationHandle>> register,
|
|
74
|
+
Action emit,
|
|
75
|
+
Action assert,
|
|
76
|
+
Action finalAssert,
|
|
77
|
+
MessageRegistrationToken token,
|
|
78
|
+
bool synchronizeDeregistrations = false
|
|
79
|
+
)
|
|
73
80
|
{
|
|
74
81
|
HashSet<MessageRegistrationHandle> handles = new();
|
|
75
82
|
try
|
|
@@ -88,7 +95,11 @@
|
|
|
88
95
|
|
|
89
96
|
if (synchronizeDeregistrations)
|
|
90
97
|
{
|
|
91
|
-
foreach (
|
|
98
|
+
foreach (
|
|
99
|
+
int index in Enumerable
|
|
100
|
+
.Range(0, indexedRegistrations.Count)
|
|
101
|
+
.OrderBy(_ => _random.Next())
|
|
102
|
+
)
|
|
92
103
|
{
|
|
93
104
|
emit();
|
|
94
105
|
assert();
|
|
@@ -101,7 +112,11 @@
|
|
|
101
112
|
}
|
|
102
113
|
else
|
|
103
114
|
{
|
|
104
|
-
foreach (
|
|
115
|
+
foreach (
|
|
116
|
+
MessageRegistrationHandle handle in handles
|
|
117
|
+
.OrderBy(_ => _random.Next())
|
|
118
|
+
.ToList()
|
|
119
|
+
)
|
|
105
120
|
{
|
|
106
121
|
emit();
|
|
107
122
|
assert();
|
|
@@ -128,7 +143,9 @@
|
|
|
128
143
|
{
|
|
129
144
|
// Reach inside and grab the token
|
|
130
145
|
FieldInfo field = typeof(MessageAwareComponent).GetField(
|
|
131
|
-
"_messageRegistrationToken",
|
|
146
|
+
"_messageRegistrationToken",
|
|
147
|
+
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic
|
|
148
|
+
);
|
|
132
149
|
Assert.IsNotNull(field);
|
|
133
150
|
MessageRegistrationToken token = field.GetValue(component) as MessageRegistrationToken;
|
|
134
151
|
Assert.IsNotNull(token);
|
|
@@ -145,8 +162,9 @@
|
|
|
145
162
|
|
|
146
163
|
bool IsStale()
|
|
147
164
|
{
|
|
148
|
-
return messageBus.RegisteredUntargeted != 0
|
|
149
|
-
|
|
165
|
+
return messageBus.RegisteredUntargeted != 0
|
|
166
|
+
|| messageBus.RegisteredTargeted != 0
|
|
167
|
+
|| messageBus.RegisteredBroadcast != 0;
|
|
150
168
|
}
|
|
151
169
|
|
|
152
170
|
while (IsStale() && timer.Elapsed < TimeSpan.FromSeconds(2.5))
|
|
@@ -157,8 +175,11 @@
|
|
|
157
175
|
Assert.IsFalse(
|
|
158
176
|
IsStale(),
|
|
159
177
|
"MessageHandler had {0} Untargeted registrations, {1} Targeted registrations, {2} Broadcast registrations. Registration log: {3}.",
|
|
160
|
-
messageBus.RegisteredUntargeted,
|
|
161
|
-
messageBus.
|
|
178
|
+
messageBus.RegisteredUntargeted,
|
|
179
|
+
messageBus.RegisteredTargeted,
|
|
180
|
+
messageBus.RegisteredBroadcast,
|
|
181
|
+
messageBus.Log
|
|
182
|
+
);
|
|
162
183
|
}
|
|
163
184
|
}
|
|
164
185
|
}
|