com.wallstop-studios.unity-helpers 2.1.0 → 2.1.2

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.
Files changed (106) hide show
  1. package/AGENTS.md +1 -0
  2. package/Docs/ILIST_SORTING_PERFORMANCE.md +92 -0
  3. package/{package-lock.json.meta → Docs/ILIST_SORTING_PERFORMANCE.md.meta} +1 -1
  4. package/Docs/INDEX.md +11 -1
  5. package/Docs/Images/random_generators.svg +7 -7
  6. package/Docs/RANDOM_PERFORMANCE.md +17 -14
  7. package/Docs/REFLECTION_HELPERS.md +84 -1
  8. package/Docs/REFLECTION_PERFORMANCE.md +169 -0
  9. package/Docs/REFLECTION_PERFORMANCE.md.meta +7 -0
  10. package/Docs/RELATIONAL_COMPONENTS.md +6 -0
  11. package/Docs/RELATIONAL_COMPONENT_PERFORMANCE.md +63 -0
  12. package/Docs/RELATIONAL_COMPONENT_PERFORMANCE.md.meta +7 -0
  13. package/Docs/SPATIAL_TREE_2D_PERFORMANCE.md +64 -64
  14. package/Docs/SPATIAL_TREE_3D_PERFORMANCE.md +64 -64
  15. package/Editor/Core/Helper/AnimationEventHelpers.cs +1 -1
  16. package/Editor/Sprites/AnimationCopier.cs +1 -1
  17. package/Editor/Sprites/AnimationViewerWindow.cs +4 -4
  18. package/Editor/Sprites/SpriteSettingsApplierAPI.cs +2 -1
  19. package/Editor/Sprites/TextureResizerWizard.cs +4 -3
  20. package/Editor/Utils/ScriptableObjectSingletonCreator.cs +3 -3
  21. package/README.md +33 -18
  22. package/Runtime/Core/Attributes/BaseRelationalComponentAttribute.cs +147 -20
  23. package/Runtime/Core/Attributes/ChildComponentAttribute.cs +630 -117
  24. package/Runtime/Core/Attributes/NotNullAttribute.cs +5 -2
  25. package/Runtime/Core/Attributes/ParentComponentAttribute.cs +477 -103
  26. package/Runtime/Core/Attributes/RelationalComponentAssigner.cs +26 -3
  27. package/Runtime/Core/Attributes/RelationalComponentExtensions.cs +19 -3
  28. package/Runtime/Core/Attributes/SiblingComponentAttribute.cs +265 -92
  29. package/Runtime/Core/CodeGen.meta +8 -0
  30. package/Runtime/Core/DataStructure/ImmutableBitSet.cs +5 -20
  31. package/Runtime/Core/Extension/IListExtensions.cs +720 -12
  32. package/Runtime/Core/Helper/Logging/UnityLogTagFormatter.cs +11 -7
  33. package/Runtime/Core/Helper/Objects.cs +1 -1
  34. package/Runtime/Core/Helper/ReflectionHelpers.Factory.cs +5142 -0
  35. package/Runtime/Core/Helper/ReflectionHelpers.Factory.cs.meta +11 -0
  36. package/Runtime/Core/Helper/ReflectionHelpers.cs +1812 -1518
  37. package/Runtime/Core/Helper/UnityMainThreadDispatcher.cs +2 -3
  38. package/Runtime/Core/Math/Line2D.cs +2 -4
  39. package/Runtime/Core/Math/Line3D.cs +2 -4
  40. package/Runtime/Core/Random/AbstractRandom.cs +52 -5
  41. package/Runtime/Core/Random/DotNetRandom.cs +3 -3
  42. package/Runtime/Core/Random/FlurryBurstRandom.cs +279 -0
  43. package/Runtime/Core/Random/FlurryBurstRandom.cs.meta +3 -0
  44. package/Runtime/Core/Random/IllusionFlow.cs +3 -3
  45. package/Runtime/Core/Random/LinearCongruentialGenerator.cs +3 -3
  46. package/Runtime/Core/Random/PcgRandom.cs +6 -6
  47. package/Runtime/Core/Random/PhotonSpinRandom.cs +387 -0
  48. package/Runtime/Core/Random/PhotonSpinRandom.cs.meta +3 -0
  49. package/Runtime/Core/Random/RomuDuo.cs +3 -3
  50. package/Runtime/Core/Random/SplitMix64.cs +3 -3
  51. package/Runtime/Core/Random/SquirrelRandom.cs +6 -4
  52. package/Runtime/Core/Random/StormDropRandom.cs +271 -0
  53. package/Runtime/Core/Random/StormDropRandom.cs.meta +3 -0
  54. package/Runtime/Core/Random/UnityRandom.cs +3 -3
  55. package/Runtime/Core/Random/WyRandom.cs +6 -4
  56. package/Runtime/Core/Random/XorShiftRandom.cs +3 -3
  57. package/Runtime/Core/Random/XoroShiroRandom.cs +3 -3
  58. package/Runtime/Tags/AttributeMetadataCache.cs +316 -9
  59. package/Runtime/Tags/CosmeticEffectData.cs +1 -1
  60. package/Runtime/Visuals/UIToolkit/MultiFileSelectorElement.cs +3 -3
  61. package/Tests/Editor/Helper/HelpersTests.cs +2 -2
  62. package/Tests/Editor/Helper/ReflectionHelpersTypedEditorTests.cs +87 -0
  63. package/Tests/Editor/Helper/ReflectionHelpersTypedEditorTests.cs.meta +11 -0
  64. package/Tests/Editor/Helper/SpriteHelpersTests.cs +1 -1
  65. package/Tests/Editor/PrefabCheckerReportTests.cs +3 -3
  66. package/Tests/Editor/Sprites/AnimationCopierFilterTests.cs +18 -12
  67. package/Tests/Editor/Sprites/AnimationCopierWindowTests.cs +8 -7
  68. package/Tests/Editor/Sprites/AnimationViewerWindowTests.cs +2 -1
  69. package/Tests/Editor/Sprites/ScriptableSpriteAtlasEditorTests.cs +6 -5
  70. package/Tests/Editor/Sprites/SpriteCropperAdditionalTests.cs +2 -1
  71. package/Tests/Editor/Sprites/SpriteCropperTests.cs +7 -6
  72. package/Tests/Editor/Sprites/SpritePivotAdjusterAdditionalTests.cs +2 -1
  73. package/Tests/Editor/Sprites/SpritePivotAdjusterTests.cs +4 -3
  74. package/Tests/Editor/Sprites/TextureResizerWizardTests.cs +10 -9
  75. package/Tests/Editor/Sprites/TextureSettingsApplierAPITests.cs +2 -1
  76. package/Tests/Editor/Tags/AttributeMetadataCacheTests.cs +192 -0
  77. package/Tests/Editor/Tags/AttributeMetadataCacheTests.cs.meta +11 -0
  78. package/Tests/Editor/Tags.meta +8 -0
  79. package/Tests/Runtime/Extensions/IListExtensionTests.cs +187 -1
  80. package/Tests/Runtime/Helper/ObjectsTests.cs +4 -4
  81. package/Tests/Runtime/Helper/ReflectionHelperCapabilityMatrixTests.cs +2923 -0
  82. package/Tests/Runtime/Helper/ReflectionHelperCapabilityMatrixTests.cs.meta +11 -0
  83. package/Tests/Runtime/Helper/ReflectionHelperTests.cs +660 -0
  84. package/Tests/Runtime/Integrations/Reflex/RelationalComponentsReflexTests.cs +2 -2
  85. package/Tests/Runtime/Performance/IListSortingPerformanceTests.cs +346 -0
  86. package/Tests/Runtime/Performance/IListSortingPerformanceTests.cs.meta +11 -0
  87. package/Tests/Runtime/Performance/RandomPerformanceTests.cs +3 -0
  88. package/Tests/Runtime/Performance/ReflectionPerformanceTests.cs +1238 -0
  89. package/Tests/Runtime/Performance/ReflectionPerformanceTests.cs.meta +11 -0
  90. package/Tests/Runtime/Performance/RelationalComponentBenchmarkTests.cs +832 -0
  91. package/Tests/Runtime/Performance/RelationalComponentBenchmarkTests.cs.meta +11 -0
  92. package/Tests/Runtime/Random/FlurryBurstRandomTests.cs +12 -0
  93. package/Tests/Runtime/Random/FlurryBurstRandomTests.cs.meta +3 -0
  94. package/Tests/Runtime/Random/PhotonSpinRandomTests.cs +12 -0
  95. package/Tests/Runtime/Random/PhotonSpinRandomTests.cs.meta +3 -0
  96. package/Tests/Runtime/Random/RandomProtoSerializationTests.cs +14 -0
  97. package/Tests/Runtime/Random/RandomTestBase.cs +39 -4
  98. package/Tests/Runtime/Random/StormDropRandomTests.cs +12 -0
  99. package/Tests/Runtime/Random/StormDropRandomTests.cs.meta +3 -0
  100. package/Tests/Runtime/Serialization/ProtoInterfaceResolutionEdgeTests.cs +2 -2
  101. package/Tests/Runtime/Serialization/ProtoRootRegistrationTests.cs +1 -1
  102. package/Tests/Runtime/Serialization/ProtoSerializeBehaviorTests.cs +1 -1
  103. package/Tests/Runtime/Tags/PeriodicEffectDefinitionSerializationTests.cs +2 -2
  104. package/package.json +1 -1
  105. package/Tests/Runtime/Performance/RelationComponentPerformanceTests.cs +0 -60
  106. package/Tests/Runtime/Performance/RelationComponentPerformanceTests.cs.meta +0 -3
