com.wallstop-studios.dxmessaging 1.0.2 → 1.0.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/README.md +20 -6
- package/Runtime/Core/MessageBus/MessageBus.cs +3 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,16 +10,19 @@ Game engine agnostic robust, synchronous pub/sub C# messaging solution, mostly g
|
|
|
10
10
|
- Scope(s): `com.wallstop-studios.dxmessaging` *and* `com.wallstop-studios.unity-helpers`
|
|
11
11
|
4. Resolve the latest `DxMessaging`
|
|
12
12
|
|
|
13
|
+
# Dependencies
|
|
14
|
+
This project has a dependency on my [`Unity Helpers`](https://github.com/wallstop/unity-helpers) project, which contains the System.Runtime.CompilerServices.Unsafe.dll, which is used for some speed hacks in DxMessaging directly. Unity Helpers bundles a few (small) dependencies, including protobuf. If you don't want these dependencies, or if they conflict in some way, you can either include a copy of the System.Runtime.CompilerServices.Unsafe.dll yourself without relying on UnityHelpers, or manually download and include the Unity Helpers project and delete anything that conflicts with your project.
|
|
15
|
+
|
|
13
16
|
# Benchmarks
|
|
14
17
|
DxMessaging is currently a bit slower (2-4x) than Unity's built in messaging solution (when running in Unity). [Source](./Tests/Runtime/Core/PerformanceTests.cs).
|
|
15
18
|
| Message Tech | Operations / Second |
|
|
16
19
|
| ------------ | ------------------- |
|
|
17
|
-
| Unity | 1,
|
|
18
|
-
| DxMessaging (GameObject) - Normal |
|
|
19
|
-
| DxMessaging (Component) - Normal |
|
|
20
|
-
| DxMessaging (GameObject) - No-Copy |
|
|
21
|
-
| DxMessaging (Component) - No-Copy |
|
|
22
|
-
| DxMessaging (Untargeted) - No-Copy | 1,
|
|
20
|
+
| Unity | 1,939,366 |
|
|
21
|
+
| DxMessaging (GameObject) - Normal | 645,241 |
|
|
22
|
+
| DxMessaging (Component) - Normal | 649,222 |
|
|
23
|
+
| DxMessaging (GameObject) - No-Copy | 630,259 |
|
|
24
|
+
| DxMessaging (Component) - No-Copy | 663,757 |
|
|
25
|
+
| DxMessaging (Untargeted) - No-Copy | 1,093,308
|
|
23
26
|
|
|
24
27
|
# Functionality
|
|
25
28
|
While not as fast, DxMessaging offers *additional functionality* as compared to Unity's messaging solution.
|
|
@@ -55,6 +58,17 @@ Receivers can subscribe to any number of message types.
|
|
|
55
58
|
|
|
56
59
|
For Unity, we have an easy-to-integrate [MessageAwareComponent](./Runtime/Unity/MessageAwareComponent.cs) - simply extend any component you want off of this base class. This will handle message registration lifetimes automatically for you.
|
|
57
60
|
If you have your own base classes or aren't using Unity, then you'll need to add lifetimes yourself. Please use the MessageAwareComponent as reference.
|
|
61
|
+
|
|
62
|
+
### Implementation Notes (Unity)
|
|
63
|
+
Please note, if you want to receive messages and inherit off of the `MessageAwareComponent`, the component implements several Unity-specific methods to manage lifetimes. Specifically,
|
|
64
|
+
* `protected virtual void Awake()`
|
|
65
|
+
* `protected virtual void OnEnable()`
|
|
66
|
+
* `protected virtual void OnDisable()`
|
|
67
|
+
* `protected virtual void OnDestroy()`
|
|
68
|
+
* `protected virtual void OnApplicationQuit()`
|
|
69
|
+
|
|
70
|
+
If you wish to use any of these methods in components that inherit from `MessageAwareComponent`, please make sure to have the overrides call the base methods, otherwise messaging *may break* or not work as expected.
|
|
71
|
+
|
|
58
72
|
## Integration
|
|
59
73
|
See the [tests](./Tests/Runtime/Scripts/) directory for examples about how to integrate with the MessageAwareComponent. But, for some starters:
|
|
60
74
|
```csharp
|
|
@@ -229,7 +229,6 @@
|
|
|
229
229
|
}
|
|
230
230
|
};
|
|
231
231
|
}
|
|
232
|
-
|
|
233
232
|
|
|
234
233
|
public void UntypedUntargetedBroadcast(IUntargetedMessage typedMessage)
|
|
235
234
|
{
|
|
@@ -250,11 +249,10 @@
|
|
|
250
249
|
Action<IUntargetedMessage> broadcast = (Action<IUntargetedMessage>)untargetedMethod;
|
|
251
250
|
broadcast.Invoke(typedMessage);
|
|
252
251
|
}
|
|
253
|
-
|
|
254
252
|
|
|
255
253
|
public void UntargetedBroadcast<TMessage>(ref TMessage typedMessage) where TMessage : IUntargetedMessage
|
|
256
254
|
{
|
|
257
|
-
Type type =
|
|
255
|
+
Type type = typeof(TMessage);
|
|
258
256
|
if (!RunUntargetedInterceptors(type, ref typedMessage))
|
|
259
257
|
{
|
|
260
258
|
return;
|
|
@@ -310,11 +308,10 @@
|
|
|
310
308
|
Action<InstanceId, ITargetedMessage> broadcast = (Action<InstanceId, ITargetedMessage>)targetedMethod;
|
|
311
309
|
broadcast.Invoke(target, typedMessage);
|
|
312
310
|
}
|
|
313
|
-
|
|
314
311
|
|
|
315
312
|
public void TargetedBroadcast<TMessage>(ref InstanceId target, ref TMessage typedMessage) where TMessage : ITargetedMessage
|
|
316
313
|
{
|
|
317
|
-
Type type =
|
|
314
|
+
Type type = typeof(TMessage);
|
|
318
315
|
if (!RunTargetedInterceptors(type, ref typedMessage, ref target))
|
|
319
316
|
{
|
|
320
317
|
return;
|
|
@@ -411,7 +408,7 @@
|
|
|
411
408
|
|
|
412
409
|
public void SourcedBroadcast<TMessage>(ref InstanceId source, ref TMessage typedMessage) where TMessage : IBroadcastMessage
|
|
413
410
|
{
|
|
414
|
-
Type type =
|
|
411
|
+
Type type = typeof(TMessage);
|
|
415
412
|
if (!RunBroadcastInterceptors(type, ref typedMessage, ref source))
|
|
416
413
|
{
|
|
417
414
|
return;
|