Allow access to `Commands` at the same time as iterating over one (or more) queries
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 171
Description
## What problem does this solve or what need does it fill?
Allow access to `Commands` and queries at the same it. This allows iterating over a (read-only) query and enqueue some mutations into the command queue based on those.
## What solution would you like?
- The simplest is `World::query_and_commands()` mirroring the existing `World::entites_and_commands()`, although this only works for a single query.
- Possibly something better that works on multiple queries, not sure what/how...
- Make `World::commands()` take a non-`mut` self so that we can just use the rest of the `World` API including queries and fetching entities while also getting `Commands` access, which would solve this issue and obsolete `entites_and_commands()` and the same time.
## What alternative(s) have you considered?
Query and `.collect()` which wastes memory and performance.
## Additional context
Asked on `#ecs-dev` looks like [at least the `query_and_commands()` is possible](https://discord.com/channels/691052431525675048/749335865876021248/1409585431158329415). Not sure about the others, I don't have a good understanding why `World::commands()` takes `&mut self` in the first place, since conceptually a command is precisely to _defer mutations_ to the world, so why does it needs mutable access?
Contributor guide
Research direction
Start by reading the World::commands() and World::entities_and_commands() entry points, then compare them with the query APIs. Determine how read-only query iteration can coexist with queued Commands, including the multiple-query case. Done means the supported API allows this usage without collecting query results first.
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
- 35/100