|
|
|
@ -9,15 +9,15 @@ public unsafe partial class Universe |
|
|
|
|
{ |
|
|
|
|
private readonly Dictionary<Type, Entity> _lookupByType = new(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void AddLookupByType(Type type, Entity entity) |
|
|
|
|
=> _lookupByType.Add(type, entity); |
|
|
|
|
public void RemoveLookupByType(Type type) |
|
|
|
|
{ if (!_lookupByType.Remove(type)) throw new InvalidOperationException( |
|
|
|
|
$"Lookup for {type} does not exist"); } |
|
|
|
|
|
|
|
|
|
private EntityRef? GetOrNull(Entity entity) |
|
|
|
|
{ var e = new EntityRef(this, entity, false); return e.IsValid ? e : null; } |
|
|
|
|
|
|
|
|
|
private EntityRef? CreateOrNull(Entity entity) |
|
|
|
|
=> EntityRef.CreateOrNull(this, entity); |
|
|
|
|
|
|
|
|
|
public EntityRef? Lookup<T>() |
|
|
|
|
=> Lookup(typeof(T)); |
|
|
|
@ -25,16 +25,16 @@ public unsafe partial class Universe |
|
|
|
|
=> Lookup(_lookupByType.GetValueOrDefault(type)); |
|
|
|
|
|
|
|
|
|
public EntityRef? Lookup(Entity value) |
|
|
|
|
=> GetOrNull(new(ecs_get_alive(this, value))); |
|
|
|
|
=> CreateOrNull(new(ecs_get_alive(this, value))); |
|
|
|
|
|
|
|
|
|
public EntityRef? Lookup(EntityPath path) |
|
|
|
|
=> Lookup(default, path); |
|
|
|
|
public EntityRef? Lookup(Entity parent, EntityPath path) |
|
|
|
|
=> GetOrNull(EntityPath.Lookup(this, parent, path)); |
|
|
|
|
=> CreateOrNull(EntityPath.Lookup(this, parent, path)); |
|
|
|
|
public EntityRef? LookupSymbol(string symbol) |
|
|
|
|
{ |
|
|
|
|
using var alloc = TempAllocator.Use(); |
|
|
|
|
return GetOrNull(new(ecs_lookup_symbol(this, alloc.AllocateCString(symbol), false))); |
|
|
|
|
return CreateOrNull(new(ecs_lookup_symbol(this, alloc.AllocateCString(symbol), false))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public EntityRef LookupOrThrow<T>() => LookupOrThrow(typeof(T)); |
|
|
|
|