com.wallstop-studios.unity-helpers 2.0.0-rc80.9 → 2.0.0-rc81
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/Runtime/Utils/Buffers.cs
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
using System.Runtime.CompilerServices;
|
|
2
|
+
|
|
3
|
+
[assembly: InternalsVisibleTo("WallstopStudios.UnityHelpers.Tests.Runtime")]
|
|
4
|
+
|
|
1
5
|
namespace WallstopStudios.UnityHelpers.Utils
|
|
2
6
|
{
|
|
3
7
|
using System;
|
|
@@ -85,6 +89,7 @@ namespace WallstopStudios.UnityHelpers.Utils
|
|
|
85
89
|
|
|
86
90
|
public WallstopGenericPool(
|
|
87
91
|
Func<T> producer,
|
|
92
|
+
int preWarmCount = 0,
|
|
88
93
|
Action<T> onGet = null,
|
|
89
94
|
Action<T> onRelease = null,
|
|
90
95
|
Action<T> onDisposal = null
|
|
@@ -95,6 +100,12 @@ namespace WallstopStudios.UnityHelpers.Utils
|
|
|
95
100
|
_onRelease = onRelease ?? (_ => { });
|
|
96
101
|
_onRelease += _pool.Push;
|
|
97
102
|
_onDispose = onDisposal;
|
|
103
|
+
for (int i = 0; i < preWarmCount; ++i)
|
|
104
|
+
{
|
|
105
|
+
T value = _producer();
|
|
106
|
+
_onGet?.Invoke(value);
|
|
107
|
+
_onRelease(value);
|
|
108
|
+
}
|
|
98
109
|
}
|
|
99
110
|
|
|
100
111
|
public PooledResource<T> Get()
|
|
@@ -125,6 +136,8 @@ namespace WallstopStudios.UnityHelpers.Utils
|
|
|
125
136
|
#else
|
|
126
137
|
public sealed class WallstopGenericPool<T> : IDisposable
|
|
127
138
|
{
|
|
139
|
+
internal int Count => _pool.Count;
|
|
140
|
+
|
|
128
141
|
private readonly Func<T> _producer;
|
|
129
142
|
private readonly Action<T> _onGet;
|
|
130
143
|
private readonly Action<T> _onRelease;
|
|
@@ -134,6 +147,7 @@ namespace WallstopStudios.UnityHelpers.Utils
|
|
|
134
147
|
|
|
135
148
|
public WallstopGenericPool(
|
|
136
149
|
Func<T> producer,
|
|
150
|
+
int preWarmCount = 0,
|
|
137
151
|
Action<T> onGet = null,
|
|
138
152
|
Action<T> onRelease = null,
|
|
139
153
|
Action<T> onDisposal = null
|
|
@@ -144,6 +158,12 @@ namespace WallstopStudios.UnityHelpers.Utils
|
|
|
144
158
|
_onRelease = onRelease ?? (_ => { });
|
|
145
159
|
_onRelease += _pool.Push;
|
|
146
160
|
_onDispose = onDisposal;
|
|
161
|
+
for (int i = 0; i < preWarmCount; ++i)
|
|
162
|
+
{
|
|
163
|
+
T value = _producer();
|
|
164
|
+
_onGet?.Invoke(value);
|
|
165
|
+
_onRelease(value);
|
|
166
|
+
}
|
|
147
167
|
}
|
|
148
168
|
|
|
149
169
|
public PooledResource<T> Get()
|
|
@@ -836,7 +836,7 @@ namespace WallstopStudios.UnityHelpers.Tests.Helper
|
|
|
836
836
|
[Test]
|
|
837
837
|
public void InvokeStaticMethodWithParameters()
|
|
838
838
|
{
|
|
839
|
-
|
|
839
|
+
int directResult = TestMethodClass.StaticMethodWithParam(10);
|
|
840
840
|
Assert.AreEqual(20, directResult);
|
|
841
841
|
|
|
842
842
|
TestMethodClass testObj = new();
|
|
@@ -852,11 +852,11 @@ namespace WallstopStudios.UnityHelpers.Tests.Helper
|
|
|
852
852
|
nameof(TestMethodClass.StaticMethodMultipleParams)
|
|
853
853
|
);
|
|
854
854
|
|
|
855
|
-
|
|
855
|
+
object result1 = ReflectionHelpers.InvokeStaticMethod(paramMethod, 10);
|
|
856
856
|
Assert.AreEqual(20, result1);
|
|
857
857
|
ReflectionHelpers.InvokeStaticMethod(voidParamMethod, 99);
|
|
858
858
|
Assert.AreEqual(99, TestMethodClass.StaticMethodCallCount);
|
|
859
|
-
|
|
859
|
+
object result3 = ReflectionHelpers.InvokeStaticMethod(multiParamMethod, 5, "abc", true);
|
|
860
860
|
Assert.AreEqual(9, result3);
|
|
861
861
|
}
|
|
862
862
|
|
|
@@ -21,6 +21,22 @@ namespace WallstopStudios.UnityHelpers.Tests.Utils
|
|
|
21
21
|
onRelease: list => list.Clear()
|
|
22
22
|
);
|
|
23
23
|
|
|
24
|
+
[Test]
|
|
25
|
+
public void PreWarmCount()
|
|
26
|
+
{
|
|
27
|
+
int retrieved = 0;
|
|
28
|
+
int released = 0;
|
|
29
|
+
using WallstopGenericPool<int> pool = new(
|
|
30
|
+
() => 0,
|
|
31
|
+
preWarmCount: 10,
|
|
32
|
+
onGet: _ => ++retrieved,
|
|
33
|
+
onRelease: _ => ++released
|
|
34
|
+
);
|
|
35
|
+
Assert.AreEqual(10, retrieved);
|
|
36
|
+
Assert.AreEqual(10, released);
|
|
37
|
+
Assert.AreEqual(10, pool.Count);
|
|
38
|
+
}
|
|
39
|
+
|
|
24
40
|
[Test]
|
|
25
41
|
public void GenericPoolListTests()
|
|
26
42
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "com.wallstop-studios.unity-helpers",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-rc81",
|
|
4
4
|
"displayName": "Unity Helpers",
|
|
5
5
|
"description": "Various Unity Helper Library",
|
|
6
6
|
"dependencies": {},
|
|
@@ -36,3 +36,4 @@
|
|
|
36
36
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
+
|