add SystemIdMarker Component to enable filtering for SystemId Entitys (#14584)

# Objective

Enables writing queries like `Query<Entity, With<SystemIdMarker>>` to
filter `Entity`s that are, or are not (with `Without`), `SystemId`s.

## Solution

Simple unit struct `SystemIdMarker` added during
`World::register_boxed_system`; `World::remove_system` already despawns
the entity, removing the marker.

## Testing

No tests, but happy to write some with direction.

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
This commit is contained in:
databasedav 2024-08-12 09:11:06 -07:00 committed by GitHub
parent 4ace888e4b
commit c8d30edf1a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -12,6 +12,10 @@ struct RegisteredSystem<I, O> {
system: BoxedSystem<I, O>, system: BoxedSystem<I, O>,
} }
/// Marker [`Component`](bevy_ecs::component::Component) for identifying [`SystemId`] [`Entity`]s.
#[derive(Component)]
pub struct SystemIdMarker;
/// A system that has been removed from the registry. /// A system that has been removed from the registry.
/// It contains the system and whether or not it has been initialized. /// It contains the system and whether or not it has been initialized.
/// ///
@ -125,10 +129,13 @@ impl World {
) -> SystemId<I, O> { ) -> SystemId<I, O> {
SystemId { SystemId {
entity: self entity: self
.spawn(RegisteredSystem { .spawn((
initialized: false, RegisteredSystem {
system, initialized: false,
}) system,
},
SystemIdMarker,
))
.id(), .id(),
marker: std::marker::PhantomData, marker: std::marker::PhantomData,
} }