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.
47 lines
1.1 KiB
47 lines
1.1 KiB
2 years ago
|
using System;
|
||
|
using gaemstone.Utility;
|
||
|
using static flecs_hub.flecs;
|
||
|
|
||
|
namespace gaemstone.ECS;
|
||
|
|
||
|
public unsafe sealed class Query
|
||
|
: IDisposable
|
||
|
{
|
||
|
public World World { get; }
|
||
|
public ecs_query_t* Handle { get; }
|
||
|
|
||
|
public Query(World world, QueryDesc desc)
|
||
|
{
|
||
|
using var alloc = TempAllocator.Use();
|
||
|
var flecsDesc = desc.ToFlecs(alloc);
|
||
|
World = world;
|
||
|
Handle = ecs_query_init(world, &flecsDesc);
|
||
|
}
|
||
|
|
||
|
public void Dispose()
|
||
|
=> ecs_query_fini(this);
|
||
|
|
||
|
public Iterator Iter()
|
||
|
=> new(World, IteratorType.Query, ecs_query_iter(World, 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;
|
||
|
}
|
||
|
}
|