com.elestrago.unity.entitas-redux 3.3.3 → 3.4.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
@@ -2,6 +2,22 @@
2
2
 
3
3
  ---
4
4
 
5
+ ## [3.4.1](https://gitlab.com/elestrago-pkg/entitas-redux/-/tags/3.4.1)
6
+
7
+ ### Fixed
8
+
9
+ - Possible command class extension generations in Rider IDE
10
+
11
+ ---
12
+
13
+ ## [3.4.0](https://gitlab.com/elestrago-pkg/entitas-redux/-/tags/3.4.0)
14
+
15
+ ### Removed
16
+
17
+ - Unify Add and Replace methods for components
18
+
19
+ ---
20
+
5
21
  ## [3.3.3](https://gitlab.com/elestrago-pkg/entitas-redux/-/tags/3.3.3)
6
22
 
7
23
  ### Fixed
@@ -64,8 +64,6 @@ namespace JCMG.EntitasRedux
64
64
 
65
65
  private EntityRepo<TEntity> _entityRepo;
66
66
 
67
- private TEntity[] _entitiesCache;
68
-
69
67
  /// <summary>
70
68
  /// The preferred way to create a context is to use the generated methods
71
69
  /// from the code generator, e.g. var context = new GameContext();
@@ -213,8 +211,6 @@ namespace JCMG.EntitasRedux
213
211
 
214
212
  private void OnDestroyEntity(IEntity entity)
215
213
  {
216
- _entitiesCache = null;
217
-
218
214
  using (_onEntityDestroyed.Invokable(out var listeners))
219
215
  {
220
216
  foreach (var listener in listeners)
@@ -328,7 +324,6 @@ namespace JCMG.EntitasRedux
328
324
  }
329
325
 
330
326
  entity.Retain(this);
331
- _entitiesCache = null;
332
327
 
333
328
  entity.OnComponentAdded += _cachedEntityChanged;
334
329
  entity.OnComponentRemoved += _cachedEntityChanged;
@@ -1,6 +1,5 @@
1
1
  using System;
2
2
  using System.Buffers;
3
- using System.Runtime.CompilerServices;
4
3
  using EntitasRedux.Core.Libs;
5
4
  using EntitasRedux.Core.Libs.Collections;
6
5
 
@@ -33,7 +32,6 @@ namespace JCMG.EntitasRedux
33
32
 
34
33
  public static class EntityRepoExtensions
35
34
  {
36
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
37
35
  public static bool Alloc<TEntity>(this ref EntityRepo<TEntity> repo, out TEntity entity)
38
36
  where TEntity : class, IEntity
39
37
  {
@@ -56,7 +54,6 @@ namespace JCMG.EntitasRedux
56
54
  return true;
57
55
  }
58
56
 
59
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
60
57
  public static bool Has<TEntity>(this ref EntityRepo<TEntity> repo, GenId id)
61
58
  where TEntity : class, IEntity
62
59
  {
@@ -67,7 +64,6 @@ namespace JCMG.EntitasRedux
67
64
  return entity.Id.CreationIndex == id.CreationIndex;
68
65
  }
69
66
 
70
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
71
67
  public static bool Release<TEntity>(this ref EntityRepo<TEntity> repo, GenId id)
72
68
  where TEntity : class, IEntity
73
69
  {
@@ -83,7 +79,6 @@ namespace JCMG.EntitasRedux
83
79
  return true;
84
80
  }
85
81
 
86
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
87
82
  public static void ReleaseAll<TEntity>(this ref EntityRepo<TEntity> repo)
88
83
  where TEntity : class, IEntity
89
84
  {
@@ -97,7 +92,6 @@ namespace JCMG.EntitasRedux
97
92
  }
98
93
  }
99
94
 
100
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
101
95
  public static TEntity GetById<TEntity>(this ref EntityRepo<TEntity> repo, GenId id)
102
96
  where TEntity : class, IEntity
103
97
  {
@@ -108,7 +102,6 @@ namespace JCMG.EntitasRedux
108
102
  return entity;
109
103
  }
110
104
 
111
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
112
105
  public static void GroupHandleEntitySilently<TEntity>(
113
106
  this ref EntityRepo<TEntity> repo,
114
107
  IGroup<TEntity> collection
@@ -124,7 +117,6 @@ namespace JCMG.EntitasRedux
124
117
  }
125
118
  }
