com.elestrago.unity.entitas-redux 3.7.3 → 3.7.5

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
@@ -2,6 +2,22 @@
2
2
 
3
3
  ---
4
4
 
5
+ ## [3.7.5](https://gitlab.com/elestrago-pkg/entitas-redux/-/tags/3.7.5)
6
+
7
+ ### Added
8
+
9
+ - `IInitializeAsyncSystem`
10
+
11
+ ---
12
+
13
+ ## [3.7.4](https://gitlab.com/elestrago-pkg/entitas-redux/-/tags/3.7.4)
14
+
15
+ ### Fixed
16
+
17
+ - `ContextObserver` do not add already created entities to observe
18
+
19
+ ---
20
+
5
21
  ## [3.7.3](https://gitlab.com/elestrago-pkg/entitas-redux/-/tags/3.7.3)
6
22
 
7
23
  ### Changed
@@ -341,6 +341,8 @@ namespace JCMG.EntitasRedux
341
341
  return entity;
342
342
  }
343
343
 
344
+ IEntity[] IContext.GetEntities() => GetEntities();
345
+
344
346
  /// <summary>
345
347
  /// Destroys all entities in the context.
346
348
  /// Throws an exception if there are still retained entities.
@@ -46,6 +46,8 @@ namespace JCMG.EntitasRedux
46
46
 
47
47
  event ContextGroupChanged OnGroupCreated;
48
48
 
49
+ IEntity[] GetEntities();
50
+
49
51
  void DestroyAllEntities();
50
52
 
51
53
  void AddEntityIndex(IEntityIndex entityIndex);
@@ -67,7 +69,7 @@ namespace JCMG.EntitasRedux
67
69
 
68
70
  bool HasEntity(TEntity entity);
69
71
 
70
- TEntity[] GetEntities();
72
+ new TEntity[] GetEntities();
71
73
 
72
74
  ArrayDisposable<TEntity> GetEntities(out Span<TEntity> entities);
73
75
 
@@ -0,0 +1,10 @@
1
+ using System.Threading;
2
+ using System.Threading.Tasks;
3
+
4
+ namespace JCMG.EntitasRedux
5
+ {
6
+ public interface IInitializeAsyncSystem : ISystem
7
+ {
8
+ Task InitializeAsync(CancellationToken ct = default);
9
+ }
10
+ }
@@ -0,0 +1,3 @@
1
+ fileFormatVersion: 2
2
+ guid: 317b63b5a6dc4edfa94787ffaacb1298
3
+ timeCreated: 1765385799
@@ -35,4 +35,4 @@ namespace JCMG.EntitasRedux
35
35
  /// </summary>
36
36
  void Initialize();
37
37
  }
38
- }
38
+ }
@@ -25,6 +25,8 @@ THE SOFTWARE.
25
25
 
26
26
  using System;
27
27
  using System.Collections.Generic;
28
+ using System.Threading;
29
+ using System.Threading.Tasks;
28
30
  using EntitasRedux.Core.Libs;
29
31
 
30
32
  namespace JCMG.EntitasRedux
@@ -37,6 +39,7 @@ namespace JCMG.EntitasRedux
37
39
  /// you added them.
38
40
  /// </summary>
39
41
  public class Systems : IInitializeSystem,
42
+ IInitializeAsyncSystem,
40
43
  IUpdateSystem,
41
44
  IFixedUpdateSystem,
42
45
  ILateUpdateSystem,
@@ -44,35 +47,21 @@ namespace JCMG.EntitasRedux
44
47
  ICleanupSystem,
45
48
  ITearDownSystem
