Fix CreateLookup throwing on same lookup creation

wip/no-type-lookup
copygirl 2 years ago
parent 948268e9ba
commit b93beed5ec
  1. 3
      src/gaemstone.ECS/Entity.cs

@ -50,7 +50,8 @@ public unsafe readonly partial struct Entity<TContext>
public Entity<TContext> CreateLookup<T>() public Entity<TContext> CreateLookup<T>()
{ {
ref var lookup = ref Lookup<TContext>.Entity<T>.Value; ref var lookup = ref Lookup<TContext>.Entity<T>.Value;
if (lookup.IsSome) throw new InvalidOperationException( if (lookup == this) { /* Don't throw if lookup already has the same entity set. */ }
else if (lookup.IsSome) throw new InvalidOperationException(
$"The lookup for type {typeof(T)} in context {typeof(TContext)} is already in use by {lookup}"); $"The lookup for type {typeof(T)} in context {typeof(TContext)} is already in use by {lookup}");
lookup = this; lookup = this;
return this; return this;

Loading…
Cancel
Save