softwareantics / FinalEngine

This repository is a WIP cross-platform Game Engine developed in C#.
Apache License 2.0
69 stars 5 forks source link

Sequencing for ECS Framework #299

Closed softwareantics closed 11 months ago

softwareantics commented 11 months ago

This should likely be added to the ECS project.

public interface IStep
{
    void Next(Enum condition);
}

public interface ISequencer
{
    void AddStep(IStep step);   
    void RemoveStep(IStep step);
    void Execute(Enum condition);
}

// Use
public class MeshRenderSystem : EntitySystemBase, IStep
{
    protected override void Process([NotNull] IEnumerable<Entity> entities)
    {
        foreach (var entity in entities)
        {
            renderingEngine.DrawMesh(entity);
        }
    }

    public void Next()
    {
        this.Process();
    }
}

public class LightRenderSystem : EntitySystemBase
{
    protected override void Process([NotNull] IEnumerable<Entity> entities)
    {
        foreach (var entity in entities)
        {
            shaderProgram.Bind();
            shaderProgram.SetUniforms(entity.GetComponent<LightComponent>());

            // Render all geometry
            this.sequencer.Next();
        }
    }
}

var sequencer = new Sequencer()
    .AddStep(new Step()
    {
        new { typeof(LightRenderSystem) },
        new { meshRenderSystem }
    });
softwareantics commented 11 months ago