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

Fix for Issue #4 on re-used Entity IDs #5

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

Gnivom
Copy link

@Gnivom Gnivom commented Oct 12, 2023

Fix for Issue #4

The first commit fixes the bug that IsAlive(deadEntity) returned true when there was a new entity re-using its ID.

The second commit goes through all (?) other places that might operate on a dead entity, and either throws, returns false, or returns an empty list; instead of just operating on whatever new entity is re-using its ID. In potentially performance-sensitive functions, I avoided calling IsAlive directly so as not to do an unnecessary lookup. It's probably unnecessary to check for equality on the Identity as opposed to just the Generation, but I wanted to be safe.

@@ -96,6 +96,10 @@ public void Despawn(Identity identity)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AddComponent(StorageType type, Identity identity, object data)
{
if (!IsAlive(identity))
Copy link

@thygrrr thygrrr Jan 26, 2024

Choose a reason for hiding this comment

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

Suggest using an assertion instead.

Nevermind, the Library throws runtime exceptions as well.

@@ -147,13 +155,21 @@ public void AddComponent(StorageType type, Identity identity, object data)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool HasComponent(StorageType type, Identity identity)
{
if (identity == Identity.None)
Copy link

Choose a reason for hiding this comment

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

Early out feels wierd here, current HEAD already checks for Identity.none - so this can be...

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public bool HasComponent(StorageType type, Identity identity)
    {
        var meta = Meta[identity.Id];
        return meta.Identity != Identity.None 
               && meta.Identity == identity 
               && Tables[meta.TableId].Types.Contains(type);
    }

@thygrrr
Copy link

thygrrr commented Jan 26, 2024

This PR should not be merged because it breaks functionality for Entity.Any.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants