Rename .Get to .GetOrThrow

wip/bindgen
copygirl 1 year ago
parent a58514d402
commit d2023961cc
  1. 4
      src/gaemstone.ECS/EntityBase.cs
  2. 2
      src/gaemstone.ECS/EntityBuilder.cs
  3. 16
      src/gaemstone.ECS/EntityRef.cs

@ -28,17 +28,17 @@ public abstract class EntityBase<TReturn>
public bool Has<TRelation, TTarget>() => Has(World.LookupByTypeOrThrow<TRelation>(), World.LookupByTypeOrThrow<TTarget>());
public abstract T Get<T>(Identifier id);
public abstract T? GetOrNull<T>(Identifier id) where T : unmanaged;
public abstract T? GetOrNull<T>(Identifier id, T _ = null!) where T : class;
public abstract T GetOrThrow<T>(Identifier id);
public abstract ref T GetMut<T>(Identifier id) where T : unmanaged;
public abstract ref T GetRefOrNull<T>(Identifier id) where T : unmanaged;
public abstract ref T GetRefOrThrow<T>(Identifier id) where T : unmanaged;
public abstract void Modified<T>(Identifier id);
public T Get<T>() => Get<T>(World.LookupByTypeOrThrow<T>());
public T? GetOrNull<T>() where T : unmanaged => GetOrNull<T>(World.LookupByTypeOrThrow<T>());
public T? GetOrNull<T>(T _ = null!) where T : class => GetOrNull<T>(World.LookupByTypeOrThrow<T>());
public T GetOrThrow<T>() => GetOrThrow<T>(World.LookupByTypeOrThrow<T>());
public ref T GetMut<T>() where T : unmanaged => ref GetMut<T>(World.LookupByTypeOrThrow<T>());
public ref T GetRefOrNull<T>() where T : unmanaged => ref GetRefOrNull<T>(World.LookupByTypeOrThrow<T>());
public ref T GetRefOrThrow<T>() where T : unmanaged => ref GetRefOrThrow<T>(World.LookupByTypeOrThrow<T>());

@ -67,9 +67,9 @@ public class EntityBuilder
=> !id.IsWildcard ? _toAdd.Contains(id)
: throw new NotSupportedException(); // TODO: Support wildcard.
public override T Get<T>(Identifier id) => throw new NotSupportedException();
public override T? GetOrNull<T>(Identifier id) => throw new NotSupportedException();
public override T? GetOrNull<T>(Identifier id, T _ = null!) where T : class => throw new NotSupportedException();
public override T GetOrThrow<T>(Identifier id) => throw new NotSupportedException();
public override ref T GetMut<T>(Identifier id) => throw new NotSupportedException();
public override ref T GetRefOrNull<T>(Identifier id) => throw new NotSupportedException();
public override ref T GetRefOrThrow<T>(Identifier id) => throw new NotSupportedException();

@ -74,14 +74,6 @@ public unsafe class EntityRef
public override EntityRef Remove(Identifier id) { ecs_remove_id(World, this, id); return this; }
public override bool Has(Identifier id) => ecs_has_id(World, this, id);
public override T Get<T>(Identifier id)
{
var ptr = ecs_get_id(World, this, id);
if (ptr == null) throw new Exception($"Component {typeof(T)} not found on {this}");
return typeof(T).IsValueType ? Unsafe.Read<T>(ptr)
: (T)((GCHandle)Unsafe.Read<nint>(ptr)).Target!;
}
public override T? GetOrNull<T>(Identifier id)
{
var ptr = ecs_get_id(World, this, id);
@ -95,6 +87,14 @@ public unsafe class EntityRef
return (ptr != null) ? (T)((GCHandle)Unsafe.Read<nint>(ptr)).Target! : null;
}
public override T GetOrThrow<T>(Identifier id)
{
var ptr = ecs_get_id(World, this, id);
if (ptr == null) throw new Exception($"Component {typeof(T)} not found on {this}");
return typeof(T).IsValueType ? Unsafe.Read<T>(ptr)
: (T)((GCHandle)Unsafe.Read<nint>(ptr)).Target!;
}
public override ref T GetRefOrNull<T>(Identifier id)
{
var @ref = ecs_ref_init_id(World, this, id);

Loading…
Cancel
Save