Вход на сайт

Просмотр новости

Найдите то, что Вас интересует

I wrote a small library for exclusive component filtering in bevy

Дата публикации: 13-10-2026 18:56:47


(Written entirely by me, a human, 100% free of slop)


Codeberg.org



bevy_exclusive_components
bevy_exclusive_components






(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
Read full topic

Схожие новости

#Наименование новостиТональностьИнформативностьДата публикации
1Multi_bimap - many-to-many bimap freely made of two arbitrary maps013.116-10-2026
2Maplike - Crate with traits for abstract containers and operations on them2706-07-2026
3[Project] sol: A self-contained browser kernel written in Rust09.7618-10-2026
4I made a Vibe-Coded Reusable Application Runtime For Any Digital Domain (Office apps, Digital Painter, Graph nodes based apps..etc)017.8312-10-2026
5Multicalc: Scientific computing for real time embedded systems in no_std rust09.428-07-2026
6Multicalc: Scientific computing for real-time embedded systems in no_std Rust014.3610-08-2026
7Zaxis 0.0.5: immediate-mode GUI on wgpu, embeddable in a host's wgpu pass, with an real overlay layer for other processes010.211-10-2026
8My state lib PurrGress012.6213-08-2026
9Sping 1.5.5 — a cross-platform network diagnostics CLI written in Rust09.1910-10-2026
10BloomCraft: twelve Bloom filter variants under one API, looking for feedback5606-07-2026

Классификация: . Схожих патентов: 0. Схожих новостей: 10. Тональность: 0. Информативность: 14.93. Источник: users.rust-lang.org.