|
|
|
using System;
|
|
|
|
using System.Linq;
|
|
|
|
using static flecs_hub.flecs;
|
|
|
|
|
|
|
|
namespace gaemstone.ECS;
|
|
|
|
|
|
|
|
public unsafe partial class Universe
|
|
|
|
{
|
|
|
|
public ecs_world_t* Handle { get; }
|
|
|
|
public ModuleManager Modules { get; }
|
|
|
|
|
|
|
|
public EntityRef Wildcard { get; }
|
|
|
|
public EntityRef Any { get; }
|
|
|
|
public EntityRef ChildOf { get; }
|
|
|
|
|
|
|
|
public bool IsDeferred => ecs_is_deferred(this);
|
|
|
|
|
|
|
|
public Universe(params string[] args)
|
|
|
|
{
|
|
|
|
Handle = ecs_init_w_args(args.Length, null);
|
|
|
|
Modules = new(this);
|
|
|
|
|
|
|
|
// Bootstrap flecs built-ins that are important to internals.
|
|
|
|
Wildcard = LookupOrThrow("/flecs/core/*");
|
|
|
|
Any = LookupOrThrow("/flecs/core/_");
|
|
|
|
ChildOf = LookupOrThrow("/flecs/core/ChildOf");
|
|
|
|
|
|
|
|
// Bootstrap custom "Relation" tag.
|
|
|
|
// This will be retrofitted to certain flecs built-ins.
|
|
|
|
New("/gaemstone/Relation")
|
|
|
|
.Add(LookupOrThrow("/flecs/core/Tag"))
|
|
|
|
.Build().CreateLookup<Relation>();
|
|
|
|
|
|
|
|
// Register built-in (static) modules, which
|
|
|
|
// are defined in the "gaemstone.Flecs" namespace.
|
|
|
|
Modules.RegisterAll(GetType().Assembly.GetTypes()
|
|
|
|
.Where(t => t.IsAbstract && t.IsSealed));
|
|
|
|
|
|
|
|
// Create "Game" entity to store global state.
|
|
|
|
New("/Game").Symbol("Game").Build()
|
|
|
|
.CreateLookup<Game>().Add<Game>();
|
|
|
|
}
|
|
|
|
|
|
|
|
public EntityBuilder New(EntityPath? path = null)
|
|
|
|
=> new(this, path);
|
|
|
|
|
|
|
|
public bool Progress(TimeSpan delta)
|
|
|
|
=> ecs_progress(this, (float)delta.TotalSeconds);
|
|
|
|
|
|
|
|
public static implicit operator ecs_world_t*(Universe w) => w.Handle;
|
|
|
|
}
|