46
49
  {
47
- protected readonly List<IFixedUpdateSystem> _fixedUpdateSystems;
48
- protected readonly List<IUpdateSystem> _updateSystems;
49
- protected readonly List<ILateUpdateSystem> _lateUpdateSystems;
50
- protected readonly List<IReactiveSystem> _reactiveSystems;
50
+ protected readonly List<IFixedUpdateSystem> _fixedUpdateSystems = new();
51
+ protected readonly List<IUpdateSystem> _updateSystems = new();
52
+ protected readonly List<ILateUpdateSystem> _lateUpdateSystems = new();
53
+ protected readonly List<IReactiveSystem> _reactiveSystems = new();
51
54
 
52
- protected readonly List<IInitializeSystem> _initializeSystems;
53
- protected readonly List<ICleanupSystem> _cleanupSystems;
54
- protected readonly List<ITearDownSystem> _tearDownSystems;
55
+ protected readonly List<IInitializeSystem> _initializeSystems = new();
56
+ protected readonly List<IInitializeAsyncSystem> _initializeAsyncSystems = new();
57
+ protected readonly List<ICleanupSystem> _cleanupSystems = new();
58
+ protected readonly List<ITearDownSystem> _tearDownSystems = new();
55
59
 
56
60
  private Memory<IFixedUpdateSystem> _fixedUpdateSystemsMemory;
57
61
  private Memory<IUpdateSystem> _updateSystemsMemory;
58
62
  private Memory<ILateUpdateSystem> _lateUpdateSystemsMemory;
59
63
  private Memory<ICleanupSystem> _cleanupSystemsMemory;
60
64
 
61
- /// <summary>
62
- /// Creates a new Systems instance.
63
- /// </summary>
64
- public Systems()
65
- {
66
- _fixedUpdateSystems = new List<IFixedUpdateSystem>();
67
- _updateSystems = new List<IUpdateSystem>();
68
- _lateUpdateSystems = new List<ILateUpdateSystem>();
69
- _reactiveSystems = new List<IReactiveSystem>();
70
-
71
- _initializeSystems = new List<IInitializeSystem>();
72
- _cleanupSystems = new List<ICleanupSystem>();
73
- _tearDownSystems = new List<ITearDownSystem>();
74
- }
75
-
76
65
  /// <summary>
77
66
  /// Adds the <see cref="ISystem"/> instance to the systems list.
78
67
  /// </summary>
@@ -85,6 +74,11 @@ namespace JCMG.EntitasRedux
85
74
  _initializeSystems.Add(initializeSystem);
86
75
  }
87
76
 
77
+ if (system is IInitializeAsyncSystem initializeAsyncSystem)
78
+ {
79
+ _initializeAsyncSystems.Add(initializeAsyncSystem);
80
+ }
81
+
88
82
  if (system is IFixedUpdateSystem fixedUpdateSystem)
89
83
  {
90
84
  _fixedUpdateSystems.Add(fixedUpdateSystem);
@@ -208,6 +202,16 @@ namespace JCMG.EntitasRedux
208
202
  }
209
203
  }
210
204
 
205
+ public virtual async Task InitializeAsync(CancellationToken ct)
206
+ {
207
+ for (var i = 0; i < _initializeAsyncSystems.Count; i++)
208
+ {
209
+ ct.ThrowIfCancellationRequested();
210
+
211
+ await _initializeAsyncSystems[i].InitializeAsync(ct);
212
+ }
213
+ }
214
+
211
215
  /// <summary>
212
216
  /// Calls Cleanup() on all <see cref="ICleanupSystem"/> and other nested systems instances in the order you
213
217
  /// added them.
@@ -54,6 +54,12 @@ namespace JCMG.EntitasRedux.VisualDebugging
54
54
 
55
55
  _context.OnEntityCreated += OnEntityCreated;
56
56
  _context.OnGroupCreated += OnGroupCreated;
57
+
58
+ var entities = _context.GetEntities();
59
+ foreach (var entity in entities)
60
+ {
61
+ OnEntityCreated(_context, entity);
62
+ }
57
63
  }
58
64
 
59
65
  public void Deactivate()
@@ -104,4 +110,4 @@ namespace JCMG.EntitasRedux.VisualDebugging
104
110
  return str;
105
111
  }
106
112
  }
107
- }
113
+ }
@@ -26,6 +26,8 @@ THE SOFTWARE.
26
26
  using System.Collections.Generic;
27
27
  using System.Diagnostics;
28
28
  using System.Linq;
29
+ using System.Threading;
30
+ using System.Threading.Tasks;
29
31
  using UnityEngine;
30
32
 
31
33
  namespace JCMG.EntitasRedux.VisualDebugging
@@ -51,6 +53,21 @@ namespace JCMG.EntitasRedux.VisualDebugging
51
53
  }
52
54
  }
53
55
 
56
+ public int TotalInitializeAsyncSystemsCount
57
+ {
58
+ get
59
+ {
60
+ var total = 0;
61
+ for (var i = 0; i < _initializeAsyncSystems.Count; i++)
62
+ {
63
+ var system = _initializeAsyncSystems[i];
64
+ total += system is DebugSystems debugSystems ? debugSystems.TotalInitializeAsyncSystemsCount : 1;
65
+ }
66
+
67
+ return total;
68
+ }
69
+ }
70
+
54
71
  /// <summary>
55
72
  /// Returns the total number of <see cref="IUpdateSystem"/> instances in this <see cref="DebugSystems"/> and
56
73
  /// any child <see cref="DebugSystems"/>.
