Skip to content

Operator for modifying the world while iterating #19

@Ralith

Description

@Ralith

Sometimes it's useful to allow components to be inserted/removed and entities to be spawned/despawned in the course of iteration. This is impossible using a conventional interface, but could be achieved with a sufficiently clever interface in the style of Vec::retain. For example:

fn modify<Q: Query, T>(
    &mut self,
    process: impl for<'a> FnMut(<Q::Fetch as Fetch<'a>>::Item) -> T,
    apply: impl FnMut(&mut ModifiableWorld, Entity, T),
)

where the two functions are called, one after the other, for each entity matching Q, and ModifiableWorld is a proxy object that adjusts the iteration state to account for entities being added/removed from the archetype currently being iterated.

The implementation is likely to be a source of significant complexity, and it does not enable anything you can't already do by making two passes and storing intermediate data in a Vec. That said, it would be neat.

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