|
|
|
@ -40,6 +40,7 @@ public unsafe class Iterator |
|
|
|
|
ecs_iter_fini(ptr); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public EntityRef GetVar(Variable var) |
|
|
|
|
{ |
|
|
|
|
fixed (ecs_iter_t* ptr = &Value) |
|
|
|
@ -53,6 +54,7 @@ public unsafe class Iterator |
|
|
|
|
return this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public bool Next() |
|
|
|
|
{ |
|
|
|
|
fixed (ecs_iter_t* ptr = &Value) { |
|
|
|
@ -68,8 +70,23 @@ public unsafe class Iterator |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public EntityRef Entity(int index) |
|
|
|
|
=> new(World, new(Value.entities[index])); |
|
|
|
|
|
|
|
|
|
public bool FieldIsSet(int index) |
|
|
|
|
{ |
|
|
|
|
fixed (ecs_iter_t* ptr = &Value) |
|
|
|
|
return ecs_field_is_set(ptr, index); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public bool FieldIs(int index, Id id) |
|
|
|
|
{ |
|
|
|
|
fixed (ecs_iter_t* ptr = &Value) |
|
|
|
|
return ecs_field_id(ptr, index) == id.Value; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// TODO: Potentially misleading, doesn't check the field's backing data type. |
|
|
|
|
// The id might be "(Identifier, Name)", but its data type "Identifier". |
|
|
|
|
public bool FieldIs<T>(int index) |
|
|
|
|
=> FieldIs(index, World.LookupByType<T>()); |
|
|
|
|
|
|
|
|
|
public IdRef FieldId(int index) |
|
|
|
|
{ |
|
|
|
@ -77,6 +94,10 @@ public unsafe class Iterator |
|
|
|
|
return new(World, new(ecs_field_id(ptr, index))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public EntityRef Entity(int index) |
|
|
|
|
=> new(World, new(Value.entities[index])); |
|
|
|
|
|
|
|
|
|
public Span<T> Field<T>(int index) |
|
|
|
|
where T : unmanaged |
|
|
|
|
{ |
|
|
|
@ -88,27 +109,15 @@ public unsafe class Iterator |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Span<T> FieldOrEmpty<T>(int index) |
|
|
|
|
where T : unmanaged => FieldIsSet(index) ? Field<T>(index) : default; |
|
|
|
|
public SpanToRef<T> Field<T>(int index, T _ = null!) where T : class
|
|
|
|
|
=> new(Field<ReferenceHandle>(index)); |
|
|
|
|
|
|
|
|
|
public SpanToRef<T> FieldRef<T>(int index) |
|
|
|
|
where T : class => new(Field<ReferenceHandle>(index)); |
|
|
|
|
public Span<T> FieldOrEmpty<T>(int index) where T : unmanaged |
|
|
|
|
=> FieldIsSet(index) ? Field<T>(index) : Span<T>.Empty; |
|
|
|
|
|
|
|
|
|
public bool FieldIsSet(int index) |
|
|
|
|
{ |
|
|
|
|
fixed (ecs_iter_t* ptr = &Value) |
|
|
|
|
return ecs_field_is_set(ptr, index); |
|
|
|
|
} |
|
|
|
|
public SpanToRef<T> FieldOrEmpty<T>(int index, T _ = null!) where T : class
|
|
|
|
|
=> FieldIsSet(index) ? Field(index, _) : SpanToRef<T>.Empty; |
|
|
|
|
|
|
|
|
|
// TODO: Potentially misleading, doesn't check the field's backing data type. |
|
|
|
|
// The id might be "(Identifier, Name)", but its data type "Identifier". |
|
|
|
|
public bool FieldIs<T>(int index) |
|
|
|
|
=> FieldIs(index, World.LookupByType<T>()); |
|
|
|
|
public bool FieldIs(int index, Id id) |
|
|
|
|
{ |
|
|
|
|
fixed (ecs_iter_t* ptr = &Value) |
|
|
|
|
return ecs_field_id(ptr, index) == id.Value; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override string ToString() |
|
|
|
|
{ |
|
|
|
@ -132,6 +141,7 @@ public unsafe class Iterator |
|
|
|
|
public readonly ref struct SpanToRef<T> |
|
|
|
|
where T : class
|
|
|
|
|
{ |
|
|
|
|
public static SpanToRef<T> Empty => default; |
|
|
|
|
private readonly Span<ReferenceHandle> _span; |
|
|
|
|
public int Length => _span.Length; |
|
|
|
|
public T? this[int index] => (T?)_span[index].Target; |
|
|
|
|