32 lines
1.1 KiB
32 lines
1.1 KiB
using System; |
|
using static flecs_hub.flecs; |
|
|
|
namespace gaemstone.ECS; |
|
|
|
public readonly struct Entity |
|
: IEquatable<Entity> |
|
{ |
|
public static readonly Entity None = default; |
|
|
|
public readonly ecs_entity_t Value; |
|
public uint Id => (uint)Value.Data; |
|
|
|
public bool IsSome => Value.Data != 0; |
|
public bool IsNone => Value.Data == 0; |
|
|
|
public Entity(ecs_entity_t value) => Value = value; |
|
|
|
public bool Equals(Entity other) => Value.Data == other.Value.Data; |
|
public override bool Equals(object? obj) => (obj is Entity other) && Equals(other); |
|
public override int GetHashCode() => Value.Data.GetHashCode(); |
|
public override string? ToString() |
|
=> IsSome ? $"Entity(0x{Value.Data.Data:X})" |
|
: "Entity.None"; |
|
|
|
public static bool operator ==(Entity left, Entity right) => left.Equals(right); |
|
public static bool operator !=(Entity left, Entity right) => !left.Equals(right); |
|
|
|
public static implicit operator ecs_entity_t(Entity e) => e.Value; |
|
public static implicit operator Identifier(Entity e) => new(e.Value.Data); |
|
public static implicit operator ecs_id_t(Entity e) => e.Value.Data; |
|
}
|
|
|