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