Skip to content

IEnumerable iterators for queries #87

@BeanCheeseBurrito

Description

@BeanCheeseBurrito

Implementing the IEnumerable interface for queries will allow them to be used iterated with foreach loops. This way of iterating is preferred when you need to capture variables outside of the loop as this way doesn't require a closure allocation.

Query<Position, Velocity> query;

float multiplier = 10; // Random variable in outer scope

foreach ((Iter it, Span<Position> p, Span<Velocity> v) in query)
{
    foreach (int i in it)
    {
        p[i].X += v[i].Y * multiplier;
        p[i].Y += v[i].Y * multiplier;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions