|
|
@ -40,6 +40,7 @@ public unsafe class Iterator |
|
|
|
ecs_iter_fini(ptr); |
|
|
|
ecs_iter_fini(ptr); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public EntityRef GetVar(Variable var) |
|
|
|
public EntityRef GetVar(Variable var) |
|
|
|
{ |
|
|
|
{ |
|
|
|
fixed (ecs_iter_t* ptr = &Value) |
|
|
|
fixed (ecs_iter_t* ptr = &Value) |
|
|
@ -53,6 +54,7 @@ public unsafe class Iterator |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public bool Next() |
|
|
|
public bool Next() |
|
|
|
{ |
|
|
|
{ |
|
|
|
fixed (ecs_iter_t* ptr = &Value) { |
|
|
|
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) |
|
|
|
public IdRef FieldId(int index) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -77,6 +94,10 @@ public unsafe class Iterator |
|
|
|
return new(World, new(ecs_field_id(ptr, index))); |
|
|
|
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) |
|
|
|
public Span<T> Field<T>(int index) |
|
|
|
where T : unmanaged |
|
|
|
where T : unmanaged |
|
|
|
{ |
|
|
|
{ |
|
|
@ -88,27 +109,15 @@ public unsafe class Iterator |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Span<T> FieldOrEmpty<T>(int index) |
|
|
|
public SpanToRef<T> Field<T>(int index, T _ = null!) where T : class
|
|
|
|
where T : unmanaged => FieldIsSet(index) ? Field<T>(index) : default; |
|
|
|
=> new(Field<ReferenceHandle>(index)); |
|
|
|
|
|
|
|
|
|
|
|
public SpanToRef<T> FieldRef<T>(int index) |
|
|
|
public Span<T> FieldOrEmpty<T>(int index) where T : unmanaged |
|
|
|
where T : class => new(Field<ReferenceHandle>(index)); |
|
|
|
=> FieldIsSet(index) ? Field<T>(index) : Span<T>.Empty; |
|
|
|
|
|
|
|
|
|
|
|
public bool FieldIsSet(int index) |
|
|
|
public SpanToRef<T> FieldOrEmpty<T>(int index, T _ = null!) where T : class
|
|
|
|
{ |
|
|
|
=> FieldIsSet(index) ? Field(index, _) : SpanToRef<T>.Empty; |
|
|
|
fixed (ecs_iter_t* ptr = &Value) |
|
|
|
|
|
|
|
return ecs_field_is_set(ptr, index); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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() |
|
|
|
public override string ToString() |
|
|
|
{ |
|
|
|
{ |
|
|
@ -132,6 +141,7 @@ public unsafe class Iterator |
|
|
|
public readonly ref struct SpanToRef<T> |
|
|
|
public readonly ref struct SpanToRef<T> |
|
|
|
where T : class
|
|
|
|
where T : class
|
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
public static SpanToRef<T> Empty => default; |
|
|
|
private readonly Span<ReferenceHandle> _span; |
|
|
|
private readonly Span<ReferenceHandle> _span; |
|
|
|
public int Length => _span.Length; |
|
|
|
public int Length => _span.Length; |
|
|
|
public T? this[int index] => (T?)_span[index].Target; |
|
|
|
public T? this[int index] => (T?)_span[index].Target; |
|
|
|