Skip to content

Commit e519122

Browse files
committed
Added new IsAlive overload to the entity to provide acess to the EntityData.
1 parent ae8b509 commit e519122

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

src/Arch/Core/Extensions/EntityExtensions.cs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public static partial class EntityExtensions
1919
/// </summary>
2020
/// <param name="entity">The <see cref="Entity"/>.</param>
2121
/// <returns>Its <see cref="Archetype"/>.</returns>
22-
2322
[Pure]
2423
public static Archetype GetArchetype(this in Entity entity)
2524
{
@@ -32,7 +31,6 @@ public static Archetype GetArchetype(this in Entity entity)
3231
/// </summary>
3332
/// <param name="entity">The <see cref="Entity"/>.</param>
3433
/// <returns>A reference to its <see cref="Chunk"/>.</returns>
35-
3634
[Pure]
3735
public static ref readonly Chunk GetChunk(this in Entity entity)
3836
{
@@ -45,9 +43,8 @@ public static ref readonly Chunk GetChunk(this in Entity entity)
4543
/// </summary>
4644
/// <param name="entity">The <see cref="Entity"/>.</param>
4745
/// <returns>Its <see cref="ComponentType"/>'s array.</returns>
48-
4946
[Pure]
50-
public static ComponentType[] GetComponentTypes(this in Entity entity)
47+
public static Signature GetComponentTypes(this in Entity entity)
5148
{
5249
var world = World.Worlds.DangerousGetReferenceAt(entity.WorldId);
5350
return world.GetSignature(entity);
@@ -59,7 +56,6 @@ public static ComponentType[] GetComponentTypes(this in Entity entity)
5956
/// </summary>
6057
/// <param name="entity">The <see cref="Entity"/>.</param>
6158
/// <returns>A newly allocated array containing the entities components.</returns>
62-
6359
[Pure]
6460
public static object?[] GetAllComponents(this in Entity entity)
6561
{
@@ -72,21 +68,32 @@ public static ComponentType[] GetComponentTypes(this in Entity entity)
7268
/// </summary>
7369
/// <param name="entity">The <see cref="Entity"/>.</param>
7470
/// <returns>True if it exists and is alive, otherwise false.</returns>
75-
7671
[Pure]
7772
public static bool IsAlive(this in Entity entity)
7873
{
7974
var world = World.Worlds.DangerousGetReferenceAt(entity.WorldId);
8075
return world.IsAlive(entity);
8176
}
8277

78+
/// <summary>
79+
/// Checks if the <see cref="Entity"/> is alive in this <see cref="World"/>.
80+
/// </summary>
81+
/// <param name="entity">The <see cref="Entity"/>.</param>
82+
/// <param name="exists">If the entity and its <see cref="EntityData"/> exists.</param>
83+
/// <returns>True if it exists and is alive, otherwise false.</returns>
84+
[Pure]
85+
public static ref EntityData IsAlive(this in Entity entity, out bool exists)
86+
{
87+
var world = World.Worlds.DangerousGetReferenceAt(entity.WorldId);
88+
return ref world.IsAlive(entity, out exists);
89+
}
90+
8391
/// <summary>
8492
/// Sets or replaces a component for an <see cref="Entity"/>.
8593
/// </summary>
8694
/// <typeparam name="T">The component type.</typeparam>
8795
/// <param name="entity">The <see cref="Entity"/>.</param>
8896
/// <param name="component">The instance, optional.</param>
89-
9097
public static void Set<T>(this in Entity entity, in T? component = default)
9198
{
9299
var world = World.Worlds.DangerousGetReferenceAt(entity.WorldId);
@@ -203,7 +210,6 @@ public static partial class EntityExtensions
203210
/// </summary>
204211
/// <param name="entity">The <see cref="Entity"/>.</param>
205212
/// <param name="cmp">The component.</param>
206-
207213
public static void Set(this in Entity entity, object cmp)
208214
{
209215
var world = World.Worlds.DangerousGetReferenceAt(entity.WorldId);
@@ -215,7 +221,6 @@ public static void Set(this in Entity entity, object cmp)
215221
/// </summary>
216222
/// <param name="entity">The <see cref="Entity"/>.</param>
217223
/// <param name="components">The components <see cref="IList{T}"/>.</param>
218-
219224
public static void SetRange(this in Entity entity, Span<object> components)
220225
{
221226
var world = World.Worlds.DangerousGetReferenceAt(entity.WorldId);
@@ -228,7 +233,6 @@ public static void SetRange(this in Entity entity, Span<object> components)
228233
/// <param name="entity">The <see cref="Entity"/>.</param>
229234
/// <param name="type">The component <see cref="ComponentType"/>.</param>
230235
/// <returns>True if it has the desired component, otherwise false.</returns>
231-
232236
[Pure]
233237
public static bool Has(this in Entity entity, ComponentType type)
234238
{
@@ -242,7 +246,6 @@ public static bool Has(this in Entity entity, ComponentType type)
242246
/// <param name="entity">The <see cref="Entity"/>.</param>
243247
/// <param name="types">The component <see cref="ComponentType"/>.</param>
244248
/// <returns>True if it has the desired component, otherwise false.</returns>
245-
246249
[Pure]
247250
public static bool HasRange(this in Entity entity, Span<ComponentType> types)
248251
{
@@ -256,7 +259,6 @@ public static bool HasRange(this in Entity entity, Span<ComponentType> types)
256259
/// <param name="entity">The <see cref="Entity"/>.</param>
257260
/// <param name="type">The component <see cref="ComponentType"/>.</param>
258261
/// <returns>A reference to the component.</returns>
259-
260262
[Pure]
261263
public static object? Get(this in Entity entity, ComponentType type)
262264
{
@@ -270,7 +272,6 @@ public static bool HasRange(this in Entity entity, Span<ComponentType> types)
270272
/// <param name="entity">The <see cref="Entity"/>.</param>
271273
/// <param name="types">The component <see cref="ComponentType"/>.</param>
272274
/// <returns>A reference to the component.</returns>
273-
274275
[Pure]
275276
public static object?[] GetRange(this in Entity entity, Span<ComponentType> types)
276277
{
@@ -286,7 +287,6 @@ public static bool HasRange(this in Entity entity, Span<ComponentType> types)
286287
/// <param name="types">The component <see cref="ComponentType"/>.</param>
287288
/// <param name="components">A <see cref="IList{T}"/> where the components are put it.</param>
288289
/// <returns>A reference to the component.</returns>
289-
290290
[Pure]
291291
public static void GetRange(this in Entity entity, Span<ComponentType> types, Span<object?> components)
292292
{
@@ -302,7 +302,6 @@ public static void GetRange(this in Entity entity, Span<ComponentType> types, Sp
302302
/// <param name="type">The component <see cref="ComponentType"/>.</param>
303303
/// <param name="component">The found component.</param>
304304
/// <returns>True if it exists, otherwise false.</returns>
305-
306305
[Pure]
307306
public static bool TryGet(this in Entity entity, ComponentType type, out object? component)
308307
{
@@ -316,7 +315,6 @@ public static bool TryGet(this in Entity entity, ComponentType type, out object?
316315
/// <param name="entity">The <see cref="Entity"/>.</param>
317316
/// <param name="cmp">The component.</param>
318317
[SkipLocalsInit]
319-
320318
public static void Add(this in Entity entity, in object cmp)
321319
{
322320
var world = World.Worlds.DangerousGetReferenceAt(entity.WorldId);
@@ -329,7 +327,6 @@ public static void Add(this in Entity entity, in object cmp)
329327
/// <param name="entity">The <see cref="Entity"/>.</param>
330328
/// <param name="components">The component <see cref="IList{T}"/>.</param>
331329
[SkipLocalsInit]
332-
333330
public static void AddRange(this in Entity entity, Span<object> components)
334331
{
335332
var world = World.Worlds.DangerousGetReferenceAt(entity.WorldId);
@@ -342,7 +339,6 @@ public static void AddRange(this in Entity entity, Span<object> components)
342339
/// <param name="entity">The <see cref="Entity"/>.</param>
343340
/// <param name="components">A <see cref="Span{T}"/> of <see cref="ComponentType"/>'s, those are added to the <see cref="Entity"/>.</param>
344341
[SkipLocalsInit]
345-
346342
public static void AddRange(this in Entity entity, Span<ComponentType> components)
347343
{
348344
var world = World.Worlds.DangerousGetReferenceAt(entity.WorldId);
@@ -355,7 +351,6 @@ public static void AddRange(this in Entity entity, Span<ComponentType> component
355351
/// <param name="entity">The <see cref="Entity"/>.</param>
356352
/// <param name="types">A <see cref="IList{T}"/> of <see cref="ComponentType"/>'s, those are removed from the <see cref="Entity"/>.</param>
357353
[SkipLocalsInit]
358-
359354
public static void RemoveRange(this in Entity entity, Span<ComponentType> types)
360355
{
361356
var world = World.Worlds.DangerousGetReferenceAt(entity.WorldId);

0 commit comments

Comments
 (0)