Open Ralith opened 1 year ago
A straw implementation might place a CommandBuffer
in the query iterator that gets executed on drop.
One significant limitation is that such queries must take &mut World
, and hence cannot contain random access to unrelated entities.
Common patterns involve iterating over a query and adding, adding if absent, or removing a component from every entity. This presently requires a somewhat awkward and suboptimal dance where operations are buffered in a
CommandBuffer
or moral equivalent and executed in a separate pass after the query completes. We could extend the query machinery to support these patterns directly with query transformers that allow components to be directly written to or consumed from archetype storage, though considerable care will be required to soundly handle corner cases including incomplete iteration, leaked queries, and failure to insert all expected components.Design notes:
len
of each archetype when the query begins, and halting iteration at that point.~Drop
impl of an object that outlives the query lifetime. This will require a guard object, and is therefore incompatible with the existingquery_mut
/query_one_mut
API.Query
methods:QueryMut
and similar must carry borrows of the wholeWorld
so they can add new archetypes