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.
54 lines
1.6 KiB
54 lines
1.6 KiB
2 years ago
|
using System;
|
||
|
using static flecs_hub.flecs;
|
||
|
|
||
|
namespace gaemstone.ECS;
|
||
|
|
||
|
public unsafe readonly struct Identifier
|
||
|
{
|
||
|
public Universe Universe { get; }
|
||
|
public ecs_id_t Value { get; }
|
||
|
|
||
|
public bool IsPair => ecs_id_is_pair(Value);
|
||
|
public IdentifierFlags Flags => (IdentifierFlags)(Value.Data & ECS_ID_FLAGS_MASK);
|
||
|
|
||
|
public Identifier(Universe universe, ecs_id_t value)
|
||
|
{ Universe = universe; Value = value; }
|
||
|
|
||
|
public static Identifier Pair(Entity first, Entity second)
|
||
|
=> new(first.Universe, Universe.ECS_PAIR | ((first.Value.Data << 32) + (uint)second.Value.Data));
|
||
|
public static Identifier Pair(ecs_entity_t first, Entity second)
|
||
|
=> new(second.Universe, Universe.ECS_PAIR | ((first.Data << 32) + (uint)second.Value.Data));
|
||
|
|
||
|
public (Entity, Entity) AsPair()
|
||
|
=> (Universe.Lookup((ecs_id_t)((Value & ECS_COMPONENT_MASK) >> 32)),
|
||
|
Universe.Lookup((ecs_id_t)(Value & ECS_ENTITY_MASK)));
|
||
|
|
||
|
// public Entity AsComponent()
|
||
|
// {
|
||
|
// var value = Value.Data & ECS_COMPONENT_MASK;
|
||
|
// return new Entity(Universe, new() { Data = value });
|
||
|
// }
|
||
|
|
||
|
public override string ToString()
|
||
|
=> ecs_id_str(Universe, Value).ToStringAndFree();
|
||
|
|
||
|
|
||
|
public static implicit operator ecs_id_t(Identifier e) => e.Value;
|
||
|
|
||
|
public static Identifier operator |(ecs_id_t left, Identifier right)
|
||
|
=> new(right.Universe, left | right.Value);
|
||
|
public static Identifier operator |(Identifier left, Identifier right)
|
||
|
=> new(left.Universe, left.Value | right.Value);
|
||
|
}
|
||
|
|
||
|
[Flags]
|
||
|
public enum IdentifierFlags : ulong
|
||
|
{
|
||
|
Pair = 1ul << 63,
|
||
|
Override = 1ul << 62,
|
||
|
Toggle = 1ul << 61,
|
||
|
Or = 1ul << 60,
|
||
|
And = 1ul << 59,
|
||
|
Not = 1ul << 58,
|
||
|
}
|