Skip to content

[RFC] Iterator/pseudo-container library #2

@Ph4ntomas

Description

@Ph4ntomas

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)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions