-
Notifications
You must be signed in to change notification settings - Fork 6
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
base: main
Are you sure you want to change the base?
Conversation
@@ -96,6 +96,10 @@ public void Despawn(Identity identity) | |||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |||
public void AddComponent(StorageType type, Identity identity, object data) | |||
{ | |||
if (!IsAlive(identity)) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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);
}
This PR should not be merged because it breaks functionality for |
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.