Skip to content

Foreach IEnumerable iterator #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

CanYouCatchMe01
Copy link

I like your ECS library, it is very easy to get started with. While developing, I missed making a standard C# foreach so I could use continue and break when iteration over the objects.

Now it is possible to type this:

foreach ((var entity, A aa, B bb, C cc, D dd) in query.Foreach<A, B, C, D>())
{
    if (aa.x > 0)
    {
        continue;
    }

    if (bb.x > 0)
    {
        break;
    }

    Console.WriteLine($"value x is {aa.x} value y is {aa.y}");
}

I created multiple IEnumerable functions that can take up to 12 components.

public IEnumerable<Tuple<Entity, C1, C2, C3, C4>> Foreach<C1, C2, C3, C4>()
{
    // ...
}

I got inspired by how ENTT makes their view() by returning a tuple.

for(auto [entity, pos, vel]: view.each()) {
    // ...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant