Add RegisterAll and RegisterAllFrom methods

They are helper methods that register
multiple modules at once, the latter
registering all modules from an Assembly.
wip/source-generators
copygirl 2 years ago
parent 9e55bffac8
commit 9683582d28
  1. 9
      src/gaemstone/ECS/Universe+Modules.cs
  2. 18
      src/gaemstone/ECS/Universe.cs

@ -17,6 +17,15 @@ public class ModuleManager
internal ModuleInfo? Lookup(Entity entity)
=> _modules.GetValueOrDefault(entity);
public void RegisterAllFrom(System.Reflection.Assembly assembly)
=> RegisterAll(assembly.GetTypes());
public void RegisterAll(IEnumerable<Type> types)
{
foreach (var type in types)
if (type.Has<ModuleAttribute>())
Register(type);
}
public EntityRef Register<T>()
where T : class => Register(typeof(T));
public EntityRef Register(Type type)

@ -1,4 +1,5 @@
using System;
using System.Linq;
using static flecs_hub.flecs;
namespace gaemstone.ECS;
@ -15,17 +16,20 @@ public unsafe partial class Universe
public Universe(params string[] args)
{
Handle = ecs_init_w_args(args.Length, null);
Handle = ecs_init_w_args(args.Length, null);
Modules = new(this);
Modules.Register(typeof(Flecs.Core));
Modules.Register(typeof(Flecs.Pipeline));
Modules.Register(typeof(Flecs.ObserverEvent));
Modules.Register(typeof(Flecs.SystemPhase));
// 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>();
New("Game").Symbol("Game").Build().CreateLookup<Game>().Add<Game>();
// Create "Game" singleton entity, which
// stores global state, configuration, ...
New("Game").Symbol("Game").Build()
.CreateLookup<Game>().Add<Game>();
}
public EntityBuilder New(EntityPath? path = null)

Loading…
Cancel
Save