126
119
 
127
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
128
120
  public static ArrayDisposable<TEntity> GetEntities<TEntity>(
129
121
  this ref EntityRepo<TEntity> repo,
130
122
  out Span<TEntity> entities
@@ -146,14 +138,12 @@ namespace JCMG.EntitasRedux
146
138
  return new ArrayDisposable<TEntity>(array);
147
139
  }
148
140
 
149
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
150
141
  public static void ResetCreationIndex<TEntity>(this ref EntityRepo<TEntity> repo)
151
142
  where TEntity : class, IEntity
152
143
  {
153
144
  repo.CreationIndex = 0;
154
145
  }
155
146
 
156
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
157
147
  public static TEntity[] ToArray<TEntity>(this ref EntityRepo<TEntity> repo)
158
148
  where TEntity : class, IEntity
159
149
  {
@@ -171,7 +161,6 @@ namespace JCMG.EntitasRedux
171
161
  return entities;
172
162
  }
173
163
 
174
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
175
164
  public static ReadOnlySpan<TEntity> AsReadOnlySpan<TEntity>(this ref EntityRepo<TEntity> repo)
176
165
  where TEntity : class, IEntity
177
166
  => new(repo.Pool, 0, repo.Length);
@@ -73,54 +73,6 @@ namespace JCMG.EntitasRedux
73
73
  return new ContextInfo("No Context", componentNames, null);
74
74
  }
75
75
 
76
- private void ReplaceComponentInternal(int index, IComponent replacement)
77
- {
78
- // TODO VD PERFORMANCE
79
- // _toStringCache = null;
80
-
81
- var previousComponent = _components[index];
82
- if (replacement != previousComponent)
83
- {
84
- _components[index] = replacement;
85
- _componentsCache = null;
86
- if (replacement != null)
87
- {
88
- using (_onComponentReplaced.Invokable(out var listeners))
89
- {
90
- foreach (var handler in listeners)
91
- handler(this, index, previousComponent, replacement);
92
- }
93
- }
94
- else
95
- {
96
- _componentIndicesCache = null;
97
-
98
- // TODO VD PERFORMANCE
99
- _toStringCache = null;
100
-
101
- using (_onComponentRemoved.Invokable(out var listeners))
102
- {
103
- foreach (var handler in listeners)
104
- handler(this, index, previousComponent);
105
- }
106
- }
107
-
108
- // ReSharper disable once SuspiciousTypeConversion.Global
109
- if (previousComponent is IDisposable disposable)
110
- disposable.Dispose();
111
-
112
- GetComponentPool(index).Push(previousComponent);
113
- }
114
- else
115
- {
116
- using (_onComponentReplaced.Invokable(out var listeners))
117
- {
118
- foreach (var handler in listeners)
119
- handler(this, index, previousComponent, replacement);
120
- }
121
- }
122
- }
123
-
124
76
  /// <summary>
125
77
  /// Returns a cached string to describe the entity
126
78
  /// with the following format:
@@ -256,6 +208,7 @@ namespace JCMG.EntitasRedux
256
208
  private readonly Event<EntityEvent> _onDestroyEntity = new();
257
209
 
258
210
  private GenId _id;
211
+
259
212
  public GenId Id => _id;
260
213
 
261
214
  /// <summary>
@@ -318,52 +271,6 @@ namespace JCMG.EntitasRedux
318
271
  _isEnabled = true;
319
272
  }
320
273
 
321
- /// <summary>
322
- /// Adds a component at the specified index.
323
- /// You can only have one component at an index.
324
- /// Each component type must have its own constant index.
325
- /// The preferred way is to use the
326
- /// generated methods from the code generator.
327
- /// </summary>
328
- /// <param name="index"></param>
329
- /// <param name="component"></param>
330
- public void AddComponent(int index, IComponent component)
331
- {
332
- if (!_isEnabled)
333
- {
334
- throw new EntityIsNotEnabledException(
335
- "Cannot add component '" +
336
- _contextInfo.componentNames[index] +
337
- "' to " +
338
- this +
339
- "!");
340
- }
341
-
342
- if (HasComponent(index))
343
- {
344
- throw new EntityAlreadyHasComponentException(
345
- index,
346
- "Cannot add component '" +
347
- _contextInfo.componentNames[index] +
348
- "' to " +
349
- this +
350
- "!",
351
- "You should check if an entity already has the component " +
352
- "before adding it or use entity.ReplaceComponent().");
353
- }
354
-
355
- _components[index] = component;
356
- _componentsCache = null;
357
- _componentIndicesCache = null;
358
- _toStringCache = null;
359
-
360
- using (_onComponentAdded.Invokable(out var listeners))
361
- {
362
- foreach (var handler in listeners)
363
- handler(this, index, component);
364
- }
365
- }
366
-
367
274
  /// <summary>
