Operator for modifying the world while iterating
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 1.4k
- Forks
- 107
- Avg merge
- 2h
- Merged PRs (30d)
- 6
Description
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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no files or tests; start by tracing the existing query-iteration and world-mutation interfaces, then compare them with the proposed modify signature and Vec::retain approach. Done would require a settled design and an implementation that safely supports inserting, removing, spawning, and despawning during iteration without invalidating traversal.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- game-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100