parent
26b9ad3a6a
commit
230d1abfe3
11 changed files with 124 additions and 124 deletions
@ -0,0 +1,55 @@ |
|||||||
|
using System; |
||||||
|
using gaemstone.Utility; |
||||||
|
using static flecs_hub.flecs; |
||||||
|
|
||||||
|
namespace gaemstone.ECS; |
||||||
|
|
||||||
|
public unsafe class IdRef |
||||||
|
: IEquatable<IdRef> |
||||||
|
{ |
||||||
|
public World World { get; } |
||||||
|
public Id Id { get; } |
||||||
|
|
||||||
|
public IdFlags Flags => Id.Flags; |
||||||
|
public bool IsPair => Id.IsPair; |
||||||
|
public bool IsWildcard => Id.IsWildcard; |
||||||
|
public bool IsValid => ecs_id_is_valid(World, this); |
||||||
|
|
||||||
|
public bool IsInUse => ecs_id_in_use(World, this); |
||||||
|
public int Count => ecs_count_id(World, this); |
||||||
|
|
||||||
|
public IdRef(World world, Id id) |
||||||
|
{ World = world; Id = id; } |
||||||
|
|
||||||
|
public static IdRef Combine(IdFlags flags, IdRef id) |
||||||
|
=> new(id.World, Id.Combine(flags, id)); |
||||||
|
|
||||||
|
public static IdRef Pair(World world, Entity relation, Entity target) |
||||||
|
=> new(world, Id.Pair(relation, target)); |
||||||
|
public static IdRef Pair(EntityRef relation, EntityRef target) |
||||||
|
=> Pair(relation.World, relation, target); |
||||||
|
public static IdRef Pair(EntityRef relation, Entity target) |
||||||
|
=> Pair(relation.World, relation, target); |
||||||
|
public static IdRef Pair(Entity relation, EntityRef target) |
||||||
|
=> Pair(target.World, relation, target); |
||||||
|
public static IdRef Pair<TRelation>(EntityRef target) |
||||||
|
=> Pair(target.World.LookupByTypeOrThrow<TRelation>(), target); |
||||||
|
|
||||||
|
public EntityRef? AsEntity() |
||||||
|
=> (Flags == default) ? World.LookupAlive(new Entity(new() { Data = Id })) : null; |
||||||
|
public (EntityRef Relation, EntityRef Target)? AsPair() |
||||||
|
=> IsPair && (World.LookupAlive(Id.RelationUnsafe) is EntityRef relation) && |
||||||
|
(World.LookupAlive(Id.TargetUnsafe ) is EntityRef target ) |
||||||
|
? (relation, target) : null; |
||||||
|
|
||||||
|
public bool Equals(IdRef? other) => (other is not null) && (World == other.World) && (Id == other.Id); |
||||||
|
public override bool Equals(object? obj) => Equals(obj as IdRef); |
||||||
|
public override int GetHashCode() => HashCode.Combine(World, Id); |
||||||
|
public override string? ToString() => ecs_id_str(World, this).FlecsToStringAndFree()!; |
||||||
|
|
||||||
|
public static bool operator ==(IdRef? left, IdRef? right) => ReferenceEquals(left, right) || (left?.Equals(right) ?? false); |
||||||
|
public static bool operator !=(IdRef? left, IdRef? right) => !(left == right); |
||||||
|
|
||||||
|
public static implicit operator Id(IdRef i) => i.Id; |
||||||
|
public static implicit operator ecs_id_t(IdRef i) => i.Id.Value; |
||||||
|
} |
@ -1,55 +0,0 @@ |
|||||||
using System; |
|
||||||
using gaemstone.Utility; |
|
||||||
using static flecs_hub.flecs; |
|
||||||
|
|
||||||
namespace gaemstone.ECS; |
|
||||||
|
|
||||||
public unsafe class IdentifierRef |
|
||||||
: IEquatable<IdentifierRef> |
|
||||||
{ |
|
||||||
public World World { get; } |
|
||||||
public Identifier Id { get; } |
|
||||||
|
|
||||||
public IdentifierFlags Flags => Id.Flags; |
|
||||||
public bool IsPair => Id.IsPair; |
|
||||||
public bool IsWildcard => Id.IsWildcard; |
|
||||||
public bool IsValid => ecs_id_is_valid(World, this); |
|
||||||
|
|
||||||
public bool IsInUse => ecs_id_in_use(World, this); |
|
||||||
public int Count => ecs_count_id(World, this); |
|
||||||
|
|
||||||
public IdentifierRef(World world, Identifier id) |
|
||||||
{ World = world; Id = id; } |
|
||||||
|
|
||||||
public static IdentifierRef Combine(IdentifierFlags flags, IdentifierRef id) |
|
||||||
=> new(id.World, Identifier.Combine(flags, id)); |
|
||||||
|
|
||||||
public static IdentifierRef Pair(World world, Entity relation, Entity target) |
|
||||||
=> new(world, Identifier.Pair(relation, target)); |
|
||||||
public static IdentifierRef Pair(EntityRef relation, EntityRef target) |
|
||||||
=> Pair(relation.World, relation, target); |
|
||||||
public static IdentifierRef Pair(EntityRef relation, Entity target) |
|
||||||
=> Pair(relation.World, relation, target); |
|
||||||
public static IdentifierRef Pair(Entity relation, EntityRef target) |
|
||||||
=> Pair(target.World, relation, target); |
|
||||||
public static IdentifierRef Pair<TRelation>(EntityRef target) |
|
||||||
=> Pair(target.World.LookupByTypeOrThrow<TRelation>(), target); |
|
||||||
|
|
||||||
public EntityRef? AsEntity() |
|
||||||
=> (Flags == default) ? World.LookupAlive(new Entity(new() { Data = Id })) : null; |
|
||||||
public (EntityRef Relation, EntityRef Target)? AsPair() |
|
||||||
=> IsPair && (World.LookupAlive(Id.RelationUnsafe) is EntityRef relation) && |
|
||||||
(World.LookupAlive(Id.TargetUnsafe ) is EntityRef target ) |
|
||||||
? (relation, target) : null; |
|
||||||
|
|
||||||
public bool Equals(IdentifierRef? other) => (other is not null) && (World == other.World) && (Id == other.Id); |
|
||||||
public override bool Equals(object? obj) => Equals(obj as IdentifierRef); |
|
||||||
public override int GetHashCode() => HashCode.Combine(World, Id); |
|
||||||
public override string? ToString() => ecs_id_str(World, this).FlecsToStringAndFree()!; |
|
||||||
|
|
||||||
public static bool operator ==(IdentifierRef? left, IdentifierRef? right) => ReferenceEquals(left, right) || (left?.Equals(right) ?? false); |
|
||||||
public static bool operator !=(IdentifierRef? left, IdentifierRef? right) => !(left == right); |
|
||||||
|
|
||||||
public static implicit operator Identifier(IdentifierRef i) => i.Id; |
|
||||||
public static implicit operator ecs_id_t(IdentifierRef i) => i.Id.Value; |
|
||||||
} |
|
Loading…
Reference in new issue