com.wallstop-studios.unity-helpers 2.0.0-rc03 → 2.0.0-rc05
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.meta +7 -7
- package/Editor/AnimationEventEditor.cs.meta +11 -11
- package/Editor.meta +8 -8
- package/LICENSE.md.meta +7 -7
- package/README.md.meta +7 -7
- package/Runtime/Core/Attributes/AnimationEventAttribute.cs.meta +11 -11
- package/Runtime/Core/Attributes/ChildComponentAttribute.cs.meta +11 -11
- package/Runtime/Core/Attributes/KSerializableAttribute.cs.meta +11 -11
- package/Runtime/Core/Attributes/NotNullAttribute.cs.meta +11 -11
- package/Runtime/Core/Attributes/ParentComponent.cs.meta +11 -11
- package/Runtime/Core/Attributes/ReadOnlyAttribute.cs.meta +11 -11
- package/Runtime/Core/Attributes/RelationalComponentExtensions.cs.meta +11 -11
- package/Runtime/Core/DataStructure/Adapters/FastVector2Int.cs.meta +11 -11
- package/Runtime/Core/DataStructure/Adapters/FastVector3Int.cs.meta +11 -11
- package/Runtime/Core/DataStructure/Adapters/KGuid.cs +31 -17
- package/Runtime/Core/DataStructure/Adapters/KGuid.cs.meta +11 -11
- package/Runtime/Core/DataStructure/Adapters/KVector2.cs.meta +11 -11
- package/Runtime/Core/DataStructure/Adapters.meta +8 -8
- package/Runtime/Core/DataStructure/Circle.cs.meta +11 -11
- package/Runtime/Core/DataStructure/CyclicBuffer.cs.meta +11 -11
- package/Runtime/Core/DataStructure/QuadTree.cs.meta +11 -11
- package/Runtime/Core/DataStructure/StringWrapper.cs.meta +11 -11
- package/Runtime/Core/DataStructure/TimedCache.cs.meta +11 -11
- package/Runtime/Core/DataStructure.meta +8 -8
- package/Runtime/Core/Extension/AnimatorExtensions.cs.meta +11 -11
- package/Runtime/Core/Extension/CircleExtensions.cs.meta +11 -11
- package/Runtime/Core/Extension/ColorExtensions.cs.meta +11 -11
- package/Runtime/Core/Extension/DictionaryExtensions.cs.meta +11 -11
- package/Runtime/Core/Extension/DirectionExtensions.cs.meta +11 -11
- package/Runtime/Core/Extension/HashSetExtensions.cs.meta +11 -11
- package/Runtime/Core/Extension/IEnumerableExtensions.cs.meta +11 -11
- package/Runtime/Core/Extension/IListExtensions.cs.meta +11 -11
- package/Runtime/Core/Extension/LoggingExtensions.cs.meta +11 -11
- package/Runtime/Core/Extension/RandomExtensions.cs.meta +11 -11
- package/Runtime/Core/Extension/StringExtensions.cs.meta +11 -11
- package/Runtime/Core/Extension/UnityExtensions.cs.meta +11 -11
- package/Runtime/Core/Extension.meta +8 -8
- package/Runtime/Core/Helper/Enumerables.cs.meta +11 -11
- package/Runtime/Core/Helper/Geometry.cs.meta +11 -11
- package/Runtime/Core/Helper/LifetimeHelpers.cs.meta +11 -11
- package/Runtime/Core/Helper/Objects.cs.meta +11 -11
- package/Runtime/Core/Helper/WallMath.cs.meta +11 -11
- package/Runtime/Core/Helper.meta +8 -8
- package/Runtime/Core/Math/Line.cs.meta +11 -11
- package/Runtime/Core/Math/Parabola.cs.meta +11 -11
- package/Runtime/Core/Math/Range.cs +6 -0
- package/Runtime/Core/Math/Range.cs.meta +11 -11
- package/Runtime/Core/Math.meta +8 -8
- package/Runtime/Core/Model/Direction.cs.meta +11 -11
- package/Runtime/Core/Model.meta +8 -8
- package/Runtime/Core/OneOf/FastOneOf.cs.meta +11 -11
- package/Runtime/Core/OneOf/None.cs.meta +11 -11
- package/Runtime/Core/OneOf.meta +8 -8
- package/Runtime/Core/Random/AbstractRandom.cs.meta +11 -11
- package/Runtime/Core/Random/DotNetRandom.cs +54 -0
- package/Runtime/Core/Random/DotNetRandom.cs.meta +3 -0
- package/Runtime/Core/Random/IRandom.cs.meta +11 -11
- package/Runtime/Core/Random/NativePcgRandom.cs.meta +11 -11
- package/Runtime/Core/Random/PcgRandom.cs +29 -20
- package/Runtime/Core/Random/PcgRandom.cs.meta +11 -11
- package/Runtime/Core/Random/RandomState.cs +13 -2
- package/Runtime/Core/Random/RandomState.cs.meta +11 -11
- package/Runtime/Core/Random/SquirrelRandom.cs +12 -7
- package/Runtime/Core/Random/SquirrelRandom.cs.meta +11 -11
- package/Runtime/Core/Random/SystemRandom.cs +15 -9
- package/Runtime/Core/Random/SystemRandom.cs.meta +11 -11
- package/Runtime/Core/Random/ThreadLocalRandom.cs.meta +11 -11
- package/Runtime/Core/Random/UnityRandom.cs +39 -4
- package/Runtime/Core/Random/WyRandom.cs +123 -0
- package/Runtime/Core/Random/WyRandom.cs.meta +3 -0
- package/Runtime/Core/Random/XorShiftRandom.cs +8 -4
- package/Runtime/Core/Random.meta +8 -8
- package/Runtime/Core/Serialization/JsonConverters/Vector2Converter.cs.meta +11 -11
- package/Runtime/Core/Serialization/JsonConverters/Vector3Converter.cs.meta +11 -11
- package/Runtime/Core/Serialization/JsonConverters.meta +8 -8
- package/Runtime/Core/Serialization/Serializer.cs.meta +11 -11
- package/Runtime/Core/Serialization.meta +8 -8
- package/Runtime/Core/Threading/SingleThreadedThreadPool.cs.meta +11 -11
- package/Runtime/Core/Threading.meta +8 -8
- package/Runtime/Core.meta +8 -8
- package/Runtime/Protobuf-Net.meta +8 -8
- package/Runtime/Utils/AnimationEventEqualityComparer.cs.meta +11 -11
- package/Runtime/Utils/AnimatorEnumStateMachine.cs +13 -4
- package/Runtime/Utils/AnimatorEnumStateMachine.cs.meta +11 -11
- package/Runtime/Utils/Buffers.cs.meta +11 -11
- package/Runtime/Utils/CircleLineRenderer.cs.meta +11 -11
- package/Runtime/Utils/Oscillator.cs.meta +11 -11
- package/Runtime/Utils/SetTextureImportData.cs.meta +11 -11
- package/Runtime/Utils.meta +8 -8
- package/Runtime/WallstopStudios.UnityHelpers.asmdef.meta +7 -7
- package/Runtime.meta +8 -8
- package/Tests/Runtime/Performance/RandomPerformanceTests.cs +18 -13
- package/Tests/Runtime/Random/DotNetRandomTests.cs +9 -0
- package/Tests/Runtime/Random/DotNetRandomTests.cs.meta +3 -0
- package/Tests/Runtime/Random/RandomTestBase.cs +69 -15
- package/Tests/Runtime/Random/WyRandomTests.cs +9 -0
- package/Tests/Runtime/Random/WyRandomTests.cs.meta +3 -0
- package/Tests.meta +8 -8
- package/Third Party Notices.md.meta +7 -7
- package/package.json +1 -1
- package/package.json.meta +7 -7
|
@@ -10,28 +10,34 @@
|
|
|
10
10
|
[Test]
|
|
11
11
|
public void Benchmark()
|
|
12
12
|
{
|
|
13
|
-
TimeSpan timeout = TimeSpan.FromSeconds(1);
|
|
13
|
+
TimeSpan timeout = TimeSpan.FromSeconds(1.125);
|
|
14
14
|
|
|
15
15
|
UnityEngine.Debug.Log($"| Random | Next | NextFloat | NextDouble |");
|
|
16
16
|
UnityEngine.Debug.Log($"| ------ | ---- | --------- | ---------- |");
|
|
17
|
-
|
|
17
|
+
|
|
18
18
|
RunTest(new PcgRandom(), timeout);
|
|
19
19
|
RunTest(new SystemRandom(), timeout);
|
|
20
20
|
RunTest(new SquirrelRandom(), timeout);
|
|
21
21
|
RunTest(new XorShiftRandom(), timeout);
|
|
22
|
+
RunTest(new DotNetRandom(), timeout);
|
|
23
|
+
RunTest(new WyRandom(), timeout);
|
|
22
24
|
}
|
|
23
25
|
|
|
24
|
-
private void RunTest<T>(T random, TimeSpan timeout)
|
|
26
|
+
private static void RunTest<T>(T random, TimeSpan timeout)
|
|
27
|
+
where T : IRandom
|
|
25
28
|
{
|
|
26
29
|
int nextInt = RunNext(timeout, random);
|
|
27
30
|
int nextFloat = RunNextFloat(timeout, random);
|
|
28
31
|
int nextDouble = RunNextDouble(timeout, random);
|
|
29
32
|
|
|
30
|
-
UnityEngine.Debug.Log(
|
|
33
|
+
UnityEngine.Debug.Log(
|
|
34
|
+
$"| {random.GetType().Name} | {(nextInt / timeout.TotalSeconds):N0} | {(nextFloat / timeout.TotalSeconds):N0} | {(nextDouble / timeout.TotalSeconds):N0} |"
|
|
35
|
+
);
|
|
31
36
|
}
|
|
32
37
|
|
|
33
38
|
// Copy-pasta'd for maximum speed
|
|
34
|
-
private int RunNext<T>(TimeSpan timeout, T random)
|
|
39
|
+
private static int RunNext<T>(TimeSpan timeout, T random)
|
|
40
|
+
where T : IRandom
|
|
35
41
|
{
|
|
36
42
|
int count = 0;
|
|
37
43
|
Stopwatch timer = Stopwatch.StartNew();
|
|
@@ -39,13 +45,13 @@
|
|
|
39
45
|
{
|
|
40
46
|
_ = random.Next();
|
|
41
47
|
++count;
|
|
42
|
-
}
|
|
43
|
-
while (timer.Elapsed < timeout);
|
|
48
|
+
} while (timer.Elapsed < timeout);
|
|
44
49
|
|
|
45
50
|
return count;
|
|
46
51
|
}
|
|
47
52
|
|
|
48
|
-
private int RunNextFloat<T>(TimeSpan timeout, T random)
|
|
53
|
+
private static int RunNextFloat<T>(TimeSpan timeout, T random)
|
|
54
|
+
where T : IRandom
|
|
49
55
|
{
|
|
50
56
|
int count = 0;
|
|
51
57
|
Stopwatch timer = Stopwatch.StartNew();
|
|
@@ -53,13 +59,13 @@
|
|
|
53
59
|
{
|
|
54
60
|
_ = random.NextFloat();
|
|
55
61
|
++count;
|
|
56
|
-
}
|
|
57
|
-
while (timer.Elapsed < timeout);
|
|
62
|
+
} while (timer.Elapsed < timeout);
|
|
58
63
|
|
|
59
64
|
return count;
|
|
60
65
|
}
|
|
61
66
|
|
|
62
|
-
private int RunNextDouble<T>(TimeSpan timeout, T random)
|
|
67
|
+
private static int RunNextDouble<T>(TimeSpan timeout, T random)
|
|
68
|
+
where T : IRandom
|
|
63
69
|
{
|
|
64
70
|
int count = 0;
|
|
65
71
|
Stopwatch timer = Stopwatch.StartNew();
|
|
@@ -67,8 +73,7 @@
|
|
|
67
73
|
{
|
|
68
74
|
_ = random.NextDouble();
|
|
69
75
|
++count;
|
|
70
|
-
}
|
|
71
|
-
while (timer.Elapsed < timeout);
|
|
76
|
+
} while (timer.Elapsed < timeout);
|
|
72
77
|
|
|
73
78
|
return count;
|
|
74
79
|
}
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
|
|
9
9
|
public abstract class RandomTestBase
|
|
10
10
|
{
|
|
11
|
-
|
|
11
|
+
private const int SampleCount = 12_500_000;
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
private readonly int[] _samples = new int[1_000];
|
|
14
14
|
|
|
15
15
|
protected abstract IRandom NewRandom();
|
|
16
16
|
|
|
@@ -48,22 +48,37 @@
|
|
|
48
48
|
public void Byte()
|
|
49
49
|
{
|
|
50
50
|
TestAndVerify(
|
|
51
|
-
random =>
|
|
52
|
-
|
|
51
|
+
random =>
|
|
52
|
+
random.NextByte(
|
|
53
|
+
0,
|
|
54
|
+
(byte)(_samples.Length < byte.MaxValue ? _samples.Length : byte.MaxValue)
|
|
55
|
+
),
|
|
56
|
+
byte.MaxValue
|
|
57
|
+
);
|
|
53
58
|
}
|
|
54
59
|
|
|
55
60
|
[Test]
|
|
56
61
|
public void Float()
|
|
57
62
|
{
|
|
58
|
-
TestAndVerify(
|
|
59
|
-
|
|
63
|
+
TestAndVerify(random =>
|
|
64
|
+
Math.Clamp(
|
|
65
|
+
(int)Math.Floor(random.NextFloat(0, _samples.Length)),
|
|
66
|
+
0,
|
|
67
|
+
_samples.Length - 1
|
|
68
|
+
)
|
|
69
|
+
);
|
|
60
70
|
}
|
|
61
71
|
|
|
62
72
|
[Test]
|
|
63
73
|
public void Double()
|
|
64
74
|
{
|
|
65
|
-
TestAndVerify(
|
|
66
|
-
|
|
75
|
+
TestAndVerify(random =>
|
|
76
|
+
Math.Clamp(
|
|
77
|
+
(int)Math.Floor(random.NextDouble(0, _samples.Length)),
|
|
78
|
+
0,
|
|
79
|
+
_samples.Length - 1
|
|
80
|
+
)
|
|
81
|
+
);
|
|
67
82
|
}
|
|
68
83
|
|
|
69
84
|
[Test]
|
|
@@ -78,7 +93,37 @@
|
|
|
78
93
|
TestAndVerify(random => (int)random.NextUlong(0, (ulong)_samples.Length));
|
|
79
94
|
}
|
|
80
95
|
|
|
81
|
-
|
|
96
|
+
[Test]
|
|
97
|
+
public void Copy()
|
|
98
|
+
{
|
|
99
|
+
const int numGeneratorChecks = 1_000;
|
|
100
|
+
IRandom random1 = NewRandom();
|
|
101
|
+
IRandom random2 = random1.Copy();
|
|
102
|
+
Assert.AreEqual(random1.InternalState, random2.InternalState);
|
|
103
|
+
// UnityRandom has shared state, the below test is not possible for it. We did all we could.
|
|
104
|
+
if (NewRandom() is not UnityRandom)
|
|
105
|
+
{
|
|
106
|
+
for (int i = 0; i < numGeneratorChecks; ++i)
|
|
107
|
+
{
|
|
108
|
+
Assert.AreEqual(random1.Next(), random2.Next());
|
|
109
|
+
Assert.AreEqual(random1.InternalState, random2.InternalState);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
Assert.AreEqual(random1.InternalState, random2.InternalState);
|
|
114
|
+
IRandom random3 = random1.Copy();
|
|
115
|
+
Assert.AreEqual(random1.InternalState, random3.InternalState);
|
|
116
|
+
if (NewRandom() is not UnityRandom)
|
|
117
|
+
{
|
|
118
|
+
for (int i = 0; i < numGeneratorChecks; ++i)
|
|
119
|
+
{
|
|
120
|
+
Assert.AreEqual(random1.Next(), random3.Next());
|
|
121
|
+
Assert.AreEqual(random1.InternalState, random3.InternalState);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
private void TestAndVerify(Func<IRandom, int> sample, int? maxLength = null)
|
|
82
127
|
{
|
|
83
128
|
IRandom random = NewRandom();
|
|
84
129
|
for (int i = 0; i < SampleCount; ++i)
|
|
@@ -114,12 +159,21 @@
|
|
|
114
159
|
}
|
|
115
160
|
|
|
116
161
|
Assert.AreEqual(
|
|
117
|
-
0,
|
|
118
|
-
|
|
162
|
+
0,
|
|
163
|
+
zeroCountIndexes.Count,
|
|
164
|
+
"No samples at {0} indices: [{1}]",
|
|
165
|
+
zeroCountIndexes.Count,
|
|
166
|
+
string.Join(",", zeroCountIndexes)
|
|
167
|
+
);
|
|
119
168
|
Assert.AreEqual(
|
|
120
|
-
0,
|
|
121
|
-
outsideRange.Count,
|
|
122
|
-
|
|
169
|
+
0,
|
|
170
|
+
outsideRange.Count,
|
|
171
|
+
"{0} indexes outside of dev {1:0.00}. Expected: {2:0.00}. Found: [{3}]",
|
|
172
|
+
outsideRange.Count,
|
|
173
|
+
deviationAllowed,
|
|
174
|
+
average,
|
|
175
|
+
string.Join(",", outsideRange.Select(index => _samples[index]))
|
|
176
|
+
);
|
|
123
177
|
}
|
|
124
178
|
}
|
|
125
|
-
}
|
|
179
|
+
}
|
package/Tests.meta
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
fileFormatVersion: 2
|
|
2
|
-
guid: 95113a6d0bd1caa45a97f7f4db1e7c0a
|
|
3
|
-
folderAsset: yes
|
|
4
|
-
DefaultImporter:
|
|
5
|
-
externalObjects: {}
|
|
6
|
-
userData:
|
|
7
|
-
assetBundleName:
|
|
8
|
-
assetBundleVariant:
|
|
1
|
+
fileFormatVersion: 2
|
|
2
|
+
guid: 95113a6d0bd1caa45a97f7f4db1e7c0a
|
|
3
|
+
folderAsset: yes
|
|
4
|
+
DefaultImporter:
|
|
5
|
+
externalObjects: {}
|
|
6
|
+
userData:
|
|
7
|
+
assetBundleName:
|
|
8
|
+
assetBundleVariant:
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
fileFormatVersion: 2
|
|
2
|
-
guid: 4908409161853e24bbbd3b2522b0fcc2
|
|
3
|
-
TextScriptImporter:
|
|
4
|
-
externalObjects: {}
|
|
5
|
-
userData:
|
|
6
|
-
assetBundleName:
|
|
7
|
-
assetBundleVariant:
|
|
1
|
+
fileFormatVersion: 2
|
|
2
|
+
guid: 4908409161853e24bbbd3b2522b0fcc2
|
|
3
|
+
TextScriptImporter:
|
|
4
|
+
externalObjects: {}
|
|
5
|
+
userData:
|
|
6
|
+
assetBundleName:
|
|
7
|
+
assetBundleVariant:
|
package/package.json
CHANGED
package/package.json.meta
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
fileFormatVersion: 2
|
|
2
|
-
guid: 37c8a4d958841ed4b9cf38ef3b01ea92
|
|
3
|
-
PackageManifestImporter:
|
|
4
|
-
externalObjects: {}
|
|
5
|
-
userData:
|
|
6
|
-
assetBundleName:
|
|
7
|
-
assetBundleVariant:
|
|
1
|
+
fileFormatVersion: 2
|
|
2
|
+
guid: 37c8a4d958841ed4b9cf38ef3b01ea92
|
|
3
|
+
PackageManifestImporter:
|
|
4
|
+
externalObjects: {}
|
|
5
|
+
userData:
|
|
6
|
+
assetBundleName:
|
|
7
|
+
assetBundleVariant:
|