Arch.Extended icon indicating copy to clipboard operation
Arch.Extended copied to clipboard

Adding systems and components dynamicly?

Open Shadowblitz16 opened this issue 1 year ago • 1 comments

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;
    }
}

Shadowblitz16 avatar Oct 11 '24 21:10 Shadowblitz16

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 ^^

genaray avatar Oct 23 '24 19:10 genaray