BeanCheeseBurrito / Flecs.NET

A C# wrapper for flecs
MIT License
145 stars 18 forks source link

Rewrite query builders to match C++ API #19

Closed BeanCheeseBurrito closed 10 months ago

BeanCheeseBurrito commented 10 months ago

This PR rewrites the query APIs to more closely match their C++ counterparts. These changes will reduce boilerplate and improve code readability of user code.

Before:

world.Routine(
    name: "MoveSystem",
    filter: world.FilterBuilder<Position, Velocity, Gravity>()
        .TermAt(1).Second<Local>()
        .TermAt(3).Singleton(),
    query: world.QueryBuilder()
        .OrderBy(...)
        .GroupBy(...),
    routine: world.RoutineBuilder()
        .Kind(Ecs.OnUpdate)
        .MultiThreaded(),
    callback: (ref Position p, ref Velocity v, ref Gravity) => { }
);

After:

world.Routine<Position, Velocity, Gravity>("MoveSystem")
    .TermAt(1).Second<Local>()
    .TermAt(3).Singleton()
    .OrderBy(...)
    .GroupBy(...)
    .Kind(Ecs.OnUpdate)
    .MultiThreaded()
    .Each((ref Position p, ref Velocity v, ref Gravity) => { });