Arch.Extended
Arch.Extended copied to clipboard
Adding systems and components dynamicly?
How would I got about dynamically adding new systems and components to the main loop without needing to modify it?
Take this for example...
public static void Main(string[] args)
{
var deltaTime = 0.05f; // This is mostly given by engines, frameworks
// Create a world and a group of systems which will be controlled
var world = World.Create();
var _systems = new Group<float>(
new MovementSystem(world), // Run in order
new MyOtherSystem(...),
...
);
_systems.Initialize(); // Inits all registered systems
_systems.BeforeUpdate(in deltaTime); // Calls .BeforeUpdate on all systems ( can be overriden )
_systems.Update(in deltaTime); // Calls .Update on all systems ( can be overriden )
_systems.AfterUpdate(in deltaTime); // Calls .AfterUpdate on all System ( can be overriden )
_systems.Dispose(); // Calls .Dispose on all systems ( can be overriden )
}
Is there a way I can do something like this?
public static void Main(string[] args)
{
var world = World.Create();
world.Run();
}
public static partial class Plugins
{
[Plugin]
public void AddMovementSystem(World world)
{
world.AddSystem(Systems.MovementSystem);
}
}
or maybe something like this...
public static void Main(string[] args)
{
var world = World.Create();
world.Run();
}
public static partial class Systems
{
//SystemAttribute automatically adds it to the main world.
[System][Query][MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void MoveEntities([Data] in float time, ref Position position, ref Velocity velocity)
{
position.X += velocity.X * time;
position.Y += velocity.Y * time;
position.Z += velocity.Z * time;
}
}
Thats possible, but not build in yet. Could come in the future tho, for now you need to manage that yourself... or you write such a generator yourself ^^