mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 20:53:53 +00:00
Add more FromWorld implementations (#3945)
# Objective Make `FromWorld` more useful for abstractions with a form similar to ```rs trait FancyAbstraction { type PreInitializedData: FromWorld; } ``` ## Solution Add a `FromWorld` implementation for `SystemState` as well as a way to group together multiple `FromWorld` implementing types as one. Note: I plan to follow up this PR with another to add `Local` support to exclusive systems, which should get a fair amount of use from the `FromWorld` implementation on `SystemState`.
This commit is contained in:
parent
ea6e6f7db2
commit
73edb11db6
2 changed files with 17 additions and 0 deletions
|
@ -2,6 +2,7 @@ use crate::{
|
||||||
archetype::{Archetype, ArchetypeComponentId, ArchetypeGeneration, ArchetypeId},
|
archetype::{Archetype, ArchetypeComponentId, ArchetypeGeneration, ArchetypeId},
|
||||||
component::ComponentId,
|
component::ComponentId,
|
||||||
entity::Entity,
|
entity::Entity,
|
||||||
|
prelude::FromWorld,
|
||||||
query::{
|
query::{
|
||||||
Access, Fetch, FetchState, FilterFetch, FilteredAccess, NopFetch, QueryCombinationIter,
|
Access, Fetch, FetchState, FilterFetch, FilteredAccess, NopFetch, QueryCombinationIter,
|
||||||
QueryIter, WorldQuery,
|
QueryIter, WorldQuery,
|
||||||
|
@ -32,6 +33,15 @@ where
|
||||||
pub(crate) filter_state: F::State,
|
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>
|
impl<Q: WorldQuery, F: WorldQuery> QueryState<Q, F>
|
||||||
where
|
where
|
||||||
F::Fetch: FilterFetch,
|
F::Fetch: FilterFetch,
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
archetype::{Archetype, ArchetypeComponentId, ArchetypeGeneration, ArchetypeId},
|
archetype::{Archetype, ArchetypeComponentId, ArchetypeGeneration, ArchetypeId},
|
||||||
component::ComponentId,
|
component::ComponentId,
|
||||||
|
prelude::FromWorld,
|
||||||
query::{Access, FilteredAccessSet},
|
query::{Access, FilteredAccessSet},
|
||||||
schedule::SystemLabel,
|
schedule::SystemLabel,
|
||||||
system::{
|
system::{
|
||||||
|
@ -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`].
|
/// 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
|
/// Use this to get a system from a function. Also note that every system implements this trait as
|
||||||
|
|
Loading…
Reference in a new issue