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.
34 lines
1.1 KiB
34 lines
1.1 KiB
2 years ago
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using static flecs_hub.flecs;
|
||
|
|
||
|
namespace gaemstone.ECS;
|
||
|
|
||
|
public unsafe class Query
|
||
|
: IEnumerable<Iterator>
|
||
|
, IDisposable
|
||
|
{
|
||
|
public Universe Universe { get; }
|
||
|
public ecs_query_t* Handle { get; }
|
||
|
|
||
|
private Query(Universe universe, ecs_query_t* handle)
|
||
|
{ Universe = universe; Handle = handle; }
|
||
|
|
||
|
public Query(Universe universe, ecs_query_desc_t desc)
|
||
|
: this(universe, ecs_query_init(universe, &desc)) { }
|
||
|
public Query(Universe universe, ecs_filter_desc_t desc)
|
||
|
: this(universe, new ecs_query_desc_t { filter = desc }) { }
|
||
|
public Query(Universe universe, string expression)
|
||
|
: this(universe, new ecs_filter_desc_t { expr = expression }) { }
|
||
|
|
||
|
~Query() => Dispose();
|
||
|
public void Dispose() { ecs_query_fini(this); GC.SuppressFinalize(this); }
|
||
|
|
||
|
public Iterator Iter() => new(Universe, IteratorType.Query, ecs_query_iter(Universe, this));
|
||
|
public IEnumerator<Iterator> GetEnumerator() => Iter().GetEnumerator();
|
||
|
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||
|
|
||
|
public static implicit operator ecs_query_t*(Query q) => q.Handle;
|
||
|
}
|