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.
 
 

46 lines
1.1 KiB

using System;
using gaemstone.Utility;
using static flecs_hub.flecs;
namespace gaemstone.ECS;
public unsafe sealed class Query
: IDisposable
{
public Universe Universe { get; }
public ecs_query_t* Handle { get; }
public Query(Universe universe, QueryDesc desc)
{
using var alloc = TempAllocator.Use();
var flecsDesc = desc.ToFlecs(alloc);
Universe = universe;
Handle = ecs_query_init(universe, &flecsDesc);
}
public void Dispose()
=> ecs_query_fini(this);
public Iterator Iter()
=> new(Universe, IteratorType.Query, ecs_query_iter(Universe, this));
public override string ToString()
=> ecs_query_str(Handle).FlecsToStringAndFree()!;
public static implicit operator ecs_query_t*(Query q) => q.Handle;
}
public class QueryDesc : FilterDesc
{
public QueryDesc(string expression) : base(expression) { }
public QueryDesc(params Term[] terms) : base(terms) { }
public new unsafe ecs_query_desc_t ToFlecs(IAllocator allocator)
{
var desc = new ecs_query_desc_t {
filter = base.ToFlecs(allocator),
// TODO: Implement more Query features.
};
return desc;
}
}