You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.2 KiB
37 lines
1.2 KiB
1 year ago
|
using System;
|
||
|
using static flecs_hub.flecs;
|
||
|
|
||
|
namespace gaemstone.ECS;
|
||
|
|
||
|
public readonly struct Id
|
||
|
: IEquatable<Id>
|
||
|
{
|
||
|
public readonly ecs_id_t Value;
|
||
|
public IdFlags Flags => (IdFlags)(Value & ECS_ID_FLAGS_MASK);
|
||
|
|
||
|
public bool IsPair => ecs_id_is_pair(this);
|
||
|
public bool IsWildcard => ecs_id_is_wildcard(this);
|
||
|
|
||
|
public Entity RelationUnsafe => new(new() { Data = (Value & ECS_COMPONENT_MASK) >> 32 });
|
||
|
public Entity TargetUnsafe => new(new() { Data = Value & ECS_ENTITY_MASK });
|
||
|
|
||
|
public Id(ecs_id_t value) => Value = value;
|
||
|
|
||
|
public static Id Pair(Entity relation, Entity target)
|
||
|
=> new(ecs_make_pair(relation, target));
|
||
|
|
||
|
public bool Equals(Id other) => Value.Data == other.Value.Data;
|
||
|
public override bool Equals(object? obj) => (obj is Id other) && Equals(other);
|
||
|
public override int GetHashCode() => Value.Data.GetHashCode();
|
||
|
public override string? ToString()
|
||
|
=> (Flags != default) ? $"Id({Value.Data}, Flags={Flags})"
|
||
|
: $"Id({Value.Data})";
|
||
|
|
||
|
public static bool operator ==(Id left, Id right) => left.Equals(right);
|
||
|
public static bool operator !=(Id left, Id right) => !left.Equals(right);
|
||
|
|
||
|
public static implicit operator ecs_id_t(Id id) => id.Value;
|
||
|
|
||
|
public static implicit operator Term(Id id) => new(id);
|
||
|
}
|