Skip to content

Commit

Permalink
Added World.IsAlive(EntityReference) for a unified API usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
genaray committed Feb 8, 2024
1 parent 3d084ac commit da1aae4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/Arch/Arch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ Fixed issue where Unsafe.As did not work on .Net 2.1 for the Dangerous-Utils.
Dangerous API now allows setting/getting of recycled ids.
Fixed archetype duplication after loading a save.
Fixed .Add when a newly non registered component was added.
Now makes use of the updated and improved JobScheduler 1.1.1.</PackageReleaseNotes>
Now makes use of the updated and improved JobScheduler 1.1.1.
ScheduleParallelInlineQuery added.
Added World.IsAlive(EntityReference);</PackageReleaseNotes>
<PackageTags>c#;.net;.net6;.net7;ecs;game;entity;gamedev; game-development; game-engine; entity-component-system;stride;unity;godot;</PackageTags>

<PackageProjectUrl>https://github.com/genaray/Arch</PackageProjectUrl>
Expand Down
10 changes: 3 additions & 7 deletions src/Arch/Core/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,21 +300,17 @@ public EntityReference()
/// </summary>
/// <param name="world">The <see cref="Entity"/> <see cref="World"/>..</param>
/// <returns>True if its alive, otherwhise false.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool IsAlive(World world)

Check failure on line 304 in src/Arch/Core/Entity.cs

View workflow job for this annotation

GitHub Actions / Build Arch

'EntityReference.IsAlive(World)': not all code paths return a value

Check failure on line 304 in src/Arch/Core/Entity.cs

View workflow job for this annotation

GitHub Actions / Build Arch

'EntityReference.IsAlive(World)': not all code paths return a value

Check failure on line 304 in src/Arch/Core/Entity.cs

View workflow job for this annotation

GitHub Actions / Build Arch

'EntityReference.IsAlive(World)': not all code paths return a value
{
if (this == Null)
{
return false;
}

var reference = world.Reference(Entity);
return this == reference;
world.IsAlive(this);
}
#else
/// <summary>
/// Checks if the referenced <see cref="Entity"/> is still valid and alife.
/// </summary>
/// <returns>True if its alive, otherwhise false.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool IsAlive()
{
if (this == Null)
Expand Down
18 changes: 18 additions & 0 deletions src/Arch/Core/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1466,6 +1466,24 @@ public bool IsAlive(Entity entity)
return EntityInfo.Has(entity.Id);
}

/// <summary>
/// Checks if the <see cref="EntityReference"/> is alive and valid in this <see cref="World"/>.
/// </summary>
/// <param name="entityReference">The <see cref="EntityReference"/>.</param>
/// <returns>True if it exists and is alive, otherwise false.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[Pure]
public bool IsAlive(EntityReference entityReference)
{
if (entityReference == EntityReference.Null)
{
return false;
}

var reference = Reference(entityReference.Entity);
return entityReference == reference;
}

/// <summary>
/// Returns the version of an <see cref="Entity"/>.
/// Indicating how often it was recycled.
Expand Down

0 comments on commit da1aae4

Please sign in to comment.