368
275
  /// Removes a component at the specified index.
369
276
  /// You can only remove a component at an index if it exists.
@@ -400,14 +307,14 @@ namespace JCMG.EntitasRedux
400
307
  }
401
308
 
402
309
  /// <summary>
403
- /// Replaces an existing component at the specified index
310
+ /// Add or replace an existing component at the specified index
404
311
  /// or adds it if it doesn't exist yet.
405
312
  /// The preferred way is to use the
406
313
  /// generated methods from the code generator.
407
314
  /// </summary>
408
315
  /// <param name="index"></param>
409
316
  /// <param name="component"></param>
410
- public void ReplaceComponent(int index, IComponent component)
317
+ public void AddComponent(int index, IComponent component)
411
318
  {
412
319
  if (!_isEnabled)
413
320
  {
@@ -425,7 +332,69 @@ namespace JCMG.EntitasRedux
425
332
  }
426
333
  else if (component != null)
427
334
  {
428
- AddComponent(index, component);
335
+ AddComponentInternal(index, component);
336
+ }
337
+ }
338
+
339
+ private void AddComponentInternal(int index, IComponent component)
340
+ {
341
+ _components[index] = component;
342
+ _componentsCache = null;
343
+ _componentIndicesCache = null;
344
+ _toStringCache = null;
345
+
346
+ using (_onComponentAdded.Invokable(out var listeners))
347
+ {
348
+ foreach (var handler in listeners)
349
+ handler(this, index, component);
350
+ }
351
+ }
352
+
353
+ private void ReplaceComponentInternal(int index, IComponent replacement)
354
+ {
355
+ // TODO VD PERFORMANCE
356
+ // _toStringCache = null;
357
+
358
+ var previousComponent = _components[index];
359
+ if (replacement != previousComponent)
360
+ {
361
+ _components[index] = replacement;
362
+ _componentsCache = null;
363
+ if (replacement != null)
364
+ {
365
+ using (_onComponentReplaced.Invokable(out var listeners))
366
+ {
367
+ foreach (var handler in listeners)
368
+ handler(this, index, previousComponent, replacement);
369
+ }
370
+ }
371
+ else
372
+ {
373
+ _componentIndicesCache = null;
374
+
375
+ // TODO VD PERFORMANCE
376
+ _toStringCache = null;
377
+
378
+ using (_onComponentRemoved.Invokable(out var listeners))
379
+ {
380
+ foreach (var handler in listeners)
381
+ handler(this, index, previousComponent);
382
+ }
383
+ }
384
+
385
+ // ReSharper disable once SuspiciousTypeConversion.Global
386
+ if (previousComponent is IDisposable disposable)
387
+ disposable.Dispose();
388
+
389
+ GetComponentPool(index).Push(previousComponent);
390
+ }
391
+ else
392
+ {
393
+ using (_onComponentReplaced.Invokable(out var listeners))
394
+ {
395
+ foreach (var handler in listeners)
396
+ handler(this, index, previousComponent, replacement);
397
+ }
429
398
  }
430
399
  }
431
400
 
@@ -60,7 +60,6 @@ namespace JCMG.EntitasRedux
60
60
 
61
61
  void AddComponent(int index, IComponent component);
62
62
  void RemoveComponent(int index);
63
- void ReplaceComponent(int index, IComponent component);
64
63
 
65
64
  IComponent GetComponent(int index);
66
65
  IComponent[] GetComponents();
@@ -442,7 +442,7 @@ public class ${ShortType}TypeDrawer : ITypeDrawer {
442
442
 
443
443
  if (changed)
444
444
  {
445
- entity.ReplaceComponent(index, newComponent);
445
+ entity.AddComponent(index, newComponent);
446
446
  }
447
447
  else
448
448
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.elestrago.unity.entitas-redux",
3
- "version": "3.3.3",
3
+ "version": "3.4.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",