using System; using gaemstone.ECS.Utility; using static flecs_hub.flecs; namespace gaemstone.ECS; public unsafe partial class World { public ecs_world_t* Handle { get; } // Flecs built-ins that are important to internals. internal EntityRef ChildOf { get; } internal EntityRef Disabled { get; } internal EntityRef DependsOn { get; } public bool IsDeferred => ecs_is_deferred(this); public bool IsQuitRequested => ecs_should_quit(this); public World(params string[] args) { ecs_os_set_api_defaults(); var api = ecs_os_get_api(); api.abort_ = new FnPtr_Void { Pointer = &FlecsAbortException.Callback }; ecs_os_set_api(&api); Handle = ecs_init_w_args(args.Length, null); ChildOf = LookupByPathOrThrow("/flecs/core/ChildOf"); Disabled = LookupByPathOrThrow("/flecs/core/Disabled"); DependsOn = LookupByPathOrThrow("/flecs/core/DependsOn"); } public void Dispose() => ecs_fini(this); public EntityBuilder New(EntityPath? path = null) => new(this, path); public EntityBuilder New(EntityRef? parent, EntityPath? path = null) { var entity = New(path); // If given path is absolute, the new entity won't be created as a // child of the specified parent. Alternatively, EntityRef.NewChild // can be used, which will throw when an absolute path is given. if ((path?.IsRelative != false) && (parent != null)) entity.ChildOf(parent); return entity; } public bool Progress(TimeSpan delta) => ecs_progress(this, (float)delta.TotalSeconds); public void Quit() => ecs_quit(this); public static implicit operator ecs_world_t*(World w) => w.Handle; }