"Arch" ECS - Update : Less boilerplate, systems and code generation. Check it out ! :)

A few weeks ago I developed a C# high performance ECS designed for game development and data oriented programming : Arch.

Recently it has received some new updates that reduce the boilerplate code and make it easier to use. For example queries now offer a chainable API :

var desc = new QueryDescription().WithAll<Position, Velocity>().WithAny<Player,Mob>().WithNone<Dead>()

Also a minimal example with monogame was added, which demonstrates some techniques and workflows.

Through Arch.Extended systems can now also be used and even generated through source generation ! :slight_smile: ( Theres also a sample for monogame ).

/// <summary>
/// The movement system makes the entities move and bounce properly. 
/// </summary>
public partial class MovementSystem : BaseSystem<World, GameTime>
{
    private readonly Rectangle _viewport;
    public MovementSystem(World world, Rectangle viewport) : base(world) { _viewport = viewport;}

    [Update]
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public void Move(ref Position pos, ref Velocity vel)
    {
        pos.Vector2 += Data.ElapsedGameTime.Milliseconds * vel.Vector2;
    }
    
    [Update]
    // [Any<...>, None<...>, All<...>] // Optional for query filtering
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public void Bounce(ref Position pos, ref Velocity vel)
    {
        if (pos.Vector2.X >= _viewport.X + _viewport.Width)
            vel.Vector2.X = -vel.Vector2.X;
            
        if (pos.Vector2.Y >= _viewport.Y + _viewport.Height)
            vel.Vector2.Y = -vel.Vector2.Y;
            
        if (pos.Vector2.X <= _viewport.X)
            vel.Vector2.X = -vel.Vector2.X;
            
        if (pos.Vector2.Y <= _viewport.Y)
            vel.Vector2.Y = -vel.Vector2.Y;
    }
}

Feel free to check it out, leave some feedback and a star ! :slight_smile:

1 Like