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.
36 lines
1.0 KiB
36 lines
1.0 KiB
2 years ago
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using static flecs_hub.flecs;
|
||
|
|
||
|
namespace gaemstone.ECS;
|
||
|
|
||
|
public unsafe sealed class Rule
|
||
|
: IEnumerable<Iterator>
|
||
|
, IDisposable
|
||
|
{
|
||
|
public Universe Universe { get; }
|
||
|
public ecs_rule_t* Handle { get; }
|
||
|
|
||
|
private Rule(Universe universe, ecs_rule_t* handle)
|
||
|
{ Universe = universe; Handle = handle; }
|
||
|
private Rule(Universe universe, ecs_filter_desc_t desc)
|
||
|
: this(universe, ecs_rule_init(universe, &desc)) { }
|
||
|
|
||
|
public Rule(Universe universe, FilterDesc desc)
|
||
|
: this(universe, desc.ToFlecs()) { }
|
||
|
|
||
|
public void Dispose()
|
||
|
=> ecs_rule_fini(this);
|
||
|
|
||
|
public override string ToString()
|
||
|
=> ecs_rule_str(Handle).FlecsToStringAndFree()!;
|
||
|
|
||
|
public static implicit operator ecs_rule_t*(Rule q) => q.Handle;
|
||
|
|
||
|
// IEnumerable implementation
|
||
|
public Iterator Iter() => new(Universe, IteratorType.Rule, ecs_rule_iter(Universe, this));
|
||
|
public IEnumerator<Iterator> GetEnumerator() => Iter().GetEnumerator();
|
||
|
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||
|
}
|