@@ -192,9 +209,11 @@ namespace JCMG.EntitasRedux.VisualDebugging
192
209
 
193
210
  public double AverageUpdateDuration => _updateSystemInfos.Select(x => x.AverageUpdateDuration).Sum();
194
211
 
195
- public double AverageFixedUpdateDuration => _fixedUpdateSystemInfos.Select(x => x.AverageFixedUpdateDuration).Sum();
212
+ public double AverageFixedUpdateDuration
213
+ => _fixedUpdateSystemInfos.Select(x => x.AverageFixedUpdateDuration).Sum();
196
214
 
197
- public double AverageLateUpdateDuration => _lateUpdateSystemInfos.Select(x => x.AverageLateUpdateDuration).Sum();
215
+ public double AverageLateUpdateDuration
216
+ => _lateUpdateSystemInfos.Select(x => x.AverageLateUpdateDuration).Sum();
198
217
 
199
218
  public double AverageReactiveDuration => _lateUpdateSystemInfos.Select(x => x.AverageReactiveDuration).Sum();
200
219
 
@@ -212,6 +231,8 @@ namespace JCMG.EntitasRedux.VisualDebugging
212
231
 
213
232
  public IReadOnlyList<SystemInfo> InitializeSystemInfos => _initializeSystemInfos;
214
233
 
234
+ public IReadOnlyList<SystemInfo> InitializeAsyncSystemInfos => _initializeAsyncSystemInfos;
235
+
215
236
  public IReadOnlyList<SystemInfo> UpdateSystemInfos => _updateSystemInfos;
216
237
 
217
238
  public IReadOnlyList<SystemInfo> FixedUpdateSystemInfos => _fixedUpdateSystemInfos;
@@ -235,6 +256,7 @@ namespace JCMG.EntitasRedux.VisualDebugging
235
256
 
236
257
  private List<SystemInfo> _allSystemInfos;
237
258
  private List<SystemInfo> _initializeSystemInfos;
259
+ private List<SystemInfo> _initializeAsyncSystemInfos;
238
260
  private List<SystemInfo> _updateSystemInfos;
239
261
  private List<SystemInfo> _fixedUpdateSystemInfos;
240
262
  private List<SystemInfo> _lateUpdateSystemInfos;
@@ -273,6 +295,7 @@ namespace JCMG.EntitasRedux.VisualDebugging
273
295
 
274
296
  _allSystemInfos = new List<SystemInfo>();
275
297
  _initializeSystemInfos = new List<SystemInfo>();
298
+ _initializeAsyncSystemInfos = new List<SystemInfo>();
276
299
  _updateSystemInfos = new List<SystemInfo>();
277
300
  _fixedUpdateSystemInfos = new List<SystemInfo>();
278
301
  _lateUpdateSystemInfos = new List<SystemInfo>();
@@ -310,6 +333,11 @@ namespace JCMG.EntitasRedux.VisualDebugging
310
333
  _initializeSystemInfos.Add(childSystemInfo);
311
334
  }
312
335
 
336
+ if (childSystemInfo.IsInitializeAsyncSystems)
337
+ {
338
+ _initializeAsyncSystemInfos.Add(childSystemInfo);
339
+ }
340
+
313
341
  if (childSystemInfo.IsUpdateSystems || childSystemInfo.IsReactiveSystems)
314
342
  {
315
343
  _updateSystemInfos.Add(childSystemInfo);
@@ -366,14 +394,32 @@ namespace JCMG.EntitasRedux.VisualDebugging
366
394
  for (var i = 0; i < _initializeSystems.Count; i++)
367
395
  {
368
396
  var systemInfo = _initializeSystemInfos[i];
369
- if (systemInfo.isActive)
370
- {
371
- _stopwatch.Reset();
372
- _stopwatch.Start();
373
- _initializeSystems[i].Initialize();
374
- _stopwatch.Stop();
375
- systemInfo.InitializationDuration = _stopwatch.Elapsed.TotalMilliseconds;
376
- }
397
+ if (!systemInfo.isActive)
398
+ continue;
399
+
400
+ _stopwatch.Reset();
401
+ _stopwatch.Start();
402
+ _initializeSystems[i].Initialize();
403
+ _stopwatch.Stop();
404
+ systemInfo.InitializationDuration = _stopwatch.Elapsed.TotalMilliseconds;
405
+ }
406
+ }
407
+
408
+ public override async Task InitializeAsync(CancellationToken ct)
409
+ {
410
+ for (var i = 0; i < _initializeAsyncSystems.Count; i++)
411
+ {
412
+ ct.ThrowIfCancellationRequested();
413
+
414
+ var systemInfo = _initializeAsyncSystemInfos[i];
415
+ if (!systemInfo.isActive)
416
+ continue;
417
+
418
+ _stopwatch.Reset();
419
+ _stopwatch.Start();
420
+ await _initializeAsyncSystems[i].InitializeAsync(ct);
421
+ _stopwatch.Stop();
422
+ systemInfo.InitializationDuration = _stopwatch.Elapsed.TotalMilliseconds;
377
423
  }
378
424
  }
