Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move EntityReference.IsAlive to World #188

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 1 addition & 18 deletions src/Arch/Core/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,24 +293,7 @@ public EntityReference()
Version = -1;
}

#if PURE_ECS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we keep this one, and just change the implementation to World.IsAlive(this)? Would be more convenient.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kept :)


/// <summary>
/// Checks if the referenced <see cref="Entity"/> is still valid and alife.
/// </summary>
/// <param name="world">The <see cref="Entity"/> <see cref="World"/>..</param>
/// <returns>True if its alive, otherwhise false.</returns>
public bool IsAlive(World world)
{
if (this == Null)
{
return false;
}

var reference = world.Reference(Entity);
return this == reference;
}
#else
#if !PURE_ECS
/// <summary>
/// Checks if the referenced <see cref="Entity"/> is still valid and alife.
/// </summary>
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 @@ -1421,6 +1421,24 @@ public void RemoveRange(Entity entity, Span<ComponentType> types)

public partial class World
{
/// <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>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool IsAlive(EntityReference entityReference)
{
if (entityReference == EntityReference.Null)
{
return false;
}

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

/// <summary>
/// Checks if the <see cref="Entity"/> is alive in this <see cref="World"/>.
/// </summary>
Expand Down
Loading