Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Add more FromWorld implementations #3945

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions crates/bevy_ecs/src/query/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::{
archetype::{Archetype, ArchetypeComponentId, ArchetypeGeneration, ArchetypeId},
component::ComponentId,
entity::Entity,
prelude::FromWorld,
query::{
Access, Fetch, FetchState, FilterFetch, FilteredAccess, NopFetch, QueryCombinationIter,
QueryIter, WorldQuery,
Expand Down Expand Up @@ -32,6 +33,15 @@ where
pub(crate) filter_state: F::State,
}

impl<Q: WorldQuery, F: WorldQuery> FromWorld for QueryState<Q, F>
where
F::Fetch: FilterFetch,
{
fn from_world(world: &mut World) -> Self {
world.query_filtered()
}
}

impl<Q: WorldQuery, F: WorldQuery> QueryState<Q, F>
where
F::Fetch: FilterFetch,
Expand Down
7 changes: 7 additions & 0 deletions crates/bevy_ecs/src/system/function_system.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{
archetype::{Archetype, ArchetypeComponentId, ArchetypeGeneration, ArchetypeId},
component::ComponentId,
prelude::FromWorld,
query::{Access, FilteredAccessSet},
schedule::SystemLabel,
system::{
Expand Down Expand Up @@ -229,6 +230,12 @@ impl<Param: SystemParam> SystemState<Param> {
}
}

impl<Param: SystemParam> FromWorld for SystemState<Param> {
fn from_world(world: &mut World) -> Self {
Self::new(world)
}
}

/// Conversion trait to turn something into a [`System`].
///
/// Use this to get a system from a function. Also note that every system implements this trait as
Expand Down