Skip to content

Foreach IEnumerable iterator#30

Open
CanYouCatchMe01 wants to merge 5 commits intoPeteyChan:masterfrom
CanYouCatchMe01:foreach-iterator
Open

Foreach IEnumerable iterator#30
CanYouCatchMe01 wants to merge 5 commits intoPeteyChan:masterfrom
CanYouCatchMe01:foreach-iterator

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