379
425
 
@@ -474,4 +520,4 @@ namespace JCMG.EntitasRedux.VisualDebugging
474
520
  }
475
521
  }
476
522
  }
477
- }
523
+ }
@@ -31,15 +31,17 @@ namespace JCMG.EntitasRedux.VisualDebugging
31
31
  public enum SystemInterfaceFlags
32
32
  {
33
33
  None = 0,
34
- InitializeSystem = 1 << 1,
35
- FixedUpdateSystem = 1 << 6,
34
+ InitializeSystem = 1 << 0,
35
+ InitializeAsyncSystem = 1 << 1,
36
36
  UpdateSystem = 1 << 2,
37
- LateUpdateSystem = 1 << 7,
38
- ReactiveSystem = 1 << 5,
39
37
  CleanupSystem = 1 << 3,
40
- TearDownSystem = 1 << 4
38
+ TearDownSystem = 1 << 4,
39
+ ReactiveSystem = 1 << 5,
40
+ FixedUpdateSystem = 1 << 6,
41
+ LateUpdateSystem = 1 << 7,
41
42
  }
42
43
 
44
+
43
45
  public class SystemInfo
44
46
  {
45
47
  public ISystem System { get; }
@@ -54,6 +56,9 @@ namespace JCMG.EntitasRedux.VisualDebugging
54
56
  public bool IsInitializeSystems =>
55
57
  (_interfaceFlags & SystemInterfaceFlags.InitializeSystem) == SystemInterfaceFlags.InitializeSystem;
56
58
 
59
+ public bool IsInitializeAsyncSystems =>
60
+ (_interfaceFlags & SystemInterfaceFlags.InitializeAsyncSystem) == SystemInterfaceFlags.InitializeAsyncSystem;
61
+
57
62
  public bool IsUpdateSystems =>
58
63
  (_interfaceFlags & SystemInterfaceFlags.UpdateSystem) == SystemInterfaceFlags.UpdateSystem;
59
64
 
@@ -311,6 +316,11 @@ namespace JCMG.EntitasRedux.VisualDebugging
311
316
  flags |= SystemInterfaceFlags.InitializeSystem;
312
317
  }
313
318
 
319
+ if (system is IInitializeAsyncSystem)
320
+ {
321
+ flags |= SystemInterfaceFlags.InitializeAsyncSystem;
322
+ }
323
+
314
324
  if (system is IFixedUpdateSystem)
