BeanCheeseBurrito / Flecs.NET

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

.Each()/.Iter()/.Run() should return the query object #47

Open BeanCheeseBurrito opened 3 weeks ago

BeanCheeseBurrito commented 3 weeks ago

Sometimes a user may want to create a single-use query and dispose of it immediately. .Each()/.Iter()/.Run() should be updated to return the query being iterated to make disposing of one-off queries easier.

Currently the recommended pattern to create a single-use query looks like this.

using Query<Position> query = world.Query<Position>();

query.Each((ref Position p) =>
{
    p.X++;
    p.Y++;
});

It is nicer to be able to do something like this.

using Query<Position> query = world.Query<Position>()
    .Each((ref Position p) =>
    {
        p.X++;
        p.Y++;
    });