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.
78 lines
3.1 KiB
78 lines
3.1 KiB
using System; |
|
using gaemstone.ECS.Internal; |
|
using static flecs_hub.flecs; |
|
|
|
namespace gaemstone.ECS; |
|
|
|
public unsafe struct World<TContext> |
|
: IEquatable<World<TContext>> |
|
, IDisposable |
|
{ |
|
public readonly World Value; |
|
|
|
public bool IsDeferred => Value.IsDeferred; |
|
public bool IsQuitRequested => Value.IsQuitRequested; |
|
|
|
public World(World value) |
|
=> Value = value; |
|
|
|
/// <summary> Initializes a new Flecs world. </summary> |
|
/// <param name="minimal"> If true, doesn't automatically import built-in modules. </param> |
|
public World(bool minimal = false) |
|
: this(new World(minimal)) { } |
|
|
|
public bool Progress(TimeSpan delta) => Value.Progress(delta); |
|
public void Quit() => Value.Quit(); |
|
public void Dispose() => Value.Dispose(); |
|
|
|
|
|
public EntityBuilder<TContext> New(EntityPath? path = null, Entity parent = default) |
|
=> new(this, parent, path); |
|
|
|
|
|
public Entity<TContext>? LookupAliveOrNull(Entity value) |
|
=> ECS.Entity<TContext>.GetOrNull(this, Value.LookupAlive(value)); |
|
public Entity<TContext> LookupAliveOrThrow(Entity value) |
|
=> LookupAliveOrNull(value) ?? throw new EntityNotFoundException( |
|
$"Entity '{value}' could not be found"); |
|
|
|
public Entity<TContext>? LookupPathOrNull(EntityPath path, Entity parent = default) |
|
=> ECS.Entity<TContext>.GetOrNull(this, Value.LookupPath(path, parent, false)); |
|
public Entity<TContext> LookupPathOrThrow(EntityPath path, Entity parent = default) |
|
=> ECS.Entity<TContext>.GetOrInvalid(this, Value.LookupPath(path, parent, true)); |
|
|
|
public Entity<TContext>? LookupSymbolOrNull(string symbol) |
|
=> ECS.Entity<TContext>.GetOrNull(this, Value.LookupSymbol(symbol)); |
|
public Entity<TContext> LookupSymbolOrThrow(string symbol) |
|
=> LookupSymbolOrNull(symbol) ?? throw new EntityNotFoundException( |
|
$"Entity with symbol '{symbol}' could not be found"); |
|
|
|
|
|
public Entity<TContext> Entity<T>() |
|
=> ECS.Entity<TContext>.GetOrThrow(this, |
|
Lookup<TContext>.Entity<T>.Value); |
|
|
|
public Id<TContext> Pair(Entity relation, Entity target) |
|
=> Id<TContext>.GetOrThrow(this, Id.Pair(relation, target)); |
|
public Id<TContext> Pair<TRelation>(Entity target) |
|
=> Pair(Entity<TRelation>(), target); |
|
public Id<TContext> Pair<TRelation, TTarget>() |
|
=> Pair(Entity<TRelation>(), Entity<TTarget>()); |
|
|
|
|
|
public Iterator<TContext> Term(Term term) => Iterator<TContext>.FromTerm(this, term); |
|
public Filter<TContext> Filter(FilterDesc desc) => new(this, desc); |
|
public Query<TContext> Query(QueryDesc desc) => new(this, desc); |
|
public Rule<TContext> Rule(FilterDesc desc) => new(this, desc); |
|
|
|
|
|
public bool Equals(World<TContext> other) => Value == other.Value; |
|
public override bool Equals(object? obj) => (obj is World<TContext> other) && Equals(other); |
|
public override int GetHashCode() => Value.GetHashCode(); |
|
|
|
public static bool operator ==(World<TContext> left, World<TContext> right) => left.Equals(right); |
|
public static bool operator !=(World<TContext> left, World<TContext> right) => !left.Equals(right); |
|
|
|
public static implicit operator World (World<TContext> world) => world.Value; |
|
public static implicit operator ecs_world_t*(World<TContext> world) => world.Value.Handle; |
|
}
|
|
|