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.
27 lines
845 B
27 lines
845 B
using System.Collections; |
|
using System.Collections.Generic; |
|
using gaemstone.ECS.Utility; |
|
using static flecs_hub.flecs; |
|
|
|
namespace gaemstone.ECS; |
|
|
|
public unsafe readonly struct EntityType<TContext> |
|
: IReadOnlyList<Id<TContext>> |
|
{ |
|
public readonly World<TContext> World; |
|
public readonly ecs_type_t* Handle; |
|
|
|
public EntityType(World<TContext> world, ecs_type_t* handle) |
|
{ World = world; Handle = handle; } |
|
|
|
public override string ToString() |
|
=> ecs_type_str(World, Handle).FlecsToStringAndFree()!; |
|
|
|
// IReadOnlyList implementation |
|
public int Count => Handle->count; |
|
public Id<TContext> this[int index] |
|
=> Id<TContext>.GetUnsafe(World, new(Handle->array[index])); |
|
public IEnumerator<Id<TContext>> GetEnumerator() |
|
{ for (var i = 0; i < Count; i++) yield return this[i]; } |
|
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); |
|
}
|
|
|