|
|
|
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; }
|
|
|
|
|
|
|
|
// flecs built-ins that are important to internals.
|
|
|
|
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);
|
|
|
|
|
|
|
|
// Register built-in (static) modules, which
|
|
|
|
// are defined in the "gaemstone.Flecs" namespace.
|
|
|
|
Modules.RegisterAll(GetType().Assembly.GetTypes()
|
|
|
|
.Where(t => t.IsAbstract && t.IsSealed));
|
|
|
|
|
|
|
|
ChildOf = LookupOrThrow<Flecs.Core.ChildOf>();
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|