@@ -321,7 +321,7 @@ namespace WallstopStudios.UnityHelpers.Tests.Integrations.Reflex
321
321
  GameObject root = Track(new GameObject("ReflexComponentPrefab"));
322
322
  ReflexRelationalTester tester = root.AddComponent<ReflexRelationalTester>();
323
323
 
324
- GameObject child = new GameObject("ReflexComponentPrefabChild");
324
+ GameObject child = new("ReflexComponentPrefabChild");
325
325
  child.AddComponent<CapsuleCollider>();
326
326
  child.transform.SetParent(root.transform, false);
327
327
 
@@ -334,7 +334,7 @@ namespace WallstopStudios.UnityHelpers.Tests.Integrations.Reflex
334
334
  GameObject root = Track(new GameObject("ReflexGameObjectPrefab"));
335
335
  root.AddComponent<ReflexRelationalTester>();
336
336
 
337
- GameObject child = new GameObject("ReflexGameObjectPrefabChild");
337
+ GameObject child = new("ReflexGameObjectPrefabChild");
338
338
  child.AddComponent<CapsuleCollider>();
339
339
  child.transform.SetParent(root.transform, false);
340
340
 
@@ -0,0 +1,346 @@
1
+ namespace WallstopStudios.UnityHelpers.Tests.Performance
2
+ {
3
+ using System;
4
+ using System.Collections.Generic;
5
+ using System.Diagnostics;
6
+ using System.Globalization;
7
+ using System.Text;
8
+ using NUnit.Framework;
9
+ using UnityEngine;
10
+ using WallstopStudios.UnityHelpers.Core.Extension;
11
+ using WallstopStudios.UnityHelpers.Core.Random;
12
+
13
+ public sealed class IListSortingPerformanceTests
14
+ {
15
+ private const string DocumentPath = "Docs/ILIST_SORTING_PERFORMANCE.md";
16
+ private const string SectionPrefix = "ILIST_SORT_";
17
+ private const int NearlySortedSwapPercentage = 50;
18
+
19
+ private static readonly DatasetSizeSpec[] DatasetSizeSpecs =
20
+ {
21
+ new DatasetSizeSpec("100", 100),
22
+ new DatasetSizeSpec("1,000", 1_000),
23
+ new DatasetSizeSpec("10,000", 10_000),
24
+ new DatasetSizeSpec("100,000", 100_000),
25
+ new DatasetSizeSpec("1,000,000", 1_000_000),
26
+ };
27
+
28
+ private static readonly DatasetState[] DatasetStates =
29
+ {
30
+ new DatasetState("Sorted", BuildSortedData),
31
+ new DatasetState("Nearly Sorted (2% swaps)", BuildNearlySortedData),
32
+ new DatasetState("Shuffled (deterministic)", BuildShuffledData),
33
+ };
34
+
35
+ private static readonly SortImplementation[] SortImplementations =
36
+ {
37
+ new SortImplementation("Ghost", SortAlgorithm.Ghost, false, int.MaxValue),
38
+ new SortImplementation("Meteor", SortAlgorithm.Meteor, false, int.MaxValue),
39
+ new SortImplementation(
40
+ "Pattern-Defeating QuickSort",
41
+ SortAlgorithm.PatternDefeatingQuickSort,
42
+ false,
43
+ int.MaxValue
44
+ ),
45
+ new SortImplementation("Grail", SortAlgorithm.Grail, true, int.MaxValue),
46
+ new SortImplementation("Power", SortAlgorithm.Power, true, int.MaxValue),
47
+ new SortImplementation("Insertion", SortAlgorithm.Insertion, true, 10_000),
48
+ };
49
+
50
+ [Test]
51
+ [Timeout(0)]
52
+ public void Benchmark()
53
+ {
54
+ string operatingSystemToken = GetOperatingSystemToken();
55
+ string sectionName = SectionPrefix + operatingSystemToken;
56
+
57
+ List<string> readmeLines = new List<string>
58
+ {
59
+ string.Format(
60
+ CultureInfo.InvariantCulture,
61
+ "_Last updated {0:yyyy-MM-dd HH:mm} UTC on {1}_",
62
+ DateTime.UtcNow,
63
+ SystemInfo.operatingSystem
64
+ ),
65
+ string.Empty,
66
+ "Times are single-pass measurements in milliseconds (lower is better). `n/a` indicates the algorithm was skipped for the dataset size.",
67
+ string.Empty,
68
+ };
69
+
70
+ IComparer<int> comparer = Comparer<int>.Default;
71
+ string headerLine = BuildHeaderLine();
72
+ string dividerLine = BuildDividerLine();
73
+
74
+ foreach (DatasetState datasetState in DatasetStates)
75
+ {
76
+ UnityEngine.Debug.Log($"IList Sorting Benchmarks - {datasetState.Label}");
77
+ UnityEngine.Debug.Log(headerLine);
78
+ UnityEngine.Debug.Log(dividerLine);
79
+
80
+ readmeLines.Add($"### {datasetState.Label}");
81
+ readmeLines.Add(headerLine);
82
+ readmeLines.Add(dividerLine);
83
+
84
+ foreach (DatasetSizeSpec sizeSpec in DatasetSizeSpecs)
85
+ {
86
+ int[] baseData = datasetState.CreateData(sizeSpec.Count);
87
+ string rowLine = BuildRowLine(sizeSpec.Label, baseData, comparer);
88
+ UnityEngine.Debug.Log(rowLine);
89
+ readmeLines.Add(rowLine);
90
+ }
91
+
92
+ readmeLines.Add(string.Empty);
93
+ UnityEngine.Debug.Log(string.Empty);
94
+ }
95
+
96
+ BenchmarkReadmeUpdater.UpdateSection(sectionName, readmeLines, DocumentPath);
97
+ }
98
+
99
+ private static string BuildHeaderLine()
100
+ {
101
+ StringBuilder headerBuilder = new StringBuilder();
102
+ headerBuilder.Append("| List Size |");
103
+ foreach (SortImplementation implementation in SortImplementations)
104
+ {
105
+ headerBuilder.Append(' ');
106
+ headerBuilder.Append(implementation.Label);
107
+ headerBuilder.Append(" |");
108
+ }
109
+
110
+ return headerBuilder.ToString();
111
+ }
112
+
113
+ private static string BuildDividerLine()
114
+ {
115
+ StringBuilder dividerBuilder = new StringBuilder();
116
+ dividerBuilder.Append("| --- |");
117
+ foreach (SortImplementation implementation in SortImplementations)
118
+ {
119
+ dividerBuilder.Append(" --- |");
120
+ }
121
+
122
+ return dividerBuilder.ToString();
123
+ }
124
+
125
+ private static string BuildRowLine(
126
+ string sizeLabel,
127
+ int[] baseData,
128
+ IComparer<int> comparer
129
+ )
130
+ {
131
+ StringBuilder rowBuilder = new StringBuilder();
132
+ rowBuilder.Append("| ");
133
+ rowBuilder.Append(sizeLabel);
134
+ rowBuilder.Append(" |");
135
+
136
+ foreach (SortImplementation implementation in SortImplementations)
137
+ {
138
+ string result = BenchmarkImplementation(implementation, baseData, comparer);
139
+ rowBuilder.Append(' ');
140
+ rowBuilder.Append(result);
141
+ rowBuilder.Append(" |");
142
+ }
143
+
144
+ return rowBuilder.ToString();
145
+ }
146
+
147
+ private static string BenchmarkImplementation(
148
+ SortImplementation implementation,
149
+ int[] baseData,
150
+ IComparer<int> comparer
151
+ )
152
+ {
153
+ if (baseData.Length > implementation.MaxSupportedCount)
154
+ {
155
+ return "n/a";
156
+ }
157
+
158
+ int[] workingData = new int[baseData.Length];
159
+ Array.Copy(baseData, workingData, baseData.Length);
160
+
161
+ IList<int> workingList = workingData;
162
+ Stopwatch stopwatch = Stopwatch.StartNew();
163
+
164
+ try
165
+ {
166
+ implementation.Execute(workingList, comparer);
167
+ }
168
+ catch (Exception exception)
169
+ {
170
+ UnityEngine.Debug.LogError(
171
+ $"Sorting benchmark failed for {implementation.Label}: {exception.Message}"
172
+ );
173
+ return "error";
174
+ }
175
+ finally
176
+ {
177
+ stopwatch.Stop();
178
+ }
179
+
180
+ double milliseconds = stopwatch.Elapsed.TotalMilliseconds;
181
+ return FormatDuration(milliseconds);
182
+ }
183
+
184
+ private static string FormatDuration(double milliseconds)
185
+ {
186
+ if (milliseconds >= 1000d)
187
+ {
188
+ double seconds = milliseconds / 1000d;
189
+ return string.Format(CultureInfo.InvariantCulture, "{0:0.00} s", seconds);
190
+ }
191
+
192
+ if (milliseconds >= 100d)
193
+ {
194
+ return string.Format(CultureInfo.InvariantCulture, "{0:0} ms", milliseconds);
195
+ }
196
+
197
+ if (milliseconds >= 10d)
198
+ {
199
+ return string.Format(CultureInfo.InvariantCulture, "{0:0.0} ms", milliseconds);
200
+ }
201
+
202
+ if (milliseconds >= 1d)
203
+ {
204
+ return string.Format(CultureInfo.InvariantCulture, "{0:0.00} ms", milliseconds);
205
+ }
206
+
207
+ return string.Format(CultureInfo.InvariantCulture, "{0:0.000} ms", milliseconds);
208
+ }
209
+
210
+ private static int[] BuildSortedData(int count)
211
+ {
212
+ int[] data = new int[count];
213
+ for (int i = 0; i < count; ++i)
214
+ {
215
+ data[i] = i;
216
+ }
217
+
218
+ return data;
219
+ }
220
+
221
+ private static int[] BuildNearlySortedData(int count)
222
+ {
223
+ int[] data = BuildSortedData(count);
224
+ if (count <= 1)
225
+ {
226
+ return data;
227
+ }
228
+
229
+ int swaps = Math.Max(1, count / NearlySortedSwapPercentage);
230
+ IRandom random = new PcgRandom(unchecked(count * 37));
231
+
232
+ for (int i = 0; i < swaps; ++i)
233
+ {
234
+ int index = random.Next(0, count - 1);
235
+ int neighbor = Math.Min(count - 1, index + 1);
236
+ int temp = data[index];
237
+ data[index] = data[neighbor];
238
+ data[neighbor] = temp;
239
+ }
240
+
241
+ return data;
242
+ }
243
+
244
+ private static int[] BuildShuffledData(int count)
245
+ {
246
+ int[] data = BuildSortedData(count);
247
+ if (count <= 1)
248
+ {
249
+ return data;
250
+ }
251
+
252
+ IRandom random = new PcgRandom(unchecked(count * 7919));
253
+
254
+ for (int i = count - 1; i > 0; --i)
255
+ {
256
+ int swapIndex = random.Next(0, i + 1);
257
+ int temp = data[i];
258
+ data[i] = data[swapIndex];
259
+ data[swapIndex] = temp;
260
+ }
261
+
262
+ return data;
263
+ }
264
+
265
+ private static string GetOperatingSystemToken()
266
+ {
267
+ RuntimePlatform platform = Application.platform;
268
+ switch (platform)
269
+ {
270
+ case RuntimePlatform.WindowsEditor:
271
+ case RuntimePlatform.WindowsPlayer:
272
+ case RuntimePlatform.WindowsServer:
273
+ return "WINDOWS";
274
+ case RuntimePlatform.OSXEditor:
275
+ case RuntimePlatform.OSXPlayer:
276
+ return "MACOS";
277
+ case RuntimePlatform.LinuxEditor:
278
+ case RuntimePlatform.LinuxPlayer:
279
+ case RuntimePlatform.LinuxServer:
280
+ return "LINUX";
281
+ default:
282
+ return "OTHER";
283
+ }
284
+ }
285
+
286
+ private readonly struct DatasetSizeSpec
287
+ {
288
+ public DatasetSizeSpec(string label, int count)
289
+ {
290
+ Label = label;
291
+ Count = count;
292
+ }
293
+
294
+ public string Label { get; }
295
+
296
+ public int Count { get; }
297
+ }
298
+
299
+ private readonly struct DatasetState
300
+ {
301
+ private readonly Func<int, int[]> generator;
302
+
303
+ public DatasetState(string label, Func<int, int[]> generator)
304
+ {
305
+ Label = label;
306
+ this.generator = generator;
307
+ }
308
+
309
+ public string Label { get; }
310
+
311
+ public int[] CreateData(int count)
312
+ {
313
+ return generator(count);
314
+ }
315
+ }
316
+
317
+ private readonly struct SortImplementation
318
+ {
319
+ public SortImplementation(
320
+ string label,
321
+ SortAlgorithm algorithm,
322
+ bool isStable,
323
+ int maxSupportedCount
324
+ )
325
+ {
326
+ Label = label;
327
+ Algorithm = algorithm;
328
+ IsStable = isStable;
329
+ MaxSupportedCount = maxSupportedCount;
330
+ }
331
+
332
+ public string Label { get; }
333
+
334
+ public SortAlgorithm Algorithm { get; }
335
+
336
+ public bool IsStable { get; }
337
+
338
+ public int MaxSupportedCount { get; }
339
+
340
+ public void Execute(IList<int> list, IComparer<int> comparer)
341
+ {
342
+ list.Sort(comparer, Algorithm);
343
+ }
344
+ }
345
+ }
346
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: c840f3e2d6f3912498b363680b22a1b2
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -31,12 +31,15 @@ namespace WallstopStudios.UnityHelpers.Tests.Performance
31
31
  LogRow(RunTest(new PcgRandom(), timeout));
32
32
  LogRow(RunTest(new RomuDuo(), timeout));
33
33
  LogRow(RunTest(new SplitMix64(), timeout));
34
+ LogRow(RunTest(new FlurryBurstRandom(), timeout));
34
35
  LogRow(RunTest(new SquirrelRandom(), timeout));
35
36
  LogRow(RunTest(new SystemRandom(), timeout));
36
37
  LogRow(RunTest(new UnityRandom(), timeout));
37
38
  LogRow(RunTest(new WyRandom(), timeout));
38
39
  LogRow(RunTest(new XorShiftRandom(), timeout));
39
40
  LogRow(RunTest(new XoroShiroRandom(), timeout));
41
+ LogRow(RunTest(new PhotonSpinRandom(), timeout));
42
+ LogRow(RunTest(new StormDropRandom(), timeout));
40
43
 
41
44
  BenchmarkReadmeUpdater.UpdateSection(
42
45
  "RANDOM_BENCHMARKS",