Skip to content
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

[RFC] Iterator/pseudo-container library #2

Open
1 of 6 tasks
Ph4ntomas opened this issue Sep 18, 2021 · 0 comments
Open
1 of 6 tasks

[RFC] Iterator/pseudo-container library #2

Ph4ntomas opened this issue Sep 18, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@Ph4ntomas
Copy link
Owner

Ph4ntomas commented Sep 18, 2021

Iterator/pseudo-container Library

Summary

A small iterator library. Mostly wrapper around concrete iterators to be able to skip some component based on certain conditions, or to iterate over several components at the same time (e.g. zip)

Motivation

Whenever a system needs to iterate over it's list of components, it has to iterate over each arrays of components manually. However, some system may need to iterate over several components at the same time, then check that some precondition holds true before doing any work (e.g. check that the entity has several components at the same time, or that at least one of these component is present).

State of the art

N/A

Drawbacks

I can't see why ATM. Some benchmarks might be needed.

Rationale and alternatives

N/A

Minimal implementation

  • A zip pseudo container, to allow iterating over several sparse arrays at once.
  • A pseudo container that check that the entity contains all component
  • A pseudo container that check that the entity contains exactly one of the components
  • A pseudo container that check that the entity contains at least one of the components
  • A pseudo container that check that the entity does not contains one or several components
  • Some way to express some basic logic to build a pseudo container that does a mix of the above.

Code example

void system(registry &r) {
    zipper z = {r.get<Cmp1>(), r.get<Cmp2>())
    
    //ranged-based for
    for (auto &[c1, c2] : z) {
        [...]
    }
    
    //std::algorithm
    for_each(z.begin(), z.end(), [](component_t<Cmp1> &c1, component_t<Cmp2> &c2)
}
@Ph4ntomas Ph4ntomas added the enhancement New feature or request label Sep 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant