Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding systems and components dynamicly? #80

Open
Shadowblitz16 opened this issue Oct 11, 2024 · 1 comment
Open

Adding systems and components dynamicly? #80

Shadowblitz16 opened this issue Oct 11, 2024 · 1 comment
Labels
enhancement New feature or request question Further information is requested

Comments

@Shadowblitz16
Copy link

Shadowblitz16 commented Oct 11, 2024

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 Shadowblitz16 changed the title Adding systems and components through plugin system? Adding systems and components dynamicly? Oct 11, 2024
@genaray genaray added enhancement New feature or request question Further information is requested labels Oct 23, 2024
@genaray
Copy link
Owner

genaray commented Oct 23, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants