(Written entirely by me, a human, 100% free of slop)
(Description copied from the README)
A library for running systems that access mutually exclusive entities in parallel with minimal boilerplate.
Example
Imagine a game with 3 kinds of entity, each of which has a position:
#[derive(Component)] struct Position { // -- SNIP -- } #[derive(Component)] #[require(Position)] struct Player; #[derive(Component)] #[require(Position)] struct Bat; #[derive(Component)] #[require(Position)] struct Ghost; And a different movement system for each entity,
the bat flies chaotically,
the ghost slowly phases through walls towards the player,
and the player is controlled by a human.
fn move_player(query: Query<&mut Position, With<Player>) { // -- SNIP -- } fn move_bat(query: Query<&mut Position, With<Bat>) { // -- SNIP -- } fn move_ghost(query: Query<&mut Position, With<Ghost>) { // -- SNIP -- } Depending on how you have bevy configured you will either get a error or warning about conflicting systems,
or the systems will not run in parallel,
To fix this issue you could add more conditions to each query
Query<&mut Position, (With<Player>, Without<Bat>, Without<Ghost>)> Query<&mut Position, (With<Bat>, Without<Player>, Without<Ghost>)> Query<&mut Position, (With<Ghost>, Without<Player>, Without<Bat>)> But that is very annoying to write, and requires updating every queries of every entity when a new entity is added.
With this library you can fix the issue without writing and updating long queries:
exclusive_category!(pub(crate) entity); add_category!(Player: entity); add_category!(Bat: entity); add_category!(Ghost: entity); Query<&mut Position, Exclusive!(Player: entity)> Query<&mut Position, Exclusive!(Bat: entity)> Query<&mut Position, Exclusive!(Ghost: entity)> Adding a new entity now requires only 1 extra line of boierplate,
and the filter is the same as the long With Without chain from before.
1 post - 1 participant