315
325
  {
316
326
  flags |= SystemInterfaceFlags.FixedUpdateSystem;
@@ -60,6 +60,7 @@ namespace JCMG.EntitasRedux.VisualDebugging.Editor
60
60
  private static bool _showSystemsList = true;
61
61
 
62
62
  private static bool _showInitializeSystems = true;
63
+ private static bool _showInitializeAsyncSystems = true;
63
64
  private static bool _showFixedUpdateSystems = true;
64
65
  private static bool _showUpdateSystems = true;
65
66
  private static bool _showLateUpdateSystems = true;
@@ -94,6 +95,7 @@ namespace JCMG.EntitasRedux.VisualDebugging.Editor
94
95
 
95
96
  // System Section Titles
96
97
  private const string INITIALIZE_SYSTEMS_TITLE = "Initialize Systems";
98
+ private const string INITIALIZE_ASYNC_SYSTEMS_TITLE = "Initialize Async Systems";
97
99
  private const string FIXED_UPDATE_SYSTEMS_TITLE = "Fixed Update Systems";
98
100
  private const string UPDATE_SYSTEMS_TITLE = "Update Systems";
99
101
  private const string LATE_UPDATE_SYSTEMS_TITLE = "Late Update Systems";
@@ -103,6 +105,7 @@ namespace JCMG.EntitasRedux.VisualDebugging.Editor
103
105
 
104
106
  // Count Labels
105
107
  private const string INITIALIZE_SYSTEMS_COUNT_LABEL = "Initialize Systems";
108
+ private const string INITIALIZE_ASYNC_SYSTEMS_COUNT_LABEL = "Initialize Async Systems";
106
109
  private const string FIXED_UPDATE_SYSTEMS_COUNT_LABEL = "Fixed Update Systems";
107
110
  private const string UPDATE_SYSTEMS_COUNT_LABEL = "Update Systems";
108
111
  private const string LATE_UPDATE_SYSTEMS_COUNT_LABEL = "Late Update Systems";
@@ -190,6 +193,7 @@ namespace JCMG.EntitasRedux.VisualDebugging.Editor
190
193
  using (new EditorGUILayout.VerticalScope(EntitasReduxStyles.SectionContent))
191
194
  {
192
195
  EditorGUILayout.LabelField(INITIALIZE_SYSTEMS_COUNT_LABEL, systems.TotalInitializeSystemsCount.ToString());
196
+ EditorGUILayout.LabelField(INITIALIZE_ASYNC_SYSTEMS_COUNT_LABEL, systems.TotalInitializeAsyncSystemsCount.ToString());
193
197
  EditorGUILayout.LabelField(FIXED_UPDATE_SYSTEMS_COUNT_LABEL, systems.TotalFixedUpdateSystemsCount.ToString());
194
198
  EditorGUILayout.LabelField(UPDATE_SYSTEMS_COUNT_LABEL, systems.TotalUpdateSystemsCount.ToString());
195
199
  EditorGUILayout.LabelField(LATE_UPDATE_SYSTEMS_COUNT_LABEL, systems.TotalLateUpdateSystemsCount.ToString());
@@ -354,6 +358,7 @@ namespace JCMG.EntitasRedux.VisualDebugging.Editor
354
358
  EditorGUILayout.Space();
355
359
 
356
360
  DrawSystemSection(INITIALIZE_SYSTEMS_TITLE, ref _showInitializeSystems, systems, SystemInterfaceFlags.InitializeSystem);
361
+ DrawSystemSection(INITIALIZE_ASYNC_SYSTEMS_TITLE, ref _showInitializeAsyncSystems, systems, SystemInterfaceFlags.InitializeAsyncSystem);
357
362
  DrawSystemSection(FIXED_UPDATE_SYSTEMS_TITLE, ref _showFixedUpdateSystems, systems, SystemInterfaceFlags.FixedUpdateSystem);
358
363
  DrawSystemSection(UPDATE_SYSTEMS_TITLE, ref _showUpdateSystems, systems, SystemInterfaceFlags.UpdateSystem);
359
364
  DrawSystemSection(LATE_UPDATE_SYSTEMS_TITLE, ref _showLateUpdateSystems, systems, SystemInterfaceFlags.LateUpdateSystem);
@@ -393,6 +398,10 @@ namespace JCMG.EntitasRedux.VisualDebugging.Editor
393
398
  systemInfos = systems.InitializeSystemInfos
394
399
  .Where(systemInfo => systemInfo.InitializationDuration >= _threshold);
395
400
  break;
401
+ case SystemInterfaceFlags.InitializeAsyncSystem:
402
+ systemInfos = systems.InitializeAsyncSystemInfos
403
+ .Where(systemInfo => systemInfo.InitializationDuration >= _threshold);
404
+ break;
396
405
  case SystemInterfaceFlags.FixedUpdateSystem:
397
406
  systemInfos = systems.FixedUpdateSystemInfos
398
407
  .Where(systemInfo => systemInfo.AverageFixedUpdateDuration >= _threshold);
@@ -479,6 +488,7 @@ namespace JCMG.EntitasRedux.VisualDebugging.Editor
479
488
  switch (type)
480
489
  {
481
490
  case SystemInterfaceFlags.InitializeSystem:
491
+ case SystemInterfaceFlags.InitializeAsyncSystem:
482
492
  DrawSimpleSystemInfoPerformance(
483
493
  systemInfo.SystemName,
484
494
  systemInfo.InitializationDuration,
@@ -614,6 +624,8 @@ namespace JCMG.EntitasRedux.VisualDebugging.Editor
614
624
  {
615
625
  case SystemInterfaceFlags.InitializeSystem:
616
626
  return systems.TotalInitializeSystemsCount > 0;
627
+ case SystemInterfaceFlags.InitializeAsyncSystem:
628
+ return systems.TotalInitializeAsyncSystemsCount > 0;
617
629
  case SystemInterfaceFlags.FixedUpdateSystem:
618
630
  return systems.TotalFixedUpdateSystemsCount > 0;
619
631
  case SystemInterfaceFlags.UpdateSystem:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.elestrago.unity.entitas-redux",
3
- "version": "3.7.3",
3
+ "version": "3.7.5",
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",