com.elestrago.unity.entitas-redux 3.3.0 → 3.3.1
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
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
using System;
|
|
2
|
+
using System.Reflection;
|
|
2
3
|
using System.Threading;
|
|
3
4
|
|
|
4
5
|
namespace JCMG.EntitasRedux.Commands
|
|
@@ -10,10 +11,21 @@ namespace JCMG.EntitasRedux.Commands
|
|
|
10
11
|
{
|
|
11
12
|
private static int _indexCounter;
|
|
12
13
|
|
|
13
|
-
internal static class
|
|
14
|
+
internal static class Info<TCommand> where TCommand : struct
|
|
14
15
|
{
|
|
15
16
|
// This value is calculated once per TCommand and cached.
|
|
16
|
-
public static readonly int
|
|
17
|
+
public static readonly int Index = Interlocked.Increment(ref _indexCounter) - 1;
|
|
18
|
+
public static readonly bool Optional;
|
|
19
|
+
|
|
20
|
+
static Info()
|
|
21
|
+
{
|
|
22
|
+
var type = typeof(TCommand);
|
|
23
|
+
var attribute = type.GetCustomAttribute<CommandAttribute>();
|
|
24
|
+
if (attribute == null)
|
|
25
|
+
return;
|
|
26
|
+
|
|
27
|
+
Optional = attribute.Optional;
|
|
28
|
+
}
|
|
17
29
|
}
|
|
18
30
|
}
|
|
19
31
|
|
|
@@ -26,7 +38,7 @@ namespace JCMG.EntitasRedux.Commands
|
|
|
26
38
|
/// </summary>
|
|
27
39
|
public void Register<TCommand>() where TCommand : struct
|
|
28
40
|
{
|
|
29
|
-
var index = CommandType.
|
|
41
|
+
var index = CommandType.Info<TCommand>.Index;
|
|
30
42
|
|
|
31
43
|
// Ensure the array is large enough, resizing if necessary.
|
|
32
44
|
if (index >= _pools.Length)
|
|
@@ -46,10 +58,13 @@ namespace JCMG.EntitasRedux.Commands
|
|
|
46
58
|
if (pool != null)
|
|
47
59
|
return ref pool.Create();
|
|
48
60
|
|
|
61
|
+
if (!CommandType.Info<TCommand>.Optional)
|
|
62
|
+
{
|
|
49
63
|
#if DEBUG
|
|
50
|
-
|
|
51
|
-
|
|
64
|
+
throw new Exception($"[CommandBuffer] Command type '{typeof(TCommand).Name}' is not registered. " +
|
|
65
|
+
$"Call Register<{typeof(TCommand).Name}>() first. Command will be ignored.");
|
|
52
66
|
#endif
|
|
67
|
+
}
|
|
53
68
|
|
|
54
69
|
// Return a reference to a dummy variable to satisfy the ref return.
|
|
55
70
|
return ref Dummy<TCommand>.Value;
|
|
@@ -64,6 +79,9 @@ namespace JCMG.EntitasRedux.Commands
|
|
|
64
79
|
return;
|
|
65
80
|
}
|
|
66
81
|
|
|
82
|
+
if (CommandType.Info<TCommand>.Optional)
|
|
83
|
+
return;
|
|
84
|
+
|
|
67
85
|
#if DEBUG
|
|
68
86
|
throw new Exception($"[CommandBuffer] Command type '{typeof(TCommand).Name}' is not registered. " +
|
|
69
87
|
$"Call Register<{typeof(TCommand).Name}>() first. Command will be ignored.");
|
|
@@ -78,7 +96,7 @@ namespace JCMG.EntitasRedux.Commands
|
|
|
78
96
|
|
|
79
97
|
private CommandPool<TCommand> GetPool<TCommand>() where TCommand : struct
|
|
80
98
|
{
|
|
81
|
-
var index = CommandType.
|
|
99
|
+
var index = CommandType.Info<TCommand>.Index;
|
|
82
100
|
|
|
83
101
|
// Use .Length for array boundary check.
|
|
84
102
|
if (index >= _pools.Length)
|
|
@@ -89,7 +107,7 @@ namespace JCMG.EntitasRedux.Commands
|
|
|
89
107
|
|
|
90
108
|
public void Clear<TCommand>() where TCommand : struct
|
|
91
109
|
{
|
|
92
|
-
var index = CommandType.
|
|
110
|
+
var index = CommandType.Info<TCommand>.Index;
|
|
93
111
|
|
|
94
112
|
// Use .Length for array boundary check.
|
|
95
113
|
if (index < _pools.Length)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "com.elestrago.unity.entitas-redux",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.1",
|
|
4
4
|
"displayName": "JCMG Entitas Redux",
|
|
5
5
|
"description": "Entitas Redux is an fast, accessible, and feature-rich ECS framework for Unity. It leverages code generation and an extensible plugin framework to make life easier for developers.",
|
|
6
6
|
"category": "Unity",
|